Where does Ubuntu store its keyboard shortcut configuration?

Since Ubuntu 17.10

On this paths:

dconf dump /org/gnome/desktop/wm/keybindings/
dconf dump /org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/  # Custom

You can also use dconf-editor (GUI) or gsettings (CLI).

Since Ubuntu 12.10-17.04

~/.config/dconf/user (in dconf-editor: org.gnome.settings-daemon.plugins.media-keys.custom-keybindings (custom shortcuts)

~/.config/compiz-1/compizconfig

Until Ubuntu 12.04

The shortcuts are placed differently depending on witch desktop you are using (gnome/unity, kde, xfce, lxde,etc).

For gnome, they are under
~/.gconf/desktop/gnome/keybindings (custom shortcuts)

and under
~/.gconf/apps/metacity.


Your window manager gets the any key events before applications do, so if it wants to consume those events, it does so and your applications will never receive them. If the window manager does not want to react to the key events itself, it passes them along to the application.

You can verify this by yourself in the following way:

  1. Start a terminal.
  2. Start xev | grep KeyPress, the X event viewer.
  3. Press Alt, note that xev shows that it got the key event in its terminal window.
  4. Press Ctrl, again note that xev got the event. Take note of what the terminal window looks like right now.
  5. Press Left arrow to go to another workspace. (I'm assuming you have that as a window manager shortcut key.)
  6. Press Right arrow to go back to where you are running xev. Note that it never received any key events for you switching workspaces via left and right arrow keys -- the output is the same as it was in Step 4.

So you see that the window manager in practice gets all key events and if it does not want to capture them, it passes them along to the application. The application then gets to do the same for its own widgets (like how you can press Enter all day long in your web browser but it won't do anything until you put the cursor in the address bar or some field where you can enter text).

It is up to the application to set its own shortcuts, and applications are configured independently of each other.

In KDE 3.x, if I recall correctly, you could set the default shortcuts (e.g. Ctrl-s for save) in the KDE Control Center and it would apply to all applications written with the Qt toolkit, but I don't know if that's still possible since their switch to KDE 4.


No, there is no single place where all shortcuts are stored. Applications can choose to store their configurations wherever they choose.

That said, you're mostly looking at two levels: the application level (like Ctrl-C for copy in Firefox), and the window manager level (like Win+D to show the desktop). Compiz uses gconf to store its configuration.

For applications, you can roughly divide them by their toolkits. Namely, GTK apps use gconf too.

Surely, Ubuntu must store this somewhere for the key combination pressed on the keyboard to be directed to what it's connected with?

Not quite. The focussed application gets first kick at an X keyboard event, but if it doesn't, it bubbles up to other applications, namely the window manager. Thus, you can have a game that captures Alt+F4 and doesn't close the window (damn you, Jamestown!). I think you're thinking it goes to some central event router, then matched against some database, and routed to its destination. It's more like passing a bottle of drink around: pass, take a swig if you want and pass the rest, or take the whole thing and be greedy.

The Linux/FOSS environment (you may have noticed) is pretty democratic, and getting all applications to agree on a single central keyboard configuration repository is a fool's errand. For one thing, you've got unmaintained applications that were written a long time ago and wouldn't know about it.

Update: According to the Xlib docs on the subject:

Starting with the source window, the X server searches up the window hierarchy until it locates the first window specified by a client as having an interest in these events. If one of the intervening windows has its do-not-propagate-mask set to prohibit generation of the event type, the events of those types will be suppressed.

Also,

To receive KeyPress , KeyRelease , ButtonPress , and ButtonRelease events, set KeyPressMask, KeyReleaseMask, ButtonPressMask, and ButtonReleaseMask bits in the event-mask attribute of the window.

And you can set an attribute to disable propagation.

The problem is, you don't tell X which keys to listen for, so you can never tell a priori what keys the application listens for (let alone what they do) or really whether they intend to propagate it up if they are in fact listening for it. Thus, a central registry is impossible at the X level, so you'd have to do it at the toolkit level, which is merely practically impossible. :D