- About Us
There are literally dozens of window managers that you can use with your favorite desktop environment to get a beautiful and appealing desktop. If you want to fine-tune your window manager, here are two programs that can help you control everything from application window size to pinning an application to all workspaces to fixing a position for your application windows to resizing desktops. One, wmctrl, works with any window managers that adheres to the Extended Window Manager Hints (EWMH), while Devil's Pie is a window-matching utility, which means it can configure application windows based on defined rules.
wmctrl is a command-line utility that can be used to manipulate or control various aspects of application windows and the desktop environment. Fedora and Ubuntu users can use yum or apt-get respectively to install wmctrl on their machines, or you can grab the compressed tarball from the software's Web site. According to the site, wmctrl is known to work with IceWM, Blackbox, Metacity, Openbox, Kwin, Enlightenment, and several other window managers.
There isn't much documentation for wmctrl, but the detailed man page is enough to start you in the right direction. The command
wmctrl -m will print out details about the desktop environment and the window manager. You can use the -l switch to get a list of all the active windows (applications) in space-separated columns. The first column is a hexadecimal number, which is unique for each window. The second is the desktop number, or the workspace -- 0 means the first workspace, 1 means the second, and so on. The machine name is listed in the third column, and the last column contains the window title:
wmctrl -l 0x03400175 0 localhost.localdomain XChat: linuxlala @ FreeNode (formerly OpenProjects.net) / #fedora (+tncrRL) 0x0240007e 0 localhost.localdomain Gmail - Inbox (33) - Mozilla Firefox 0x03c00035 0 localhost.localdomain wmctrl_devilspie_article (~/Desktop) - gedit 0x03e0001e 0 localhost.localdomain linuxlala@localhost:~
To manipulate any window, you need to know its title. The command,
wmctrl -a gedit will make the Gedit window active. This is most useful when you have several windows open in various workspaces. But what happens if you are simultaneously working with several Gedit windows? You can easily retitle any window with the command
wmctrl -r :SELECT: -T "cool feature". The :SELECT: option enables you to select the application window whose title you wish to change by clicking on it -- though not by using the Alt-Tab key combination. When you click on any window, its title immediately changes to the one specified. You can specify the current title of the window instead of using the :SELECT: option. For example,
wmctrl -r XChat -T "IRC" would retitle my XChat window to IRC.
You can also resize windows with wmctrl using the
-r and the
-e switches. The
-r switch specifies a window and the
-e switch resizes a window already specified.
wmctrl -r gedit -e 1,20,30,750,1200 would resize the Gedit application window. For this to work, the application window must not be in a maximized state. The
-e swtich expects five values: gravity, X-position, Y-position, width, and height. The X and Y positions respectively describe the position of the window from the left and top of the screen. Gravity is used to specify the position of the window's frame and it can be any value from 1 to 9. Each value maps to a position on the screen. The values it can take are northwest (1), north (2), northeast (3), west (4), center (5), east (6), southwest (7), south (8), and southeast (9).
Devil's Pie can perform all of the same functions as wmctrl, but it's actually a more powerful tool for manipulating windows. Being a window matching utility, Devil's Pie works on a set of defined rules. As new application windows are created, Devil's Pie looks through the defined rules to see if any are defined for the window being created and then, based on the defined rules, it models the window.
Devil's Pie was created to incorporate window matching into Metacity, the default window manager on the GNOME desktop environment. The rules for each window are defined as a set of S-Expressions. To install Devil's Pie, simply grab the compressed tarball from its Web site, or use yum or apt-get depending on the distribution running on your machine. Rules for each window are defined in individual files with a .ds extension and stored in the ~/.devilspie directory.
The first file you should create is the debug.ds file. Open a text editor and type
debug. Save this file as ~/.devilspie/debug.ds. When you now run Devil's Pie, it will display on the screen the application name, window name, window class, and various other properties of all the open windows. You should always refer to your applications with the correct names to make Devil's Pie perform correctly.
Let's create a rule that forces the Gedit text editor to always open in the second workspace:
(if (is (application_name) "gedit") (begin (set_workspace 2) ) )
Save this as gedit.ds in ~/.devilspie. Open a terminal, type
devilspie, and press Enter. Now when you launch Gedit, it will automatically shift to the second workspace no matter what workspace you launch it from.
You can use regular expressions when writing rules. For example, if you have two active instances of gnome-terminal, you can use regular expressions to write a rule for each:
(if (matches (application_name) "linuxlala") (begin (set_workspace 3) ) )
The above rule applies to the default gnome-terminal. With the matches keyword, you can make Devil's Pie look for partial matches. Suppose you have another gnome-terminal window within which you've browsed to the /etc directory. To refer to this window, you can use
(matches (application_name) "etc". If you wish to make use of regular expressions, you must also use the matches keyword in place of is.
You can similarly write rules to make your applications open as maximized or in a certain position of the screen. You can also use pin to make sure the application is available on all workspaces. This can be helpful for IM or chat programs that you might want in all workspaces so as to not miss an important message.
You can even perform multiple actions on an application by adding them within the begin structure.
(if (matches (application_name) "linuxlala") (begin (set_workspace 3) (maximize) (undecorate) ) )
To add Devil's Pie to your startup programs list, click System -> Preferences -> Personal -> Sessions. Click New and type Devil's Pie in the Name field and
/usr/bin/devilspie in the Command field. Now every time you log into your machine, Devil's Pie will run automatically and manipulate the applications as described in the rules.
wmctrl and Devil's Pie put you in charge of your windowed applications by giving you complete control over all their aspects.