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")
16 -- from https://github.com/tony/awesome-config/blob/master/helpers.lua
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
24 -- {{{ Variable definitions
25 -- Themes define colours, icons, and wallpapers
26 beautiful.init("/usr/share/awesome/themes/default/theme.lua")
29 -- if file_exists("apw/widget.lua") then
30 local APW = require("apw/widget")
34 local vicious = require("vicious")
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")
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")
47 hostname = awful.util.pread("hostname -f"):gsub("\n", "")
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.
56 -- Table of layouts to cover with awful.layout.inc, order matters.
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
75 -- Define a tag table which hold all screen tags.
76 tags = {names={"mail","emacs","www","remotes",5,6,7,8,9}
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)
86 -- Create a laucher widget and a main menu
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 }
94 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
95 { "Debian", debian.menu.Debian_menu.Debian },
96 { "open terminal", terminal }
100 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
105 -- Create a textclock widget
106 mytextclock = awful.widget.textclock() --{ align = "right" }, " %c ", 1)
108 -- mybattery = obvious.battery()
110 -- mytemp = obvious.temp_info()
112 -- Create a wibox for each screen and add it
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)
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])
134 awful.button({ }, 3, function ()
139 instance = awful.menu.clients({ width=250 })
142 awful.button({ }, 4, function ()
143 awful.client.focus.byidx(1)
144 if client.focus then client.focus:raise() end
146 awful.button({ }, 5, function ()
147 awful.client.focus.byidx(-1)
148 if client.focus then client.focus:raise() end
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)
165 -- Create a tasklist widget
166 mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
169 mywibox[s] = awful.wibox({ position = "top", screen = s })
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])
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
181 right_layout:add(cpuwidget)
182 right_layout:add(batwidget)
183 right_layout:add(mytextclock)
184 right_layout:add(mylayoutbox[s])
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)
192 mywibox[s]:set_widget(layout)
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)
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),
213 awful.key({ modkey, }, "j",
215 awful.client.focus.byidx( 1)
216 if client.focus then client.focus:raise() end
219 awful.key({ modkey, }, "k",
221 awful.client.focus.byidx(-1)
222 if client.focus then client.focus:raise() end
225 awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
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",
235 -- awful.client.focus.history.previous()
236 awful.client.focus.byidx(-1)
242 awful.key({ modkey, "Shift" }, "Tab",
244 -- awful.client.focus.history.previous()
245 awful.client.focus.byidx(1)
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),
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),
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),
274 awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
276 awful.key({ modkey }, "x",
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")
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",
298 c.maximized_horizontal = not c.maximized_horizontal
299 c.maximized_vertical = not c.maximized_vertical
303 -- Compute the maximum number of digit we need, limited to 9
305 for s = 1, screen.count() do
306 keynumber = math.min(9, math.max(#tags[s], keynumber));
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,
316 local screen = mouse.screen
317 if tags[screen][i] then
318 awful.tag.viewonly(tags[screen][i])
321 awful.key({ modkey, "Control" }, "#" .. i + 9,
323 local screen = mouse.screen
324 if tags[screen][i] then
325 awful.tag.viewtoggle(tags[screen][i])
328 awful.key({ modkey, "Shift" }, "#" .. i + 9,
330 if client.focus and tags[client.focus.screen][i] then
331 awful.client.movetotag(tags[client.focus.screen][i])
334 awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
336 if client.focus and tags[client.focus.screen][i] then
337 awful.client.toggletag(tags[client.focus.screen][i])
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))
348 root.keys(globalkeys)
352 awful.rules.rules = {
353 -- All clients will match this rule.
355 properties = { border_width = beautiful.border_width,
356 border_color = beautiful.border_normal,
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] } },
373 -- Signal function to execute when a new client appears.
374 client.add_signal("manage", function (c, startup)
376 -- awful.titlebar.add(c, { modkey = modkey })
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
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)
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)
399 function warp_mouse()
402 local g = c:geometry()
403 mouse.coords({ x = g.x + 1, y = g.y + 1}, true)
407 -- for s = 1, screen.count() do
408 -- screen[s]:add_signal("arrange", function (screen)
409 -- warp_mouse(screen)
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)
419 wallpaper_dir = home .. "/media/background"
420 if (not file_exists(wallpaper_dir)) then
421 wallpaper_dir = "/usr/share/awesome/themes/default/background.png"
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"
428 -- set up the wallpaper timer
429 -- wallpaper_timer = timer({ timeout = 0 })
430 -- wallpaper_timer:add_signal("timeout",
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()
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()
444 -- wallpaper_timer:start();