]> git.donarmstrong.com Git - x_base.git/blob - .config/awesome/rc.lua
update awesome configuration for newer versions of awesome
[x_base.git] / .config / awesome / rc.lua
1 -- Standard awesome library
2 local gears = require("gears")
3 local awful = require("awful")
4 awful.rules = require("awful.rules")
5 require("awful.autofocus")
6 -- Widget and layout library
7 local wibox = require("wibox")
8 -- Theme handling library
9 local beautiful = require("beautiful")
10 -- Notification library
11 local naughty = require("naughty")
12 local menubar = require("menubar")
13 -- Load Debian menu entries
14 require("debian.menu")
15
16 -- from https://github.com/tony/awesome-config/blob/master/helpers.lua
17
18 function file_exists(file)
19    s = awful.util.pread("/bin/dash -c 'if [ -e " .. file .. " ]; then echo true; fi;'"):gsub("\n","")
20    if s == 'true' then return true else return nil end
21 end
22
23
24 -- {{{ Variable definitions
25 -- Themes define colours, icons, and wallpapers
26 beautiful.init("/usr/share/awesome/themes/default/theme.lua")
27
28 -- local APW
29 -- if file_exists("apw/widget.lua") then
30 local APW = require("apw/widget")
31 -- end
32
33 -- local vicious
34 local vicious = require("vicious")
35
36 local cpuwidget = wibox.widget.textbox()
37 vicious.register(cpuwidget, vicious.widgets.cpu, "$1%CPU ")
38 local batwidget = wibox.widget.textbox()
39 vicious.register(batwidget,vicious.widgets.bat," $2%$1 $3",120,"BAT0")
40
41 -- This is used later as the default terminal and editor to run.
42 terminal = "x-terminal-emulator"
43 editor = os.getenv("EDITOR") or "editor"
44 editor_cmd = terminal .. " -e " .. editor
45 home = os.getenv("HOME")
46
47 hostname = awful.util.pread("hostname -f"):gsub("\n", "")
48
49 -- Default modkey.
50 -- Usually, Mod4 is the key with a logo between Control and Alt.
51 -- If you do not like this or do not have such a key,
52 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
53 -- However, you can use another modifier like Mod1, but it may interact with others.
54 modkey = "Mod4"
55
56 -- Table of layouts to cover with awful.layout.inc, order matters.
57 local layouts =
58 {
59     awful.layout.suit.tile,
60     awful.layout.suit.tile.left,
61     awful.layout.suit.tile.bottom,
62     awful.layout.suit.tile.top,
63     awful.layout.suit.fair,
64     awful.layout.suit.fair.horizontal,
65     awful.layout.suit.spiral,
66     awful.layout.suit.spiral.dwindle,
67     awful.layout.suit.max,
68     awful.layout.suit.max.fullscreen,
69     awful.layout.suit.magnifier,
70     awful.layout.suit.floating
71 }
72 -- }}}
73
74 -- {{{ Tags
75 -- Define a tag table which hold all screen tags.
76 tags = {names={"mail","emacs","www","remotes",5,6,7,8,9}
77        }
78 for s = 1, screen.count() do
79     -- Each screen has its own tag table.
80    local defaultlayout=layouts[9]
81    tags[s] = awful.tag(tags.names, s, defaultlayout)
82 end
83 -- }}}
84
85 -- {{{ Menu
86 -- Create a laucher widget and a main menu
87 myawesomemenu = {
88    { "manual", terminal .. " -e man awesome" },
89    { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
90    { "restart", awesome.restart },
91    { "quit", awesome.quit }
92 }
93
94 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
95                                     { "Debian", debian.menu.Debian_menu.Debian },
96                                     { "open terminal", terminal }
97                                   }
98                         })
99
100 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
101                                      menu = mymainmenu })
102 -- }}}
103
104 -- {{{ Wibox
105 -- Create a textclock widget
106 mytextclock = awful.widget.textclock() --{ align = "right" }, " %c ", 1)
107
108 -- mybattery = obvious.battery()
109
110 -- mytemp = obvious.temp_info()
111
112 -- Create a wibox for each screen and add it
113 mywibox = {}
114 mypromptbox = {}
115 mylayoutbox = {}
116 mytaglist = {}
117 mytaglist.buttons = awful.util.table.join(
118                     awful.button({ }, 1, awful.tag.viewonly),
119                     awful.button({ modkey }, 1, awful.client.movetotag),
120                     awful.button({ }, 3, awful.tag.viewtoggle),
121                     awful.button({ modkey }, 3, awful.client.toggletag),
122                     awful.button({ }, 4, awful.tag.viewnext),
123                     awful.button({ }, 5, awful.tag.viewprev)
124                     )
125 mytasklist = {}
126 mytasklist.buttons = awful.util.table.join(
127                      awful.button({ }, 1, function (c)
128                                               if not c:isvisible() then
129                                                   awful.tag.viewonly(c:tags()[1])
130                                               end
131                                               client.focus = c
132                                               c:raise()
133                                           end),
134                      awful.button({ }, 3, function ()
135                                               if instance then
136                                                   instance:hide()
137                                                   instance = nil
138                                               else
139                                                   instance = awful.menu.clients({ width=250 })
140                                               end
141                                           end),
142                      awful.button({ }, 4, function ()
143                                               awful.client.focus.byidx(1)
144                                               if client.focus then client.focus:raise() end
145                                           end),
146                      awful.button({ }, 5, function ()
147                                               awful.client.focus.byidx(-1)
148                                               if client.focus then client.focus:raise() end
149                                           end))
150
151 for s = 1, screen.count() do
152     -- Create a promptbox for each screen
153     mypromptbox[s] = awful.widget.prompt()
154     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
155     -- We need one layoutbox per screen.
156     mylayoutbox[s] = awful.widget.layoutbox(s)
157     mylayoutbox[s]:buttons(awful.util.table.join(
158                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
159                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
160                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
161                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
162     -- Create a taglist widget
163     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
164
165     -- Create a tasklist widget
166     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
167
168     -- Create the wibox
169     mywibox[s] = awful.wibox({ position = "top", screen = s })
170
171     -- Widgets that are aligned to the left
172     local left_layout = wibox.layout.fixed.horizontal()
173     left_layout:add(mylauncher)
174     left_layout:add(mytaglist[s])
175     left_layout:add(mypromptbox[s])
176
177     -- Widgets that are aligned to the right
178     local right_layout = wibox.layout.fixed.horizontal()
179     if s == 1 then right_layout:add(wibox.widget.systray()) end
180     
181     right_layout:add(cpuwidget)
182     right_layout:add(batwidget)
183     right_layout:add(mytextclock)
184     right_layout:add(mylayoutbox[s])
185
186     -- Now bring it all together (with the tasklist in the middle)
187     local layout = wibox.layout.align.horizontal()
188     layout:set_left(left_layout)
189     layout:set_middle(mytasklist[s])
190     layout:set_right(right_layout)
191
192     mywibox[s]:set_widget(layout)
193 end
194 -- }}}
195
196 -- {{{ Mouse bindings
197 root.buttons(awful.util.table.join(
198     awful.button({ }, 3, function () mymainmenu:toggle() end),
199     awful.button({ }, 4, awful.tag.viewnext),
200     awful.button({ }, 5, awful.tag.viewprev)
201 ))
202 -- }}}
203
204 -- {{{ Key bindings
205 globalkeys = awful.util.table.join(
206     -- awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
207     -- awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
208    awful.key({},"XF86AudioRaiseVolume",APW.Up),
209    awful.key({},"XF86AudioLowerVolume",APW.Down),
210    awful.key({},"XF86RotateWindows", function () awful.util.spawn("rotate_monitor") end),
211     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
212
213     awful.key({ modkey,           }, "j",
214         function ()
215             awful.client.focus.byidx( 1)
216             if client.focus then client.focus:raise() end
217             warp_mouse()
218         end),
219     awful.key({ modkey,           }, "k",
220         function ()
221             awful.client.focus.byidx(-1)
222             if client.focus then client.focus:raise() end
223             warp_mouse()
224         end),
225     awful.key({ modkey,           }, "w", function () mymainmenu:show({keygrabber=true}) end),
226
227     -- Layout manipulation
228     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
229     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
230     awful.key({ modkey,           }, "Left", function () awful.screen.focus_relative( 1) end),
231     awful.key({ modkey,           }, "Right", function () awful.screen.focus_relative(-1) end),
232     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
233     awful.key({ modkey,           }, "Tab",
234               function ()
235                  -- awful.client.focus.history.previous()
236                  awful.client.focus.byidx(-1)
237                  if client.focus then
238                     client.focus:raise()
239                  end
240               end),
241     
242     awful.key({ modkey, "Shift"   }, "Tab",
243               function ()
244                  -- awful.client.focus.history.previous()
245                  awful.client.focus.byidx(1)
246                  if client.focus then
247                     client.focus:raise()
248                  end
249               end),
250     -- Standard program
251     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
252     awful.key({ modkey, "Control", "Shift" }, "r", awesome.restart),
253     awful.key({ modkey, "Control", "Shift"   }, "q", awesome.quit),
254
255     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
256     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
257     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
258     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
259     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
260     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
261     awful.key({ modkey,           }, "n", function () awful.layout.inc(layouts,  1) end),
262     awful.key({ modkey, "Shift"   }, "n", function () awful.layout.inc(layouts, -1) end),
263
264     -- resize floats
265     awful.key({ modkey, "Control" }, "Down",  function () awful.client.moveresize(0, 20, 0, 0) end),
266     awful.key({ modkey, "Control" }, "Up",    function () awful.client.moveresize(0, -20, 0, 0) end),
267     awful.key({ modkey, "Control" }, "Left",  function () awful.client.moveresize(-20, 0, 0, 0) end),
268     awful.key({ modkey, "Control" }, "Right", function () awful.client.moveresize(20, 0, 0, 0) end),
269     awful.key({ modkey, "Control" , "Shift" }, "Down",  function () awful.client.moveresize(0, 0, 0, -20) end),
270     awful.key({ modkey, "Control" , "Shift" }, "Up",    function () awful.client.moveresize(0, 0, 0, 20) end),
271     awful.key({ modkey, "Control" , "Shift" }, "Left",  function () awful.client.moveresize(0, 0, -20, 0) end),
272     awful.key({ modkey, "Control" , "Shift" }, "Right", function () awful.client.moveresize(0, 0, 20, 0) end),
273    -- Prompt
274     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
275
276     awful.key({ modkey }, "x",
277               function ()
278                   awful.prompt.run({ prompt = "Run Lua code: " },
279                   mypromptbox[mouse.screen].widget,
280                   awful.util.eval, nil,
281                   awful.util.getdir("cache") .. "/history_eval")
282               end)
283 )
284
285 clientkeys = awful.util.table.join(
286     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
287     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
288     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
289     awful.key({ modkey,           }, "space", function (c) c:swap(awful.client.getmaster()) end),
290     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
291     awful.key({ modkey, "Shift"   }, "Right",  function(c) awful.client.movetoscreen(c,c.screen-1 % screen.count())      end),
292     awful.key({ modkey, "Shift"   }, "Left",   function(c) awful.client.movetoscreen(c,c.screen+1 % screen.count())     end),
293     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
294     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
295     awful.key({ modkey, "Shift"   }, "m",      function (c) c.minimized = not c.minimized    end),
296     awful.key({ modkey,           }, "m",
297         function (c)
298             c.maximized_horizontal = not c.maximized_horizontal
299             c.maximized_vertical   = not c.maximized_vertical
300         end)
301 )
302
303 -- Compute the maximum number of digit we need, limited to 9
304 keynumber = 0
305 for s = 1, screen.count() do
306    keynumber = math.min(9, math.max(#tags[s], keynumber));
307 end
308
309 -- Bind all key numbers to tags.
310 -- Be careful: we use keycodes to make it works on any keyboard layout.
311 -- This should map on the top row of your keyboard, usually 1 to 9.
312 for i = 1, keynumber do
313     globalkeys = awful.util.table.join(globalkeys,
314         awful.key({ modkey }, "#" .. i + 9,
315                   function ()
316                         local screen = mouse.screen
317                         if tags[screen][i] then
318                             awful.tag.viewonly(tags[screen][i])
319                         end
320                   end),
321         awful.key({ modkey, "Control" }, "#" .. i + 9,
322                   function ()
323                       local screen = mouse.screen
324                       if tags[screen][i] then
325                           awful.tag.viewtoggle(tags[screen][i])
326                       end
327                   end),
328         awful.key({ modkey, "Shift" }, "#" .. i + 9,
329                   function ()
330                       if client.focus and tags[client.focus.screen][i] then
331                           awful.client.movetotag(tags[client.focus.screen][i])
332                       end
333                   end),
334         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
335                   function ()
336                       if client.focus and tags[client.focus.screen][i] then
337                           awful.client.toggletag(tags[client.focus.screen][i])
338                       end
339                   end))
340 end
341
342 clientbuttons = awful.util.table.join(
343     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
344     awful.button({ modkey }, 1, awful.mouse.client.move),
345     awful.button({ modkey }, 3, awful.mouse.client.resize))
346
347 -- Set keys
348 root.keys(globalkeys)
349 -- }}}
350
351 -- {{{ Rules
352 awful.rules.rules = {
353     -- All clients will match this rule.
354     { rule = { },
355       properties = { border_width = beautiful.border_width,
356                      border_color = beautiful.border_normal,
357                      focus = true,
358                      keys = clientkeys,
359                      buttons = clientbuttons } },
360     { rule = { class = "MPlayer" },
361       properties = { floating = true , ontop=true } },
362     { rule = { class = "pinentry" },
363       properties = { floating = true , ontop=true } },
364     { rule = { class = "gimp" },
365       properties = { floating = true } },
366     -- Set Firefox to always map on tags number 2 of screen 1.
367     -- { rule = { class = "Firefox" },
368     --   properties = { tag = tags[1][2] } },
369 }
370 -- }}}
371
372 -- {{{ Signals
373 -- Signal function to execute when a new client appears.
374 client.add_signal("manage", function (c, startup)
375     -- Add a titlebar
376     -- awful.titlebar.add(c, { modkey = modkey })
377
378     -- Enable sloppy focus
379     c:add_signal("mouse::enter", function(c)
380         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
381             and awful.client.focus.filter(c) then
382             client.focus = c
383         end
384     end)
385
386     if not startup then
387         -- Set the windows at the slave,
388         -- i.e. put it at the end of others instead of setting it master.
389         -- awful.client.setslave(c)
390
391         -- Put windows in a smart way, only if they does not set an initial position.
392         if not c.size_hints.user_position and not c.size_hints.program_position then
393             awful.placement.no_overlap(c)
394             awful.placement.no_offscreen(c)
395         end
396     end
397 end)
398
399 function warp_mouse()
400     c = client.focus
401     if c then
402         local g = c:geometry()
403         mouse.coords({ x = g.x + 1, y = g.y + 1}, true)
404     end
405 end
406
407 -- for s = 1, screen.count() do
408 --     screen[s]:add_signal("arrange", function (screen)
409 --         warp_mouse(screen)
410 --     end)
411 -- end
412
413
414 client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
415 client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
416 -- }}}
417
418
419 wallpaper_dir = home .. "/media/background"
420 if (not file_exists(wallpaper_dir)) then
421    wallpaper_dir = "/usr/share/awesome/themes/default/background.png"
422 end
423
424 wallpaper_cmd = "find " .. wallpaper_dir ..
425    " -xtype f \\( -iname '*.jpg' -o -iname '*.png' \\) " ..
426    " -not -name '.*' -print0 | shuf -n" .. screen.count() .. " -z | xargs -0 feh --draw-exif -d --bg-max"
427
428 -- set up the wallpaper timer
429 -- wallpaper_timer = timer({ timeout = 0 })
430 -- wallpaper_timer:add_signal("timeout",
431 --   function()
432 --      -- tell awsetbg to randomly choose a wallpaper from your wallpaper directory
433 --      os.execute(wallpaper_cmd)
434 --      -- stop the timer (we don't need multiple instances running at the same time)
435 --      wallpaper_timer:stop()
436 --      
437 --      -- define the interval in which the next wallpaper change should occur in seconds
438 --      -- (in this case anytime between 10 and 20 minutes)
439 --      --restart the timer
440 --      wallpaper_timer.timeout = math.random(600,1200)
441 --      wallpaper_timer:start()
442 --   end
443 -- )
444 -- wallpaper_timer:start();