#!/usr/bin/env lua -- -- Copyrigh (c) 2007, Bart Trojanowski -- -- Some stuff below will eventually go to a separate file, and configuration -- will remain here similar to the split between the wmii+ruby wmiirc and -- wmiirc-config. For now I just want to get the feel of how things will -- work in lua. -- -- http://www.jukie.net/~bart/blog/tag/wmiirc-lua -- git://www.jukie.net/wmiirc-lua.git/ -- io.stderr:write ("----------------------------------------------\n") -- load wmii.lua local wmiidir = ("~/.wmii-lua"):gsub("^~", os.getenv("HOME")) package.path = wmiidir .. "/core/?.lua;" .. wmiidir .. "/plugins/?.lua;" .. package.path require "wmii" require "os" -- Setup my environment (completely optional) local hostname = os.getenv("HOSTNAME") local homedir = os.getenv("HOME") or "~" os.execute ("setxkbmap us") os.execute ("/usr/bin/lsusb | grep -q PFU-65 || xmodmap .xmodmap-oxygen") -- os.execute ("if ( ! ssh-add -l >/dev/null ) || test $(ssh-add -l | wc -l) = 0 ; then " -- .. "ssh-add /dev/null&") --[[ if type(hostname) == 'string' and hostname:match("^oxygen") then -- lsusb -v | grep -i 'vendor.*0472.*product.*0065' os.execute ("xmodmap ~/.xmodmaprc") end ]]-- os.execute ("xmodmap ~/.xmodmap-thinkpad-buttons") -- This is the base configuration of wmii, it writes to the /ctl file. wmii.set_ctl ({ border = 1, font = '-windows-proggytiny-medium-r-normal--10-80-96-96-c-60-iso8859-1', focuscolors = '#FFFFaa #007700 #88ff88', normcolors = '#FFFFFF #222222 #333333', grabmod = 'Mod1' }) -- Set slightly different colors on each screen. wmii.set_screen_ctl(0, { focuscolors = '#FFFFaa #007700 #88ff88' }) wmii.set_screen_ctl(1, { focuscolors = '#FFFFaa #770000 #ff8888' }) wmii.set_screen_ctl(2, { focuscolors = '#FFFFaa #000077 #8888ff' }) -- This overrides some variables that are used by event and key handlers. -- TODO: need to have a list of the standard ones somewhere. -- For now look in the wmii.lua for the key_handlers table, it -- will reference the variables as getconf("varname"). -- If you add your own actions, or key handlers you are encouraged to -- use configuration values as appropriate with wmii.setconf("var", "val"), or -- as a table like the example below. wmii.set_conf ({ xterm = 'x-terminal-emulator', xlock = '/home/oxygen/bart/usr/bin/slock || slock', --debug = true, }) -- slock needs to be suid os.execute ("sudo chown root.root "..homedir.."/usr/bin/slock") os.execute ("sudo chmod +s "..homedir.."/usr/bin/slock") -- colrules file contains a list of rules which affect the width of newly -- created columns. Rules have a form of -- /regexp/ -> width[+width[+width...]] -- When a new column, n, is created on a view whose name matches regex, the -- n'th given width percentage of the screen is given to it. If there is -- no nth width, 1/ncolth of the screen is given to it. -- wmii.write ("/colrules", "/.*/ -> 50+50\n" .. "/gaim/ -> 80+20\n") -- tagrules file contains a list of riles which affect which tags are -- applied to a new client. Rules has a form of -- /regexp/ -> tag[+tag[+tag...]] -- When client's name:class:title matches regex, it is given the -- tagstring tag(s). There are two special tags: -- sel (or the deprecated form: !) represents the current tag, and -- ~ which represents the floating layer wmii.write ("/tagrules", "/XMMS.*/ -> ~\n" .. "/Firefox.*/ -> www\n" .. "/Iceweasel.*/ -> www\n" .. "/vimperator/ -> www\n" .. "/a[Kk]regator/ -> www\n" .. "/Uzbl browser/ -> uzbl\n" .. "/Chromium/ -> www\n" .. "/Evolution/ -> mail\n" .. "/Gimp.*/ -> ~\n" .. "/Gimp.*/ -> gimp\n" .. "/Gaim.*/ -> gaim\n" .. "/gitk/ -> ~\n" .. "/MPlayer.*/ -> ~\n" .. "/x?vnc[^ ]*viewer.*/ -> ~\n" .. "/VNC.*:VNC.*/ -> ~\n" .. "/.*/ -> sel\n" .. "/.*/ -> 1\n") -- load some plugins wmii.load_plugin ("messages") wmii.load_plugin ("clock") wmii.load_plugin ("loadavg") --wmii.load_plugin ("volume") wmii.load_plugin ("browser") wmii.set_conf ("browser", "x-www-browser") wmii.load_plugin ("view_workdir") wmii.load_plugin ("cpu") wmii.load_plugin ("battery") wmii.load_plugin ("ssh") wmii.add_key_handler ("Mod1-z", ssh.show_menu) wmii.load_plugin ("resize") --]] -- other handlers wmii.add_key_handler ('XF86KbdBrightnessUp', function (key) os.execute("xbacklight -steps 1 -time 0 -inc 10") end) wmii.add_key_handler ('XF86KbdBrightnessDown', function (key) os.execute("xbacklight -steps 1 -time 0 -dec 10") end) wmii.add_action_handler ("hibernate-disk", function(act,args) os.execute ('slock & sleep 1 ; gksudo ifdown wlan0 ; scrub-modules ; gksudo hibernate-disk') end) wmii.add_action_handler ("hibernate-ram", function(act,args) os.execute ('slock & sleep 1 ; gksudo ifdown wlan0 ; scrub-modules ; gksudo hibernate-ram') end) wmii.add_action_handler ("net-rj45", function(act,args) os.execute ('(gksudo "ifdown wlan0" || gksudo "ifconfig wlan0 down" ;' .. 'gksudo "rmmod ipw2200 ieee80211 ieee80211_crypt" ;' .. 'gksudo "dhclient br0" || gksudo "ifup --force br0") &') end) wmii.add_action_handler ("net-wifi", function(act,args) os.execute ('(gksudo "ifdown wlan0" || gksudo "ifconfig wlan0 down" ;' .. 'gksudo "ifdown br0" || gksudo "ifconfig br0 down" ;' .. 'gksudo "dhclient wlan0" || gksudo "ifup --force wlan0") &') end) -- keyboard handling wmii.add_key_handler ("XF86AudioMute", function(key) os.execute ('amixer set Master toggle') end) wmii.add_key_handler ("XF86AudioLowerVolume", function(key) os.execute ('amixer set Master 2dB-') end) wmii.add_key_handler ("XF86AudioRaiseVolume", function(key) os.execute ('amixer set Master 2dB+') end) --[[ local brightness_ctl = '/proc/acpi/video/VID1/LCD0/brightness' local brightness_levels local function brightness_levels_parse(txt) local skip1,skip2,txt = txt:match("levels:%s*(%d+) (%d+) ([%d%s]*)\n") brightness_levels = {} local w for w in string.gmatch(txt, "%d+") do local n = tonumber(w) table.insert(brightness_levels, n) end if not table.maxn(brightness_levels) then brightness_levels = { 20, 30, 40, 50, 60, 70, 80, 90, 100 } end -- wmii.log ("## brightness_levels: " .. table.concat(brightness_levels,' ')) end local function brightness_handler(key) local fbr = io.open(brightness_ctl, 'r') if fbr then local txt = fbr:read("*a") fbr:close() if not brightness_levels then brightness_levels_parse(txt) end local current = txt:match("current: (%d+)") if type(current) ~= 'string' or current:len() == 0 then return end current = tonumber(current) -- wmii.log ("\n" .. tostring (txt) .. "\n") -- wmii.log ("current = " .. tostring(current)) local offset = 1 if key == brightness_down then offset = -1 end local i,value,new_value for i,value in ipairs(brightness_levels) do if value == current then new_value = brightness_levels[i + offset] break end end if new_value and type(new_value) == 'number' then new_value = tostring(new_value) wmii.log ("## " .. tostring(key) .. " " .. new_value) os.execute ("sudo sh -c 'echo " .. new_value .. " > "..brightness_ctl.."'") end end end --]] -- shell-fm stuff wmii.add_key_handler ('XF86AudioStop', function (key) wmii.log('## shell-fm stop') os.execute ('echo stop | nc 127.0.0.1 54311') end) wmii.add_key_handler ('XF86AudioPlay', function (key) wmii.log('## shell-fm pause') os.execute ('echo pause | nc 127.0.0.1 54311') end) wmii.add_key_handler ('XF86AudioPrev', function (key) wmii.log('## shell-fm prev (TODO)') -- TODO end) wmii.add_key_handler ('XF86AudioNext', function (key) wmii.log('## shell-fm next') os.execute ('echo skip | nc 127.0.0.1 54311') end) -- forward/backward wmii.add_key_handler ('XF86Back', function (key) wmii.set_view_ofs (-1) end) wmii.add_key_handler ('XF86Forward', function (key) wmii.set_view_ofs (1) end) --[[ -- xrandr stuff wmii.add_key_handler ('XF86RotateWindows', function (key) -- TODO: rotate display end) wmii.add_key_handler ('XF86Display', function (key) -- TODO: cycle VGA on off end) -- action buttons on the tablet wmii.add_key_handler ('XF86Launch1', function (key) -- TODO: toolbox end) wmii.add_key_handler ('XF86Launch2', function (key) -- TODO: reset end) --]] -- here are some other examples... --[[ -- use Mod1-tab to flip to the previous view wmii.remap_key_handler ("Mod1-r", "Mod1-tab") --]] -- ------------------------------------------------------------------------ -- configuration is finished, run the event loop wmii.run_event_loop()