Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constrain mouse inside shadow window #3415

Closed
stdedos opened this issue Jan 8, 2022 · 9 comments
Closed

Constrain mouse inside shadow window #3415

stdedos opened this issue Jan 8, 2022 · 9 comments
Labels
client enhancement New feature or request

Comments

@stdedos
Copy link
Collaborator

stdedos commented Jan 8, 2022

Is your feature request related to a problem? Please describe.
Somewhat related to #3388, I'd like to be able to constrain the mouse pointer within the Shadow window.

Again related to #3388, it could be released on a specific shortcut - VM software have already figured this out

@stdedos stdedos added the enhancement New feature or request label Jan 8, 2022
@totaam totaam added the client label Jan 9, 2022
@totaam
Copy link
Collaborator

totaam commented Jan 10, 2022

Gdk.pointer_grab used to do this in GTK2 (pygtk):

import pygtk
pygtk.require("2.0")
import gobject, gtk

def release_me():
    gtk.main_quit()
    return True

def on_destroy(widget):
    gtk.main_quit()

def on_enter(widget, event):
    if event.type == gtk.gdk.ENTER_NOTIFY:
        cursor = gtk.gdk.Cursor(gtk.gdk.PIRATE)     # Pirates!!
        gtk.gdk.pointer_grab(widget.window, False, gtk.gdk.POINTER_MOTION_MASK,
                             widget.window, cursor, long(event.time))
        gobject.timeout_add(15000, release_me)
    else:
        # leaving: won't happen
        gtk.gdk.pointer_ungrab(long(event.time))
    return False

def on_move(widget, event):
    print "move to:", event.x, event.y

def main():
    w = gtk.Window()
    w.set_title("Grabby")

    w.connect('destroy', on_destroy)
    w.connect('enter-notify-event', on_enter)
    w.connect('motion-notify-event', on_move)

    w.show_all()

    gtk.main()

    gdk.pointer_ungrab(long(event.time))

if __name__ == '__main__':
    main()

But this doesn't seem to work with GTK3 anymore?

@totaam
Copy link
Collaborator

totaam commented Jan 11, 2022

Actually, I just remembered that we already have this ClipCursor workaround: #1229 (comment) - f0301e1.

But I've just tried it and it doesn't seem to confine the pointer, only trap focus / input.
-d grab doesn't show anything useful so I have no idea why it stopped working.
Tested using --key-shortcut=Shift+F2:toggle_pointer_grab on MS Windows 10.

@totaam
Copy link
Collaborator

totaam commented Jan 11, 2022

Minimal reproducer

#!/usr/bin/env python3

import gi
from xpra.util import AdHocStruct
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib
from xpra.platform.win32.gui import pointer_grab

w = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
w._client = AdHocStruct()
w.show()
GLib.timeout_add(1000, pointer_grab, w)
Gtk.main()

@totaam
Copy link
Collaborator

totaam commented Jan 11, 2022

Just found an old note in #1229 : virtualbox's mouse integration interferes with pointer grabs, turn it off for testing
So perhaps everything still works and I'm just testing it wrong!

@stdedos please try toggle_pointer_grab.

@stdedos
Copy link
Collaborator Author

stdedos commented Jan 11, 2022

It works as expected.

However ... at least, you should auto-disengage it on Alt+Tab.
Try it: enable_pointer_grab, verify confinement, Alt+Tab, Alt+Tab back, verify confinement: FAIL.
Then, it's not enough to just toggle_pointer_grab once (i.e. re-enable it); instead, you have to do toggle_pointer_grab twice (once to disable it, once to re-enable it).

... Which will also MAY be more complicated to judge if you need to auto-disengage_pointer_grab, if you implement #3388 (then Alt+Tab is directed to the server, instead of client interpreting it).

totaam added a commit that referenced this issue Jan 11, 2022
so we only reset the 'pointer_grabbed' value when we actually owned it
@totaam
Copy link
Collaborator

totaam commented Jan 11, 2022

Try it: ..

I just don't have any hardware available that runs MS Windows native so I can't try it!
(but I'll take your word for it)

instead, you have to do toggle_pointer_grab twice

The first commit above should fix that (totally untested), the second one is not strictly needed.

We track and manage keyboard grabs and pointer grabs separately and I'm not sure that makes any sense but I don't have to courage to change it, especially if I can't test the only platform that actually honours it properly.

@stdedos
Copy link
Collaborator Author

stdedos commented Jan 11, 2022

Again, take the VM example (Virtualbox):

"Simple keys" can just pass on as-is. If you'd like to grab the mouse (because I like the constraint), I can. If I need to capture the keyboard (#3388 eg for Alt+Tab), I can

@totaam
Copy link
Collaborator

totaam commented Jan 12, 2022

@stdedos is the double-grab issue fixed? Can we close this ticket?

@stdedos
Copy link
Collaborator Author

stdedos commented Jan 12, 2022

Yes, it's all good now! Thanks 😄

@stdedos stdedos closed this as completed Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants