updated rc file for the Awesome 3.5 (widgets are still not working)
[awesome-config] / 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
14 -- Load Debian menu entries
15 require("debian.menu")
16
17 -- {{{ Error handling
18 -- Check if awesome encountered an error during startup and fell back to
19 -- another config (This code will only ever execute for the fallback config)
20 if awesome.startup_errors then
21     naughty.notify({ preset = naughty.config.presets.critical,
22                      title = "Oops, there were errors during startup!",
23                      text = awesome.startup_errors })
24 end
25
26 -- Handle runtime errors after startup
27 do
28     local in_error = false
29     awesome.connect_signal("debug::error", function (err)
30         -- Make sure we don't go into an endless error loop
31         if in_error then return end
32         in_error = true
33
34         naughty.notify({ preset = naughty.config.presets.critical,
35                          title = "Oops, an error happened!",
36                          text = err })
37         in_error = false
38     end)
39 end
40 -- }}}
41
42 -- {{{ Variable definitions
43 -- Themes define colours, icons, font and wallpapers.
44 beautiful.init("/usr/share/awesome/themes/sky/theme.lua")
45 theme.wallpaper = "/home/mako/images/Flag_of_Cascadia.png"
46 -- beautiful.init("~/.config/awesome/themes/default/theme.lua")
47 for s = 1, screen.count() do
48     gears.wallpaper.maximized(beautiful.wallpaper, s, true)
49 end
50 -- recipes here: https://wiki.archlinux.org/index.php/Awesome#Wallpaper
51
52 -- This is used later as the default terminal and editor to run.
53 terminal = "x-terminal-emulator"
54 editor = os.getenv("EDITOR") or "editor"
55 editor_cmd = terminal .. " -e " .. editor
56
57 -- Default modkey.
58 -- Usually, Mod4 is the key with a logo between Control and Alt.
59 -- If you do not like this or do not have such a key,
60 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
61 -- However, you can use another modifier like Mod1, but it may interact with others.
62 modkey = "Mod1"
63
64 -- Table of layouts to cover with awful.layout.inc, order matters.
65 local layouts =
66 {
67     awful.layout.suit.tile,
68     awful.layout.suit.max,
69     awful.layout.suit.floating
70 }
71 -- }}}
72
73 -- {{{ Wallpaper
74 -- if beautiful.wallpaper then
75 --     for s = 1, screen.count() do
76 --        gears.wallpaper.maximized(beautiful.wallpaper, s, true)
77 --    end
78 -- end
79 -- }}}
80
81
82 -- {{{ Tags
83 -- Define a tag table which hold all screen tags.
84 tags = {}
85 for s = 1, screen.count() do
86     -- Each screen has its own tag table.
87     tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
88 end
89 -- }}}
90
91 -- {{{ Menu
92 -- Create a laucher widget and a main menu
93 myawesomemenu = {
94    { "manual", terminal .. " -e man awesome" },
95    { "edit config", editor_cmd .. " " .. awesome.conffile },
96    { "restart", awesome.restart },
97    { "quit", awesome.quit }
98 }
99
100 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
101                                     { "Debian", debian.menu.Debian_menu.Debian },
102                                     { "open terminal", terminal }
103                                   }
104                         })
105
106 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
107                                      menu = mymainmenu })
108
109 -- Menubar configuration
110 menubar.utils.terminal = terminal -- Set the terminal for applications that require it
111 -- }}}
112
113 -- {{{ Wibox
114 -- Create a textclock widget
115 mytextclock = awful.widget.textclock()
116
117 -- Create a wibox for each screen and add it
118 mywibox = {}
119 mypromptbox = {}
120 mylayoutbox = {}
121 mytaglist = {}
122 mytaglist.buttons = awful.util.table.join(
123                     awful.button({ }, 1, awful.tag.viewonly),
124                     awful.button({ modkey }, 1, awful.client.movetotag),
125                     awful.button({ }, 3, awful.tag.viewtoggle),
126                     awful.button({ modkey }, 3, awful.client.toggletag),
127                     awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
128                     awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
129                     )
130 mytasklist = {}
131 mytasklist.buttons = awful.util.table.join(
132                      awful.button({ }, 1, function (c)
133                                               if c == client.focus then
134                                                   c.minimized = true
135                                               else
136                                                   -- Without this, the following
137                                                   -- :isvisible() makes no sense
138                                                   c.minimized = false
139                                                   if not c:isvisible() then
140                                                       awful.tag.viewonly(c:tags()[1])
141                                                   end
142                                                   -- This will also un-minimize
143                                                   -- the client, if needed
144                                                   client.focus = c
145                                                   c:raise()
146                                               end
147                                           end),
148                      awful.button({ }, 3, function ()
149                                               if instance then
150                                                   instance:hide()
151                                                   instance = nil
152                                               else
153                                                   instance = awful.menu.clients({
154                                                       theme = { width = 250 }
155                                                   })
156                                               end
157                                           end),
158                      awful.button({ }, 4, function ()
159                                               awful.client.focus.byidx(1)
160                                               if client.focus then client.focus:raise() end
161                                           end),
162                      awful.button({ }, 5, function ()
163                                               awful.client.focus.byidx(-1)
164                                               if client.focus then client.focus:raise() end
165                                           end))
166
167 for s = 1, screen.count() do
168     -- Create a promptbox for each screen
169     mypromptbox[s] = awful.widget.prompt()
170     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
171     -- We need one layoutbox per screen.
172     mylayoutbox[s] = awful.widget.layoutbox(s)
173     mylayoutbox[s]:buttons(awful.util.table.join(
174                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
175                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
176                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
177                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
178     -- Create a taglist widget
179     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
180
181     -- Create a tasklist widget
182     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
183
184     -- Create the wibox
185     mywibox[s] = awful.wibox({ position = "top", screen = s })
186
187     -- Widgets that are aligned to the left
188     local left_layout = wibox.layout.fixed.horizontal()
189     left_layout:add(mylauncher)
190     left_layout:add(mytaglist[s])
191     left_layout:add(mypromptbox[s])
192
193     -- Widgets that are aligned to the right
194     local right_layout = wibox.layout.fixed.horizontal()
195     if s == 1 then right_layout:add(wibox.widget.systray()) end
196     right_layout:add(mytextclock)
197     right_layout:add(mylayoutbox[s])
198
199     -- Now bring it all together (with the tasklist in the middle)
200     local layout = wibox.layout.align.horizontal()
201     layout:set_left(left_layout)
202     layout:set_middle(mytasklist[s])
203     layout:set_right(right_layout)
204
205     mywibox[s]:set_widget(layout)
206 end
207 -- }}}
208
209 -- {{{ Mouse bindings
210 root.buttons(awful.util.table.join(
211     awful.button({ }, 3, function () mymainmenu:toggle() end),
212     awful.button({ }, 4, awful.tag.viewnext),
213     awful.button({ }, 5, awful.tag.viewprev)
214 ))
215 -- }}}
216
217 -- {{{ Key bindings
218 globalkeys = awful.util.table.join(
219     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
220     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
221     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
222
223     awful.key({ modkey,           }, "j",
224         function ()
225             awful.client.focus.byidx( 1)
226             if client.focus then client.focus:raise() end
227         end),
228     awful.key({ modkey,           }, "k",
229         function ()
230             awful.client.focus.byidx(-1)
231             if client.focus then client.focus:raise() end
232         end),
233     awful.key({ modkey,           }, "w", function () mymainmenu:show() end),
234
235     -- Layout manipulation
236     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
237     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
238     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
239     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
240     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
241     awful.key({ modkey,           }, "Tab",
242         function ()
243             awful.client.focus.history.previous()
244             if client.focus then
245                 client.focus:raise()
246             end
247         end),
248
249     -- Standard program
250     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
251     awful.key({ modkey, "Control" }, "r", awesome.restart),
252     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
253
254     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
255     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
256     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
257     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
258     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
259     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
260     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
261     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
262
263     awful.key({ modkey, "Control" }, "n", awful.client.restore),
264
265     -- Prompt
266     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
267
268     awful.key({ modkey }, "x",    
269                function () 
270                   awful.prompt.run({ prompt = "Run in Terminal: " },
271                   mypromptbox[mouse.screen].widget,
272                   function (prog) awful.util.spawn_with_shell(terminal .. " -title " .. prog .. " -e " .. prog) end) end),
273
274     awful.key({ modkey, "Shift" }, "x",
275               function ()
276                   awful.prompt.run({ prompt = "Run Lua code: " },
277                   mypromptbox[mouse.screen].widget,
278                   awful.util.eval, nil,
279                   awful.util.getdir("cache") .. "/history_eval")
280               end),
281     awful.key({ modkey }, "q",
282                   function ()
283                       awful.tag.incnmaster(-1)
284                       awful.tag.incncol(3)
285               end),
286     -- Menubar
287     awful.key({ modkey }, "p", function() menubar.show() 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, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
295     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
296     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
297     awful.key({ modkey,           }, "n",
298         function (c)
299             -- The client currently has the input focus, so it cannot be
300             -- minimized, since minimized clients can't have the focus.
301             c.minimized = true
302         end),
303     awful.key({ modkey,           }, "m",
304         function (c)
305             c.maximized_horizontal = not c.maximized_horizontal
306             c.maximized_vertical   = not c.maximized_vertical
307         end)
308 )
309
310 -- Bind all key numbers to tags.
311 -- Be careful: we use keycodes to make it works on any keyboard layout.
312 -- This should map on the top row of your keyboard, usually 1 to 9.
313 for i = 1, 9 do
314     globalkeys = awful.util.table.join(globalkeys,
315         -- View tag only.
316         awful.key({ modkey }, "#" .. i + 9,
317                   function ()
318                         local screen = mouse.screen
319                         local tag = awful.tag.gettags(screen)[i]
320                         if tag then
321                            awful.tag.viewonly(tag)
322                         end
323                   end),
324         -- Toggle tag.
325         awful.key({ modkey, "Control" }, "#" .. i + 9,
326                   function ()
327                       local screen = mouse.screen
328                       local tag = awful.tag.gettags(screen)[i]
329                       if tag then
330                          awful.tag.viewtoggle(tag)
331                       end
332                   end),
333         -- Move client to tag.
334         awful.key({ modkey, "Shift" }, "#" .. i + 9,
335                   function ()
336                       if client.focus then
337                           local tag = awful.tag.gettags(client.focus.screen)[i]
338                           if tag then
339                               awful.client.movetotag(tag)
340                           end
341                      end
342                   end),
343         -- Toggle tag.
344         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
345                   function ()
346                       if client.focus then
347                           local tag = awful.tag.gettags(client.focus.screen)[i]
348                           if tag then
349                               awful.client.toggletag(tag)
350                           end
351                       end
352                   end))
353 end
354
355 clientbuttons = awful.util.table.join(
356     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
357     awful.button({ modkey }, 1, awful.mouse.client.move),
358     awful.button({ modkey }, 3, awful.mouse.client.resize))
359
360 -- Set keys
361 root.keys(globalkeys)
362 -- }}}
363
364 -- {{{ Rules
365 -- Rules to apply to new clients (through the "manage" signal).
366 awful.rules.rules = {
367     -- All clients will match this rule.
368     { rule = { },
369       properties = { border_width = beautiful.border_width,
370                      border_color = beautiful.border_normal,
371                      focus = awful.client.focus.filter,
372                      raise = true,
373                      keys = clientkeys,
374                      buttons = clientbuttons } },
375     { rule = { class = "MPlayer" },
376       properties = { floating = true } },
377     { rule = { class = "pinentry" },
378       properties = { floating = true } },
379     { rule = { class = "gimp" },
380       properties = { floating = true } },
381     -- Set Firefox to always map on tags number 2 of screen 1.
382     -- { rule = { class = "Firefox" },
383     --   properties = { tag = tags[1][2] } },
384 }
385 -- }}}
386
387 -- {{{ Signals
388 -- Signal function to execute when a new client appears.
389 client.connect_signal("manage", function (c, startup)
390     -- Enable sloppy focus
391     c:connect_signal("mouse::enter", function(c)
392         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
393             and awful.client.focus.filter(c) then
394             client.focus = c
395         end
396     end)
397
398     if not startup then
399         -- Set the windows at the slave,
400         -- i.e. put it at the end of others instead of setting it master.
401         -- awful.client.setslave(c)
402
403         -- Put windows in a smart way, only if they does not set an initial position.
404         if not c.size_hints.user_position and not c.size_hints.program_position then
405             awful.placement.no_overlap(c)
406             awful.placement.no_offscreen(c)
407         end
408     elseif not c.size_hints.user_position and not c.size_hints.program_position then
409         -- Prevent clients from being unreachable after screen count change
410         awful.placement.no_offscreen(c)
411     end
412
413     local titlebars_enabled = false
414     if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
415         -- buttons for the titlebar
416         local buttons = awful.util.table.join(
417                 awful.button({ }, 1, function()
418                     client.focus = c
419                     c:raise()
420                     awful.mouse.client.move(c)
421                 end),
422                 awful.button({ }, 3, function()
423                     client.focus = c
424                     c:raise()
425                     awful.mouse.client.resize(c)
426                 end)
427                 )
428
429         -- Widgets that are aligned to the left
430         local left_layout = wibox.layout.fixed.horizontal()
431         left_layout:add(awful.titlebar.widget.iconwidget(c))
432         left_layout:buttons(buttons)
433
434         -- Widgets that are aligned to the right
435         local right_layout = wibox.layout.fixed.horizontal()
436         right_layout:add(awful.titlebar.widget.floatingbutton(c))
437         right_layout:add(awful.titlebar.widget.maximizedbutton(c))
438         right_layout:add(awful.titlebar.widget.stickybutton(c))
439         right_layout:add(awful.titlebar.widget.ontopbutton(c))
440         right_layout:add(awful.titlebar.widget.closebutton(c))
441
442         -- The title goes in the middle
443         local middle_layout = wibox.layout.flex.horizontal()
444         local title = awful.titlebar.widget.titlewidget(c)
445         title:set_align("center")
446         middle_layout:add(title)
447         middle_layout:buttons(buttons)
448
449         -- Now bring it all together
450         local layout = wibox.layout.align.horizontal()
451         layout:set_left(left_layout)
452         layout:set_right(right_layout)
453         layout:set_middle(middle_layout)
454
455         awful.titlebar(c):set_widget(layout)
456     end
457 end)
458
459 client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
460 client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
461 -- }}}

Benjamin Mako Hill || Want to submit a patch?