70 lines
2.1 KiB
C#
70 lines
2.1 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
public class X11CursorHider
|
|
{
|
|
const string X11Lib = "libX11.so";
|
|
|
|
[DllImport(X11Lib)]
|
|
static extern IntPtr XOpenDisplay(IntPtr display);
|
|
|
|
[DllImport(X11Lib)]
|
|
static extern int XCloseDisplay(IntPtr display);
|
|
|
|
[DllImport(X11Lib)]
|
|
static extern IntPtr XCreatePixmap(IntPtr display, IntPtr drawable, uint width, uint height, uint depth);
|
|
|
|
[DllImport(X11Lib)]
|
|
static extern IntPtr XCreateBitmapFromData(IntPtr display, IntPtr drawable, byte[] data, uint width, uint height);
|
|
|
|
[DllImport(X11Lib)]
|
|
static extern IntPtr XCreatePixmapCursor(IntPtr display, IntPtr source, IntPtr mask, ref XColor foreground, ref XColor background, uint x, uint y);
|
|
|
|
[DllImport(X11Lib)]
|
|
static extern int XDefineCursor(IntPtr display, IntPtr window, IntPtr cursor);
|
|
|
|
[DllImport(X11Lib)]
|
|
static extern int XFreeCursor(IntPtr display, IntPtr cursor);
|
|
|
|
[DllImport(X11Lib)]
|
|
static extern int XFlush(IntPtr display);
|
|
|
|
[DllImport(X11Lib)]
|
|
static extern IntPtr XDefaultRootWindow(IntPtr display);
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
struct XColor
|
|
{
|
|
public ulong pixel;
|
|
public ushort red, green, blue;
|
|
public byte flags;
|
|
public byte pad;
|
|
}
|
|
|
|
public static void HideCursor()
|
|
{
|
|
IntPtr display = XOpenDisplay(IntPtr.Zero);
|
|
if (display == IntPtr.Zero)
|
|
{
|
|
Console.WriteLine("Cannot open X display");
|
|
return;
|
|
}
|
|
|
|
IntPtr root = XDefaultRootWindow(display);
|
|
|
|
byte[] emptyData = new byte[1] { 0 }; // 1x1 empty bitmap
|
|
IntPtr pixmap = XCreateBitmapFromData(display, root, emptyData, 1, 1);
|
|
|
|
XColor dummy = new XColor();
|
|
|
|
IntPtr invisibleCursor = XCreatePixmapCursor(display, pixmap, pixmap, ref dummy, ref dummy, 0, 0);
|
|
|
|
XDefineCursor(display, root, invisibleCursor);
|
|
XFlush(display);
|
|
|
|
// Keep the cursor hidden until app closes, remember to call:
|
|
// XFreeCursor(display, invisibleCursor);
|
|
// XCloseDisplay(display);
|
|
}
|
|
}
|