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

Hotkey bindings fail on Ubuntu 22/GNOME #164

Closed
godmar opened this issue Aug 19, 2022 · 6 comments
Closed

Hotkey bindings fail on Ubuntu 22/GNOME #164

godmar opened this issue Aug 19, 2022 · 6 comments
Assignees
Labels

Comments

@godmar
Copy link
Contributor

godmar commented Aug 19, 2022

As discussed in #121 gromit-mpx requires the installation/registration of custom key bindings with the compositor in order to regain the hot key functionality independent of the window that has the focus when running under Wayland with Wayland applications.

Commit 6501486 checked whether XDG_CURRENT_DESKTOP is GNOME and if so, adds a number of keybindings.

This doesn't appear to work on Ubuntu 22.04. First, by default, the value of XDG_CURRENT_DESKTOP is not GNOME but ubuntu:GNOME.

Second, even if I run the current git with

env XDG_CURRENT_DESKTOP=GNOME gromit-mpx/build/gromit-mpx -d

it won't work.
I see

DEBUG: Grabbing hot key 'XF86AudioMicMute' from keyboard '3' .
DEBUG: Grabbing undo key 'F8' from keyboard '3' .
DEBUG: Detected GNOME under Wayland, removing our hotkeys from compositor
DEBUG:   removing /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ with name 'gromit-mpx-wayland-hotkey --toggle'
DEBUG:   removing /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/ with name 'gromit-mpx-wayland-hotkey --clear'
DEBUG:   removing /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/ with name 'gromit-mpx-wayland-hotkey --visibility'
DEBUG:   removing /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/ with name 'gromit-mpx-wayland-hotkey --quit'
DEBUG:   removing /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/ with name 'gromit-mpx-wayland-hotkey --undo'
DEBUG:   removing /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/ with name 'gromit-mpx-wayland-hotkey --redo'
DEBUG: Detected GNOME under Wayland, adding our hotkeys to compositor

I checked that the keybindings are added correctly like so:

$ gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ command
'gromit-mpx --toggle'
$ gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ name
'gromit-mpx-wayland-hotkey --toggle'
$ gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/ binding
'XF86AudioMicMute'

