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