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