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

Benjamin Mako Hill || Want to submit a patch?