Exemplo n.º 1
0
        private void LeftDragTitle(XMotionEvent ev)
        {
            if (this.MouseMovement == null)
            {
                return;
            }

            // If we hit the screen edges, snap to edge
            Xlib.XGetWindowAttributes(this.display, this.root, out var attr);
            if (ev.y_root == attr.height - 1 || // Snap to bottom
                ev.y_root == 0 || // snap to top
                ev.x_root == attr.width - 1 || // snap to right
                ev.x_root == 0)     // snap left
            {
                var frame = this.WindowIndexByTitle[ev.window].frame;
                SnapFrameToEdge(frame, ev.x_root, ev.y_root, attr.width, attr.height);
                return;
            }

            // Move the window, after converting co-ordinates into offsets relative to the origin point of motion
            var new_y = ev.y_root - this.MouseMovement.MotionStartY;
            var new_x = ev.x_root - this.MouseMovement.MotionStartX;

            Xlib.XMoveWindow(this.display, WindowIndexByTitle[ev.window].frame,
                             this.MouseMovement.WindowOriginPointX + new_x, this.MouseMovement.WindowOriginPointY + new_y);
        }
Exemplo n.º 2
0
        public void HandleMotionNotify(XMotionEvent e, XWindow window, XWindow root, XWindow subwindow)
        {
            int xdiff = e.x_root - start.x_root;
            int ydiff = e.y_root - start.y_root;

            if ((e.window == resize_top_left_win.ID) || (e.window == resize_bottom_left_win.ID) || (e.window == resize_top_right_win.ID) || (e.window == resize_bottom_right_win.ID))
            {
                if (e.window == resize_top_left_win.ID)
                {
                    ResizeTopLeft(xdiff, ydiff);
                }
                else if (e.window == resize_bottom_left_win.ID)
                {
                    ResizeBottomLeft(xdiff, ydiff);
                }
                else if (e.window == resize_top_right_win.ID)
                {
                    ResizeTopRight(xdiff, ydiff);
                }
                else if (e.window == resize_bottom_right_win.ID)
                {
                    ResizeBottomRight(xdiff, ydiff);
                }

                if (resize_win_width < min_size || resize_win_height < min_size)
                {
                    return;
                }

                resize_main_win.MoveResize(new Rectangle(resize_win_x, resize_win_y, resize_win_width, resize_win_height));

                DrawClock();

                PlaceHandles();
            }
            else if (e.window == resize_main_win.ID)
            {
                int x = old_resize_x + (e.x_root - start.x_root);
                int y = old_resize_y + (e.y_root - start.y_root);

                resize_main_win.Move(new Point(x, y));

                resize_win_x = x;
                resize_win_y = y;
            }
        }
Exemplo n.º 3
0
        private void HandleMotionEvent(XMotionEvent evt)
        {
            if (_stopGrab)
            {
                return;
            }

            int relX = (evt.x_root - lastX);
            int relY = (evt.y_root - lastY);

            lastX = evt.x_root;
            lastY = evt.y_root;

            if (evt.send_event)
            {
                do
                {
                    XMaskEvent(xConnection.XDisplay, EventMask.PointerMotionMask, out _a);
                } while (!_a.AnyEvent.send_event);
                return;
            }

            //We need to put the cursor back to the middle of the window, but we also need to make sure that we don't
            //read the event

            //After a lot of testing, this seems like the best possible solution. Before we warp the cursor we send an event,
            //which we can detect by checking the send_event flag, we then discard any pointer events until we detect the
            //send_input event. Not a perfect solution but not too bad.

            SendIgnoreNext();
            //XTestFakeMotionEvent(xConnection.XDisplay, 0, lastX, lastY, 0);
            XWarpPointer(xConnection.XDisplay, xConnection.XRootWindow, xConnection.XRootWindow, 0, 0, 0, 0, backX, backY);
            SendIgnoreNext();
            XFlush(xConnection.XDisplay);

            OnInputReceived(new ISInputData(ISInputCode.IS_MOUSEMOVERELATIVE, (short)relX, (short)relY));
        }
 /// <summary> Initializing constructor. </summary>
 /// <param name="evt"> The event to wrap. <see cref="XMotionEvent"/> </param>
 public XrwMotionEvent(ref XMotionEvent evt)
 {
     Event = evt;
 }
