wmii-3.1 configuration in Ruby
- Quick & light Ruby interface
- Interactive Ruby shell
- Logging and recovery
- Related works
- Screen shots
- Requirements
- Interactive live demonstration
- Installation
This article presents my patches to the wmii window manager and my Ruby-based configuration thereof. You can download wmii-3.1 with my patches pre-applied or clone it yourself from my GitHub repository:
git clone git://github.com/sunaku/wmii.git
Quick & light Ruby interface
The ruby-ixp library is used to communicate directly with wmii’s IXP file system instead of the wmiir tool. Thus, wmii’s responsiveness is dramatically improved.
A light abstraction layer
is built atop the ruby-ixp library to encapsulate access to wmii. This layer
includes the ability to dynamically traverse the IXP file system by simply
calling methods (thanks to Ruby’s method_missing
facility). For instance,
you can write “foo” into the file /view/sel/sel/tags
via any of the
following:
Wmii.current_client.tags = 'foo'
Wmii.fs.view.sel.sel.tags = 'foo'
Ixp::Client.write '/view/sel/sel/tags', 'foo'
Interactive Ruby shell
The wmiish tool can be used to interact with wmii without having to install my wmiirc. It presents the previously discussed light abstraction layer within a standard IRB session. In fact, it even accepts the standard IRB command-line options!
Logging and recovery
Unhandled exceptions are logged to ~/.wmii-3/wmiirc.log
and then reported to
the user, who can then choose to recover from or fix the error. Thus, you
won’t be left helpless if your configuration breaks.
Related works
ruby-wmii is Mauricio Fernandez’s popular Ruby-based configuration for wmii. It is very sophisticated and extensible, through a nice plugin interface.
Screen shots
As they say, “a picture is worth a thousand words”. So whet your appetite with these screen shots before diving into the discussion below. But don’t forget that you’ll be trying these out yourself shortly, in the interactive live demonstration!
A colorful mess
I first made a mess, colored generously for aesthetics, in my view by
executing for c in red green blue black orange brown gray navy gold; do xterm
-bg $c -title $c -e read & done
in my shell. Then, I started up wmiish to
demonstrate some of the stuff discussed below.
Automated arrangements
The tile arrangement, caused by the current_view.tile!
command:
The grid arrangement, caused by the current_view.grid!
command:
The diamond arrangement, caused by the current_view.diamond!
command:
Multiple client selection
Here I reorganized the view to give enough space for the terminal by typing the following code.
# apply tiling arrangement
current_view.tile!
# set second column to stacking mode
current_view[2].mode = :stack
Next I selected the three primary colored clients (NOTE: I normally do this by right-clicking on their title bars or through other shortcuts, because that’s how my wmiirc‘s event loop is configured) by typing the following code. Notice that those clients also appear in the “SEL” view.
# the primary colors
colors = %w[ red green blue ]
# select clients named after the primary colors
clients.each do |c|
if colors.include? c.name
c.select!
end
end
Finally I put each client in the selection into its own view by typing the following code.
# tag each selected client with its own name
selected_clients.each do |c|
c.tag! c.name
end
Requirements
Ruby
You need at least version 1.8 of Ruby installed.
wmii
Apply this giant patch, which includes all of my patches, before compiling and installing wmii-3.1. Note that if you’re only interested in trying wmiish, then only the “unique client ID numbers in file system” patch is necessary.
$ ls
wmii-3.1.patch wmii-3.1.tar.gz
$ tar zxf wmii-3.1.tar.gz
$ patch -p0 < wmii-3.1.patch
patching file wmii-3.1/cmd/wm/area.c
patching file wmii-3.1/cmd/wm/client.c
patching file wmii-3.1/cmd/wm/fs.c
patching file wmii-3.1/cmd/wm/wm.h
$ cd wmii-3.1
$ make install
Patches
Column focus wraps horizontally in a view. When the right-most column is currently focused, selecting the nonexistent column at the right will put focus on the left-most column, and vice versa.
Unique client ID numbers are presented in the IXP file system to avoid many race conditions and simpify the task of scripting. For example, without this patch, when the number of clients in an area changes, the area’s indices, through which those clients are accessed, change. Thus, you lose track of your client(s) of interest every time there is a change to the current area. :-(
Prevents a segfault from occuring when a client is sent to the column it is already in.
Enables sending of clients from the floating area to any other area, via the
sendto area_number
command.Enables swapping of a client with the currently focused client in any column, via the
swap column_number
command.Enables creation and focusing of an empty view, as long as it is currently focused, via the
view name_of_view
command.Fixes a bug that causes wmii-3.1 to freeze when the /event file is read too quickly by too many readers.
Interactive live demonstration
Once you’ve satisfied the requirements, you can try this demonstration (in real-time!) using wmiish. Also, have a look at the provided documentation for available commands and my wmiirc configuration for more examples to try.
Operations on multiple clients
You can select multiple clients and perform operations on them. This is useful when you want to do something with a group of clients but don’t want to manually focus one, perform the action, focus the next one, and so on.
Another important aspect is that selected clients stay selected until they are unselected. This allows you to continue performing tasks on the selection without having to reselect the same clients after every operation.
For example, try executing the following commands in wmiish.
- Make all clients, except those in the current column, also appear inside the “foo” view:
current_view.select! current_area.unselect! selected_clients.each {|c| c.tag! 'foo'}
- Make all unselected clients in the current view also appear in the “qux” view:
current_view.invert_selection! selected_clients.each {|c| c.tag! 'qux'}
current_view.invert_selection!
Easy column manipulation
You can insert a group of clients to the top, bottom, or after the currently focused client of any column using these simple methods.
For example, try executing the following commands in wmiish.
- Send all clients in the current column to the floating area:
current_view[0].concat! current_area
- Move the second two clients from the first column to the top of the third column:
current_view[3].unshift! current_view[1].clients[1..2]
Automated client arrangement
You can arrange all clients in the current view using these automated arrangements. They help you maintain clean, uncluttered, usable views.
For example, try executing the following commands in wmiish.
- Apply LarsWM style tiling arrangement:
current_view.tile!
- Apply wmii-2 style grid arrangement:
current_view.grid!
- Apply a diamond-shaped arrangement:
current_view.diamond!
- Put each client in its own column:
current_view.grid! 1
- Put three clients per each column:
current_view.grid! 3
- Squeeze all clients into a single column:
current_view.grid! 0
Temporary working area
You can send selected clients to a temporary working area (see the rationale
and use case for
this idea) and bring them back again when you’re finished. Try this by
executing toggle_temp_view
in wmiish.
Installation
Download and extract the contents of the package into your
~/.wmii-3
directory.Edit the
~/.wmii-3/wmiirc-config.rb
file to accomodate your needs.Reboot wmii.