Ubuntu 18.04 LTS is finally out, and with it you now have Gnome out of the box.
I've been using Gnome for several years, and have enjoyed its minimalism. It took me some time to make it work like I wanted (keyboard, extensions, application menu, etc), but I'm quite happy with everything. Or almost everything.
One thing I enjoyed over the years was the ability to customize my keyboard shortcuts. I have a shortcut for pretty much everything - to center windows on my screen, to open programs, start and stop Spotify, to run macros, to log in to my remote servers, and so on.
One of my handy shortcuts is <Super>+<F1>
to open an xterm with superuser, and <Super>+<F2>
for regular user. I use custom xterm profiles, so I can easily check if I'm running under a privileged context by looking at the color of the window.
This worked well for years under Ubuntu 14.04 and Gnome 3.20, but stopped working with the upgrade to Bionic Beaver. More specifically, <Super>+<F1>
started opening System Help, and there was no way to change it.
"No problem", I thought; this can be easily adjusted in System Settings.
Nops.
I searched around, and found other folks with the same problem, but no solution.
I then decided to dug into the source code, and discovered the improbable: it seems that Gnome devs decided the help was SO important that it deserved its own unique, hardcoded, and immutable shortcut. If you want to reassign it, you're out of luck.
According to gnome-settings-daemon changelog:
===============
Version 3.21.90
===============
...
Media keys:
- Add Super+F1 as a hardcoded shortcut for launching Help
...
REALLY? What's wrong with a default icon in the toolbar, or maybe a popup window when you boot for the first time? Also, does anyone really care about reading the basic documentation for a windows manager?
I wasn't convinced yet, but a closer look at the source code confirmed my fears: there it was: (file /gnome-settings-daemon/blob/master/plugins/media-keys/shortcuts-list.h):
...
{ HELP_KEY, NULL, N_("Help"), "<Super>F1", GSD_ACTION_MODE_LAUNCHER },
...
So if you're really determined to regain control of your <Super>+<F1>
, there's only one solution: to recompile gnome-settings-daemon, and replace the gsd-media-keys plugin. Spoiler alert: I'm glad to report that my patch was successful, but beware: getting the right dependencies and recompiling Gnome is not an easy feat. Keep reading if you're interested in doing the same:
- Download and install Gnome Builder
- Click on "Clone", select a local directory (e.g., ~/Projects/) and use the official repo at
https://gitlab.gnome.org/GNOME/gnome-settings-daemon
- Open xterm, and enter
cd ~/Projects/gnome-settings-daemon; git checkout tags/GNOME_SETTINGS_DAEMON_3_28_1
(you can check your exact version withgnome-shell --version
. Check all tags available withgit tag -l
) Install all dependencies. These were the ones missing in my system, but YMMV:
apt install libcolord-dev \ libgeocode-glib-dev \ gnome-desktop3-data \ libgnome-desktop-3-dev \ libgweather-3-dev \ libcanberra-gtk3-dev \ libgeoclue-2-dev \ libnotify-dev \ libpulse-mainloop-glib0 \ libpulse-dev \ gobject-introspection \ libupower-glib-dev \ libpolkit-gobject-1-dev \ libasound2-dev \ libgudev-1.0-dev \ libwacom-dev \ libnss3-dev \ libcups2-dev \ libnm-dev
Patch the source code by editing
~/Projects/gnome-settings-daemon/plugins/media-keys/shortcuts-list.h
, and add a comment in front of the offender, like below (for Gnome 3.28.1 it is in line 69):// disabled! // { HELP_KEY, NULL, N_("Help"), "<Super>F1", GSD_ACTION_MODE_LAUNCHER },
Click [Rebuild] button in the Builder UI to compile (note: you need to click Rebuild, and not
Build). You may want to turn off the deprecation warnings by editingmeson.build
and adding'-Wno-deprecated-declarations'
totest_cflags = [...];
(line 70). If you installed all the dependencies correctly, you should have no warnings nor errors.Find the compiled binaries. You're looking specifically for the plugin
gsd-media-keys
, so it'll likely be in the directory ~/.var/app/org.gnome.Builder/cache/gnome-builder/projects/gnome-settings-daemon/builds/default-host-HEAD/plugins/media-keyscd ~/.var/app/org.gnome.Builder/cache/gnome-builder/projects/gnome-settings-daemon/builds/default-host-HEAD/plugins/media-keys ~ cp ./gsd-media-keys ~/gsd-media-keys.patched
Before proceeding, you may want to inspect your binary to confirm it successfully linked with shared libraries by using
ldd ~/gsd-media-keys.patched
. In my case I had problems findinglibgsd.so
, so I solved it by adding the path to ldconfig (although the correct solution would be to fix this in the build system):sudo sh -c 'echo "# gnome-settings-daemon\n/usr/lib/x86_64-linux-gnu/gnome-settings-daemon-3.0/\n" > /etc/ld.so.conf.d/gnome-settings-daemon.conf' sudo ldconfig
You're now ready to install the patched
gsd-media-keys
binary in your system:cd /usr/lib/gnome-settings-daemon/ sudo mv ~/gsd-media-keys.patched . sudo strip -s ./gsd-media-keys.patched sudo mv gsd-media-keys gsd-media-keys.orig sudo ln -s gsd-media-keys.patched gsd-media-keys
Log out or reboot, and you're done!
If all goes well, your system now should be running the gsd-media-keys plugin without the <Super>+<F1>
hardcoded, so you can reassign to anything you like.
If anything goes wrong and you can't log in, don't despair. Simply open a console terminal by using <Ctrl>+<Alt>+<F2>
and restore your original gsd-media-keys binary by doing:
cd /usr/lib/gnome-settings-daemon/
sudo rm gsd-media-keys
sudo ln -s gsd-media-keys.orig gsd-media-keys
Use <Ctrl>+<Alt><F1>
to go back to Gnome and log in again. You can then inspect /var/log/syslog
to understand what went wrong (search for "media-keys"). It's likely that you had problems with the dynamic libraries in step 8 above.