Advertisement
Guest User

rc.lua

a guest
Apr 11th, 2018
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 30.77 KB | None | 0 0
  1. --[[
  2.  
  3.      Awesome WM configuration template
  4.      github.com/lcpz
  5.  
  6. --]]
  7.  
  8. -- {{{ Required libraries
  9. local awesome, client, mouse, screen, tag = awesome, client, mouse, screen, tag
  10. local ipairs, string, os, table, tostring, tonumber, type = ipairs, string, os, table, tostring, tonumber, type
  11.  
  12. local gears         = require("gears")
  13. local awful         = require("awful")
  14.                       require("awful.autofocus")
  15. local wibox         = require("wibox")
  16. local beautiful     = require("beautiful")
  17. local naughty       = require("naughty")
  18. local lain          = require("lain")
  19. --local menubar       = require("menubar")
  20. local freedesktop   = require("freedesktop")
  21. local hotkeys_popup = require("awful.hotkeys_popup").widget
  22. local my_table      = awful.util.table or gears.table -- 4.{0,1} compatibility
  23. -- }}}
  24.  
  25. -- Load Debian menu entries
  26. require("debian.menu")
  27.  
  28. -- {{{ Error handling
  29. if awesome.startup_errors then
  30.     naughty.notify({ preset = naughty.config.presets.critical,
  31.                      title = "Oops, there were errors during startup!",
  32.                      text = awesome.startup_errors })
  33. end
  34.  
  35. do
  36.     local in_error = false
  37.     awesome.connect_signal("debug::error", function (err)
  38.         if in_error then return end
  39.         in_error = true
  40.  
  41.         naughty.notify({ preset = naughty.config.presets.critical,
  42.                          title = "Oops, an error happened!",
  43.                          text = tostring(err) })
  44.         in_error = false
  45.     end)
  46. end
  47. -- }}}
  48.  
  49. -- {{{ Autostart windowless processes
  50. local function run_once(cmd_arr)
  51.     for _, cmd in ipairs(cmd_arr) do
  52.         findme = cmd
  53.         firstspace = cmd:find(" ")
  54.         if firstspace then
  55.             findme = cmd:sub(0, firstspace-1)
  56.         end
  57.         awful.spawn.with_shell(string.format("pgrep -u $USER -x %s > /dev/null || (%s)", findme, cmd))
  58.     end
  59. end
  60.  
  61. -- awful.spawn.with_shell("setxkbmap us,ru")
  62. -- awful.spawn.with_shell("setxkbmap -model pc105")
  63. -- awful.spawn.with_shell("setxkbmap -option grp:alt_shift_toggle")
  64.  
  65. --run_once({ "unclutter -root" }) -- entries must be comma-separated
  66. -- }}}
  67.  
  68. -- {{{ Variable definitions
  69.  
  70. local themes = {
  71.     "blackburn",       -- 1
  72.     "copland",         -- 2
  73.     "dremora",         -- 3
  74.     "holo",            -- 4
  75.     "multicolor",      -- 5
  76.     "powerarrow",      -- 6
  77.     "powerarrow-dark", -- 7
  78.     "rainbow",         -- 8
  79.     "steamburn",       -- 9
  80.     "vertex",          -- 10
  81. }
  82.  
  83. local chosen_theme = themes[7] --4, 6, 7, 10
  84. local modkey       = "Mod4"
  85. local altkey       = "Mod1"
  86. -- local terminal     = "tilix"
  87. local terminal     = "xfce4-terminal"
  88. local editor       = os.getenv("EDITOR") or "emacs -nw"
  89. local gui_editor   = "emacs"
  90. local browser      = "firefox"
  91. local guieditor    = "emacs"
  92. local scrlocker    = "lock"
  93.  
  94. awful.util.terminal = terminal
  95. awful.util.tagnames = { "1", "2", "3", "4", "5" }
  96. awful.layout.layouts = {
  97.     awful.layout.suit.floating,
  98.     awful.layout.suit.tile,
  99.     awful.layout.suit.tile.left,
  100.     awful.layout.suit.tile.bottom,
  101.     awful.layout.suit.tile.top,
  102.     --awful.layout.suit.fair,
  103.     --awful.layout.suit.fair.horizontal,
  104.     --awful.layout.suit.spiral,
  105.     --awful.layout.suit.spiral.dwindle,
  106.     --awful.layout.suit.max,
  107.     --awful.layout.suit.max.fullscreen,
  108.     --awful.layout.suit.magnifier,
  109.     --awful.layout.suit.corner.nw,
  110.     --awful.layout.suit.corner.ne,
  111.     --awful.layout.suit.corner.sw,
  112.     --awful.layout.suit.corner.se,
  113.     --lain.layout.cascade,
  114.     --lain.layout.cascade.tile,
  115.     --lain.layout.centerwork,
  116.     --lain.layout.centerwork.horizontal,
  117.     --lain.layout.termfair,
  118.     --lain.layout.termfair.center,
  119. }
  120. awful.util.taglist_buttons = my_table.join(
  121.                     awful.button({ }, 1, function(t) t:view_only() end),
  122.                     awful.button({ modkey }, 1, function(t)
  123.                                               if client.focus then
  124.                                                   client.focus:move_to_tag(t)
  125.                                               end
  126.                                           end),
  127.                     awful.button({ }, 3, awful.tag.viewtoggle),
  128.                     awful.button({ modkey }, 3, function(t)
  129.                                               if client.focus then
  130.                                                   client.focus:toggle_tag(t)
  131.                                               end
  132.                                           end),
  133.                     awful.button({ }, 4, function(t) awful.tag.viewnext(t.screen) end),
  134.                     awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end)
  135.                 )
  136. awful.util.tasklist_buttons = my_table.join(
  137.                      awful.button({ }, 1, function (c)
  138.                                               if c == client.focus then
  139.                                                   c.minimized = true
  140.                                               else
  141.                                                   -- Without this, the following
  142.                                                   -- :isvisible() makes no sense
  143.                                                   c.minimized = false
  144.                                                   if not c:isvisible() and c.first_tag then
  145.                                                       c.first_tag:view_only()
  146.                                                   end
  147.                                                   -- This will also un-minimize
  148.                                                   -- the client, if needed
  149.                                                   client.focus = c
  150.                                                   c:raise()
  151.                                               end
  152.                                           end),
  153.                      awful.button({ }, 3, function()
  154.                          local instance = nil
  155.  
  156.                          return function ()
  157.                              if instance and instance.wibox.visible then
  158.                                  instance:hide()
  159.                                  instance = nil
  160.                              else
  161.                                  instance = awful.menu.clients({ theme = { width = 250 } })
  162.                              end
  163.                         end
  164.                      end),
  165.                      awful.button({ }, 4, function ()
  166.                                               awful.client.focus.byidx(1)
  167.                                           end),
  168.                      awful.button({ }, 5, function ()
  169.                                               awful.client.focus.byidx(-1)
  170.                                           end))
  171.  
  172. lain.layout.termfair.nmaster           = 3
  173. lain.layout.termfair.ncol              = 1
  174. lain.layout.termfair.center.nmaster    = 3
  175. lain.layout.termfair.center.ncol       = 1
  176. lain.layout.cascade.tile.offset_x      = 2
  177. lain.layout.cascade.tile.offset_y      = 32
  178. lain.layout.cascade.tile.extra_padding = 5
  179. lain.layout.cascade.tile.nmaster       = 5
  180. lain.layout.cascade.tile.ncol          = 2
  181.  
  182. local theme_path = string.format("%s/.config/awesome/themes/%s/theme.lua", os.getenv("HOME"), chosen_theme)
  183. beautiful.init(theme_path)
  184. -- }}}
  185.  
  186. -- {{{ Menu
  187. local myawesomemenu = {
  188.     { "hotkeys", function() return false, hotkeys_popup.show_help end },
  189.     { "manual", terminal .. " -e man awesome" },
  190.     { "edit config", string.format("%s -e %s %s", terminal, editor, awesome.conffile) },
  191.     { "restart", awesome.restart },
  192.     { "quit", function() awesome.quit() end }
  193. }
  194. --[[awful.util.mymainmenu = freedesktop.menu.build({
  195.     icon_size = beautiful.menu_height or 16,
  196.     before = {
  197.         { "Awesome", myawesomemenu, beautiful.awesome_icon },
  198.         -- other triads can be put here
  199.     },
  200.     after = {
  201.         { "Open terminal", terminal },
  202.         -- other triads can be put here
  203.     }
  204.    })--]]
  205.  
  206. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  207.                                     { "Debian", debian.menu.Debian_menu.Debian },
  208.                                     { "open terminal", terminal }
  209.                                   }
  210.                })
  211. --[[mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  212.                                      menu = mymainmenu })
  213. ]]--
  214. --menubar.utils.terminal = terminal -- Set the Menubar terminal for applications that require it
  215. -- }}}
  216.  
  217. -- {{{ Screen
  218. -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
  219. screen.connect_signal("property::geometry", function(s)
  220.     -- Wallpaper
  221.     if beautiful.wallpaper then
  222.         local wallpaper = beautiful.wallpaper
  223.         -- If wallpaper is a function, call it with the screen
  224.         if type(wallpaper) == "function" then
  225.             wallpaper = wallpaper(s)
  226.         end
  227.         gears.wallpaper.maximized(wallpaper, s, true)
  228.     end
  229. end)
  230. -- Create a wibox for each screen and add it
  231. awful.screen.connect_for_each_screen(function(s) beautiful.at_screen_connect(s) end)
  232. -- }}}
  233.  
  234. -- {{{ Mouse bindings
  235. root.buttons(my_table.join(
  236.     awful.button({ }, 3, function () awful.util.mymainmenu:toggle() end),
  237.     awful.button({ }, 4, awful.tag.viewnext),
  238.     awful.button({ }, 5, awful.tag.viewprev)
  239. ))
  240. -- }}}
  241.  
  242. -- {{{ Key bindings
  243. globalkeys = my_table.join(
  244.     -- Take a screenshot
  245.     -- https://github.com/lcpz/dots/blob/master/bin/screenshot
  246.     awful.key({ altkey }, "p", function() os.execute("screenshot") end,
  247.               {description = "take a screenshot", group = "hotkeys"}),
  248.  
  249.     -- X screen locker
  250.     awful.key({ altkey, "Control" }, "l", function () os.execute(scrlocker) end,
  251.               {description = "lock screen", group = "hotkeys"}),
  252.  
  253.     -- Hotkeys
  254.     awful.key({ modkey,           }, "s",      hotkeys_popup.show_help,
  255.               {description = "show help", group="awesome"}),
  256.     -- Tag browsing
  257.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev,
  258.               {description = "view previous", group = "tag"}),
  259.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext,
  260.               {description = "view next", group = "tag"}),
  261.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore,
  262.               {description = "go back", group = "tag"}),
  263.  
  264.     -- Non-empty tag browsing
  265.     awful.key({ altkey }, "Left", function () lain.util.tag_view_nonempty(-1) end,
  266.               {description = "view  previous nonempty", group = "tag"}),
  267.     awful.key({ altkey }, "Right", function () lain.util.tag_view_nonempty(1) end,
  268.               {description = "view  previous nonempty", group = "tag"}),
  269.  
  270.     -- Default client focus
  271.     awful.key({ altkey,           }, "j",
  272.         function ()
  273.             awful.client.focus.byidx( 1)
  274.         end,
  275.         {description = "focus next by index", group = "client"}
  276.     ),
  277.     awful.key({ altkey,           }, "k",
  278.         function ()
  279.             awful.client.focus.byidx(-1)
  280.         end,
  281.         {description = "focus previous by index", group = "client"}
  282.     ),
  283.  
  284.     -- By direction client focus
  285.     awful.key({ modkey }, "j",
  286.         function()
  287.             awful.client.focus.global_bydirection("down")
  288.             if client.focus then client.focus:raise() end
  289.         end,
  290.         {description = "focus down", group = "client"}),
  291.     awful.key({ modkey }, "k",
  292.         function()
  293.             awful.client.focus.global_bydirection("up")
  294.             if client.focus then client.focus:raise() end
  295.         end,
  296.         {description = "focus up", group = "client"}),
  297.     awful.key({ modkey }, "h",
  298.         function()
  299.             awful.client.focus.global_bydirection("left")
  300.             if client.focus then client.focus:raise() end
  301.         end,
  302.         {description = "focus left", group = "client"}),
  303.     awful.key({ modkey }, "l",
  304.         function()
  305.             awful.client.focus.global_bydirection("right")
  306.             if client.focus then client.focus:raise() end
  307.         end,
  308.         {description = "focus right", group = "client"}),
  309.     awful.key({ modkey,           }, "w", function () awful.util.mymainmenu:show() end,
  310.               {description = "show main menu", group = "awesome"}),
  311.  
  312.     -- Layout manipulation
  313.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end,
  314.               {description = "swap with next client by index", group = "client"}),
  315.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end,
  316.               {description = "swap with previous client by index", group = "client"}),
  317.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end,
  318.               {description = "focus the next screen", group = "screen"}),
  319.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end,
  320.               {description = "focus the previous screen", group = "screen"}),
  321.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto,
  322.               {description = "jump to urgent client", group = "client"}),
  323.     awful.key({ modkey,           }, "Tab",
  324.         function ()
  325.             awful.client.focus.history.previous()
  326.             if client.focus then
  327.                 client.focus:raise()
  328.             end
  329.         end,
  330.         {description = "go back", group = "client"}),
  331.  
  332.     -- Show/Hide Wibox
  333.     awful.key({ modkey }, "b", function ()
  334.             for s in screen do
  335.                 s.mywibox.visible = not s.mywibox.visible
  336.                 if s.mybottomwibox then
  337.                     s.mybottomwibox.visible = not s.mybottomwibox.visible
  338.                 end
  339.             end
  340.         end,
  341.         {description = "toggle wibox", group = "awesome"}),
  342.  
  343.     -- On the fly useless gaps change
  344.     awful.key({ altkey, "Control" }, "+", function () lain.util.useless_gaps_resize(1) end,
  345.               {description = "increment useless gaps", group = "tag"}),
  346.     awful.key({ altkey, "Control" }, "-", function () lain.util.useless_gaps_resize(-1) end,
  347.               {description = "decrement useless gaps", group = "tag"}),
  348.  
  349.     -- Dynamic tagging
  350.     awful.key({ modkey, "Shift" }, "n", function () lain.util.add_tag() end,
  351.               {description = "add new tag", group = "tag"}),
  352.     awful.key({ modkey, "Shift" }, "r", function () lain.util.rename_tag() end,
  353.               {description = "rename tag", group = "tag"}),
  354.     awful.key({ modkey, "Shift" }, "Left", function () lain.util.move_tag(-1) end,
  355.               {description = "move tag to the left", group = "tag"}),
  356.     awful.key({ modkey, "Shift" }, "Right", function () lain.util.move_tag(1) end,
  357.               {description = "move tag to the right", group = "tag"}),
  358.     awful.key({ modkey, "Shift" }, "d", function () lain.util.delete_tag() end,
  359.               {description = "delete tag", group = "tag"}),
  360.  
  361.     -- Standard program
  362.     awful.key({ modkey,           }, "Return", function () awful.spawn(terminal) end,
  363.               {description = "open a terminal", group = "launcher"}),
  364.     awful.key({ modkey, "Control" }, "r", awesome.restart,
  365.               {description = "reload awesome", group = "awesome"}),
  366.     awful.key({ modkey, "Shift"   }, "q", awesome.quit,
  367.               {description = "quit awesome", group = "awesome"}),
  368.  
  369.     awful.key({ altkey, "Shift"   }, "l",     function () awful.tag.incmwfact( 0.05)          end,
  370.               {description = "increase master width factor", group = "layout"}),
  371.     awful.key({ altkey, "Shift"   }, "h",     function () awful.tag.incmwfact(-0.05)          end,
  372.               {description = "decrease master width factor", group = "layout"}),
  373.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1, nil, true) end,
  374.               {description = "increase the number of master clients", group = "layout"}),
  375.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1, nil, true) end,
  376.               {description = "decrease the number of master clients", group = "layout"}),
  377.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1, nil, true)    end,
  378.               {description = "increase the number of columns", group = "layout"}),
  379.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1, nil, true)    end,
  380.               {description = "decrease the number of columns", group = "layout"}),
  381.     awful.key({ modkey,           }, "space", function () awful.layout.inc( 1)                end,
  382.               {description = "select next", group = "layout"}),
  383.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(-1)                end,
  384.               {description = "select previous", group = "layout"}),
  385.  
  386.     awful.key({ modkey, "Control" }, "n",
  387.               function ()
  388.                   local c = awful.client.restore()
  389.                   -- Focus restored client
  390.                   if c then
  391.                       client.focus = c
  392.                       c:raise()
  393.                   end
  394.               end,
  395.               {description = "restore minimized", group = "client"}),
  396.  
  397.     -- Dropdown application
  398.     awful.key({ modkey, }, "z", function () awful.screen.focused().quake:toggle() end,
  399.               {description = "dropdown application", group = "launcher"}),
  400.  
  401.     -- Widgets popups
  402.     awful.key({ altkey, }, "c", function () lain.widget.calendar.show(7) end,
  403.               {description = "show calendar", group = "widgets"}),
  404.     awful.key({ altkey, }, "h", function () if beautiful.fs then beautiful.fs.show(7) end end,
  405.               {description = "show filesystem", group = "widgets"}),
  406.     awful.key({ altkey, }, "w", function () if beautiful.weather then beautiful.weather.show(7) end end,
  407.               {description = "show weather", group = "widgets"}),
  408.  
  409.     -- Brightness
  410.     awful.key({ }, "XF86MonBrightnessUp", function () awful.util.spawn("xbacklight -inc 10") end,
  411.               {description = "+10%", group = "hotkeys"}),
  412.     awful.key({ }, "XF86MonBrightnessDown", function () awful.util.spawn("xbacklight -dec 10") end,
  413.               {description = "-10%", group = "hotkeys"}),
  414.  
  415.     -- ALSA volume control
  416.     awful.key({ altkey }, "Up",
  417.         function ()
  418.             os.execute(string.format("amixer -q set %s 1%%+", beautiful.volume.channel))
  419.             beautiful.volume.update()
  420.         end,
  421.         {description = "volume up", group = "hotkeys"}),
  422.     awful.key({ altkey }, "Down",
  423.         function ()
  424.             os.execute(string.format("amixer -q set %s 1%%-", beautiful.volume.channel))
  425.             beautiful.volume.update()
  426.         end,
  427.         {description = "volume down", group = "hotkeys"}),
  428.     awful.key({ altkey }, "m",
  429.         function ()
  430.             os.execute(string.format("amixer -q set %s toggle", beautiful.volume.togglechannel or beautiful.volume.channel))
  431.             beautiful.volume.update()
  432.         end,
  433.         {description = "toggle mute", group = "hotkeys"}),
  434.     awful.key({ altkey, "Control" }, "m",
  435.         function ()
  436.             os.execute(string.format("amixer -q set %s 100%%", beautiful.volume.channel))
  437.             beautiful.volume.update()
  438.         end,
  439.         {description = "volume 100%", group = "hotkeys"}),
  440.     awful.key({ altkey, "Control" }, "0",
  441.         function ()
  442.             os.execute(string.format("amixer -q set %s 0%%", beautiful.volume.channel))
  443.             beautiful.volume.update()
  444.         end,
  445.         {description = "volume 0%", group = "hotkeys"}),
  446.  
  447.     -- MPD control
  448.     awful.key({ altkey, "Control" }, "Up",
  449.         function ()
  450.             awful.spawn.with_shell("mpc toggle")
  451.             beautiful.mpd.update()
  452.         end,
  453.         {description = "mpc toggle", group = "widgets"}),
  454.     awful.key({ altkey, "Control" }, "Down",
  455.         function ()
  456.             awful.spawn.with_shell("mpc stop")
  457.             beautiful.mpd.update()
  458.         end,
  459.         {description = "mpc stop", group = "widgets"}),
  460.     awful.key({ altkey, "Control" }, "Left",
  461.         function ()
  462.             awful.spawn.with_shell("mpc prev")
  463.             beautiful.mpd.update()
  464.         end,
  465.         {description = "mpc prev", group = "widgets"}),
  466.     awful.key({ altkey, "Control" }, "Right",
  467.         function ()
  468.             awful.spawn.with_shell("mpc next")
  469.             beautiful.mpd.update()
  470.         end,
  471.         {description = "mpc next", group = "widgets"}),
  472.     awful.key({ altkey }, "0",
  473.         function ()
  474.             local common = { text = "MPD widget ", position = "top_middle", timeout = 2 }
  475.             if beautiful.mpd.timer.started then
  476.                 beautiful.mpd.timer:stop()
  477.                 common.text = common.text .. lain.util.markup.bold("OFF")
  478.             else
  479.                 beautiful.mpd.timer:start()
  480.                 common.text = common.text .. lain.util.markup.bold("ON")
  481.             end
  482.             naughty.notify(common)
  483.         end,
  484.         {description = "mpc on/off", group = "widgets"}),
  485.  
  486.     -- Copy primary to clipboard (terminals to gtk)
  487.     awful.key({ modkey }, "c", function () awful.spawn("xsel | xsel -i -b") end,
  488.               {description = "copy terminal to gtk", group = "hotkeys"}),
  489.     -- Copy clipboard to primary (gtk to terminals)
  490.     awful.key({ modkey }, "v", function () awful.spawn("xsel -b | xsel") end,
  491.               {description = "copy gtk to terminal", group = "hotkeys"}),
  492.  
  493.     -- User programs
  494.     awful.key({ modkey }, "q", function () awful.spawn(browser) end,
  495.               {description = "run browser", group = "launcher"}),
  496.     awful.key({ modkey }, "a", function () awful.spawn(guieditor) end,
  497.               {description = "run gui editor", group = "launcher"}),
  498.  
  499.     -- Default
  500.     --[[ Menubar
  501.     awful.key({ modkey }, "p", function() menubar.show() end,
  502.               {description = "show the menubar", group = "launcher"})
  503.     --]]
  504.     --[[ dmenu
  505.     awful.key({ modkey }, "x", function ()
  506.         awful.spawn(string.format("dmenu_run -i -fn 'Monospace' -nb '%s' -nf '%s' -sb '%s' -sf '%s'",
  507.         beautiful.bg_normal, beautiful.fg_normal, beautiful.bg_focus, beautiful.fg_focus))
  508.         end,
  509.         {description = "show dmenu", group = "launcher"})
  510.     --]]
  511.     -- Prompt
  512.     awful.key({ modkey }, "r", function () awful.screen.focused().mypromptbox:run() end,
  513.               {description = "run prompt", group = "launcher"}),
  514.  
  515.     awful.key({ modkey }, "x",
  516.               function ()
  517.                   awful.prompt.run {
  518.                     prompt       = "Run Lua code: ",
  519.                     textbox      = awful.screen.focused().mypromptbox.widget,
  520.                     exe_callback = awful.util.eval,
  521.                     history_path = awful.util.get_cache_dir() .. "/history_eval"
  522.                   }
  523.               end,
  524.               {description = "lua execute prompt", group = "awesome"})
  525.     --]]
  526. )
  527.  
  528. clientkeys = my_table.join(
  529.     awful.key({ altkey, "Shift"   }, "m",      lain.util.magnify_client,
  530.               {description = "magnify client", group = "client"}),
  531.     awful.key({ modkey,           }, "f",
  532.         function (c)
  533.             c.fullscreen = not c.fullscreen
  534.             c:raise()
  535.         end,
  536.         {description = "toggle fullscreen", group = "client"}),
  537.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end,
  538.               {description = "close", group = "client"}),
  539.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ,
  540.               {description = "toggle floating", group = "client"}),
  541.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end,
  542.               {description = "move to master", group = "client"}),
  543.     awful.key({ modkey,           }, "o",      function (c) c:move_to_screen()               end,
  544.               {description = "move to screen", group = "client"}),
  545.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end,
  546.               {description = "toggle keep on top", group = "client"}),
  547.     awful.key({ modkey,           }, "n",
  548.         function (c)
  549.             -- The client currently has the input focus, so it cannot be
  550.             -- minimized, since minimized clients can't have the focus.
  551.             c.minimized = true
  552.         end ,
  553.         {description = "minimize", group = "client"}),
  554.     awful.key({ modkey,           }, "m",
  555.         function (c)
  556.             c.maximized = not c.maximized
  557.             c:raise()
  558.         end ,
  559.         {description = "maximize", group = "client"})
  560. )
  561.  
  562. -- Bind all key numbers to tags.
  563. -- Be careful: we use keycodes to make it works on any keyboard layout.
  564. -- This should map on the top row of your keyboard, usually 1 to 9.
  565. for i = 1, 9 do
  566.     -- Hack to only show tags 1 and 9 in the shortcut window (mod+s)
  567.     local descr_view, descr_toggle, descr_move, descr_toggle_focus
  568.     if i == 1 or i == 9 then
  569.         descr_view = {description = "view tag #", group = "tag"}
  570.         descr_toggle = {description = "toggle tag #", group = "tag"}
  571.         descr_move = {description = "move focused client to tag #", group = "tag"}
  572.         descr_toggle_focus = {description = "toggle focused client on tag #", group = "tag"}
  573.     end
  574.     globalkeys = my_table.join(globalkeys,
  575.         -- View tag only.
  576.         awful.key({ modkey }, "#" .. i + 9,
  577.                   function ()
  578.                         local screen = awful.screen.focused()
  579.                         local tag = screen.tags[i]
  580.                         if tag then
  581.                            tag:view_only()
  582.                         end
  583.                   end,
  584.                   descr_view),
  585.         -- Toggle tag display.
  586.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  587.                   function ()
  588.                       local screen = awful.screen.focused()
  589.                       local tag = screen.tags[i]
  590.                       if tag then
  591.                          awful.tag.viewtoggle(tag)
  592.                       end
  593.                   end,
  594.                   descr_toggle),
  595.         -- Move client to tag.
  596.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  597.                   function ()
  598.                       if client.focus then
  599.                           local tag = client.focus.screen.tags[i]
  600.                           if tag then
  601.                               client.focus:move_to_tag(tag)
  602.                           end
  603.                      end
  604.                   end,
  605.                   descr_move),
  606.         -- Toggle tag on focused client.
  607.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  608.                   function ()
  609.                       if client.focus then
  610.                           local tag = client.focus.screen.tags[i]
  611.                           if tag then
  612.                               client.focus:toggle_tag(tag)
  613.                           end
  614.                       end
  615.                   end,
  616.                   descr_toggle_focus)
  617.     )
  618. end
  619.  
  620. clientbuttons = my_table.join(
  621.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  622.     awful.button({ modkey }, 1, awful.mouse.client.move),
  623.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  624.  
  625. -- Set keys
  626. root.keys(globalkeys)
  627. -- }}}
  628.  
  629. -- {{{ Rules
  630. -- Rules to apply to new clients (through the "manage" signal).
  631. awful.rules.rules = {
  632.     -- All clients will match this rule.
  633.     { rule = { },
  634.       properties = { border_width = beautiful.border_width,
  635.                      border_color = beautiful.border_normal,
  636.                      focus = awful.client.focus.filter,
  637.                      raise = true,
  638.                      keys = clientkeys,
  639.                      buttons = clientbuttons,
  640.                      screen = awful.screen.preferred,
  641.                      placement = awful.placement.no_overlap+awful.placement.no_offscreen,
  642.                      size_hints_honor = false
  643.      }
  644.     },
  645.  
  646.     -- Titlebars
  647.     { rule_any = { type = { "dialog", "normal" } },
  648.       properties = { titlebars_enabled = false } },
  649.  
  650.     -- Set Firefox to always map on the first tag on screen 1.
  651.     { rule = { class = "Firefox" },
  652.       properties = { screen = 1, tag = awful.util.tagnames[1] } },
  653.  
  654.     { rule = { class = "Gimp", role = "gimp-image-window" },
  655.           properties = { maximized = true } },
  656. }
  657. -- }}}
  658.  
  659. -- {{{ Signals
  660. -- Signal function to execute when a new client appears.
  661. client.connect_signal("manage", function (c)
  662.     -- Set the windows at the slave,
  663.     -- i.e. put it at the end of others instead of setting it master.
  664.     -- if not awesome.startup then awful.client.setslave(c) end
  665.  
  666.     if awesome.startup and
  667.       not c.size_hints.user_position
  668.       and not c.size_hints.program_position then
  669.         -- Prevent clients from being unreachable after screen count changes.
  670.         awful.placement.no_offscreen(c)
  671.     end
  672. end)
  673.  
  674. -- Add a titlebar if titlebars_enabled is set to true in the rules.
  675. client.connect_signal("request::titlebars", function(c)
  676.     -- Custom
  677.     if beautiful.titlebar_fun then
  678.         beautiful.titlebar_fun(c)
  679.         return
  680.     end
  681.  
  682.     -- Default
  683.     -- buttons for the titlebar
  684.     local buttons = my_table.join(
  685.         awful.button({ }, 1, function()
  686.             client.focus = c
  687.             c:raise()
  688.             awful.mouse.client.move(c)
  689.         end),
  690.         awful.button({ }, 3, function()
  691.             client.focus = c
  692.             c:raise()
  693.             awful.mouse.client.resize(c)
  694.         end)
  695.     )
  696.  
  697.     awful.titlebar(c, {size = 16}) : setup {
  698.         { -- Left
  699.             awful.titlebar.widget.iconwidget(c),
  700.             buttons = buttons,
  701.             layout  = wibox.layout.fixed.horizontal
  702.         },
  703.         { -- Middle
  704.             { -- Title
  705.                 align  = "center",
  706.                 widget = awful.titlebar.widget.titlewidget(c)
  707.             },
  708.             buttons = buttons,
  709.             layout  = wibox.layout.flex.horizontal
  710.         },
  711.         { -- Right
  712.             awful.titlebar.widget.floatingbutton (c),
  713.             awful.titlebar.widget.maximizedbutton(c),
  714.             awful.titlebar.widget.stickybutton   (c),
  715.             awful.titlebar.widget.ontopbutton    (c),
  716.             awful.titlebar.widget.closebutton    (c),
  717.             layout = wibox.layout.fixed.horizontal()
  718.         },
  719.         layout = wibox.layout.align.horizontal
  720.     }
  721. end)
  722.  
  723. -- Enable sloppy focus, so that focus follows mouse.
  724. client.connect_signal("mouse::enter", function(c)
  725.     if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  726.         and awful.client.focus.filter(c) then
  727.         client.focus = c
  728.     end
  729. end)
  730.  
  731. -- No border for maximized clients
  732. function border_adjust(c)
  733.     if c.maximized then -- no borders if only 1 client visible
  734.         c.border_width = 0
  735.     elseif #awful.screen.focused().clients > 1 then
  736.         c.border_width = beautiful.border_width
  737.         c.border_color = beautiful.border_focus
  738.     end
  739. end
  740.  
  741. client.connect_signal("focus", border_adjust)
  742. client.connect_signal("property::maximized", border_adjust)
  743. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  744. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement