After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 697001 - keybindings: Add API to freeze/unfreeze the keyboard
keybindings: Add API to freeze/unfreeze the keyboard
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: mutter-maint
mutter-maint
Depends on:
Blocks: 697007
 
 
Reported: 2013-03-31 21:43 UTC by Rui Matos
Modified: 2013-05-24 21:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
keybindings: Add API to freeze/unfreeze the keyboard (4.23 KB, patch)
2013-03-31 21:44 UTC, Rui Matos
none Details | Review
keybindings: Add API to freeze/unfreeze the keyboard (3.75 KB, patch)
2013-04-12 14:12 UTC, Rui Matos
reviewed Details | Review
X server patch (1.97 KB, text/plain)
2013-04-12 14:15 UTC, Rui Matos
  Details
keybindings: Add API to freeze/unfreeze the keyboard (4.60 KB, patch)
2013-05-13 21:06 UTC, Rui Matos
committed Details | Review

Description Rui Matos 2013-03-31 21:43:59 UTC
.
Comment 1 Rui Matos 2013-03-31 21:44:01 UTC
Created attachment 240260 [details] [review]
keybindings: Add API to freeze/unfreeze the keyboard

We'll use this in gnome-shell to freeze the keyboard right before
switching input source and unfreeze it after that's finished so that
we don't lose any key events to the wrong input source.
Comment 2 Jasper St. Pierre (not reading bugmail) 2013-03-31 21:54:46 UTC
Review of attachment 240260 [details] [review]:

What's the utility of meta_display_grab_keyboard / meta_display_ungrab_keyboard?
Comment 3 Rui Matos 2013-03-31 22:45:08 UTC
(In reply to comment #2)
> Review of attachment 240260 [details] [review]:
> 
> What's the utility of meta_display_grab_keyboard /
> meta_display_ungrab_keyboard?

See bug 697007. If we have an active key grab (e.g. pushModal()) we have to freeze the key events otherwise we have to establish a keyboard grab in sync mode.
Comment 4 Rui Matos 2013-04-12 14:12:02 UTC
Created attachment 241352 [details] [review]
keybindings: Add API to freeze/unfreeze the keyboard

--

Found some problems with this:

As opposed to what I thought, XIAllowEvents(..., XISyncDevice, ...)
doesn't actually freeze events unless the initial grab was setup in
XIGrabModeSync which is not the case when we are in a compositor grab,
i.e. meta_begin_modal_for_plugin().

That means that when we want to freeze keyboard events we have to call
XIGrabDevice() with XIGrabModeSync regardless of already having a
grab. It also means that we can't grab on the root window as I was
doing before but instead have to grab on the stage's window otherwise
the stage would lose the focus and everything would stop working so I
also had to add a Window parameter so that the shell can pass in the
stage's window.

This uncovered a bug in the server's implementation of XIGrabDevice()
and to work around it we have to freeze both the keyboard and the
pointer and thus then have to XIAllowEvents() on both devices as well.
Comment 5 Rui Matos 2013-04-12 14:15:04 UTC
Created attachment 241353 [details]
X server patch

(In reply to comment #4)
> This uncovered a bug in the server's implementation of XIGrabDevice()
> and to work around it we have to freeze both the keyboard and the
> pointer and thus then have to XIAllowEvents() on both devices as well.

For the record, this is the patch for that server's bug which I'm going to submit upstream.
Comment 6 Florian Müllner 2013-05-13 13:16:51 UTC
Review of attachment 241352 [details] [review]:

Looks good, but the XI workarounds are not obvious enough to leave them uncommented ...

::: src/core/keybindings.c
@@ +1287,3 @@
                               timestamp,
                               None,
+                              grab_mode, grab_mode,

Please add a comment why the mode is applied to the paired device as well (it's too non-obvious to only have it in bugzilla)

@@ +1440,3 @@
+                 XIAsyncDevice, timestamp);
+  XIAllowEvents (display->xdisplay, META_VIRTUAL_CORE_POINTER_ID,
+                 XIAsyncDevice, timestamp);

Same as above.
Comment 7 Rui Matos 2013-05-13 21:06:26 UTC
Created attachment 244111 [details] [review]
keybindings: Add API to freeze/unfreeze the keyboard

--
(In reply to comment #6)
> Looks good, but the XI workarounds are not obvious enough to leave them
> uncommented ...
>
> ::: src/core/keybindings.c
> @@ +1287,3 @@
>                                timestamp,
>                                None,
> +                              grab_mode, grab_mode,
>
> Please add a comment why the mode is applied to the paired device as well (it's
> too non-obvious to only have it in bugzilla)

Of course. What about this?
Comment 8 Florian Müllner 2013-05-13 21:30:29 UTC
Review of attachment 244111 [details] [review]:

Works for me

::: src/core/keybindings.c
@@ +1448,3 @@
+  XIAllowEvents (display->xdisplay, META_VIRTUAL_CORE_KEYBOARD_ID,
+                 XIAsyncDevice, timestamp);
+  /* We shouldn't need to unfreeze the pointer device here however we

Should there be a comma between "here" and "however"?
Comment 9 Rui Matos 2013-05-24 21:52:47 UTC
Attachment 244111 [details] pushed as 056cc16 - keybindings: Add API to freeze/unfreeze the keyboard