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/
14 print ('-----------------------')
17 local wmiirc
= os
.getenv("HOME") .. "/.wmii-3.5/wmiirc"
21 io
.stderr
:write (str
.. "\n")
25 my_log("wmii: loading wmii.lua")
26 package
.path
= package
.path
.. ";" .. os
.getenv("HOME") .. "/.wmii-3.5/?.lua"
29 my_log("wmii: wmii.lua loaded")
31 -- stop any other instance of wmiirc
32 wmii
.write ("/event", "Start wmiirc")
34 -- this is the base configuration
36 xterm
= 'x-terminal-emulator'
38 my_log("wmii: setting confg")
42 font
= '-windows-proggytiny-medium-r-normal--10-80-96-96-c-60-iso8859-1',
43 focuscolors
= '#FFFFaa #007700 #88ff88',
44 normcolors
= '#888888 #222222 #333333',
47 wmii
.configure (wconfig
)
49 my_log("wmii: config set")
51 wmii
.write ("/colrules", "/.*/ -> 58+42")
52 wmii
.write ("/tagrules", "/XMMS.*/ -> ~\n"
53 .. "/MPlayer.*/ -> ~\n"
58 -- ------------------------------------------------------------------------
61 local action_handlers
= {
63 wmii
.write ("/ctl", "quit")
66 exec
= function (act
, args
)
67 local what
= args
or wmiirc
68 wmii
.write ("/ctl", "exec " .. what
)
72 posix
.exec ("lua", wmiirc
)
76 -- TODO: consider storing list of executables around, and
77 -- this will then reinitialize that list
78 my_log (" TODO: rehash")
82 -- TODO: this should eventually update something on the /rbar
83 my_log (" TODO: status")
87 -- ------------------------------------------------------------------------
90 local key_handlers
= {
91 ["*"] = function (key
)
95 -- execution and actions
96 ["Mod1-Return"] = function (key
)
97 my_log (" executing: " .. config
.xterm
)
98 os
.execute (config
.xterm
.. " &")
100 ["Mod1-a"] = function (key
)
101 local text
= wmii
.menu (action_handlers
)
105 local si
= text
:find("%s")
107 act
,args
= string.match(text
.. " ", "(%w+)%s(.+)")
110 local fn
= action_handlers
[act
]
117 ["Mod1-p"] = function (key
)
118 local prog
= wmii
.progmenu()
120 my_log (" executing: " .. prog
)
121 os
.execute (prog
.. " &")
124 ["Mod1-Shift-c"] = function (key
)
125 wmii
.write ("/client/sel/ctl", "kill")
128 -- HJKL active selection
129 ["Mod1-h"] = function (key
)
130 wmii
.write ("/tag/sel/ctl", "select left")
132 ["Mod1-l"] = function (key
)
133 wmii
.write ("/tag/sel/ctl", "select right")
135 ["Mod1-j"] = function (key
)
136 wmii
.write ("/tag/sel/ctl", "select down")
138 ["Mod1-k"] = function (key
)
139 wmii
.write ("/tag/sel/ctl", "select up")
143 ["Mod1-Shift-h"] = function (key
)
144 wmii
.write ("/tag/sel/ctl", "send sel left")
146 ["Mod1-Shift-l"] = function (key
)
147 wmii
.write ("/tag/sel/ctl", "send sel right")
149 ["Mod1-Shift-j"] = function (key
)
150 wmii
.write ("/tag/sel/ctl", "send sel down")
152 ["Mod1-Shift-k"] = function (key
)
153 wmii
.write ("/tag/sel/ctl", "send sel up")
157 ["Mod1-space"] = function (key
)
158 wmii
.write ("/tag/sel/ctl", "select toggle")
160 ["Mod1-Shift-space"] = function (key
)
161 wmii
.write ("/tag/sel/ctl", "send sel toggle")
165 ["Mod4-#"] = function (key
, num
)
166 wmii
.write ("/ctl", "view " .. tostring(num
))
168 ["Mod4-Shift-#"] = function (key
, num
)
169 wmii
.write ("/client/sel/tags", tostring(num
))
173 -- switching views and retagging
174 ["Mod1-t"] = function (key
)
175 local tag = wmii
.tagmenu()
177 wmii
.write ("/ctl", "view " .. tag)
181 ["Mod1-Shift-t"] = function (key
)
182 local tag = wmii
.tagmenu()
184 local cli
= wmii
.read ("/client/sel/ctl")
185 wmii
.write ("/client/" .. cli
.. "/tags", tag)
188 ["Mod1-Control-t"] = function (key
)
189 my_log (" TODO: Mod1-Control-t: " .. key
)
193 ["Mod1-d"] = function (key
)
194 wmii
.write("/tag/sel/ctl", "colmode sel default")
196 ["Mod1-s"] = function (key
)
197 wmii
.write("/tag/sel/ctl", "colmode sel stack")
199 ["Mod1-m"] = function (key
)
200 wmii
.write("/tag/sel/ctl", "colmode sel max")
204 -- ------------------------------------------------------------------------
205 -- update the /keys wmii file with the list of all handlers
210 for x
,y
in pairs(key_handlers
) do
212 local i
= x
:find("#")
225 local all_keys
= table.concat(t
, "\n")
226 my_log ("setting /keys to...\n" .. all_keys
.. "\n");
227 wmii
.write ("/keys", all_keys
)
231 -- ------------------------------------------------------------------------
234 local ev_handlers
= {
235 ["*"] = function (ev
, arg
)
236 my_log ("ev: " .. ev
.. " - " .. arg
)
239 -- exit if another wmiirc started up
240 Start
= function (ev
, arg
)
241 if arg
== "wmiirc" then
247 CreateTag
= function (ev
, arg
)
248 wmii
.create ("/lbar/" .. arg
,
249 wconfig
.normcolors
.. " " .. arg
)
251 DestroyTag
= function (ev
, arg
)
252 wmii
.remove ("/lbar/" .. arg
)
255 FocusTag
= function (ev
, arg
)
256 my_log ("FocusTag: " .. arg
)
257 wmii
.create ("/lbar/" .. arg
,
258 wconfig
.focuscolors
.. " " .. arg
)
259 wmii
.write ("/lbar/" .. arg
,
260 wconfig
.focuscolors
.. " " .. arg
)
262 UnfocusTag
= function (ev
, arg
)
263 my_log ("UnfocusTag: " .. arg
)
264 wmii
.create ("/lbar/" .. arg
,
265 wconfig
.normcolors
.. " " .. arg
)
266 wmii
.write ("/lbar/" .. arg
,
267 wconfig
.normcolors
.. " " .. arg
)
270 -- key event handling
271 Key
= function (ev
, arg
)
272 my_log ("Key: " .. arg
)
274 -- can we find an exact match?
275 local fn
= key_handlers
[arg
]
277 local key
= arg
:gsub("-%d+", "-#")
278 -- can we find a match with a # wild card for the number
279 fn
= key_handlers
[key
]
281 -- convert the trailing number to a number
282 num
= tonumber(arg
:match("-(%d+)"))
284 -- everything else failed, try default match
285 fn
= key_handlers
["*"]
294 ClientMouseDown
= function (ev
, arg
)
295 my_log ("ClientMouseDown: " .. arg
)
297 LeftBarClick
= function (ev
, arg
)
298 my_log ("LeftBarClick: " .. arg
)
299 -- wmiir xwrite /ctl view "$@"
303 UrgentTag
= function (ev
, arg
)
304 my_log ("UrgentTag: " .. arg
)
305 -- wmiir xwrite "/lbar/$@" "*$@"
307 NotUrgentTag
= function (ev
, arg
)
308 my_log ("NotUrgentTag: " .. arg
)
309 -- wmiir xwrite "/lbar/$@" "$@"
314 -- ------------------------------------------------------------------------
316 my_log("wmii: starting event loop")
318 for ev
, arg
in wmii
.ievents() do
320 local fn
= ev_handlers
[ev
] or ev_handlers
["*"]
325 my_log("wmii: event loop exited")