Exemplo n.º 5
0
        public override void EnterMessageLoop(bool runInBackground)
        {
            IntPtr e       = System.Runtime.InteropServices.Marshal.AllocHGlobal(24 * sizeof(long));
            bool   running = true;

            while (running)
            {
                while (XPending(_display) != 0)
                {
                    XNextEvent(_display, e);

                    if (XFilterEvent(e, IntPtr.Zero))
                    {
                        continue;
                    }

                    XAnyEvent anyEvent = (XAnyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XAnyEvent));

                    switch ((Event)anyEvent.type)
                    {
                    case Event.ClientMessage:
                    {
                        running = false;
                        break;
                    }

                    case Event.ConfigureNotify:
                    {
                        XConfigureEvent configureEvent = (XConfigureEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XConfigureEvent));

                        LocationChanged?.Invoke(this, configureEvent.x, configureEvent.y);
                        SizeChanged?.Invoke(this, configureEvent.width, configureEvent.height);
                        break;
                    }

                    case Event.FocusIn:
                    {
                        Activated?.Invoke(this);
                        break;
                    }

                    case Event.FocusOut:
                    {
                        Deactivated?.Invoke(this);
                        break;
                    }

                    case Event.MotionNotify:
                    {
                        XMotionEvent motionEvent = (XMotionEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XMotionEvent));
                        MouseMove?.Invoke(this, motionEvent.x, motionEvent.y);
                        break;
                    }

                    case Event.ButtonPress:
                    {
                        XButtonEvent buttonEvent = (XButtonEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XButtonEvent));

                        switch ((Button)buttonEvent.button)
                        {
                        case Button.Button1:
                        {
                            MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Left);
                            break;
                        }

                        case Button.Button2:
                        {
                            MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Middle);
                            break;
                        }

                        case Button.Button3:
                        {
                            MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Right);
                            break;
                        }

                        case Button.Button4:
                        {
                            MouseWheel?.Invoke(this, buttonEvent.x, buttonEvent.y, 120);
                            break;
                        }

                        case Button.Button5:
                        {
                            MouseWheel?.Invoke(this, buttonEvent.x, buttonEvent.y, -120);
                            break;
                        }
                        }
                        break;
                    }

                    case Event.ButtonRelease:
                    {
                        XButtonEvent buttonEvent = (XButtonEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XButtonEvent));

                        switch ((Button)buttonEvent.button)
                        {
                        case Button.Button1:
                        {
                            MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Left);
                            break;
                        }

                        case Button.Button2:
                        {
                            MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Middle);
                            break;
                        }

                        case Button.Button3:
                        {
                            MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Right);
                            break;
                        }
                        }
                        break;
                    }

                    case Event.KeyPress:
                    {
                        XKeyEvent keyEvent = (XKeyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XKeyEvent));
                        KeySym    ks       = XLookupKeysym(ref keyEvent, 0);
                        Key       key      = NoesisKey(ks);
                        if (key != Key.None)
                        {
                            KeyDown?.Invoke(this, key);
                        }

                        if (_xic != IntPtr.Zero)
                        {
                            Status status = 0;
                            byte[] buffer = new byte[256];
                            KeySym ret_ks = (KeySym)0;
                            int    size   = Xutf8LookupString(_xic, e, buffer, 255, ref ret_ks, ref status);
                            if (size > 0 && ((int)status == XLookupChars || (int)status == XLookupBoth))
                            {
                                buffer[size] = 0;
                                Decoder decoder   = _utf8.GetDecoder();
                                char[]  text      = new char[256];
                                int     bytesUsed = 0;
                                int     charsUsed = 0;
                                bool    completed = false;
                                decoder.Convert(buffer, 0, size, text, 0, 255, true, out bytesUsed, out charsUsed, out completed);
                                for (int i = 0; i < charsUsed; ++i)
                                {
                                    Char?.Invoke(this, text[i]);
                                }
                            }
                        }
                        break;
                    }

                    case Event.KeyRelease:
                    {
                        XKeyEvent keyEvent = (XKeyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XKeyEvent));
                        KeySym    ks       = XLookupKeysym(ref keyEvent, 0);
                        Key       key      = NoesisKey(ks);
                        if (key != Key.None)
                        {
                            KeyUp?.Invoke(this, key);
                        }
                        break;
                    }
                    }
                }

                Render?.Invoke(this);
            }
            System.Runtime.InteropServices.Marshal.FreeHGlobal(e);
        }
        public RCode HandleSystemEvent()
        {
            while (Xlib.XPending(display) > 0)
            {
                Xlib.XNextEvent(display, ev);
                XAnyEvent xevent = Marshal.PtrToStructure <XAnyEvent>(ev);

                switch (xevent.type)
                {
                case (int)Event.ClientMessage:
                    XClientMessageEvent xClientMessageEvent = Marshal.PtrToStructure <XClientMessageEvent>(ev);
                    if (xClientMessageEvent.data == (IntPtr)deleteWindowMessage)
                    {
                        PixelGameEngine.Instance.Terminate();
                    }
                    break;

                case (int)Event.KeyPress:
                case (int)Event.KeyRelease:
                    XKeyEvent xKeyEvent = Marshal.PtrToStructure <XKeyEvent>(ev);
                    KeySym    sym       = XlibExt.XLookupKeysym(new XKeyEvent[] { xKeyEvent }, 0);
                    pge.Input.UpdateKeyState((int)mapKeys[(long)sym], xevent.type == (int)Event.KeyPress);
                    break;

                case (int)Event.ButtonPress:
                case (int)Event.ButtonRelease:
                    XButtonEvent xButtonEvent = Marshal.PtrToStructure <XButtonEvent>(ev);
                    bool         pressed      = xevent.type == (int)Event.ButtonPress;

                    switch (xButtonEvent.button)
                    {
                    case 1:
                    case 2:
                    case 3:
                        pge.Input.UpdateMouseState((int)xButtonEvent.button - 1, pressed);
                        break;

                    case 4:
                        pge.Input.UpdateMouseWheel(120);
                        break;

                    case 5:
                        pge.Input.UpdateMouseWheel(-120);
                        break;

                    case 6:
                    case 7:
                    case 8:
                    case 9:
                        pge.Input.UpdateMouseState((int)xButtonEvent.button - 3, pressed);
                        break;
                    }
                    break;

                case (int)Event.MotionNotify:
                    XMotionEvent xMotionEvent = Marshal.PtrToStructure <XMotionEvent>(ev);
                    pge.Input.UpdateMouse(xMotionEvent.x, xMotionEvent.y);
                    break;

                case (int)Event.EnterNotify:
                    pge.Input.UpdateMouseFocus(true);
                    break;

                case (int)Event.LeaveNotify:
                    pge.Input.UpdateMouseFocus(false);
                    break;

                case (int)Event.FocusIn:
                    pge.Input.UpdateKeyFocus(true);
                    break;

                case (int)Event.FocusOut:
                    pge.Input.UpdateKeyFocus(false);
                    break;
                }
            }
            return(RCode.OK);
        }