(XF86AudioMicMute is the keysym that's triggered when I press the button on my Dell Active Pen)
Although I am running a git build here, I also have gromit-mpx v1.4.2 in my PATH under /usr/bin/gromit-mpx

When I run gromit-mpx --toggle on the command line, it turns on.

So:

  • does GNOME on Ubuntu 22 use different schemas or keys for hot keys?
  • is there an issue with whichever process that tries to run gromit-mpx being unable to do so? (I'll investigate that next. Does GNOME keep logs anywhere?)
@godmar godmar added the bug label Aug 19, 2022
@godmar
Copy link
Contributor Author

godmar commented Aug 19, 2022

PS: even though gsettings get displays these entries under org.gnome.settings-daemon.plugins.media-keys.custom-keybinding, when I go to "Settings" -> "Keyboard" -> "View and Customize Shortcuts" -> "Custom Shortcuts" I don't see any.

I then tried to add one manually using the Gnome GUI. This worked!
And interestingly, running env XDG_CURRENT_DESKTOP=GNOME gromit-mpx subsequently worked and the key bindings added by gromit-mpx show up in the Settings GUI.

Did gromit-mpx's attempt to add custom keys fail because I hadn't used this user interface for custom keys before? (Shouldn't, right?)

A separate problem now popped up. Gromit's shortcuts only work for F9. The key I want is AudioMicMute.
However, apparently, the actual code is <Super>AudioMicMute (this is what I get when I press the button and let GNOME's custom key settings sniff it.) If I specify HOTKEY=XF86AudioMicMute or HOTKEY=AudioMicMute it will not turn on. I tried <Super>AudioMicMute and Super+AudioMicMute - neither worked. How would I specify Super? Is this even possible, given that gromit-mpx appears to be using Modifiers like SHIFT and CTRL itself?

@godmar
Copy link
Contributor Author

godmar commented Aug 19, 2022

I also tested this patch:

diff --git a/src/input.c b/src/input.c
index 3f59ed8..b3a1d56 100644
--- a/src/input.c
+++ b/src/input.c
@@ -66,7 +66,7 @@ static void remove_hotkeys_from_compositor(GromitData *data) {
     if (!data->hot_keycode && !data->undo_keycode)
        return;
 
-    if (xdg_current_desktop && strcmp(xdg_current_desktop, "GNOME") == 0) {
+    if (xdg_current_desktop && strstr(xdg_current_desktop, "GNOME") != 0) {
        /*
          Get all custom key bindings and save back the ones that are not from us.
        */
@@ -120,7 +120,7 @@ static void add_hotkeys_to_compositor(GromitData *data) {
     if (!data->hot_keycode && !data->undo_keycode)
        return;
 
-    if (xdg_current_desktop && strcmp(xdg_current_desktop, "GNOME") == 0) {
+    if (xdg_current_desktop && strstr(xdg_current_desktop, "GNOME") != 0) {
 
        if(data->debug)
            g_print("DEBUG: Detected GNOME under Wayland, adding our hotkeys to compositor\n");

and it works as expected.

@bk138 bk138 self-assigned this Aug 19, 2022
@bk138
Copy link
Owner

bk138 commented Aug 19, 2022

I also tested this patch:

diff --git a/src/input.c b/src/input.c
index 3f59ed8..b3a1d56 100644
--- a/src/input.c
+++ b/src/input.c
@@ -66,7 +66,7 @@ static void remove_hotkeys_from_compositor(GromitData *data) {
     if (!data->hot_keycode && !data->undo_keycode)
        return;
 
-    if (xdg_current_desktop && strcmp(xdg_current_desktop, "GNOME") == 0) {
+    if (xdg_current_desktop && strstr(xdg_current_desktop, "GNOME") != 0) {
        /*
          Get all custom key bindings and save back the ones that are not from us.
        */
@@ -120,7 +120,7 @@ static void add_hotkeys_to_compositor(GromitData *data) {
     if (!data->hot_keycode && !data->undo_keycode)
        return;
 
-    if (xdg_current_desktop && strcmp(xdg_current_desktop, "GNOME") == 0) {
+    if (xdg_current_desktop && strstr(xdg_current_desktop, "GNOME") != 0) {
 
        if(data->debug)
            g_print("DEBUG: Detected GNOME under Wayland, adding our hotkeys to compositor\n");

and it works as expected.

@godmar that's the fix. You can open a pull request with that one :-)

@godmar
Copy link
Contributor Author

godmar commented Aug 19, 2022

To answer my own question, how to do <Super>, this works for me:

@@ -154,16 +154,16 @@ static void add_hotkeys_to_compositor(GromitData *data) {
          add our keybindings
         */
        gchar *modifier_hotkey_option[18];
-       modifier_hotkey_option[0] = "";
+       modifier_hotkey_option[0] = "<Super>";
        modifier_hotkey_option[1] = data->hot_keyval;
        modifier_hotkey_option[2] = "--toggle";
-       modifier_hotkey_option[3] = "<Shift>";
+       modifier_hotkey_option[3] = "<Super><Shift>";
        modifier_hotkey_option[4] = data->hot_keyval;
        modifier_hotkey_option[5] = "--clear";
-       modifier_hotkey_option[6] = "<Ctrl>";
+       modifier_hotkey_option[6] = "<Super><Ctrl>";
        modifier_hotkey_option[7] = data->hot_keyval;
        modifier_hotkey_option[8] = "--visibility";
-       modifier_hotkey_option[9] = "<Alt>";
+       modifier_hotkey_option[9] = "<Super><Alt>";
        modifier_hotkey_option[10] = data->hot_keyval;
        modifier_hotkey_option[11] = "--quit";
        modifier_hotkey_option[12] = "";

@godmar
Copy link
Contributor Author

godmar commented Aug 19, 2022

One more thing: I think the user interface (of GNOME's Custom Key Bindings) is buggy.
What's displayed there is not identical to what you get with gsettings.
I wrote this script:

for i in 0 1 2 3 4 5 
do
    echo "Custom #" $i
    echo -n 'name ->'
    gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom${i}/ name
    echo -n 'binding ->'
    gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom${i}/ binding
    echo -n 'command ->'
    gsettings get org.gnome.settings-daemon.plugins.media-keys.custom-keybinding:/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom${i}/ command
    echo -------------------------------
done

when I run it, I see:

$ . /tmp/get.sh 
Custom # 0
name ->'gromit-mpx-wayland-hotkey --toggle'
binding ->'<Super>AudioMicMute'
command ->'gromit-mpx --toggle'
-------------------------------
Custom # 1
name ->'gromit-mpx-wayland-hotkey --clear'
binding ->'<Super><Shift>AudioMicMute'
command ->'gromit-mpx --clear'
-------------------------------
Custom # 2
name ->'gromit-mpx-wayland-hotkey --visibility'
binding ->'<Super><Ctrl>AudioMicMute'
command ->'gromit-mpx --visibility'
-------------------------------
Custom # 3
name ->'gromit-mpx-wayland-hotkey --quit'
binding ->'<Super><Alt>AudioMicMute'
command ->'gromit-mpx --quit'
-------------------------------
Custom # 4
name ->'gromit-mpx-wayland-hotkey --undo'
binding ->'F8'
command ->'gromit-mpx --undo'
-------------------------------
Custom # 5
name ->'gromit-mpx-wayland-hotkey --redo'
binding ->'<Shift>F8'
command ->'gromit-mpx --redo'
-------------------------------

At the same time, I see:

image

which is clearly out of whack:
"--toggle" is listed as "Shift+Super+AudioMicMute" in the screenshot but gromit-mpx set it correctly as "Super_AudioMicMute" as the output above shows.

@godmar
Copy link
Contributor Author

godmar commented Aug 19, 2022

I opened PR #165 for the XDG_CURRENT_DESKTOP issue.
I also shared an idea of how to handle the issue with the <Super> modifier in PR #166.

@bk138 bk138 closed this as completed in 2f9c6d2 Aug 19, 2022
bk138 pushed a commit that referenced this issue Aug 19, 2022
...instead of checking whether XDG_CURRENT_DESKTOP equals `GNOME` when installing hotkeys into the compositor under Wayland. This will support both `GNOME` and `ubuntu:GNOME` for instance, the latter is the setting on Ubuntu 22.

Closes #164
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants