Pages - Menu

Saturday, September 20, 2008

Window control with wmctrl

wmctrl is a useful little commandline tool for manipulating windows. it works with any window manager that complies to the freedesktop.org spec, which is most common ones

to install it within a debian-based distro, just type sudo apt-get install wmctrl

what can it do? alot, but i mostly use it for resizing windows to certain sizes (which can be useful for testing a web layout in smaller resolutions), positioning windows at a particular place on the monitor, and for "shading" windows, which means drawing the window up to the titlebar

to see what windows wmctrl can see, type wmctrl -l in a terminal, you'll get a list like this:

jamie@one:~$ wmctrl -l
0x01000003 -1 one Bottom Expanded Edge Panel
0x0100002a -1 one Bottom Expanded Edge Panel
0x0120001f -1 one Desktop
0x028000c8 0 one : Linux Aleph : Tips for using Linux - Mozilla Firefox
0x03200021 0 one jamie@one: ~

so you can see a window ID, a number which is the workspace the window appears on (-1 means "sticky" on all workspaces), the X server the window is running on (my PC's hostname is "one"), and the window titles

to address a window, you can either use the window ID, or do a match on part of the title. so wmctrl -i -r 0x028000c8 and wmctrl -r Firefox will both address the same window. you can also address windows with -r :ACTIVE:, which is the active window, and -r :SELECT:, which gives you a mouse cursor to choose the window you wish to control

to resize a window, use the -e parameter, with a syntax that goes gravity,x,y,width,height, and a -1 option leaves a pixel value unchanged

don't worry about changing window gravity, just set it to 0, so to resize our Firefox window inplace to 1024x768, type wmctrl -r Firefox -e 0,-1,-1,1024,768 or to positon a window 100 pixels in without resizing it, use the command wmctrl -r Firefox -e 0,100,100,-1,-1

to change window shading, use the option -b toggle,shaded, you could even bind this to a keystroke (like Ctrl-Escape) to make it easy to get to quickly

there is alot more wmctrl can do, such as maximising, minimising, changing titles, the list goes on. type man wmctrl in a terminal to find out more

No comments: