anderstornvig / config-files

Various config files primarily for Linux stuff

This URL has Read+Write access

40bedfc6 » Anders Tornvig 2009-04-04 Loads of config files uploa... 1 -- Standard awesome library
2 require("awful")
3 -- Theme handling library
4 require("beautiful")
5 -- Notification library
6 require("naughty")
7 -- Widget library
8 --require("wicked")
9
10 -- {{{ Variable definitions
11 -- Themes define colours, icons, and wallpapers
12 -- The default is a dark theme
13 --theme_path = "/usr/share/awesome/themes/default/theme"
14 -- Uncommment this for a lighter theme
15 theme_path = "/usr/share/awesome/themes/sky/theme"
16
17 -- Actually load theme
18 beautiful.init(theme_path)
19
20 -- This is used later as the default terminal and editor to run.
21 terminal = "urxvt"
22 editor = os.getenv("EDITOR") or "nano"
23 editor_cmd = terminal .. " -e " .. editor
24
25 -- Default modkey.
26 -- Usually, Mod4 is the key with a logo between Control and Alt.
27 -- If you do not like this or do not have such a key,
28 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
29 -- However, you can use another modifier like Mod1, but it may interact with others.
30 modkey = "Mod4"
31
32 -- Table of layouts to cover with awful.layout.inc, order matters.
33 layouts =
34 {
35 awful.layout.suit.tile,
36 awful.layout.suit.tile.left,
37 awful.layout.suit.tile.bottom,
38 awful.layout.suit.tile.top,
39 awful.layout.suit.fair,
40 awful.layout.suit.fair.horizontal,
41 awful.layout.suit.max,
42 awful.layout.suit.max.fullscreen,
43 awful.layout.suit.magnifier,
44 awful.layout.suit.floating
45 }
46
47 -- Table of clients that should be set floating. The index may be either
48 -- the application class or instance. The instance is useful when running
49 -- a console app in a terminal like (Music on Console)
50 -- xterm -name mocp -e mocp
51 floatapps =
52 {
53 -- by class
54 ["MPlayer"] = true,
55 ["pinentry"] = true,
56 ["gimp"] = true,
57 -- by instance
58 ["mocp"] = true
59 }
60
61 -- Applications to be moved to a pre-defined tag by class or instance.
62 -- Use the screen and tags indices.
63 apptags =
64 {
65 -- ["Firefox"] = { screen = 1, tag = 2 },
66 -- ["mocp"] = { screen = 2, tag = 4 },
67 ["Firefox"] = { screen = 1, tag = 1 },
68 -- ["Pidgin"] = { screen = 1, tag = 3 },
69 -- ["xchat"] = { screen = 1, tag = 3 },
70 }
71
72 -- Define if we want to use titlebar on all applications.
73 use_titlebar = false
74 -- }}}
75
76 -- {{{ Tags
77 -- Define tags table.
78 tags = {}
79 for s = 1, screen.count() do
80 -- Each screen has its own tag table.
81 tags[s] = {}
82 -- Create 9 tags per screen.
83 for tagnumber = 1, 9 do
84 tags[s][tagnumber] = tag(tagnumber)
85 -- Add tags to screen one by one
86 tags[s][tagnumber].screen = s
87 awful.layout.set(layouts[1], tags[s][tagnumber])
88 end
89 -- I'm sure you want to see at least one tag.
90 tags[s][1].selected = true
91 end
92 -- }}}
93
94 -- {{{ Wibox
95 -- Create a textbox widget
96 mytextbox = widget({ type = "textbox", align = "right" })
97 -- Set the default text in textbox
98 mytextbox.text = "<b><small> " .. AWESOME_RELEASE .. " </small></b>"
99
100 -- Create a laucher widget and a main menu
101 myawesomemenu = {
102 { "manual", terminal .. " -e man awesome" },
103 { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
104 { "restart", awesome.restart },
105 { "quit", awesome.quit }
106 }
107
108 mymainmenu = awful.menu.new({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
109 { "open terminal", terminal }
110 }
111 })
112
113 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
114 menu = mymainmenu })
115
116 -- Create a systray
117 mysystray = widget({ type = "systray", align = "right" })
118
119 -- Wifi widget
120 function wifiInfo(adapter)
121 spacer = " "
122 local f = io.open("/sys/class/net/"..adapter.."/wireless/link")
123 local wifiStrength = f:read()
124 if wifiStrength == "0" then
125 wifiStrength = "Network Down"
126 else
127 wifiStrength = "Wifi:"..spacer..wifiStrength.."%"
128 end
129 wifiwidget.text = spacer..wifiStrength..spacer
130 f:close()
131 end
132
133 wifiwidget = widget({type = "textbox", name = "wifiwidget", align = "right" })
134
135
136 --battery widget
137 function batteryInfo(adapter)
138 spacer = " "
139 local fcur = io.open("/sys/class/power_supply/"..adapter.."/charge_now")
140 local fcap = io.open("/sys/class/power_supply/"..adapter.."/charge_full")
141 local fsta = io.open("/sys/class/power_supply/"..adapter.."/status")
142 local cur = fcur:read()
143 local cap = fcap:read()
144 local sta = fsta:read()
145 local battery = math.floor(cur * 100 / cap)
146 if sta:match("Charging") then
147 dir = "^"
148 battery = "A/C ("..battery..")"
149 elseif sta:match("Discharging") then
150 dir = "v"
151 if tonumber(battery) > 25 and tonumber(battery) < 75 then
152 battery = battery
153 elseif tonumber(battery) < 25 then
154 if tonumber(battery) < 10 then
155 naughty.notify({ title = "Battery Warning"
156 , text = "Battery low!"..spacer..battery.."%"..spacer.."left!"
157 , timeout = 5
158 , position = "top_right"
159 , fg = beautiful.fg_focus
160 , bg = beautiful.bg_focus
161 })
162 end
163 battery = battery
164 else
165 battery = battery
166 end
167 else
168 dir = "="
169 battery = "A/C"
170 end
171 batterywidget.text = spacer.."Bat:"..spacer..dir..battery..dir..spacer
172 fcur:close()
173 fcap:close()
174 fsta:close()
175 end
176
177 batterywidget = widget({type = "textbox", name = "batterywidget", align = "right" })
178
179
180 tb_volume = widget({ type = "textbox", name = "tb_volume", align = "right" })
181 tb_volume:buttons({
182 button({ }, 4, function () volume("up", tb_volume) end),
183 button({ }, 5, function () volume("down", tb_volume) end),
184 button({ }, 1, function () volume("mute", tb_volume) end)
185 })
186 cardid = 0
187 channel = "Master"
188 function volume (mode, widget)
189 if mode == "update" then
190 local fd = io.popen("amixer -c " .. cardid .. " -- sget " .. channel)
191 local status = fd:read("*all")
192 fd:close()
193
194 local volume = string.match(status, "(%d?%d?%d)%%")
195 volume = string.format("% 3d", volume)
196
197 status = string.match(status, "%[(o[^%]]*)%]")
198
199 if string.find(status, "on", 1, true) then
200 volume = volume .. "%"
201 else
202 volume = volume .. "M"
203 end
204 widget.text = " Vol:" .. volume .. " "
205 elseif mode == "up" then
206 io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%+"):read("*all")
207 volume("update", widget)
208 elseif mode == "down" then
209 io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%-"):read("*all")
210 volume("update", widget)
211 else
212 io.popen("amixer -c " .. cardid .. " sset " .. channel .. " toggle"):read("*all")
213 volume("update", widget)
214 end
215 end
216
217 volume("update", tb_volume)
218
219
220
221
222 -- Create a memory widget
223 --memwidget = widget({
224 -- type = 'textbox',
225 -- name = 'memwidget'
226 -- })
227 --wicked.register(memwidget, wicked.widgets.mem,
228 -- ' <span color="white">Memory:</span> $1 ($2Mb/$3Mb)')
229
230
231
232 -- Create a wibox for each screen and add it
233 mywibox = {}
234 mypromptbox = {}
235 mylayoutbox = {}
236 mytaglist = {}
237 mytaglist.buttons = { button({ }, 1, awful.tag.viewonly),
238 button({ modkey }, 1, awful.client.movetotag),
239 button({ }, 3, function (tag) tag.selected = not tag.selected end),
240 button({ modkey }, 3, awful.client.toggletag),
241 button({ }, 4, awful.tag.viewnext),
242 button({ }, 5, awful.tag.viewprev) }
243 mytasklist = {}
244 mytasklist.buttons = { button({ }, 1, function (c)
245 if not c:isvisible() then
246 awful.tag.viewonly(c:tags()[1])
247 end
248 client.focus = c
249 c:raise()
250 end),
251 button({ }, 3, function () if instance then instance:hide() end instance = awful.menu.clients({ width=250 }) end),
252 button({ }, 4, function ()
253 awful.client.focus.byidx(1)
254 if client.focus then client.focus:raise() end
255 end),
256 button({ }, 5, function ()
257 awful.client.focus.byidx(-1)
258 if client.focus then client.focus:raise() end
259 end) }
260
261 for s = 1, screen.count() do
262 -- Create a promptbox for each screen
263 mypromptbox[s] = widget({ type = "textbox", align = "left" })
264 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
265 -- We need one layoutbox per screen.
266 mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
267 mylayoutbox[s]:buttons({ button({ }, 1, function () awful.layout.inc(layouts, 1) end),
268 button({ }, 3, function () awful.layout.inc(layouts, -1) end),
269 button({ }, 4, function () awful.layout.inc(layouts, 1) end),
270 button({ }, 5, function () awful.layout.inc(layouts, -1) end) })
271 -- Create a taglist widget
272 mytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, mytaglist.buttons)
273
274 -- Create a tasklist widget
275 mytasklist[s] = awful.widget.tasklist.new(function(c)
276 return awful.widget.tasklist.label.currenttags(c, s)
277 end, mytasklist.buttons)
278
279 -- Create the wibox
280 mywibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = beautiful.bg_normal })
281 -- Add widgets to the wibox - order matters
282 mywibox[s].widgets = { mylauncher,
283 mytaglist[s],
284 mytasklist[s],
285 mypromptbox[s],
286 -- memwidget,
287 wifiwidget,
288 batterywidget,
289 tb_volume,
290 mytextbox,
291 mylayoutbox[s],
292 s == 1 and mysystray or nil }
293 mywibox[s].screen = s
294 end
295 -- }}}
296
297 -- {{{ Mouse bindings
298 root.buttons({
299 button({ }, 3, function () mymainmenu:toggle() end),
300 button({ }, 4, awful.tag.viewnext),
301 button({ }, 5, awful.tag.viewprev)
302 })
303 -- }}}
304
305 -- {{{ Key bindings
306 -- keybinding({ }, "XF86AudioRaiseVolume", function () volume("up", tb_volume) end):add()
307 -- keybinding({ }, "XF86AudioLowerVolume", function () volume("down", tb_volume) end):add()
308 -- keybinding({ }, "XF86AudioMute", function () volume("mute", tb_volume) end):add()
309
310
311 globalkeys =
312 {
313 key({ modkey, }, "Left", awful.tag.viewprev ),
314 key({ modkey, }, "Right", awful.tag.viewnext ),
315 key({ modkey, }, "Escape", awful.tag.history.restore),
316
317 key({ modkey, }, "j",
318 function ()
319 awful.client.focus.byidx( 1)
320 if client.focus then client.focus:raise() end
321 end),
322 key({ modkey, }, "k",
323 function ()
324 awful.client.focus.byidx(-1)
325 if client.focus then client.focus:raise() end
326 end),
327
328 -- Layout manipulation
329 key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
330 key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
331 key({ modkey, "Control" }, "j", function () awful.screen.focus( 1) end),
332 key({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end),
333 key({ modkey, }, "u", awful.client.urgent.jumpto),
334 key({ modkey, }, "Tab",
335 function ()
336 awful.client.focus.history.previous()
337 if client.focus then
338 client.focus:raise()
339 end
340 end),
341
342 -- Standard program
343 key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
344 key({ modkey, "Control" }, "r", awesome.restart),
345 key({ modkey, "Shift" }, "q", awesome.quit),
346
347 key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
348 key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
349 key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
350 key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
351 key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
352 key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
353 key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
354 key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
355
356 -- Prompt
357 key({ modkey }, "F2",
358 function ()
359 awful.prompt.run({ prompt = "Run: " },
360 mypromptbox[mouse.screen],
361 awful.util.spawn, awful.completion.bash,
362 awful.util.getdir("cache") .. "/history")
363 end),
364
365 key({ modkey }, "F4",
366 function ()
367 awful.prompt.run({ prompt = "Run Lua code: " },
368 mypromptbox[mouse.screen],
369 awful.util.eval, awful.prompt.bash,
370 awful.util.getdir("cache") .. "/history_eval")
371 end),
372 }
373 table.insert(globalkeys, key({ }, "XF86AudioRaiseVolume", function () volume("up", tb_volume) end))
374 table.insert(globalkeys, key({ }, "XF86AudioLowerVolume", function () volume("down", tb_volume) end))
375 table.insert(globalkeys, key({ }, "XF86AudioMute", function () volume("mute", tb_volume) end))
376
377 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
378 clientkeys =
379 {
380 key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
381 key({ modkey, "Shift" }, "c", function (c) c:kill() end),
382 key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
383 key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
384 key({ modkey, }, "o", awful.client.movetoscreen ),
385 key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
386 key({ modkey }, "t", awful.client.togglemarked),
387 key({ modkey,}, "m",
388 function (c)
389 c.maximized_horizontal = not c.maximized_horizontal
390 c.maximized_vertical = not c.maximized_vertical
391 end),
392 }
393
394 -- Compute the maximum number of digit we need, limited to 9
395 keynumber = 0
396 for s = 1, screen.count() do
397 keynumber = math.min(9, math.max(#tags[s], keynumber));
398 end
399
400 for i = 1, keynumber do
401 table.insert(globalkeys,
402 key({ modkey }, i,
403 function ()
404 local screen = mouse.screen
405 if tags[screen][i] then
406 awful.tag.viewonly(tags[screen][i])
407 end
408 end))
409 table.insert(globalkeys,
410 key({ modkey, "Control" }, i,
411 function ()
412 local screen = mouse.screen
413 if tags[screen][i] then
414 tags[screen][i].selected = not tags[screen][i].selected
415 end
416 end))
417 table.insert(globalkeys,
418 key({ modkey, "Shift" }, i,
419 function ()
420 if client.focus and tags[client.focus.screen][i] then
421 awful.client.movetotag(tags[client.focus.screen][i])
422 end
423 end))
424 table.insert(globalkeys,
425 key({ modkey, "Control", "Shift" }, i,
426 function ()
427 if client.focus and tags[client.focus.screen][i] then
428 awful.client.toggletag(tags[client.focus.screen][i])
429 end
430 end))
431 end
432
433
434 for i = 1, keynumber do
435 table.insert(globalkeys, key({ modkey, "Shift" }, "F" .. i,
436 function ()
437 local screen = mouse.screen
438 if tags[screen][i] then
439 for k, c in pairs(awful.client.getmarked()) do
440 awful.client.movetotag(tags[screen][i], c)
441 end
442 end
443 end))
444 end
445
446 -- Set keys
447 root.keys(globalkeys)
448 -- }}}
449
450 -- {{{ Hooks
451 -- Hook function to execute when focusing a client.
452 awful.hooks.focus.register(function (c)
453 if not awful.client.ismarked(c) then
454 c.border_color = beautiful.border_focus
455 end
456 end)
457
458 -- Hook function to execute when unfocusing a client.
459 awful.hooks.unfocus.register(function (c)
460 if not awful.client.ismarked(c) then
461 c.border_color = beautiful.border_normal
462 end
463 end)
464
465 -- Hook function to execute when marking a client
466 awful.hooks.marked.register(function (c)
467 c.border_color = beautiful.border_marked
468 end)
469
470 -- Hook function to execute when unmarking a client.
471 awful.hooks.unmarked.register(function (c)
472 c.border_color = beautiful.border_focus
473 end)
474
475 -- Hook function to execute when the mouse enters a client.
476 awful.hooks.mouse_enter.register(function (c)
477 -- Sloppy focus, but disabled for magnifier layout
478 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
479 and awful.client.focus.filter(c) then
480 client.focus = c
481 end
482 end)
483
484 -- Hook function to execute when a new client appears.
485 awful.hooks.manage.register(function (c, startup)
486 -- If we are not managing this application at startup,
487 -- move it to the screen where the mouse is.
488 -- We only do it for filtered windows (i.e. no dock, etc).
489 if not startup and awful.client.focus.filter(c) then
490 c.screen = mouse.screen
491 end
492
493 if use_titlebar then
494 -- Add a titlebar
495 awful.titlebar.add(c, { modkey = modkey })
496 end
497 -- Add mouse bindings
498 c:buttons({
499 button({ }, 1, function (c) client.focus = c; c:raise() end),
500 button({ modkey }, 1, awful.mouse.client.move),
501 button({ modkey }, 3, awful.mouse.client.resize)
502 })
503 -- New client may not receive focus
504 -- if they're not focusable, so set border anyway.
505 c.border_width = beautiful.border_width
506 c.border_color = beautiful.border_normal
507
508 -- Check if the application should be floating.
509 local cls = c.class
510 local inst = c.instance
511 if floatapps[cls] then
512 awful.client.floating.set(c, floatapps[cls])
513 elseif floatapps[inst] then
514 awful.client.floating.set(c, floatapps[inst])
515 end
516
517 -- Check application->screen/tag mappings.
518 local target
519 if apptags[cls] then
520 target = apptags[cls]
521 elseif apptags[inst] then
522 target = apptags[inst]
523 end
524 if target then
525 c.screen = target.screen
526 awful.client.movetotag(tags[target.screen][target.tag], c)
527 end
528
529 -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
530 client.focus = c
531
532 -- Set key bindings
533 c:keys(clientkeys)
534
535 -- Set the windows at the slave,
536 -- i.e. put it at the end of others instead of setting it master.
537 -- awful.client.setslave(c)
538
539 -- Honor size hints: if you want to drop the gaps between windows, set this to false.
540 -- c.size_hints_honor = false
541 end)
542
543 -- Hook function to execute when arranging the screen.
544 -- (tag switch, new client, etc)
545 awful.hooks.arrange.register(function (screen)
546 local layout = awful.layout.getname(awful.layout.get(screen))
547 if layout and beautiful["layout_" ..layout] then
548 mylayoutbox[screen].image = image(beautiful["layout_" .. layout])
549 else
550 mylayoutbox[screen].image = nil
551 end
552
553 -- Give focus to the latest client in history if no window has focus
554 -- or if the current window is a desktop or a dock one.
555 if not client.focus then
556 local c = awful.client.focus.history.get(screen, 0)
557 if c then client.focus = c end
558 end
559 end)
560
561 -- Hook called every minute
562 awful.hooks.timer.register(60, function ()
563 mytextbox.text = os.date(" %a %b %d, %H:%M ")
564 end)
565
566
567 -- wifi hook
568 awful.hooks.timer.register(5, function()
569 wifiInfo("wlan0")
570 end)
571
572 -- bat hook
573 awful.hooks.timer.register(20, function()
574 batteryInfo("BAT0")
575 end)
576
577
578 awful.hooks.timer.register(10, function () volume("update", tb_volume) end)
579
580
581 -- }}}