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 784702 - media-keys: Fix grabbing of previously disabled shortcuts
media-keys: Fix grabbing of previously disabled shortcuts
Status: RESOLVED FIXED
Product: gnome-settings-daemon
Classification: Core
Component: media-keys
unspecified
Other All
: Normal normal
: ---
Assigned To: gnome-settings-daemon-maint
gnome-settings-daemon-maint
Depends on:
Blocks:
 
 
Reported: 2017-07-08 18:17 UTC by Florian Müllner
Modified: 2017-07-19 16:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
media-keys: Fix grabbing of previously disabled shortcuts (1.71 KB, patch)
2017-07-08 18:17 UTC, Florian Müllner
none Details | Review
media-keys: Use hash table keys that uniquely identify a key (4.52 KB, patch)
2017-07-10 22:28 UTC, Florian Müllner
committed Details | Review
media-keys: Fix grabbing of previously disabled shortcuts (1.92 KB, patch)
2017-07-10 22:28 UTC, Florian Müllner
none Details | Review
media-keys: Fix grabbing of previously disabled shortcuts (2.43 KB, patch)
2017-07-19 15:56 UTC, Florian Müllner
committed Details | Review

Description Florian Müllner 2017-07-08 18:17:45 UTC
See patch.
Comment 1 Florian Müllner 2017-07-08 18:17:51 UTC
Created attachment 355178 [details] [review]
media-keys: Fix grabbing of previously disabled shortcuts

If a key is not actually grabbed when we try to ungrab it, we register
the request and ungrab the key after the grab operation has completed.
This avoids leaking bindings when a shortcut is disabled while a grab
operation is in progress, however it means that any grab operation done
after trying to ungrab an unset shortcut will be immediately undone.
This is the currently the case when a shortcut settings changes, which
we handle as a simple combination of ungrab and grab - we need to make
sure to only ungrab a key that has been grabbed previously for the
latter operation to have an effect.
Comment 2 Rui Matos 2017-07-10 14:07:15 UTC
Review of attachment 355178 [details] [review]:

changes to this file should use 8 spaces indentation

::: plugins/media-keys/gsd-media-keys-manager.c
@@ +601,3 @@
                 if (strcmp (settings_key, key->settings_key) == 0) {
+                        if (key->accel_id > 0)
+                          ungrab_media_key (key, manager);

this defeats the purpose. the core issue is that accel_id == 0 means two different things: binding unset and binding set but pending grab.

to fix this we should change the accel_id == 0 in ungrab_media_key() to instead check for the binding presence in keys_pending_grab and the request the ungrab in that case.
Comment 3 Florian Müllner 2017-07-10 14:36:20 UTC
(In reply to Rui Matos from comment #2)
> to fix this we should change the accel_id == 0 in ungrab_media_key() to
> instead check for the binding presence in keys_pending_grab and the request
> the ungrab in that case.

Isn't that the same as removing the ungrab_media_key() call altogether? If there's a pending grab, the entry in keys_pending_grab is based on the previous settings value that we no longer have access to, so the lookup for get_key_string() should never find anything in this case ...
Comment 4 Rui Matos 2017-07-10 14:59:51 UTC
(In reply to Florian Müllner from comment #3)
> (In reply to Rui Matos from comment #2)
> > to fix this we should change the accel_id == 0 in ungrab_media_key() to
> > instead check for the binding presence in keys_pending_grab and the request
> > the ungrab in that case.
> 
> Isn't that the same as removing the ungrab_media_key() call altogether? If
> there's a pending grab, the entry in keys_pending_grab is based on the
> previous settings value that we no longer have access to, so the lookup for
> get_key_string() should never find anything in this case ...

ugh. I guess the hash table usage here is wrong then. we're using the binding's combo string as an index but it's written with the assumption that it's the binding's name...
Comment 5 Florian Müllner 2017-07-10 22:28:43 UTC
Created attachment 355299 [details] [review]
media-keys: Use hash table keys that uniquely identify a key

We keep track of ongoing and requested grab operations by registering
a key in a corresponding hash table. However currently we use the
key's current binding as hash table key, which is subject to changes.
To not mess up the tracking when a setting changes at the wrong time,
base the hash table keys on immutable properties that uniquely identify
the key.
Comment 6 Florian Müllner 2017-07-10 22:28:55 UTC
Created attachment 355300 [details] [review]
media-keys: Fix grabbing of previously disabled shortcuts

If a key is not actually grabbed when we try to ungrab it, we register
the request and ungrab the key after the grab operation has completed.
This avoids leaking bindings when a shortcut is disabled while a grab
operation is in progress, however it means that any grab operation done
after trying to ungrab an unset shortcut will be immediately undone.
This is the currently the case when a shortcut settings changes, which
we handle as a simple combination of ungrab and grab - we need to make
sure to only request a later ungrab if there's a pending grab.
Comment 7 Florian Müllner 2017-07-10 22:36:00 UTC
I'm not quite sure about the hash key change - it seems that it can mess up when an existing accelerator is reassigned to a different key?

I wonder whether switching to sync IO is an option here - we don't have any GUI we could block, so off-hand that seems acceptable?
Comment 8 Rui Matos 2017-07-19 13:35:16 UTC
Review of attachment 355299 [details] [review]:

right, this is how we should have been using these hash tables from the beginning
Comment 9 Rui Matos 2017-07-19 13:47:27 UTC
Review of attachment 355300 [details] [review]:

::: plugins/media-keys/gsd-media-keys-manager.c
@@ +586,3 @@
 {
         if (key->accel_id == 0) {
+                key->ungrab_requested = is_pending_grab (key, manager);

in grab_accelerator_complete() we should remove the key from keys_pending_grab before calling ungrab_media_key() otherwise we'll reset ->ungrab_requested erroneously
Comment 10 Florian Müllner 2017-07-19 15:56:20 UTC
Created attachment 355960 [details] [review]
media-keys: Fix grabbing of previously disabled shortcuts

If a key is not actually grabbed when we try to ungrab it, we register
the request and ungrab the key after the grab operation has completed.
This avoids leaking bindings when a shortcut is disabled while a grab
operation is in progress, however it means that any grab operation done
after trying to ungrab an unset shortcut will be immediately undone.
This is the currently the case when a shortcut settings changes, which
we handle as a simple combination of ungrab and grab - we need to make
sure to only request a later ungrab if there's a pending grab.
Comment 11 Rui Matos 2017-07-19 16:12:21 UTC
Review of attachment 355960 [details] [review]:

looks good, thanks
Comment 12 Florian Müllner 2017-07-19 16:18:23 UTC
Attachment 355299 [details] pushed as 7d73194 - media-keys: Use hash table keys that uniquely identify a key
Attachment 355960 [details] pushed as 19ce2c1 - media-keys: Fix grabbing of previously disabled shortcuts