Guest User

Untitled

a guest
May 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.75 KB | None | 0 0
  1. -- rc.lua by Mathias Andreasen
  2.  
  3. -- Standard awesome library
  4. require("awful")
  5. require("awful.autofocus")
  6. require("awful.rules")
  7. -- User libraries
  8. require("vicious")
  9. -- Theme handling library
  10. require("beautiful")
  11. -- Notification library
  12. require("naughty")
  13.  
  14. -- {{{ Error handling
  15. -- Check if awesome encountered an error during startup and fell back to
  16. -- another config (This code will only ever execute for the fallback config)
  17. if awesome.startup_errors then
  18.     naughty.notify({ preset = naughty.config.presets.critical,
  19.                      title = "Oops, there were errors during startup!",
  20.                      text = awesome.startup_errors })
  21. end
  22.  
  23. -- Handle runtime errors after startup
  24. do
  25.     local in_error = false
  26.     awesome.add_signal("debug::error", function (err)
  27.         -- Make sure we don't go into an endless error loop
  28.         if in_error then return end
  29.         in_error = true
  30.  
  31.         naughty.notify({ preset = naughty.config.presets.critical,
  32.                          title = "Oops, an error happened!",
  33.                          text = err })
  34.         in_error = false
  35.     end)
  36. end
  37. -- }}}
  38.  
  39. -- {{{ Variable definitions
  40. -- Themes define colours, icons, and wallpapers
  41. beautiful.init("/usr/share/awesome/themes/default/theme.lua")
  42.  
  43. -- This is used later as the default terminal and editor to run.
  44. terminal = "urxvt"
  45. editor = os.getenv("EDITOR") or "nano"
  46. editor_cmd = terminal .. " -e " .. editor
  47.  
  48. -- Default modkey.
  49. modkey = "Mod4"
  50.  
  51. -- Table of layouts to cover with awful.layout.inc, order matters.
  52. layouts =
  53. {
  54.     awful.layout.suit.floating,     -- 1
  55.     awful.layout.suit.tile,     -- 2
  56.     awful.layout.suit.tile.left,    -- 3
  57.     awful.layout.suit.tile.bottom,  -- 4
  58.     awful.layout.suit.tile.top,     -- 5
  59.     awful.layout.suit.max,      -- 6
  60.    -- awful.layout.suit.fair,      
  61.    -- awful.layout.suit.fair.horizontal,
  62.    -- awful.layout.suit.spiral,
  63.    -- awful.layout.suit.spiral.dwindle,
  64.    -- awful.layout.suit.max.fullscreen,
  65.    -- awful.layout.suit.magnifier
  66. }
  67. -- }}}
  68.  
  69. -- {{{ Tags
  70. -- Define a tag table which hold all screen tags.
  71. tags = {
  72.     names = { "a", "b", "c", "d", "e" },
  73.     layout = { layouts[2], layouts[1], layouts[3], layouts[1], layouts[1] }
  74. }
  75. for s = 1, screen.count() do
  76.     -- Each screen has its own tag table.
  77.     tags[s] = awful.tag(tags.names, s, tags.layout)
  78. end
  79. -- }}}
  80.  
  81. -- {{{ Menu
  82. -- Create a laucher widget and a main menu
  83. myawesomemenu = {
  84.    { "manual", terminal .. " -e man awesome" },
  85.    { "edit config", editor_cmd .. " " .. awesome.conffile },
  86.    { "restart", awesome.restart },
  87.    { "quit", awesome.quit }
  88. }
  89.  
  90. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  91.                                     { "open terminal", terminal }
  92.                                   }
  93.                         })
  94.  
  95. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  96.                                      menu = mymainmenu })
  97. -- }}}
  98.  
  99. -- {{{ Wibox
  100. -- Create a textclock widget
  101. mytextclock = awful.widget.textclock({ align = "right" })
  102.  
  103. -- Create a systray
  104. mysystray = widget({ type = "systray" })
  105.  
  106. -- Create a wibox for each screen and add it
  107. mywibox = {}
  108. mypromptbox = {}
  109. mylayoutbox = {}
  110. mytaglist = {}
  111. mytaglist.buttons = awful.util.table.join(
  112.                     awful.button({ }, 1, awful.tag.viewonly),
  113.                     awful.button({ modkey }, 1, awful.client.movetotag),
  114.                     awful.button({ }, 3, awful.tag.viewtoggle),
  115.                     awful.button({ modkey }, 3, awful.client.toggletag),
  116.                     awful.button({ }, 4, awful.tag.viewnext),
  117.                     awful.button({ }, 5, awful.tag.viewprev)
  118.                     )
  119. mytasklist = {}
  120. mytasklist.buttons = awful.util.table.join(
  121.                      awful.button({ }, 1, function (c)
  122.                                               if c == client.focus then
  123.                                                   c.minimized = true
  124.                                               else
  125.                                                   if not c:isvisible() then
  126.                                                       awful.tag.viewonly(c:tags()[1])
  127.                                                   end
  128.                                                   -- This will also un-minimize
  129.                                                   -- the client, if needed
  130.                                                   client.focus = c
  131.                                                   c:raise()
  132.                                               end
  133.                                           end),
  134.                      awful.button({ }, 3, function ()
  135.                                               if instance then
  136.                                                   instance:hide()
  137.                                                   instance = nil
  138.                                               else
  139.                                                   instance = awful.menu.clients({ width=250 })
  140.                                               end
  141.                                           end),
  142.                      awful.button({ }, 4, function ()
  143.                                               awful.client.focus.byidx(1)
  144.                                               if client.focus then client.focus:raise() end
  145.                                           end),
  146.                      awful.button({ }, 5, function ()
  147.                                               awful.client.focus.byidx(-1)
  148.                                               if client.focus then client.focus:raise() end
  149.                                           end))
  150.  
  151. for s = 1, screen.count() do
  152.     -- Create a promptbox for each screen
  153.     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  154.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  155.     -- We need one layoutbox per screen.
  156.     mylayoutbox[s] = awful.widget.layoutbox(s)
  157.     mylayoutbox[s]:buttons(awful.util.table.join(
  158.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  159.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  160.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  161.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  162.     -- Create a taglist widget
  163.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  164.  
  165.     -- Create a tasklist widget
  166.     mytasklist[s] = awful.widget.tasklist(function(c)
  167.                                               return awful.widget.tasklist.label.currenttags(c, s)
  168.                                           end, mytasklist.buttons)
  169.  
  170.     -- Create the wibox
  171.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  172.     -- Add widgets to the wibox - order matters
  173.     mywibox[s].widgets = {
  174.         {
  175.             mylauncher,
  176.             mytaglist[s],
  177.             mypromptbox[s],
  178.             layout = awful.widget.layout.horizontal.leftright
  179.         },
  180.         mylayoutbox[s],
  181.         mytextclock,
  182.         s == 1 and mysystray or nil,
  183.         mytasklist[s],
  184.         layout = awful.widget.layout.horizontal.rightleft
  185.     }
  186. end
  187. -- }}}
  188.  
  189. -- {{{ Mouse bindings
  190. root.buttons(awful.util.table.join(
  191.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  192.     awful.button({ }, 4, awful.tag.viewnext),
  193.     awful.button({ }, 5, awful.tag.viewprev)
  194. ))
  195. -- }}}
  196.  
  197. -- {{{ Key bindings
  198. globalkeys = awful.util.table.join(
  199.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  200.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  201.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  202.  
  203.     awful.key({ modkey,           }, "j",
  204.         function ()
  205.             awful.client.focus.byidx( 1)
  206.             if client.focus then client.focus:raise() end
  207.         end),
  208.     awful.key({ modkey,           }, "k",
  209.         function ()
  210.             awful.client.focus.byidx(-1)
  211.             if client.focus then client.focus:raise() end
  212.         end),
  213.     awful.key({ modkey,           }, "w", function () mymainmenu:show({keygrabber=true}) end),
  214.  
  215.     -- Layout manipulation
  216.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  217.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  218.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  219.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  220.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  221.     awful.key({ modkey,           }, "Tab",
  222.         function ()
  223.             awful.client.focus.history.previous()
  224.             if client.focus then
  225.                 client.focus:raise()
  226.             end
  227.         end),
  228.  
  229.     -- Standard program
  230.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  231.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  232.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  233.  
  234.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  235.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  236.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  237.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  238.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  239.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  240.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  241.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  242.  
  243.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  244.  
  245.  
  246.     -- Multimedia keys
  247.     awful.key({}, "XF86AudioRaiseVolume", function () awful.util.spawn("amixer sset Master 1+ unmute") end),
  248.     awful.key({}, "XF86AudioLowerVolume", function () awful.util.spawn("amixer sset Master 1- unmute") end),
  249.     awful.key({}, "XF86AudioMute", function () awful.util.spawn("amixer sset Master toggle") end),
  250.  
  251.     -- Application startup
  252.     awful.key({ modkey }, "F1", function () awful.util.spawn("/usr/bin/firefox") end),
  253.     awful.key({ modkey }, "F2", function () awful.util.spawn("/usr/bin/skype") end),
  254.     awful.key({ modkey }, "e", function () awful.util.spawn("/usr/bin/pcmanfm") end),
  255.  
  256.     -- Prompt
  257.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  258.  
  259.     awful.key({ modkey }, "x",
  260.               function ()
  261.                   awful.prompt.run({ prompt = "Run Lua code: " },
  262.                   mypromptbox[mouse.screen].widget,
  263.                   awful.util.eval, nil,
  264.                   awful.util.getdir("cache") .. "/history_eval")
  265.               end)
  266. )
  267.  
  268. clientkeys = awful.util.table.join(
  269.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  270.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  271.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  272.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  273.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  274.     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
  275.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  276.     awful.key({ modkey,           }, "n",
  277.         function (c)
  278.             -- The client currently has the input focus, so it cannot be
  279.             -- minimized, since minimized clients can't have the focus.
  280.             c.minimized = true
  281.         end),
  282.     awful.key({ modkey,           }, "m",
  283.         function (c)
  284.             c.maximized_horizontal = not c.maximized_horizontal
  285.             c.maximized_vertical   = not c.maximized_vertical
  286.         end)
  287. )
  288.  
  289. -- Compute the maximum number of digit we need, limited to 9
  290. keynumber = 0
  291. for s = 1, screen.count() do
  292.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  293. end
  294.  
  295. -- Bind all key numbers to tags.
  296. -- Be careful: we use keycodes to make it works on any keyboard layout.
  297. -- This should map on the top row of your keyboard, usually 1 to 9.
  298. for i = 1, keynumber do
  299.     globalkeys = awful.util.table.join(globalkeys,
  300.         awful.key({ modkey }, "#" .. i + 9,
  301.                   function ()
  302.                         local screen = mouse.screen
  303.                         if tags[screen][i] then
  304.                             awful.tag.viewonly(tags[screen][i])
  305.                         end
  306.                   end),
  307.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  308.                   function ()
  309.                       local screen = mouse.screen
  310.                       if tags[screen][i] then
  311.                           awful.tag.viewtoggle(tags[screen][i])
  312.                       end
  313.                   end),
  314.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  315.                   function ()
  316.                       if client.focus and tags[client.focus.screen][i] then
  317.                           awful.client.movetotag(tags[client.focus.screen][i])
  318.                       end
  319.                   end),
  320.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  321.                   function ()
  322.                       if client.focus and tags[client.focus.screen][i] then
  323.                           awful.client.toggletag(tags[client.focus.screen][i])
  324.                       end
  325.                   end))
  326. end
  327.  
  328. clientbuttons = awful.util.table.join(
  329.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  330.     awful.button({ modkey }, 1, awful.mouse.client.move),
  331.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  332.  
  333. -- Set keys
  334. root.keys(globalkeys)
  335. -- }}}
  336.  
  337. -- {{{ Rules
  338. awful.rules.rules = {
  339.     -- All clients will match this rule.
  340.     { rule = { },
  341.       properties = { border_width = beautiful.border_width,
  342.                      border_color = beautiful.border_normal,
  343.                      focus = true,
  344.                      keys = clientkeys,
  345.                      buttons = clientbuttons } },
  346.  
  347.    
  348.     { rule = { class = "Skype" },
  349.         properties { tag = tags[1][3] } },
  350.     { rule = { class = "Firefox" },
  351.         properties = { tag = tags[1][2] } },
  352.     -- Set Firefox to always map on tags number 2 of screen 1.
  353.     -- { rule = { class = "Firefox" },
  354.     --   properties = { tag = tags[1][2] } },
  355. }
  356. -- }}}
  357.  
  358. -- {{{ Signals
  359. -- Signal function to execute when a new client appears.
  360. client.add_signal("manage", function (c, startup)
  361.     -- Add a titlebar
  362.     -- awful.titlebar.add(c, { modkey = modkey })
  363.  
  364.     -- Enable sloppy focus
  365.     c:add_signal("mouse::enter", function(c)
  366.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  367.             and awful.client.focus.filter(c) then
  368.             client.focus = c
  369.         end
  370.     end)
  371.  
  372.     if not startup then
  373.         -- Set the windows at the slave,
  374.         -- i.e. put it at the end of others instead of setting it master.
  375.         -- awful.client.setslave(c)
  376.  
  377.         -- Put windows in a smart way, only if they does not set an initial position.
  378.         if not c.size_hints.user_position and not c.size_hints.program_position then
  379.             awful.placement.no_overlap(c)
  380.             awful.placement.no_offscreen(c)
  381.         end
  382.     end
  383. end)
  384.  
  385. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  386. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  387. -- }}}
Add Comment
Please, Sign In to add comment