Advertisement
Guest User

Awesome

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