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