Advertisement
Guest User

rc.lua

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