simple view switching and retagging now works
[wmiirc-lua.git] / wmiirc.lua
blobe7d2bda150cb388aae6b167260276c73cf1c60d9
1 #!/usr/bin/env lua
3 -- some stuff below will eventually go to a separate file, and configuration
4 -- will remain here similar to the split between the wmii+ruby wmiirc
5 -- and wmiirc-config
6 --
7 -- for now I just want to get the feel of how things will work in lua
9 require "posix"
11 -- debug
12 function my_log (str)
13 io.stderr:write (str .. "\n")
14 end
16 -- load wmii.lua
17 my_log("wmii: loading wmii.lua")
18 package.path = './.wmii-3.5/?.lua;' .. package.path
19 require "wmii"
21 my_log("wmii: wmii.lua loaded")
23 -- this is the base configuration
24 local config = {
25 xterm = 'x-terminal-emulator'
27 my_log("wmii: setting confg")
28 wmii.configure ({
29 view = 1,
30 border = 1,
31 font = '-windows-proggytiny-medium-r-normal--10-80-96-96-c-60-iso8859-1',
32 focuscolors = '#FFFFaa #007700 #88ff88',
33 normcolors = '#888888 #222222 #333333',
34 grabmod = 'Mod1'
37 my_log("wmii: config set")
39 wmii.write ("/colrules", "/.*/ -> 58+42")
40 wmii.write ("/tagrules", "/XMMS.*/ -> ~\n"
41 .. "/MPlayer.*/ -> ~\n"
42 .. "/.*/ -> sel\n"
43 .. "/.*/ -> 1\n")
45 -- key handlers
47 local key_handlers = {
48 ["*"] = function (key)
49 my_log ("*: " .. key)
50 end,
52 -- execution and actions
53 ["Mod1-Return"] = function (key)
54 my_log (" executing: " .. config.xterm)
55 os.execute (config.xterm .. " &")
56 end,
57 ["Mod1-a"] = function (key)
58 my_log (" Mod1-a: " .. key)
59 -- for now just restart us
61 my_log ("*****************************************************\n"
62 .. "******** HACK!!! Just restart wmiirc for now ********\n"
63 .. "*****************************************************\n")
64 posix.exec ("lua", os.getenv("home") .. ".wmii-3.5/wmiirc")
65 end
66 end,
67 ["Mod1-p"] = function (key)
68 my_log (" Mod1-p: " .. key)
69 end,
71 -- HJKL active selection
72 ["Mod1-h"] = function (key)
73 wmii.write ("/tag/sel/ctl", "select left")
74 end,
75 ["Mod1-l"] = function (key)
76 wmii.write ("/tag/sel/ctl", "select right")
77 end,
78 ["Mod1-j"] = function (key)
79 wmii.write ("/tag/sel/ctl", "select down")
80 end,
81 ["Mod1-k"] = function (key)
82 wmii.write ("/tag/sel/ctl", "select up")
83 end,
85 -- HJKL movement
86 ["Mod1-Shift-h"] = function (key)
87 my_log (" Mod1-Shift-h: " .. key)
88 wmii.write ("/tag/sel/ctl", "send sel left")
89 end,
90 ["Mod1-Shift-l"] = function (key)
91 wmii.write ("/tag/sel/ctl", "send sel right")
92 end,
93 ["Mod1-Shift-j"] = function (key)
94 wmii.write ("/tag/sel/ctl", "send sel down")
95 end,
96 ["Mod1-Shift-k"] = function (key)
97 wmii.write ("/tag/sel/ctl", "send sel up")
98 end,
100 -- floating vs tiled
101 ["Mod1-space"] = function (key)
102 wmii.write ("/tag/sel/ctl", "select toggle")
103 end,
104 ["Mod1-Shift-space"] = function (key)
105 wmii.write ("/tag/sel/ctl", "send sel toggle")
106 end,
108 -- work spaces
109 ["Mod4-#"] = function (key, num)
110 my_log (" Mod4-#: " .. tostring(num))
111 wmii.write ("/ctl", "view " .. tostring(num))
112 end,
113 ["Mod4-Shift-#"] = function (key, num)
114 my_log (" Mod4-Shift-#: " .. tostring(num))
115 wmii.write ("/client/sel/tags", tostring(num))
116 end,
119 -- ...
121 ["Mod1-Control-t"] = function (key)
122 my_log (" Mod1-Control-t: " .. key)
123 end,
124 ["Mod1-d"] = function (key)
125 my_log (" Mod1-d: " .. key)
126 end,
127 ["Mod1-s"] = function (key)
128 my_log (" Mod1-s: " .. key)
129 end,
130 ["Mod1-m"] = function (key)
131 my_log (" Mod1-m: " .. key)
132 end,
133 ["Mod1-t"] = function (key)
134 my_log (" Mod1-t: " .. key)
135 end,
136 ["Mod1-Shift-c"] = function (key)
137 my_log (" Mod1-Shift-c: " .. key)
138 end,
139 ["Mod1-Shift-t"] = function (key)
140 my_log (" Mod1-Shift-t: " .. key)
144 -- update the /keys wmii file with the list of all handlers
147 local t = {}
148 local x, y
149 for x,y in pairs(key_handlers) do
150 if x:find("%w") then
151 local i = x:find("#")
152 if i then
153 local j
154 for j=0,9 do
155 t[#t + 1]
156 = x:sub(1,i-1) .. j
158 else
159 t[#t + 1]
160 = tostring(x)
164 local all_keys = table.concat(t, "\n")
165 my_log ("setting /keys to...\n" .. all_keys .. "\n");
166 wmii.write ("/keys", all_keys)
170 -- event handlers
172 local ev_handlers = {
173 ["*"] = function (ev, arg)
174 my_log ("ev: " .. ev .. " - " .. arg)
175 end,
177 ClientMouseDown = function (ev, arg)
178 my_log ("ClientMouseDown: " .. arg)
179 end,
181 CreateTag = function (ev, arg)
182 my_log ("CreateTag: " .. arg)
183 end,
185 DestroyTag = function (ev, arg)
186 my_log ("DestroyTag: " .. arg)
187 end,
189 FocusTag = function (ev, arg)
190 my_log ("FocusTag: " .. arg)
191 end,
193 Key = function (ev, arg)
194 my_log ("Key: " .. arg)
195 local num = nil
196 -- can we find an exact match?
197 local fn = key_handlers[arg]
198 if not fn then
199 local key = arg:gsub("-%d+", "-#")
200 -- can we find a match with a # wild card for the number
201 fn = key_handlers[key]
202 if fn then
203 -- convert the trailing number to a number
204 num = tonumber(arg:match("-(%d+)"))
205 else
206 -- everything else failed, try default match
207 fn = key_handlers["*"]
210 if fn then
211 fn (arg, num)
213 end,
215 LeftBarClick = function (ev, arg)
216 my_log ("LeftBarClick: " .. arg)
217 end,
219 NotUrgentTag = function (ev, arg)
220 my_log ("NotUrgentTag: " .. arg)
221 end,
223 Start = function (ev, arg)
224 my_log ("Start: " .. arg)
225 end,
227 UnfocusTag = function (ev, arg)
228 my_log ("UnfocusTag: " .. arg)
229 end,
231 UrgentTag = function (ev, arg)
232 my_log ("UrgentTag: " .. arg)
236 --[[
237 Action quit
238 Action exec
239 Action rehash
240 Action status
241 ]]--
243 -- reading events
244 my_log("wmii: starting event loop")
245 local ev, arg
246 for ev, arg in wmii.ievents() do
248 local fn = ev_handlers[ev] or ev_handlers["*"]
249 if fn then
250 fn (ev, arg)
253 my_log("wmii: event loop exited")