3 -- Copyrigh (c) 2007, Bart Trojanowski <bart@jukie.net>
5 -- Some stuff below will eventually go to a separate file, and configuration
6 -- will remain here similar to the split between the wmii+ruby wmiirc and
7 -- wmiirc-config. For now I just want to get the feel of how things will
10 -- git://www.jukie.net/wmiirc-lua.git/
15 local wmiirc
= os
.getenv("HOME") .. "/.wmii-3.5/wmiirc"
19 io
.stderr
:write (str
.. "\n")
23 my_log("wmii: loading wmii.lua")
24 package
.path
= './.wmii-3.5/?.lua;' .. package
.path
27 my_log("wmii: wmii.lua loaded")
29 -- stop any other instance of wmiirc
30 wmii
.write ("/event", "Start wmiirc")
32 -- this is the base configuration
34 xterm
= 'x-terminal-emulator'
36 my_log("wmii: setting confg")
40 font
= '-windows-proggytiny-medium-r-normal--10-80-96-96-c-60-iso8859-1',
41 focuscolors
= '#FFFFaa #007700 #88ff88',
42 normcolors
= '#888888 #222222 #333333',
46 my_log("wmii: config set")
48 wmii
.write ("/colrules", "/.*/ -> 58+42")
49 wmii
.write ("/tagrules", "/XMMS.*/ -> ~\n"
50 .. "/MPlayer.*/ -> ~\n"
55 -- ------------------------------------------------------------------------
58 local action_handlers
= {
60 wmii
.write ("/ctl", "quit")
63 exec
= function (act
, args
)
64 local what
= args
or wmiirc
65 wmii
.write ("/ctl", "exec " .. what
)
69 posix
.exec ("lua", wmiirc
)
73 -- TODO: consider storing list of executables around, and
74 -- this will then reinitialize that list
75 my_log (" TODO: rehash")
79 -- TODO: this should eventually update something on the /rbar
80 my_log (" TODO: status")
84 -- ------------------------------------------------------------------------
87 local key_handlers
= {
88 ["*"] = function (key
)
92 -- execution and actions
93 ["Mod1-Return"] = function (key
)
94 my_log (" executing: " .. config
.xterm
)
95 os
.execute (config
.xterm
.. " &")
97 ["Mod1-a"] = function (key
)
98 local text
= wmii
.menu (action_handlers
)
102 local si
= text
:find("%s")
104 act
,args
= string.match(text
.. " ", "(%w+)%s(.+)")
107 local fn
= action_handlers
[act
]
114 ["Mod1-p"] = function (key
)
115 local prog
= wmii
.progmenu()
117 my_log (" executing: " .. prog
)
118 os
.execute (prog
.. " &")
121 ["Mod1-Shift-c"] = function (key
)
122 wmii
.write ("/client/sel/ctl", "kill")
125 -- HJKL active selection
126 ["Mod1-h"] = function (key
)
127 wmii
.write ("/tag/sel/ctl", "select left")
129 ["Mod1-l"] = function (key
)
130 wmii
.write ("/tag/sel/ctl", "select right")
132 ["Mod1-j"] = function (key
)
133 wmii
.write ("/tag/sel/ctl", "select down")
135 ["Mod1-k"] = function (key
)
136 wmii
.write ("/tag/sel/ctl", "select up")
140 ["Mod1-Shift-h"] = function (key
)
141 wmii
.write ("/tag/sel/ctl", "send sel left")
143 ["Mod1-Shift-l"] = function (key
)
144 wmii
.write ("/tag/sel/ctl", "send sel right")
146 ["Mod1-Shift-j"] = function (key
)
147 wmii
.write ("/tag/sel/ctl", "send sel down")
149 ["Mod1-Shift-k"] = function (key
)
150 wmii
.write ("/tag/sel/ctl", "send sel up")
154 ["Mod1-space"] = function (key
)
155 wmii
.write ("/tag/sel/ctl", "select toggle")
157 ["Mod1-Shift-space"] = function (key
)
158 wmii
.write ("/tag/sel/ctl", "send sel toggle")
162 ["Mod4-#"] = function (key
, num
)
163 wmii
.write ("/ctl", "view " .. tostring(num
))
165 ["Mod4-Shift-#"] = function (key
, num
)
166 wmii
.write ("/client/sel/tags", tostring(num
))
170 -- switching views and retagging
171 ["Mod1-t"] = function (key
)
172 local tag = wmii
.tagmenu()
174 wmii
.write ("/ctl", "view " .. tag)
178 ["Mod1-Shift-t"] = function (key
)
179 local tag = wmii
.tagmenu()
181 local cli
= wmii
.read ("/client/sel/ctl")
182 wmii
.write ("/client/" .. cli
.. "/tags", tag)
185 ["Mod1-Control-t"] = function (key
)
186 my_log (" TODO: Mod1-Control-t: " .. key
)
190 ["Mod1-d"] = function (key
)
191 wmii
.write("/tag/sel/ctl", "colmode sel default")
193 ["Mod1-s"] = function (key
)
194 wmii
.write("/tag/sel/ctl", "colmode sel stack")
196 ["Mod1-m"] = function (key
)
197 wmii
.write("/tag/sel/ctl", "colmode sel max")
201 -- ------------------------------------------------------------------------
202 -- update the /keys wmii file with the list of all handlers
207 for x
,y
in pairs(key_handlers
) do
209 local i
= x
:find("#")
222 local all_keys
= table.concat(t
, "\n")
223 my_log ("setting /keys to...\n" .. all_keys
.. "\n");
224 wmii
.write ("/keys", all_keys
)
228 -- ------------------------------------------------------------------------
231 local ev_handlers
= {
232 ["*"] = function (ev
, arg
)
233 my_log ("ev: " .. ev
.. " - " .. arg
)
236 ClientMouseDown
= function (ev
, arg
)
237 my_log ("ClientMouseDown: " .. arg
)
240 CreateTag
= function (ev
, arg
)
241 my_log ("CreateTag: " .. arg
)
244 DestroyTag
= function (ev
, arg
)
245 my_log ("DestroyTag: " .. arg
)
248 FocusTag
= function (ev
, arg
)
249 my_log ("FocusTag: " .. arg
)
252 Key
= function (ev
, arg
)
253 my_log ("Key: " .. arg
)
255 -- can we find an exact match?
256 local fn
= key_handlers
[arg
]
258 local key
= arg
:gsub("-%d+", "-#")
259 -- can we find a match with a # wild card for the number
260 fn
= key_handlers
[key
]
262 -- convert the trailing number to a number
263 num
= tonumber(arg
:match("-(%d+)"))
265 -- everything else failed, try default match
266 fn
= key_handlers
["*"]
274 LeftBarClick
= function (ev
, arg
)
275 my_log ("LeftBarClick: " .. arg
)
278 NotUrgentTag
= function (ev
, arg
)
279 my_log ("NotUrgentTag: " .. arg
)
282 Start
= function (ev
, arg
)
283 if arg
== "wmiirc" then
288 UnfocusTag
= function (ev
, arg
)
289 my_log ("UnfocusTag: " .. arg
)
292 UrgentTag
= function (ev
, arg
)
293 my_log ("UrgentTag: " .. arg
)
297 -- ------------------------------------------------------------------------
299 my_log("wmii: starting event loop")
301 for ev
, arg
in wmii
.ievents() do
303 local fn
= ev_handlers
[ev
] or ev_handlers
["*"]
308 my_log("wmii: event loop exited")