Exemplo n.º 1
0
        private void LeftClickTitleBar(XButtonEvent ev)
        {
            Window frame;
            var    wg = WindowIndexByTitle[ev.window];

            frame = wg.frame;
            var child = wg.child;

            FocusAndRaiseWindow(child);
            Xlib.XGetWindowAttributes(this.display, frame, out var attr);
            this.MouseMovement = new MouseMovement(MouseMoveType.TitleDrag, ev.x_root, ev.y_root, attr.x, attr.y);
            return;
        }
Exemplo n.º 2
0
        private void LeftClickFrame(XButtonEvent ev)
        {
            Xlib.XGetWindowAttributes(this.display, ev.window, out var attr);

            var control_width  = (attr.width / 2) <= 40 ? attr.width / 2 : 40;
            var control_height = (attr.height / 2) <= 40 ? attr.width / 2 : 40;

            if (ev.x >= attr.width - control_width) // right side
            {
                if (ev.y >= attr.height - control_height)
                {
                    this.MouseMovement = new MouseMovement(MouseMoveType.BottomRightFrameDrag, ev.x_root, ev.y_root, attr.x, attr.y);
                }
                else if (ev.y <= control_height)
                {
                    this.MouseMovement = new MouseMovement(MouseMoveType.TopRightFrameDrag, ev.x_root, ev.y_root, attr.x, attr.y);
                }
                else
                {
                    this.MouseMovement = new MouseMovement(MouseMoveType.RightFrameDrag, ev.x_root, ev.y_root, attr.x, attr.y);
                }
            }
            else if (ev.x <= control_width)
            {
                if (ev.y >= attr.height - control_height)
                {
                    this.MouseMovement = new MouseMovement(MouseMoveType.BottomLeftFrameDrag, ev.x_root, ev.y_root, attr.x, attr.y);
                }
                else if (ev.y <= control_height)
                {
                    this.MouseMovement = new MouseMovement(MouseMoveType.TopLeftFrameDrag, ev.x_root, ev.y_root, attr.x, attr.y);
                }
                else
                {
                    this.MouseMovement = new MouseMovement(MouseMoveType.LeftFrameDrag, ev.x_root, ev.y_root, attr.x, attr.y);
                }
            }
            else if (ev.y >= attr.height / 2)
            {
                this.MouseMovement = new MouseMovement(MouseMoveType.BottomFrameDrag, ev.x_root, ev.y_root, attr.x, attr.y);
            }
            else
            {
                this.MouseMovement = new MouseMovement(MouseMoveType.TopFrameDrag, ev.x_root, ev.y_root, attr.x, attr.y);
            }
            return;
        }
Exemplo n.º 3
0
        public int Run()
        {
            IntPtr ev = Marshal.AllocHGlobal(24 * sizeof(long));

            Window ReturnedParent = 0, ReturnedRoot = 0;


            Xlib.XGrabServer(this.display); // Lock the server during initialization
            var r = Xlib.XQueryTree(this.display, this.root, ref ReturnedRoot, ref ReturnedParent,
                                    out var ChildWindows);

            Log.Debug($"Reparenting and framing pre-existing child windows: {ChildWindows.Count}");
            for (var i = 0; i < ChildWindows.Count; i++)
            {
                Log.Debug($"Framing child {i}, {ChildWindows[i]}");
                AddFrame(ChildWindows[i]);
            }
            Xlib.XUngrabServer(this.display); // Release the lock on the server.


            while (true)
            {
                Xlib.XNextEvent(this.display, ev);
                var xevent = Marshal.PtrToStructure <X11.XAnyEvent>(ev);

                switch (xevent.type)
                {
                case (int)Event.DestroyNotify:
                    var destroy_event = Marshal.PtrToStructure <X11.XDestroyWindowEvent>(ev);
                    OnDestroyNotify(destroy_event);
                    break;

                case (int)Event.CreateNotify:
                    var create_event = Marshal.PtrToStructure <X11.XCreateWindowEvent>(ev);
                    OnCreateNotify(create_event);
                    break;

                case (int)Event.MapNotify:
                    var map_notify = Marshal.PtrToStructure <X11.XMapEvent>(ev);
                    OnMapNotify(map_notify);
                    break;

                case (int)Event.MapRequest:
                    var map_event = Marshal.PtrToStructure <X11.XMapRequestEvent>(ev);
                    OnMapRequest(map_event);
                    break;

                case (int)Event.ConfigureRequest:
                    var cfg_event = Marshal.PtrToStructure <X11.XConfigureRequestEvent>(ev);
                    OnConfigureRequest(cfg_event);
                    break;

                case (int)Event.UnmapNotify:
                    var unmap_event = Marshal.PtrToStructure <X11.XUnmapEvent>(ev);
                    OnUnmapNotify(unmap_event);
                    break;

                case (int)Event.ReparentNotify:
                    var reparent_event = Marshal.PtrToStructure <X11.XReparentEvent>(ev);
                    OnReparentNotify(reparent_event);
                    break;

                case (int)Event.ButtonPress:
                    var button_press_event = Marshal.PtrToStructure <X11.XButtonEvent>(ev);
                    OnButtonPressEvent(button_press_event);
                    break;

                case (int)Event.ButtonRelease:
                    this.MouseMovement = null;
                    break;

                case (int)Event.MotionNotify:
                    // We only want the newest motion event in order to reduce perceived lag
                    while (Xlib.XCheckMaskEvent(this.display, EventMask.Button1MotionMask, ev)) /* skip over */ } {
                    var motion_event = Marshal.PtrToStructure <X11.XMotionEvent>(ev);
                    OnMotionEvent(motion_event);
                    break;