Key Bindings HOWTO
Not logged in

Minx is a keyboard-centric window manager. Thus, it allows you to bind arbitrary keystroke combinations to arbitrary functions. Minx uses its hooks mechanism to support key bindings. This page explains how you can customize Minx by specifying your own key bindings.

Key Binding Names

A key binding is simply a hook with a special pattern to its name. This pattern is shown below:

   ^(([CAS]|M[1-5]?)-)*key$

The above quasi-regular expression can be boiled down to:

   [modifier-]*key

Thus, the name of a key binding consists of zero or more hyphen-separated modifier key specifications followed by a single non-modifier key. The supported modifiers are:

The key specification is the name of a keysym as returned by the X server. Usually, these would be the printable characters on your keyboard and the function and special keys (Home, Insert, Page Up, etc.). Hopefully, the following examples clarify the above technobabble:

Name Key Binding
C-A-T CTRL + ALT + T
S-F1 SHIFT + F1
A-Tab ALT + Tab
M-R META + R
M5-S Mod5 + S
C-C CTRL + C
A-S-S ALT + SHIFT + S

If you're familiar with Emacs, Minx's key bindings specification should be quite familiar.

Adding Key Bindings

Because key bindings are just specially named hooks, adding a new key binding is simply a matter of adding a new hook. The following example shows you how to get Minx to cycle input focus using F1 and SHIFT + F1 and to launch The Gimp with Mod4 + G:

   #!/usr/bin/env python

   import minx

   wm = minx.core.wm()
   wm.hooks.add(  'F1', wm.focus_next)
   wm.hooks.add('S-F1', wm.focus_prev)
   wm.hooks.add('M4-G', lambda: wm.spawn('gimp'))
   wm.start()

You are not restricted to tying keys to window manager functions. The hook functions for key bindings can do pretty much anything you can code up in Python. The following non-functional example illustrates the principle:

   #!/usr/bin/env python

   import minx

   def skynet():
       fire_all_nukes(get_launch_codes())
       wait_for_explosions()
       if not kill_remaining_humans():
          invent_time_machine()
          send_terminator_to_1984()
          try:
             kill_sarah_connor()
          except unable_to_kill_sarah_connor:
             just_finish_em_off_in_the_future()

       # Okay humans terminated; now...
       get_those_pesky_bears()

   wm = minx.core.wm()
   wm.hooks.add('C-A-Delete', skynet)
   wm.start()

Now, when you press CTRL + ALT + DEL, you will end up destroying humanity. Umm, that's pretty rude; don't do it, m'kay.

NOTE: Initiating global mayhem will probably be fairly time-consuming. And, as pointed out in the Hooks HOWTO, hook functions should be quick. Thus, you may want to execute the skynet() function in the above example in another thread or process so that the window manager can return to the more mundane task of managing your windows.

Removing Key Bindings

In the benign focus cycling example from the previous section, we setup F1 and SHIFT + F1 to switch input focus from window to window. But Minx already has defaults for that, viz., ALT + Tab and ALT + SHIFT + Tab. Once you've specified your own key bindings for some purpose, you may want to disable the defaults (if any). To do that, you will have to call the remove() method on the window manager object's hooks attribute.

Here's some relevant code:

   #!/usr/bin/env python

   import minx

   wm = minx.core.wm()
   wm.hooks.add(  'F1', wm.focus_next)
   wm.hooks.add('S-F1', wm.focus_prev)
   wm.hooks.remove(  'A-Tab')
   wm.hooks.remove('S-A-Tab')
   wm.start()

Now, the only way to switch input focus will be to use F1 and SHIFT + F1. Of course, after removing the default key bindings, you can also rebind those keys to some other functions.

Renaming Key Bindings

Another way to install your own key bindings for existing window manager functions is to rename the defaults:

   #!/usr/bin/env python

   import minx

   wm = minx.core.wm()
   wm.hooks.rename(  'A-Tab',   'F1')
   wm.hooks.rename('S-A-Tab', 'S-F1')
   wm.start()