How to have two sets of shortcut keys for Compiz grid commands "Put Left" and "Put Right"?

I would like to have two shortcuts each for "Put Left" and "Put Right" for positioning windows in the left and right position.

Specifically, I would like the default keys as well as some custom keys that are more accessible when typing:

i.e.:

  • Put Left: <Control><Alt>KP4 and <Shift><Alt>H
  • Put Right: <Control><Alt>KP6 and <Shift><Alt>L

The CompizConfig dialogue box appears to only allow one shortcut key to be assigned.

How can I have two shortcut keys enabled for a single grid compiz-config setting?


One way to do it is simply map the custom secondary keyboard shortcut to the primary (Compiz) shortcut using xdotool.

  1. xdotool is a small command-line utility which allows automation of keyboard and mouse clicks/movements; install it with sudo apt-get install xdotool
  2. We'll assume here that the default shortcuts for Grid Left/Right are as below: (Ctrl+Super+Left/Right):

    enter image description here

  3. Open Settings...Keyboard, and go to the Shortcuts tab. Click + to create a custom shortcut, naming it say Compiz GridRightAlt, and setting the "Command" field to:

    xdotool key --clearmodifiers Ctrl+Super+Right
    

    Click Apply. The right-column will say Disabled, click on it and you'll see "New Accelerator": press your shortcut key combo, e.g. Shift+Alt+L.

    enter image description here

    • Repeat the steps for the left Compiz GridLeftAlt, setting the command to:
    xdotool key --clearmodifiers Ctrl+Super+Left

    and the shortcut keycombo to Shift+Alt+H.

Close the Keyboard settings and that's it!


As far as I can tell compiz will only allow one keybind as you noticed.

However with a tiny bit of work you can get around this limitation!

First install pycompiz found here. If you have svn you can do this using

svn checkout http://pycompiz.googlecode.com/svn/trunk/ pycompiz-read-only

Install after navigating into the projects folder,

sudo python setup.py install

Next create these two tiny python scripts, and place them in your ~/bin folder. Then either make them executable (chmod u+x FILENAME) or when setting the keybindings use python SCRIPTNAME.

file: putleft

#/usr/bin/python 
import compiz
compiz.call('grid', 'put_left')

file: putright

#/usr/bin/python 
import compiz
compiz.call('grid', 'put_right')

Lastly you can create two custom command shortcuts for each of these scripts in the custom commands section of the compiz config (ccsm), and hey presto - two keybinds to achieve the same effect. As mentioned above, if you made the scripts executable, the commands will be putleft and putright, else they will be python ~/bin/putleft and python ~/bin/putright.

Enjoy!