Jun'uary
Jan'uary » 日志 » Add awesome like layout to WMII
Add awesome like layout to WMII
Jan 发表于 2008-08-31 23:42:26
Awesome is another tiling window manager which has many users on this planet (maybe more than wmii users?) It's very similar to xmonad(both use vim-style key-bindings), the main difference between them is awesome's configuration is written in a simple self-defined syntax instead of haskell which used by xmonad.
Simple syntax for configuration means easy to use, but its possibility of customization may be less than wmii and xmonad, that's why I still use wmii now. However, awesome(and xmonad) has an useful concept named 'layout' which wmii lack of. User is always working in a certain layout. Usually layout is composed of a main window who occupies the most area and other windows.

Screenshot is an example of layout: vim is now the main window. Awesome will move the new create window to the right area (the second picture shows the screen after I created a new terminal in wmii with awesome layout support), so you can do some temporary work or tail a log there then come back to main window.
In the contrast, wmii always open new window in the same column, make your main workarea smaller, and you have to manually move it to a new column (the last picture shows the screen after I created a new terminal in normal wmii).
That's why I wrote this piece of code to simulate the behavior of awesome in wmii. I think the code is self-explaination enough. It must be used with ruby-wmii.
First create a new file named jan-plugin.rb (or whatever name you like) in $HOME/.wmii-3.5/plugins dir.
Extend WMII::Configuration in your wmiirc-config.rb:
Set colrules in wmiirc-config:
Then you'll have a awesome like layout in wmii!
ps. Notice how cool is ruby's kernel#open method? In the script I pass it a string "|wmiir read /event", then it will read "wmiir read /event"'s output from pipe! So smart. If we don't add "|" before the string the call will block, because read /event will never get EOF. kernel#open can do more than this, you can even pass a url to it and it will fetch the resource for you by using open-uri lib.
Simple syntax for configuration means easy to use, but its possibility of customization may be less than wmii and xmonad, that's why I still use wmii now. However, awesome(and xmonad) has an useful concept named 'layout' which wmii lack of. User is always working in a certain layout. Usually layout is composed of a main window who occupies the most area and other windows.

Screenshot is an example of layout: vim is now the main window. Awesome will move the new create window to the right area (the second picture shows the screen after I created a new terminal in wmii with awesome layout support), so you can do some temporary work or tail a log there then come back to main window.
In the contrast, wmii always open new window in the same column, make your main workarea smaller, and you have to manually move it to a new column (the last picture shows the screen after I created a new terminal in normal wmii).
That's why I wrote this piece of code to simulate the behavior of awesome in wmii. I think the code is self-explaination enough. It must be used with ruby-wmii.
First create a new file named jan-plugin.rb (or whatever name you like) in $HOME/.wmii-3.5/plugins dir.
Plugin.define "jan" do
author '"Jan X" <jan.h.xie@gmail.com>'
layouts = {:default => nil,
# keep left column as main area
:right_main => lambda do |wmii, id|
wmii.write '/tag/sel/ctl', 'send sel right'
end,
:left_main => lambda do |wmii, id|
columns = wmii.read('/tag/sel/index').split("\n")
has_only_one_column = (columns.find_all{|l| l =~ /^#/}.size < 3)
cur = columns.find{|l| l =~ /#{id}/}
# the strategy used here:
# 1. do nothing to screen terminal
# 2. when there's only one column, create new column at right, move new window to the column
# 3. when there's multi column, if the new window is created in column 1, move it to right column
# 4. else, do nothing
wmii.write '/tag/sel/ctl', 'send sel right' if cur && (cur =~ /urxvt:URxvt/) && !(cur =~ /urxvt:URxvt:screen/) && (has_only_one_column || (cur[0..0] == '1'))
end
}
bar_applet('layout', 999) do |wmii, bar|
rules = wmii.plugin_config['jan:layout']['rules'] || {}
tag = wmii.read('/tag/sel/ctl').split("\n")[0]
# bar action
switch = lambda do
end
wmii.on_key(*([wmii.plugin_config["jan:layout"]["layout_toggle_keys"] || ["MODKEY-/"]]).flatten, &switch)
bar.on_click(&switch)
bar.data = rules[tag] || "Default"
Thread.new do
open("|wmiir read /event") do |is|
loop do
case is.gets
when /CreateClient (.*)/
id =
tag = wmii.read('/tag/sel/ctl').split("\n")[0]
layouts[rules[tag]].call(wmii, id) if rules[tag] && layouts[rules[tag]]
when /FocusTag (.*)/
bar.data = rules[] || "Default"
end
end
end
end
end
end
Extend WMII::Configuration in your wmiirc-config.rb:
class WMII::Configuration
def colrules(*val)
if val[0].nil?
@ixp_conn.read("/colrules")
else
@ixp_conn.write "/colrules", val[0]
end
end
end
Set colrules in wmiirc-config:
WMII:Configuration.define doNow the new created column in www tag will has a width equal to 30% of screen width. Finally set applet params and use the new applet:
...
colrules <<EOF
/www/ -> 70+30
/.*/ -> 60+40
EOF
...
end
plugin_config["jan:layout"]["rules"] = {
"www" => :left_main
}
from "jan" do
use_bar_applet "acpi", 850
use_bar_applet "layout", 950 # here we tell ruby-wmii to use the new defined layout applet
use_binding "open-document" # this's another extension I made, I'll post it later when I have time
end
Then you'll have a awesome like layout in wmii!
ps. Notice how cool is ruby's kernel#open method? In the script I pass it a string "|wmiir read /event", then it will read "wmiir read /event"'s output from pipe! So smart. If we don't add "|" before the string the call will block, because read /event will never get EOF. kernel#open can do more than this, you can even pass a url to it and it will fetch the resource for you by using open-uri lib.
曾经的这一天...
- » 2006年: 莫斯科地铁站的同志们
- » 2006年: 把YouTube上的Video转换成Xvid或者DivX格式
- » 2005年: Microsoft收购了一家VoIP公司
- » 2005年: Microsoft要来中国淌ERP的混水
- » 2005年: Opera 10周年,现在可以免费注册...
- » 2005年: Linux with Laptops, Notebooks, PDAs, Mobile Phones and Other Portable Devices
- » 2005年: Freemind
- » 2005年: Chinese go mental for nude web chat
- » 2005年: GM drives Hummer-branded laptop
- » 2005年: 创新说苹果侵犯了它的专利,不过还没上法庭
相关日志:
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
