Controlling windows in X with wmctrl

Restarting a computer sucks. You have to typing in passwords, starting your windows manager, get all your default applications going and so on. It takes me several minutes to restart a system and get it into a workable state.

Particularly in the last days, I had to restart various times forcefully. A critical error in the intel grahicstack breaks the multi monitor setup. Not working suspend to ram. A half way down suspended system, in which the fan keeps being active while remaining part of the systems is without a responses. Each time a system reset was necessary.

However, i found some useful tool that allows me to ‘accelerate’ the startup by quite a bit. wmctrlis the tool, that was found by browsing through the man page of fluxbox. What’s it? It’s a protocol the X Server is speaking, allowing to ask the Windows Manager for some information and/or actions. It allows you to give the windows manager some commands. Neat. The installation on archlinux was easy:

pacaur -S wmctrl

Why do you need this? Simple: To allow to start up any application in fluxbux and place it on the right virtual desktop. Window Manager like KDE allows you to remember the state of windows before a logout, fluxbox don’t. So when you login again with KDE, all your old windows will be start on the right virtual desktop. But KDE consumes way to much resources…so a solution for fluxbox is necessary.

The man page has all the details one might need to use it. I wrote down an example:

urxvt -title urxvt -e tmux a &
sleep 1
wmctrl -F -r 'urxvt' -t 2

What does this example do?

It starts a urxvt terminal with a define title and within it will start the tmux a to re-attach to an open tmux session. Defining the title allow wmctrl to find the windows to move it to the right virtual desktop. The ID of a virtual desktop can be displayed with wmctrl -G -l command. One thing that did’t work out (yet), was setting the window to fullscreen. You can start urxvt will the paraemter -g with the right size. But this lead to some strange rendering bug and you can’t read anything from the terminal down. wmctrl can do this too. But I didn’t do it yet.

Anyways, this makes a reboot a bit easier. But in the end, reboot sucks.