How is a keyboard shortcut given to the correct program

Architecturekeyboard shortcutsx11

in Ubuntu (or for that matter most other linux distros), I could use the shortcut ctrl+t to open a new tab (in firefox or similar), or I could use alt+tab to make unity switch highlighted window, or I could use alt+ctrl+F<1-6> to get to another tty. What part of linux handles and resolves these shortcuts? What if several programs/processes share the same shortcut, how is priority resolved?

(For the latter I'm assuming that this is only relevant for programs on different 'levels', e.g. firefox and the session script might compete, but firefox and chrome would never compete because they should not both be responding at the same time)

Best Answer

What part of linux handles and resolves these shortcuts?

For the most part, individual applications or a window manager(WM)/desktop environment(DE). There are a few caught and handled by the kernel, such as VT switching with Cntl-Alt-F[N].

The actual event propagates:

  • From the kernel
  • To the Xorg server
  • To the WM/DE
  • To the application

If caught and handled at any point therein, it will probably not continue to the next level down.

If you run a (non-GUI) application inside a GUI terminal, the GUI terminal will have precedence over it.

What if several programs/processes share the same shortcut, how is priority resolved?

The WM/DE will take priority over the application.

Related Question