Exemplo n.º 7
0
 void handleClientMotionNotifyEvent(XMotionEvent e, Client c)
 {
 }
Exemplo n.º 8
0
 void handleMotionNotifyEvent(XMotionEvent e, XWindow window, XWindow root, XWindow subwindow)
 {
 }
Exemplo n.º 9
0
        private void LeftDragFrame(XMotionEvent ev)
        {
            var frame  = ev.window;
            var title  = WindowIndexByFrame[frame].title;
            var client = WindowIndexByFrame[frame].child;

            var y_delta = 0;
            var x_delta = 0;

            var w_delta = 0;
            var h_delta = 0;

            var t = this.MouseMovement.Type;

            // Stretch to the right, or compress left, no lateral relocation of window origin.
            if (t == MouseMoveType.RightFrameDrag ||
                t == MouseMoveType.TopRightFrameDrag ||
                t == MouseMoveType.BottomRightFrameDrag)
            {
                w_delta = ev.x_root - this.MouseMovement.MotionStartX; // width change
            }
            // Stretch down, or compress upwards, no vertical movement of the window origin.
            if (t == MouseMoveType.BottomFrameDrag ||
                t == MouseMoveType.BottomRightFrameDrag ||
                t == MouseMoveType.BottomLeftFrameDrag)
            {
                h_delta = ev.y_root - this.MouseMovement.MotionStartY;
            }
            // Combine vertical stretch with movement of the window origin.
            if (t == MouseMoveType.TopFrameDrag ||
                t == MouseMoveType.TopRightFrameDrag ||
                t == MouseMoveType.TopLeftFrameDrag)
            {
                h_delta = this.MouseMovement.MotionStartY - ev.y_root;
                y_delta = -h_delta;
            }
            // Combined left stretch with movement of the window origin
            if (t == MouseMoveType.LeftFrameDrag ||
                t == MouseMoveType.TopLeftFrameDrag ||
                t == MouseMoveType.BottomLeftFrameDrag)
            {
                w_delta = this.MouseMovement.MotionStartX - ev.x_root;
                x_delta = -w_delta;
            }

            //// Resize and move the frame
            Xlib.XGetWindowAttributes(this.display, frame, out var attr);
            var new_width  = (uint)(attr.width + w_delta);
            var new_height = (uint)(attr.height + h_delta);

            Xlib.XMoveResizeWindow(this.display, frame, attr.x + x_delta, attr.y + y_delta, new_width, new_height);

            //// Resize and move the title bar
            Xlib.XGetWindowAttributes(this.display, title, out attr);
            new_width  = (uint)(attr.width + w_delta);
            new_height = (uint)attr.height;
            Xlib.XResizeWindow(this.display, title, new_width, new_height);

            //// Resize and move the client window bar
            Xlib.XGetWindowAttributes(this.display, client, out attr);
            new_width  = (uint)(attr.width + w_delta);
            new_height = (uint)(attr.height + h_delta);
            Xlib.XResizeWindow(this.display, client, new_width, new_height);

            this.MouseMovement.MotionStartX = ev.x_root;
            this.MouseMovement.MotionStartY = ev.y_root;
        }