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
= os
.getenv("HOME") .. '/.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',
45 wmii
.configure (wconfig
)
47 my_log("wmii: config set")
49 wmii
.write ("/colrules", "/.*/ -> 58+42")
50 wmii
.write ("/tagrules", "/XMMS.*/ -> ~\n"
51 .. "/MPlayer.*/ -> ~\n"
56 -- ------------------------------------------------------------------------
59 local action_handlers
= {
61 wmii
.write ("/ctl", "quit")
64 exec
= function (act
, args
)
65 local what
= args
or wmiirc
66 wmii
.write ("/ctl", "exec " .. what
)
70 posix
.exec ("lua", wmiirc
)
74 -- TODO: consider storing list of executables around, and
75 -- this will then reinitialize that list
76 my_log (" TODO: rehash")
80 -- TODO: this should eventually update something on the /rbar
81 my_log (" TODO: status")
85 -- ------------------------------------------------------------------------
88 local key_handlers
= {
89 ["*"] = function (key
)
93 -- execution and actions
94 ["Mod1-Return"] = function (key
)
95 my_log (" executing: " .. config
.xterm
)
96 os
.execute (config
.xterm
.. " &")
98 ["Mod1-a"] = function (key
)
99 local text
= wmii
.menu (action_handlers
)
103 local si
= text
:find("%s")
105 act
,args
= string.match(text
.. " ", "(%w+)%s(.+)")
108 local fn
= action_handlers
[act
]
115 ["Mod1-p"] = function (key
)
116 local prog
= wmii
.progmenu()
118 my_log (" executing: " .. prog
)
119 os
.execute (prog
.. " &")
122 ["Mod1-Shift-c"] = function (key
)
123 wmii
.write ("/client/sel/ctl", "kill")
126 -- HJKL active selection
127 ["Mod1-h"] = function (key
)
128 wmii
.write ("/tag/sel/ctl", "select left")
130 ["Mod1-l"] = function (key
)
131 wmii
.write ("/tag/sel/ctl", "select right")
133 ["Mod1-j"] = function (key
)
134 wmii
.write ("/tag/sel/ctl", "select down")
136 ["Mod1-k"] = function (key
)
137 wmii
.write ("/tag/sel/ctl", "select up")
141 ["Mod1-Shift-h"] = function (key
)
142 wmii
.write ("/tag/sel/ctl", "send sel left")
144 ["Mod1-Shift-l"] = function (key
)
145 wmii
.write ("/tag/sel/ctl", "send sel right")
147 ["Mod1-Shift-j"] = function (key
)
148 wmii
.write ("/tag/sel/ctl", "send sel down")
150 ["Mod1-Shift-k"] = function (key
)
151 wmii
.write ("/tag/sel/ctl", "send sel up")
155 ["Mod1-space"] = function (key
)
156 wmii
.write ("/tag/sel/ctl", "select toggle")
158 ["Mod1-Shift-space"] = function (key
)
159 wmii
.write ("/tag/sel/ctl", "send sel toggle")
163 ["Mod4-#"] = function (key
, num
)
164 wmii
.write ("/ctl", "view " .. tostring(num
))
166 ["Mod4-Shift-#"] = function (key
, num
)
167 wmii
.write ("/client/sel/tags", tostring(num
))
171 -- switching views and retagging
172 ["Mod1-t"] = function (key
)
173 local tag = wmii
.tagmenu()
175 wmii
.write ("/ctl", "view " .. tag)
179 ["Mod1-Shift-t"] = function (key
)
180 local tag = wmii
.tagmenu()
182 local cli
= wmii
.read ("/client/sel/ctl")
183 wmii
.write ("/client/" .. cli
.. "/tags", tag)
186 ["Mod1-Control-t"] = function (key
)
187 my_log (" TODO: Mod1-Control-t: " .. key
)
191 ["Mod1-d"] = function (key
)
192 wmii
.write("/tag/sel/ctl", "colmode sel default")
194 ["Mod1-s"] = function (key
)
195 wmii
.write("/tag/sel/ctl", "colmode sel stack")
197 ["Mod1-m"] = function (key
)
198 wmii
.write("/tag/sel/ctl", "colmode sel max")
202 -- ------------------------------------------------------------------------
203 -- update the /keys wmii file with the list of all handlers
208 for x
,y
in pairs(key_handlers
) do
210 local i
= x
:find("#")
223 local all_keys
= table.concat(t
, "\n")
224 my_log ("setting /keys to...\n" .. all_keys
.. "\n");
225 wmii
.write ("/keys", all_keys
)
229 -- ------------------------------------------------------------------------
232 local ev_handlers
= {
233 ["*"] = function (ev
, arg
)
234 my_log ("ev: " .. ev
.. " - " .. arg
)
237 -- exit if another wmiirc started up
238 Start
= function (ev
, arg
)
239 if arg
== "wmiirc" then
245 CreateTag
= function (ev
, arg
)
246 wmii
.create ("/lbar/" .. arg
,
247 wconfig
.normcolors
.. " " .. arg
)
249 DestroyTag
= function (ev
, arg
)
250 wmii
.remove ("/lbar/" .. arg
)
253 FocusTag
= function (ev
, arg
)
254 my_log ("FocusTag: " .. arg
)
255 wmii
.create ("/lbar/" .. arg
,
256 wconfig
.focuscolors
.. " " .. arg
)
257 wmii
.write ("/lbar/" .. arg
,
258 wconfig
.focuscolors
.. " " .. arg
)
260 UnfocusTag
= function (ev
, arg
)
261 my_log ("UnfocusTag: " .. arg
)
262 wmii
.create ("/lbar/" .. arg
,
263 wconfig
.normcolors
.. " " .. arg
)
264 wmii
.write ("/lbar/" .. arg
,
265 wconfig
.normcolors
.. " " .. arg
)
268 -- key event handling
269 Key
= function (ev
, arg
)
270 my_log ("Key: " .. arg
)
272 -- can we find an exact match?
273 local fn
= key_handlers
[arg
]
275 local key
= arg
:gsub("-%d+", "-#")
276 -- can we find a match with a # wild card for the number
277 fn
= key_handlers
[key
]
279 -- convert the trailing number to a number
280 num
= tonumber(arg
:match("-(%d+)"))
282 -- everything else failed, try default match
283 fn
= key_handlers
["*"]
292 ClientMouseDown
= function (ev
, arg
)
293 my_log ("ClientMouseDown: " .. arg
)
295 LeftBarClick
= function (ev
, arg
)
296 my_log ("LeftBarClick: " .. arg
)
297 -- wmiir xwrite /ctl view "$@"
301 UrgentTag
= function (ev
, arg
)
302 my_log ("UrgentTag: " .. arg
)
303 -- wmiir xwrite "/lbar/$@" "*$@"
305 NotUrgentTag
= function (ev
, arg
)
306 my_log ("NotUrgentTag: " .. arg
)
307 -- wmiir xwrite "/lbar/$@" "$@"
312 -- ------------------------------------------------------------------------
314 my_log("wmii: starting event loop")
316 for ev
, arg
in wmii
.ievents() do
318 local fn
= ev_handlers
[ev
] or ev_handlers
["*"]
323 my_log("wmii: event loop exited")