]> projects.mako.cc - awesome-config/blob - rc.lua
keep chrome apps from floating
[awesome-config] / rc.lua
1 -- read the timezone from /etc/timezone (this doesn't work, somehow)
2 local function read_tz_file(path)
3     local file = io.open(path, "r") -- r read mode and b binary mode
4     if not file then return nil end
5     local content = file:read "*a" -- *a or *all reads the whole file
6     file:close()
7     content = content:gsub("^%s*", "")
8     content = content:gsub("%s*$", "")
9     return content
10 end
11
12 local tz_string = read_tz_file("/etc/timezone")
13
14 -- If LuaRocks is installed, make sure that packages installed through it are
15 -- found (e.g. lgi). If LuaRocks is not installed, do nothing.
16 pcall(require, "luarocks.loader")
17
18 -- Standard awesome library
19 local gears = require("gears")
20 local awful = require("awful")
21 require("awful.autofocus")
22 -- Widget and layout library
23 local wibox = require("wibox")
24 -- Theme handling library
25 local beautiful = require("beautiful")
26 -- Notification library
27 local naughty = require("naughty")
28 local menubar = require("menubar")
29 local hotkeys_popup = require("awful.hotkeys_popup")
30 -- Enable hotkeys help widget for VIM and other apps
31 -- when client with a matching name is opened:
32 require("awful.hotkeys_popup.keys")
33
34 -- load the volume widget code and set settings
35 local volume_control = require("volume-control")
36 volumecfg = volume_control({})
37
38 -- Load Debian menu entries
39 local debian = require("debian.menu")
40 local has_fdo, freedesktop = pcall(require, "freedesktop")
41
42 -- {{{ Error handling
43 -- Check if awesome encountered an error during startup and fell back to
44 -- another config (This code will only ever execute for the fallback config)
45 if awesome.startup_errors then
46     naughty.notify({ preset = naughty.config.presets.critical,
47                      title = "Oops, there were errors during startup!",
48                      text = awesome.startup_errors })
49 end
50
51 -- Handle runtime errors after startup
52 do
53     local in_error = false
54     awesome.connect_signal("debug::error", function (err)
55         -- Make sure we don't go into an endless error loop
56         if in_error then return end
57         in_error = true
58
59         naughty.notify({ preset = naughty.config.presets.critical,
60                          title = "Oops, an error happened!",
61                          text = tostring(err) })
62         in_error = false
63     end)
64 end
65 -- }}}
66
67 -- {{{ Variable definitions
68 -- Themes define colours, icons, font and wallpapers.
69 beautiful.init(awful.util.get_themes_dir() .. "sky/theme.lua")
70 beautiful.wallpaper = "/home/mako/images/Flag_of_Cascadia.png"
71
72 -- This is used later as the default terminal and editor to run.
73 terminal = "x-terminal-emulator"
74 editor = os.getenv("EDITOR") or "editor"
75 editor_cmd = terminal .. " -e " .. editor
76
77 -- Default modkey.
78 -- Usually, Mod4 is the key with a logo between Control and Alt.
79 -- If you do not like this or do not have such a key,
80 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
81 -- However, you can use another modifier like Mod1, but it may interact with others.
82 modkey = "Mod4"
83
84 -- Table of layouts to cover with awful.layout.inc, order matters.
85 awful.layout.layouts = {
86     awful.layout.suit.tile,
87     awful.layout.suit.max,
88     awful.layout.suit.floating
89 }
90 -- }}}
91
92 -- {{{ Menu
93 -- Create a launcher widget and a main menu
94 myawesomemenu = {
95    { "hotkeys", function() hotkeys_popup.show_help(nil, awful.screen.focused()) end },
96    { "manual", terminal .. " -e man awesome" },
97    { "edit config", editor_cmd .. " " .. awesome.conffile },
98    { "restart", awesome.restart },
99    { "quit", function() awesome.quit() end },
100 }
101
102 local menu_awesome = { "awesome", myawesomemenu, beautiful.awesome_icon }
103 local menu_terminal = { "open terminal", terminal }
104
105 if has_fdo then
106     mymainmenu = freedesktop.menu.build({
107         before = { menu_awesome },
108         after =  { menu_terminal }
109     })
110 else
111     mymainmenu = awful.menu({
112         items = {
113                   menu_awesome,
114                   { "Debian", debian.menu.Debian_menu.Debian },
115                   menu_terminal,
116                 }
117     })
118 end
119
120
121 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
122                                      menu = mymainmenu })
123
124 -- Menubar configuration
125 menubar.utils.terminal = terminal -- Set the terminal for applications that require it
126 -- }}}
127
128 -- Keyboard map indicator and switcher
129 mykeyboardlayout = awful.widget.keyboardlayout()
130
131 -- {{{ Wibar
132 -- Create a textclock widget
133 mytextclock = wibox.widget.textclock("%a %m %d %H:%M", 60, tz_string)
134
135 -- Create a wibox for each screen and add it
136 local taglist_buttons = gears.table.join(
137                     awful.button({ }, 1, function(t) t:view_only() end),
138                     awful.button({ modkey }, 1, function(t)
139                                               if client.focus then
140                                                   client.focus:move_to_tag(t)
141                                               end
142                                           end),
143                     awful.button({ }, 3, awful.tag.viewtoggle),
144                     awful.button({ modkey }, 3, function(t)
145                                               if client.focus then
146                                                   client.focus:toggle_tag(t)
147                                               end
148                                           end),
149                     awful.button({ }, 4, function(t) awful.tag.viewnext(t.screen) end),
150                     awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end)
151                 )
152
153 local tasklist_buttons = gears.table.join(
154                      awful.button({ }, 1, function (c)
155                                               if c == client.focus then
156                                                   c.minimized = true
157                                               else
158                                                   c:emit_signal(
159                                                       "request::activate",
160                                                       "tasklist",
161                                                       {raise = true}
162                                                   )
163                                               end
164                                           end),
165                      awful.button({ }, 3, function()
166                                               awful.menu.client_list({ theme = { width = 250 } })
167                                           end),
168                      awful.button({ }, 4, function ()
169                                               awful.client.focus.byidx(1)
170                                           end),
171                      awful.button({ }, 5, function ()
172                                               awful.client.focus.byidx(-1)
173                                           end))
174
175 local function set_wallpaper(s)
176     -- Wallpaper
177     if beautiful.wallpaper then
178         local wallpaper = beautiful.wallpaper
179         -- If wallpaper is a function, call it with the screen
180         if type(wallpaper) == "function" then
181             wallpaper = wallpaper(s)
182         end
183         gears.wallpaper.maximized(wallpaper, s, true)
184     end
185 end
186
187 -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
188 screen.connect_signal("property::geometry", set_wallpaper)
189
190 awful.screen.connect_for_each_screen(function(s)
191     -- Wallpaper
192     set_wallpaper(s)
193
194     -- Each screen has its own tag table.
195     awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1])
196
197     -- Create a promptbox for each screen
198     s.mypromptbox = awful.widget.prompt()
199     -- Create an imagebox widget which will contain an icon indicating which layout we're using.
200     -- We need one layoutbox per screen.
201     s.mylayoutbox = awful.widget.layoutbox(s)
202     s.mylayoutbox:buttons(gears.table.join(
203                            awful.button({ }, 1, function () awful.layout.inc( 1) end),
204                            awful.button({ }, 3, function () awful.layout.inc(-1) end),
205                            awful.button({ }, 4, function () awful.layout.inc( 1) end),
206                            awful.button({ }, 5, function () awful.layout.inc(-1) end)))
207     -- Create a taglist widget
208     s.mytaglist = awful.widget.taglist {
209         screen  = s,
210         filter  = awful.widget.taglist.filter.all,
211         buttons = taglist_buttons
212     }
213
214     -- Create a tasklist widget
215     s.mytasklist = awful.widget.tasklist {
216         screen  = s,
217         filter  = awful.widget.tasklist.filter.currenttags,
218         buttons = tasklist_buttons
219     }
220
221     -- Create the wibox
222     s.mywibox = awful.wibar({ position = "top", screen = s })
223
224     -- Add widgets to the wibox
225     s.mywibox:setup {
226         layout = wibox.layout.align.horizontal,
227         { -- Left widgets
228             layout = wibox.layout.fixed.horizontal,
229             mylauncher,
230             s.mytaglist,
231             s.mypromptbox,
232         },
233         s.mytasklist, -- Middle widget
234         { -- Right widgets
235             layout = wibox.layout.fixed.horizontal,
236             mykeyboardlayout,
237             wibox.widget.systray(),
238             -- volumecfg.widget,
239             mytextclock,
240             s.mylayoutbox,
241         },
242     }
243 end)
244 -- }}}
245
246 -- right_layout:add(volumecfg.widget)
247
248 -- {{{ Mouse bindings
249 root.buttons(gears.table.join(
250     awful.button({ }, 3, function () mymainmenu:toggle() end),
251     awful.button({ }, 4, awful.tag.viewnext),
252     awful.button({ }, 5, awful.tag.viewprev)
253 ))
254 -- }}}
255
256 -- {{{ Key bindings
257 globalkeys = gears.table.join(
258     awful.key({ modkey,           }, "s",      hotkeys_popup.show_help,
259               {description="show help", group="awesome"}),
260     awful.key({ modkey,           }, "Left",   awful.tag.viewprev,
261               {description = "view previous", group = "tag"}),
262     awful.key({ modkey,           }, "Right",  awful.tag.viewnext,
263               {description = "view next", group = "tag"}),
264     awful.key({ modkey,           }, "Escape", awful.tag.history.restore,
265               {description = "go back", group = "tag"}),
266
267     awful.key({ modkey,           }, "j",
268         function ()
269             awful.client.focus.byidx( 1)
270         end,
271         {description = "focus next by index", group = "client"}
272     ),
273     awful.key({ modkey,           }, "k",
274         function ()
275             awful.client.focus.byidx(-1)
276         end,
277         {description = "focus previous by index", group = "client"}
278     ),
279     awful.key({ modkey,           }, "w", function () mymainmenu:show() end,
280               {description = "show main menu", group = "awesome"}),
281
282     -- Layout manipulation
283     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end,
284               {description = "swap with next client by index", group = "client"}),
285     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end,
286               {description = "swap with previous client by index", group = "client"}),
287     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end,
288               {description = "focus the next screen", group = "screen"}),
289     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end,
290               {description = "focus the previous screen", group = "screen"}),
291     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto,
292               {description = "jump to urgent client", group = "client"}),
293     awful.key({ modkey,           }, "Tab",
294         function ()
295             awful.client.focus.history.previous()
296             if client.focus then
297                 client.focus:raise()
298             end
299         end,
300         {description = "go back", group = "client"}),
301
302     -- Standard program
303     awful.key({ modkey,           }, "Return", function () awful.spawn(terminal) end,
304               {description = "open a terminal", group = "launcher"}),
305     awful.key({ modkey, "Control" }, "r", awesome.restart,
306               {description = "reload awesome", group = "awesome"}),
307     awful.key({ modkey, "Shift"   }, "q", awesome.quit,
308               {description = "quit awesome", group = "awesome"}),
309
310     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)          end,
311               {description = "increase master width factor", group = "layout"}),
312     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)          end,
313               {description = "decrease master width factor", group = "layout"}),
314     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1, nil, true) end,
315               {description = "increase the number of master clients", group = "layout"}),
316     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1, nil, true) end,
317               {description = "decrease the number of master clients", group = "layout"}),
318     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1, nil, true)    end,
319               {description = "increase the number of columns", group = "layout"}),
320     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1, nil, true)    end,
321               {description = "decrease the number of columns", group = "layout"}),
322     awful.key({ modkey,           }, "space", function () awful.layout.inc( 1)                end,
323               {description = "select next", group = "layout"}),
324     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(-1)                end,
325               {description = "select previous", group = "layout"}),
326
327     awful.key({ modkey, "Control" }, "n",
328               function ()
329                   local c = awful.client.restore()
330                   -- Focus restored client
331                   if c then
332                     c:emit_signal(
333                         "request::activate", "key.unminimize", {raise = true}
334                     )
335                   end
336               end,
337               {description = "restore minimized", group = "client"}),
338
339     -- Prompt
340     awful.key({ modkey },            "r",     function () awful.screen.focused().mypromptbox:run() end,
341               {description = "run prompt", group = "launcher"}),
342     
343     awful.key({ modkey,  }, "x",
344               function ()
345                   awful.prompt.run {
346                     prompt       = "Run in terminal: ",
347                     textbox      = awful.screen.focused().mypromptbox.widget,
348                     exe_callback = function (prog) awful.util.spawn_with_shell(terminal .. " -title " .. prog .. " -e " .. prog) end
349                   }
350               end,
351               {description = "terminal execute prompt", group = "awesome"}),
352
353     -- Mako's additional keybindings
354     --- {{{
355     awful.key({ modkey, "Shift", }, "x",
356               function ()
357                   awful.prompt.run {
358                     prompt       = "Run Lua code: ",
359                     textbox      = awful.screen.focused().mypromptbox.widget,
360                     exe_callback = awful.util.eval,
361                     history_path = awful.util.get_cache_dir() .. "/history_eval"
362                   }
363               end,
364               {description = "lua execute prompt", group = "awesome"}),
365
366     awful.key({ modkey }, "q",
367                   function ()
368                       awful.tag.incnmaster(-1)
369                       awful.tag.incncol(3)
370               end),
371
372     awful.key({ modkey, "Shift" }, "t", awful.titlebar.toggle),
373
374     --- }}}
375
376     -- Menubar
377     awful.key({ modkey }, "p", function() menubar.show() end,
378               {description = "show the menubar", group = "launcher"})
379 )
380
381 clientkeys = gears.table.join(
382     awful.key({ modkey,           }, "f",
383         function (c)
384             c.fullscreen = not c.fullscreen
385             c:raise()
386         end,
387         {description = "toggle fullscreen", group = "client"}),
388     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end,
389               {description = "close", group = "client"}),
390     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ,
391               {description = "toggle floating", group = "client"}),
392     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end,
393               {description = "move to master", group = "client"}),
394     awful.key({ modkey,           }, "o",      function (c) c:move_to_screen()               end,
395               {description = "move to screen", group = "client"}),
396     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end,
397               {description = "toggle keep on top", group = "client"}),
398     awful.key({ modkey,           }, "n",
399         function (c)
400             -- The client currently has the input focus, so it cannot be
401             -- minimized, since minimized clients can't have the focus.
402             c.minimized = true
403         end ,
404         {description = "minimize", group = "client"}),
405     awful.key({ modkey,           }, "m",
406         function (c)
407             c.maximized = not c.maximized
408             c:raise()
409         end ,
410         {description = "(un)maximize", group = "client"}),
411     awful.key({ modkey, "Control" }, "m",
412         function (c)
413             c.maximized_vertical = not c.maximized_vertical
414             c:raise()
415         end ,
416         {description = "(un)maximize vertically", group = "client"}),
417     awful.key({ modkey, "Shift"   }, "m",
418         function (c)
419             c.maximized_horizontal = not c.maximized_horizontal
420             c:raise()
421         end ,
422         {description = "(un)maximize horizontally", group = "client"})
423 )
424
425 -- Bind all key numbers to tags.
426 -- Be careful: we use keycodes to make it work on any keyboard layout.
427 -- This should map on the top row of your keyboard, usually 1 to 9.
428 for i = 1, 9 do
429     globalkeys = gears.table.join(globalkeys,
430         -- View tag only.
431         awful.key({ modkey }, "#" .. i + 9,
432                   function ()
433                         local screen = awful.screen.focused()
434                         local tag = screen.tags[i]
435                         if tag then
436                            tag:view_only()
437                         end
438                   end,
439                   {description = "view tag #"..i, group = "tag"}),
440         -- Toggle tag display.
441         awful.key({ modkey, "Control" }, "#" .. i + 9,
442                   function ()
443                       local screen = awful.screen.focused()
444                       local tag = screen.tags[i]
445                       if tag then
446                          awful.tag.viewtoggle(tag)
447                       end
448                   end,
449                   {description = "toggle tag #" .. i, group = "tag"}),
450         -- Move client to tag.
451         awful.key({ modkey, "Shift" }, "#" .. i + 9,
452                   function ()
453                       if client.focus then
454                           local tag = client.focus.screen.tags[i]
455                           if tag then
456                               client.focus:move_to_tag(tag)
457                           end
458                      end
459                   end,
460                   {description = "move focused client to tag #"..i, group = "tag"}),
461         -- Toggle tag on focused client.
462         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
463                   function ()
464                       if client.focus then
465                           local tag = client.focus.screen.tags[i]
466                           if tag then
467                               client.focus:toggle_tag(tag)
468                           end
469                       end
470                   end,
471                   {description = "toggle focused client on tag #" .. i, group = "tag"}),
472         awful.key({}, "XF86AudioRaiseVolume", function() volumecfg:up() end),
473         awful.key({}, "XF86AudioLowerVolume", function() volumecfg:down() end),
474         awful.key({}, "XF86AudioMute",        function() volumecfg:toggle() end)
475     )
476 end
477
478 clientbuttons = gears.table.join(
479     awful.button({ }, 1, function (c)
480         c:emit_signal("request::activate", "mouse_click", {raise = true})
481     end),
482     awful.button({ modkey }, 1, function (c)
483         c:emit_signal("request::activate", "mouse_click", {raise = true})
484         awful.mouse.client.move(c)
485     end),
486     awful.button({ modkey }, 3, function (c)
487         c:emit_signal("request::activate", "mouse_click", {raise = true})
488         awful.mouse.client.resize(c)
489     end)
490 )
491
492 -- Set keys
493 root.keys(globalkeys)
494 -- }}}
495
496 -- {{{ Rules
497 -- Rules to apply to new clients (through the "manage" signal).
498 awful.rules.rules = {
499     -- All clients will match this rule.
500     { rule = { },
501       properties = { border_width = beautiful.border_width,
502                      border_color = beautiful.border_normal,
503                      focus = awful.client.focus.filter,
504                      raise = true,
505                      keys = clientkeys,
506                      buttons = clientbuttons,
507                      screen = awful.screen.preferred,
508                      placement = awful.placement.no_overlap+awful.placement.no_offscreen
509      }
510     },
511     -- Floating clients.
512     { rule_any = {
513         instance = {
514           "DTA",  -- Firefox addon DownThemAll.
515           "copyq",  -- Includes session name in class.
516           "pinentry",
517         },
518         class = {
519           "Arandr",
520           "Blueman-manager",
521           "Gpick",
522           "Kruler",
523           "MessageWin",  -- kalarm.
524           "Sxiv",
525           "Tor Browser", -- Needs a fixed window size to avoid fingerprinting by screen size.
526           "Wpa_gui",
527           "veromix",
528           "xtightvncviewer"},
529
530         -- Note that the name property shown in xprop might be set slightly after creation of the client
531         -- and the name shown there might not match defined rules here.
532         name = {
533           "Event Tester",  -- xev.
534         },
535         role = {
536           "AlarmWindow",  -- Thunderbird's calendar.
537           "ConfigManager",  -- Thunderbird's about:config.
538           -- this is commented out to try to keep all chrom(e|ium) apps from being floating
539           -- "pop-up",       -- e.g. Google Chrome's (detached) Developer Tools.
540         }
541       }, properties = { floating = true }},
542
543     -- Add titlebars to normal clients and dialogs
544     -- { rule_any = {type = { "normal", "dialog" }
545     --   }, properties = { titlebars_enabled = true }
546     -- },
547     -- make so that overleaf is not floating
548     { rule = { class = "crx_gjoaplgcpnmemdaklplebdapjihcoibe" },
549       properties = {floating = false}
550     },
551
552     -- Set Firefox to always map on the tag named "2" on screen 1.
553     -- { rule = { class = "Firefox" },
554     --   properties = { screen = 1, tag = "2" } },
555 }
556 -- }}}
557
558 -- {{{ Signals
559 -- Signal function to execute when a new client appears.
560 client.connect_signal("manage", function (c)
561     -- Set the windows at the slave,
562     -- i.e. put it at the end of others instead of setting it master.
563     -- if not awesome.startup then awful.client.setslave(c) end
564
565     if awesome.startup
566       and not c.size_hints.user_position
567       and not c.size_hints.program_position then
568         -- Prevent clients from being unreachable after screen count changes.
569         awful.placement.no_offscreen(c)
570     end
571 end)
572
573 -- Add a titlebar if titlebars_enabled is set to true in the rules.
574 client.connect_signal("request::titlebars", function(c)
575     -- buttons for the titlebar
576     local buttons = gears.table.join(
577         awful.button({ }, 1, function()
578             c:emit_signal("request::activate", "titlebar", {raise = true})
579             awful.mouse.client.move(c)
580         end),
581         awful.button({ }, 3, function()
582             c:emit_signal("request::activate", "titlebar", {raise = true})
583             awful.mouse.client.resize(c)
584         end)
585     )
586
587     awful.titlebar(c) : setup {
588         { -- Left
589             awful.titlebar.widget.iconwidget(c),
590             buttons = buttons,
591             layout  = wibox.layout.fixed.horizontal
592         },
593         { -- Middle
594             { -- Title
595                 align  = "center",
596                 widget = awful.titlebar.widget.titlewidget(c)
597             },
598             buttons = buttons,
599             layout  = wibox.layout.flex.horizontal
600         },
601         { -- Right
602             awful.titlebar.widget.floatingbutton (c),
603             awful.titlebar.widget.maximizedbutton(c),
604             awful.titlebar.widget.stickybutton   (c),
605             awful.titlebar.widget.ontopbutton    (c),
606             awful.titlebar.widget.closebutton    (c),
607             layout = wibox.layout.fixed.horizontal()
608         },
609         layout = wibox.layout.align.horizontal
610     }
611 end)
612
613 -- Enable sloppy focus, so that focus follows mouse.
614 client.connect_signal("mouse::enter", function(c)
615     c:emit_signal("request::activate", "mouse_enter", {raise = false})
616 end)
617
618 client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
619 client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
620 -- }}}

Benjamin Mako Hill || Want to submit a patch?