Beispiel #1
0
        public static Tuple<int, int> GetCursorPosition(int win)
        {
            IntPtr r = IntPtr.Zero, c = IntPtr.Zero;
            int rx = -1, ry = -1, wx = -1, wy = -1;
            uint m = 0;

            using(var l = new XLibLocker(DisplayHandle))
            {
                XQueryPointer(DisplayHandle, win, ref r, ref c, ref rx, ref ry, ref wx, ref wy, ref m);
            }
            return Tuple.Create(rx, ry);
        }
Beispiel #2
0
        public static Tuple <int, int> GetCursorPosition(int win)
        {
            IntPtr r = IntPtr.Zero, c = IntPtr.Zero;
            int    rx = -1, ry = -1, wx = -1, wy = -1;
            uint   m = 0;

            using (var l = new XLibLocker(DisplayHandle))
            {
                XQueryPointer(DisplayHandle, win, ref r, ref c, ref rx, ref ry, ref wx, ref wy, ref m);
            }
            return(Tuple.Create(rx, ry));
        }
Beispiel #3
0
        public static void RestoreCursor(int windowId)
        {
            lock (locker)
            {
                using (var l = new XLibLocker(DisplayHandle))
                {
                    XUndefineCursor(DisplayHandle, windowId);
                }

                XCloseDisplay(DisplayHandle);
                DisplayHandle = XOpenDisplay(IntPtr.Zero);
            }
        }
Beispiel #4
0
        public static void MakeCursorTransparent(int windowId)
        {
            lock (locker)
            {
                using (var l = new XLibLocker(DisplayHandle))
                {
                    XDefineCursor(DisplayHandle, windowId, DefineEmptyCursor(windowId));
                }

                XCloseDisplay(DisplayHandle);
                DisplayHandle = XOpenDisplay(IntPtr.Zero);
            }
        }
Beispiel #5
0
        public static void UngrabCursor()
        {
            lock (locker)
            {
                using (var l = new XLibLocker(DisplayHandle))
                {
                    XUngrabPointer(DisplayHandle, 0);
                    XUngrabKeyboard(DisplayHandle, 0);
                }

                XCloseDisplay(DisplayHandle);
                DisplayHandle = XOpenDisplay(IntPtr.Zero);
            }
        }
Beispiel #6
0
        public static void UngrabCursor()
        {
            lock(locker)
            {
                using(var l = new XLibLocker(DisplayHandle))
                {
                    XUngrabPointer(DisplayHandle, 0);
                    XUngrabKeyboard(DisplayHandle, 0);
                }

                XCloseDisplay(DisplayHandle);
                DisplayHandle = XOpenDisplay(IntPtr.Zero);
            }
        }
Beispiel #7
0
        private static IntPtr DefineEmptyCursor(int windowId)
        {
            var    c           = Marshal.AllocHGlobal(80);
            var    cursor_bits = new byte[2 * 16];
            IntPtr cursor;

            using (var l = new XLibLocker(DisplayHandle))
            {
                var pixmap = XCreatePixmapFromBitmapData(DisplayHandle, windowId, cursor_bits, 16, 16, (IntPtr)1, (IntPtr)0, 1);
                cursor = XCreatePixmapCursor(DisplayHandle, pixmap, pixmap, ref c, ref c, 0, 0);
                XFreePixmap(DisplayHandle, pixmap);
            }
            Marshal.FreeHGlobal(c);

            return(cursor);
        }
Beispiel #8
0
        public static void GrabCursorByWindow(int windowId)
        {
            lock (locker)
            {
                using (var l = new XLibLocker(DisplayHandle))
                {
                    int res = 1;
                    do
                    {
                        // Not always grabbing mouse works at the first time, so the loop is necessary
                        res = XGrabPointer(DisplayHandle, windowId, true, 0x4 | 0x8 | 0x40, 1, 1, windowId, DefineEmptyCursor(windowId), 0);
                        Thread.Sleep(100);
                    }while (res != 0);

                    XGrabKeyboard(DisplayHandle, windowId, true, 1, 1, 0);
                }
            }
        }
Beispiel #9
0
        public static void GrabCursorByWindow(int windowId)
        {
            lock(locker)
            {
                using(var l = new XLibLocker(DisplayHandle))
                {
                    int res = 1;
                    do
                    {
                        // Not always grabbing mouse works at the first time, so the loop is necessary
                        res = XGrabPointer(DisplayHandle, windowId, true, 0x4 | 0x8 | 0x40, 1, 1, windowId, DefineEmptyCursor(windowId), 0);
                        Thread.Sleep(100);
                    }
                    while(res != 0);

                    XGrabKeyboard(DisplayHandle, windowId, true, 1, 1, 0);
                }
            }
        }
Beispiel #10
0
        private static IntPtr DefineEmptyCursor(int windowId)
        {
            var c = Marshal.AllocHGlobal(80);
            var cursor_bits = new byte[2 * 16];
            IntPtr cursor;

            using(var l = new XLibLocker(DisplayHandle))
            {
                var pixmap = XCreatePixmapFromBitmapData(DisplayHandle, windowId, cursor_bits, 16, 16, (IntPtr)1, (IntPtr)0, 1);
                cursor = XCreatePixmapCursor(DisplayHandle, pixmap, pixmap, ref c, ref c, 0, 0);
                XFreePixmap(DisplayHandle, pixmap);
            }
            Marshal.FreeHGlobal(c);

            return cursor;
        }