Example #1
0
        public void DetachHandler()
        {
            Stop = true;
            XLibHelper.UngrabCursor();

            handler = null;
        }
Example #2
0
        public void AttachHandler(IOHandler h)
        {
            handler = h;

            if (!XLibHelper.IsAvailable)
            {
                MessageDialog.ShowError("libX11 library not found");
                return;
            }

            int pid;

            try
            {
                pid = source.ParentWindow.Id;
            }
            catch (DllNotFoundException)
            {
                MessageDialog.ShowError("gdk x11 library not found");
                return;
            }

            XLibHelper.GrabCursorByWindow(pid);
            XLibHelper.MoveCursorAbsolute(pid, (int)(source.ParentWindow.Size.Width / 2), (int)(source.ParentWindow.Size.Height / 2));

            XLibHelper.StartEventListenerLoop(this);
        }
        public override void PointerMoved(int x, int y, int dx, int dy)
        {
            var image = widget.Image;

            if (image == null)
            {
                return;
            }

            var ainput  = (IAbsolutePositionPointerInput)input;
            var imgRect = widget.ActualImageArea;

            // if cursor doesn't touch actual image, return
            if (!imgRect.IntersectsWith(new Rectangle(x, y, 1, 1)))
            {
                XLibHelper.RestoreCursor(widget.ParentWindow.Id);
                isCursorOverImageRectangle = false;
                return;
            }
            if (!isCursorOverImageRectangle || isTabletButtonJustReleased)
            {
                widget.CanGetFocus = true;
                widget.SetFocus();
                isCursorOverImageRectangle = true;
                isTabletButtonJustReleased = false;
                XLibHelper.MakeCursorTransparent(widget.ParentWindow.Id);
            }

            //  this fragment converts click-point coordinates:
            //  from
            //     FrameBufferAnalyzer coordinates system (i.e., XWT coordinates of canvas on which the buffer was drawn)
            //  through
            //     Buffer coordinates system (i.e., resolution set on emulated graphic card)
            //  to
            //     Touchscreen coordinates system
            var maxX = (int)image.Width;
            var maxY = (int)image.Height;

            var imageX = ((x - imgRect.X) / imgRect.Width) * maxX;
            var imageY = ((y - imgRect.Y) / imgRect.Height) * maxY;

            X = (int)imageX;
            Y = (int)imageY;

            var touchscreenX = (int)Math.Round(imageX * ainput.MaxX / maxX);
            var touchscreenY = (int)Math.Round(imageY * ainput.MaxY / maxY);

            ainput.MoveTo(touchscreenX, touchscreenY);

            var opm = OnPointerMoved;

            if (opm != null)
            {
                opm(X, Y);
            }
        }
        public override void ButtonReleased(int button)
        {
            base.ButtonReleased(button);
            XLibHelper.MakeCursorTransparent(widget.ParentWindow.Id);

            //TODO: After releasing button, the real cursor over canvas is getting visible.
            // As a temporary dirty solution, variable below is set, and cursor is hidden
            // again by moving it in MoveTablet()
            isTabletButtonJustReleased = true;
        }