1 -- Standard awesome library
3 require("awful.autofocus")
5 -- Theme handling library
7 -- Notification library
10 require("obvious.volume_alsa")
11 require("obvious.battery")
13 -- Load Debian menu entries
14 require("debian.menu")
16 -- from https://github.com/tony/awesome-config/blob/master/helpers.lua
17 function clean(string)
18 s = string.gsub(string, '^%s+', '')
19 s = string.gsub(s, '%s+$', '')
20 s = string.gsub(s, '[\n\r]+', ' ')
24 function file_exists(file)
25 local cmd = "/bin/dash -c 'if [ -e " .. file .. " ]; then echo true; fi;'"
26 local fh = io.popen(cmd)
28 s = clean(fh:read('*a'))
30 if s == 'true' then return true else return nil end
33 -- {{{ Variable definitions
34 -- Themes define colours, icons, and wallpapers
35 beautiful.init("/usr/share/awesome/themes/default/theme.lua")
37 -- This is used later as the default terminal and editor to run.
38 terminal = "x-terminal-emulator"
39 editor = os.getenv("EDITOR") or "editor"
40 editor_cmd = terminal .. " -e " .. editor
41 home = os.getenv("HOME")
43 hostname = awful.util.pread("hostname -f"):gsub("\n", "")
45 wallpaper_dir = home .. "/media/photos/gallery.donarmstrong.com/"
46 if (not file_exists(wallpaper_dir)) then
47 wallpaper_dir = "/usr/share/awesome/themes/default/background.png"
50 wallpaper_cmd = "find " .. wallpaper_dir ..
51 " -xtype f \\( -iname '*.jpg' -o -iname '*.png' \\) " ..
52 " -not -name '.*' -print0 | shuf -n" .. screen.count() .. " -z | xargs -0 feh --bg-max"
54 -- set up the wallpaper timer
55 wallpaper_timer = timer { timeout = 0 }
56 wallpaper_timer:add_signal("timeout",
58 -- tell awsetbg to randomly choose a wallpaper from your wallpaper directory
59 if file_exists(wallpaper_dir) and whereis_app('feh') then
60 os.execute(wallpaper_cmd)
62 -- stop the timer (we don't need multiple instances running at the same time)
65 -- define the interval in which the next wallpaper change should occur in seconds
66 -- (in this case anytime between 10 and 20 minutes)
68 mytimer.timeout = math.random(600,1200)
74 -- Usually, Mod4 is the key with a logo between Control and Alt.
75 -- If you do not like this or do not have such a key,
76 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
77 -- However, you can use another modifier like Mod1, but it may interact with others.
80 -- Table of layouts to cover with awful.layout.inc, order matters.
83 awful.layout.suit.tile,
84 awful.layout.suit.tile.left,
85 awful.layout.suit.tile.bottom,
86 awful.layout.suit.tile.top,
87 awful.layout.suit.fair,
88 awful.layout.suit.fair.horizontal,
89 awful.layout.suit.spiral,
90 awful.layout.suit.spiral.dwindle,
91 awful.layout.suit.max,
92 awful.layout.suit.max.fullscreen,
93 awful.layout.suit.magnifier,
94 awful.layout.suit.floating
99 -- Define a tag table which hold all screen tags.
100 tags = {names={"mail","emacs","www","remotes",5,6,7,8,9}
102 for s = 1, screen.count() do
103 -- Each screen has its own tag table.
104 defaultlayout=layouts[9]
105 tags[s] = awful.tag(tags.names, s, defaultlayout)
110 -- Create a laucher widget and a main menu
112 { "manual", terminal .. " -e man awesome" },
113 { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
114 { "restart", awesome.restart },
115 { "quit", awesome.quit }
118 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
119 { "Debian", debian.menu.Debian_menu.Debian },
120 { "open terminal", terminal }
124 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
129 -- Create a textclock widget
130 mytextclock = awful.widget.textclock({ align = "right" }, " %c ", 1)
132 myvolumealsa = obvious.volume_alsa()
133 mybattery = obvious.battery()
136 mysystray = widget({ type = "systray" })
138 -- Create a wibox for each screen and add it
143 mytaglist.buttons = awful.util.table.join(
144 awful.button({ }, 1, awful.tag.viewonly),
145 awful.button({ modkey }, 1, awful.client.movetotag),
146 awful.button({ }, 3, awful.tag.viewtoggle),
147 awful.button({ modkey }, 3, awful.client.toggletag),
148 awful.button({ }, 4, awful.tag.viewnext),
149 awful.button({ }, 5, awful.tag.viewprev)
152 mytasklist.buttons = awful.util.table.join(
153 awful.button({ }, 1, function (c)
154 if not c:isvisible() then
155 awful.tag.viewonly(c:tags()[1])
160 awful.button({ }, 3, function ()
165 instance = awful.menu.clients({ width=250 })
168 awful.button({ }, 4, function ()
169 awful.client.focus.byidx(1)
170 if client.focus then client.focus:raise() end
172 awful.button({ }, 5, function ()
173 awful.client.focus.byidx(-1)
174 if client.focus then client.focus:raise() end
177 for s = 1, screen.count() do
178 -- Create a promptbox for each screen
179 mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
180 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
181 -- We need one layoutbox per screen.
182 mylayoutbox[s] = awful.widget.layoutbox(s)
183 mylayoutbox[s]:buttons(awful.util.table.join(
184 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
185 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
186 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
187 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
188 -- Create a taglist widget
189 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
191 -- Create a tasklist widget
192 mytasklist[s] = awful.widget.tasklist(function(c)
193 return awful.widget.tasklist.label.currenttags(c, s)
194 end, mytasklist.buttons)
197 mywibox[s] = awful.wibox({ position = "top", screen = s })
198 -- Add widgets to the wibox - order matters
199 mywibox[s].widgets = {
204 layout = awful.widget.layout.horizontal.leftright
210 s == 1 and mysystray or nil,
212 layout = awful.widget.layout.horizontal.rightleft
217 -- {{{ Mouse bindings
218 root.buttons(awful.util.table.join(
219 awful.button({ }, 3, function () mymainmenu:toggle() end),
220 awful.button({ }, 4, awful.tag.viewnext),
221 awful.button({ }, 5, awful.tag.viewprev)
226 globalkeys = awful.util.table.join(
227 -- awful.key({ modkey, }, "Left", awful.tag.viewprev ),
228 -- awful.key({ modkey, }, "Right", awful.tag.viewnext ),
229 awful.key({},"XF86AudioRaiseVolume",function () obvious.volume_alsa.raise(0, "Master", 2) end),
230 awful.key({},"XF86AudioLowerVolume",function () obvious.volume_alsa.lower(0, "Master", 2) end),
231 awful.key({ modkey, }, "Escape", awful.tag.history.restore),
233 awful.key({ modkey, }, "j",
235 awful.client.focus.byidx( 1)
236 if client.focus then client.focus:raise() end
239 awful.key({ modkey, }, "k",
241 awful.client.focus.byidx(-1)
242 if client.focus then client.focus:raise() end
245 awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
247 -- Layout manipulation
248 awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
249 awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
250 awful.key({ modkey, }, "Left", function () awful.screen.focus_relative( 1) end),
251 awful.key({ modkey, }, "Right", function () awful.screen.focus_relative(-1) end),
252 awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
253 awful.key({ modkey, }, "Tab",
255 awful.client.focus.history.previous()
262 awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
263 awful.key({ modkey, "Control", "Shift" }, "r", awesome.restart),
264 awful.key({ modkey, "Control", "Shift" }, "q", awesome.quit),
266 awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
267 awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
268 awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
269 awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
270 awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
271 awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
272 awful.key({ modkey, }, "n", function () awful.layout.inc(layouts, 1) end),
273 awful.key({ modkey, "Shift" }, "n", function () awful.layout.inc(layouts, -1) end),
276 awful.key({ modkey, "Control" }, "Down", function () awful.client.moveresize(0, 20, 0, 0) end),
277 awful.key({ modkey, "Control" }, "Up", function () awful.client.moveresize(0, -20, 0, 0) end),
278 awful.key({ modkey, "Control" }, "Left", function () awful.client.moveresize(-20, 0, 0, 0) end),
279 awful.key({ modkey, "Control" }, "Right", function () awful.client.moveresize(20, 0, 0, 0) end),
280 awful.key({ modkey, "Control" , "Shift" }, "Down", function () awful.client.moveresize(0, 0, 0, -20) end),
281 awful.key({ modkey, "Control" , "Shift" }, "Up", function () awful.client.moveresize(0, 0, 0, 20) end),
282 awful.key({ modkey, "Control" , "Shift" }, "Left", function () awful.client.moveresize(0, 0, -20, 0) end),
283 awful.key({ modkey, "Control" , "Shift" }, "Right", function () awful.client.moveresize(0, 0, 20, 0) end),
285 awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
287 awful.key({ modkey }, "x",
289 awful.prompt.run({ prompt = "Run Lua code: " },
290 mypromptbox[mouse.screen].widget,
291 awful.util.eval, nil,
292 awful.util.getdir("cache") .. "/history_eval")
296 clientkeys = awful.util.table.join(
297 awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
298 awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
299 awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
300 awful.key({ modkey, }, "space", function (c) c:swap(awful.client.getmaster()) end),
301 awful.key({ modkey, }, "o", awful.client.movetoscreen ),
302 awful.key({ modkey, "Shift" }, "Right", function(c) awful.client.movetoscreen(c,c.screen-1 % screen.count()) end),
303 awful.key({ modkey, "Shift" }, "Left", function(c) awful.client.movetoscreen(c,c.screen+1 % screen.count()) end),
304 awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
305 awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
306 awful.key({ modkey, "Shift" }, "m", function (c) c.minimized = not c.minimized end),
307 awful.key({ modkey, }, "m",
309 c.maximized_horizontal = not c.maximized_horizontal
310 c.maximized_vertical = not c.maximized_vertical
314 -- Compute the maximum number of digit we need, limited to 9
316 for s = 1, screen.count() do
317 keynumber = math.min(9, math.max(#tags[s], keynumber));
320 -- Bind all key numbers to tags.
321 -- Be careful: we use keycodes to make it works on any keyboard layout.
322 -- This should map on the top row of your keyboard, usually 1 to 9.
323 for i = 1, keynumber do
324 globalkeys = awful.util.table.join(globalkeys,
325 awful.key({ modkey }, "#" .. i + 9,
327 local screen = mouse.screen
328 if tags[screen][i] then
329 awful.tag.viewonly(tags[screen][i])
332 awful.key({ modkey, "Control" }, "#" .. i + 9,
334 local screen = mouse.screen
335 if tags[screen][i] then
336 awful.tag.viewtoggle(tags[screen][i])
339 awful.key({ modkey, "Shift" }, "#" .. i + 9,
341 if client.focus and tags[client.focus.screen][i] then
342 awful.client.movetotag(tags[client.focus.screen][i])
345 awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
347 if client.focus and tags[client.focus.screen][i] then
348 awful.client.toggletag(tags[client.focus.screen][i])
353 clientbuttons = awful.util.table.join(
354 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
355 awful.button({ modkey }, 1, awful.mouse.client.move),
356 awful.button({ modkey }, 3, awful.mouse.client.resize))
359 root.keys(globalkeys)
363 awful.rules.rules = {
364 -- All clients will match this rule.
366 properties = { border_width = beautiful.border_width,
367 border_color = beautiful.border_normal,
370 buttons = clientbuttons } },
371 { rule = { class = "MPlayer" },
372 properties = { floating = true , ontop=true } },
373 { rule = { class = "pinentry" },
374 properties = { floating = true , ontop=true } },
375 { rule = { class = "gimp" },
376 properties = { floating = true } },
377 -- Set Firefox to always map on tags number 2 of screen 1.
378 -- { rule = { class = "Firefox" },
379 -- properties = { tag = tags[1][2] } },
384 -- Signal function to execute when a new client appears.
385 client.add_signal("manage", function (c, startup)
387 -- awful.titlebar.add(c, { modkey = modkey })
389 -- Enable sloppy focus
390 c:add_signal("mouse::enter", function(c)
391 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
392 and awful.client.focus.filter(c) then
398 -- Set the windows at the slave,
399 -- i.e. put it at the end of others instead of setting it master.
400 -- awful.client.setslave(c)
402 -- Put windows in a smart way, only if they does not set an initial position.
403 if not c.size_hints.user_position and not c.size_hints.program_position then
404 awful.placement.no_overlap(c)
405 awful.placement.no_offscreen(c)
410 function warp_mouse()
413 local g = c:geometry()
414 mouse.coords({ x = g.x + 1, y = g.y + 1}, true)
418 -- for s = 1, screen.count() do
419 -- screen[s]:add_signal("arrange", function (screen)
420 -- warp_mouse(screen)
425 client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
426 client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)