wmctrl -- Shade, move, resize windows from a shell
wmctrl tool. With this you can access all of the Extended Window Manager Hints functions of your windows from the command line. What does this mean? Imagine hitting a key sequence and a specific window moves, and resizes to a certain section of your desktop. Hit another button and it shades, no matter what window has focus. I'll get into how to unlock all of this potential below.
Now, being a user of the enlightenment window manager for some time, I have been accustomed to being able to script window events through their included eesh tool. The downside to eesh is that it only works for enlightenment. This sort of feature was one of the main things keeping me using enlightenment apart from fine-grained window memory. Since fluxbox recently gained similar window memory functionality all that was missing was eesh--until today. The wmctrl tool works with any window manager that supports Extended Window Manager Hints which means that it will work with icewm, kwin, metacity, openbox, fluxbox, enlightenment, sawfish, xfce, and a ton of other window managers.
To illustate why this is a cool program, I will show you how to use it to create a "quake console." If you have ever played doom or quake, you are familiar with the little command console that shows up whenever you press the ~ key. I wanted to have similar functionality on my desktop so that when I hit alt-~ a terminal would pop down to type in, but otherwise it would disappear out of my way. To do this you need to hide a window up at the top of your screen in a shaded state, and then have it unshade whenever you hit ~ (or alt-~ so you can type ~ inside the terminal).
First, download wmctrl from http://sweb.cz/tripie/utils/wmctrl/, unpack it, and build it with the standard
Once wmctrl is installed, type
The first column is a unique ID number assigned to each window, the second column specifies which desktop the program is on, the third column tells you which machine the window is running from, and the fourth column tells you the all-important title of the window.
If you want to create a quake console, open a terminal and use command-line arguments to give it a unique title. This argument varies depending on your terminal, but if you used xterm you would type something like
Now, to shade this window, all you need to do is open up a different terminal and run
This is only the beginning of the possibilities a program like this presents. Say you usually like your web browser to fill up your desktop, except for when you are IMing with friends. In those cases you resize it to make room for both windows. With this program you could set up all of those resizing and movement functions inside a script and bind it to a key sequence. Want to browse and IM? Hit a key sequence and all the windows move and resize. You can then hit another key sequence and be back where you started. If you wanted, you could even write a script that made a window bounce across the screen.
The sorts of things you can do with wmctrl are mostly limited by your own scripting ability. What's nice about it is that once you have your scripts set up, you can move from one window manager to the next and your scripts will still work. Want to switch from KDE to Gnome? All you have to do is reset your key bindings and wmctrl will still work the same.
Kyle Rankin is a system administrator who enjoys troubleshooting, problem solving, and system recovery. He is also the author of Knoppix Hacks, Knoppix Pocket Reference, Linux Multimedia Hacks, and Ubuntu Hacks for O'Reilly Media.
Comments on this weblog
Return to weblogs.oreilly.com.