Advertisement
Guest User

rc.lua

a guest
Oct 31st, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.27 KB | None | 0 0
  1. vicious = require("vicious")
  2. -- Standard awesome library
  3. local gears = require("gears")
  4. local awful = require("awful")
  5. awful.rules = require("awful.rules")
  6. require("awful.autofocus")
  7. local revelation = require("revelation")
  8. -- Composite Manager
  9. awful.util.spawn_with_shell("unagi &")
  10. -- Widget and layout library
  11. local wibox = require("wibox")
  12. -- Theme handling library
  13. local beautiful = require("beautiful")
  14. -- Notification library
  15. local naughty = require("naughty")
  16. local menubar = require("menubar")
  17.  
  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/custom/theme.lua")
  47. revelation.init()
  48.  
  49. -- This is used later as the default terminal and editor to run.
  50. terminal = "urxvt"
  51. editor = "gvim" or os.getenv("EDITOR") or "nano"
  52. editor_cmd = terminal .. " -e " .. editor
  53.  
  54. -- Default modkey.
  55. -- Usually, Mod4 is the key with a logo between Control and Alt.
  56. -- If you do not like this or do not have such a key,
  57. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  58. -- However, you can use another modifier like Mod1, but it may interact with others.
  59. modkey = "Mod4"
  60.  
  61. -- Table of layouts to cover with awful.layout.inc, order matters.
  62. local layouts =
  63. {
  64.     awful.layout.suit.floating,
  65.     awful.layout.suit.tile,
  66. --    awful.layout.suit.tile.left,
  67. --    awful.layout.suit.tile.bottom,
  68. --    awful.layout.suit.tile.top,
  69.     awful.layout.suit.fair,
  70. --    awful.layout.suit.fair.horizontal,
  71. --    awful.layout.suit.spiral,
  72. --    awful.layout.suit.spiral.dwindle,
  73. --    awful.layout.suit.max,
  74. --    awful.layout.suit.max.fullscreen,
  75. --    awful.layout.suit.magnifier
  76. }
  77. -- }}}
  78.  
  79. -- {{{ Wallpaper
  80. if beautiful.wallpaper then
  81.     for s = 1, screen.count() do
  82.         gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  83.     end
  84. end
  85. -- }}}
  86.  
  87. -- {{{ Tags
  88. -- Define a tag table which hold all screen tags.
  89. tags = {
  90.     names = { "α" , "β" , "γ" , "δ" }  
  91. }
  92. for s = 1, screen.count() do
  93.     -- Each screen has its own tag table.
  94.     tags[s] = awful.tag(tags.names, s, layouts[1])
  95. end
  96. -- }}}
  97.  
  98. -- {{{ Menu
  99. -- Create a laucher widget and a main menu
  100. myawesomemenu = {
  101.    { "manual", terminal .. " -e man awesome" },
  102.    { "edit config", editor_cmd .. " " .. awesome.conffile },
  103.    { "restart", awesome.restart },
  104.    { "quit", awesome.quit }
  105. }
  106.  
  107. gamesmenu = {  
  108.    { "Hamachi" , "haguichi" },
  109.    { "Legend of Grimrock", "Grimrock" },
  110.    { "Mumble" , "mumble" },
  111.    { "Planescape: Torment", "playonlinux --run 'Planescape: Torment'" },
  112.    { "PlayOnLinux", "playonlinux" },
  113.    { "Steam" , "sh -c 'STEAM_FRAME_FORCE_CLOSE=1 steam' %U" }
  114.  }
  115.  
  116. internetmenu = {
  117.    { "Chromium" , "chromium" },
  118.    { "Deluge" , "deluge" },
  119.    { "Firefox" , "firefox" },
  120.    { "MPS Youtube" , terminal .. " -e mpsyt" },
  121.    { "Pidgin" , "pidgin" }
  122. }
  123.  
  124. toolsmenu = {
  125.    { "Android Studio" , "android-studio" },
  126.    { "Blender" , "blender" },
  127.    { "GIMP" , "gimp" }
  128. }
  129.  
  130. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  131.                     { "Games", gamesmenu },
  132.                     { "Internet" , internetmenu },
  133.                     { "Tools" , toolsmenu },
  134.                     { "open explorer", "thunar" },
  135.                                     { "open terminal", terminal },
  136.                                   }
  137.                         })
  138.  
  139. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  140.                                      menu = mymainmenu })
  141.  
  142. -- Menubar configuration
  143. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  144. -- }}}
  145.  
  146. -- {{ MPD widget
  147. mpdwidget = wibox.widget.textbox()
  148. vicious.register(mpdwidget, vicious.widgets.mpd,
  149.     function (widget, args)
  150.         if args["{state}"] == "Stop" then
  151.             return "♫ stopped"
  152.         else
  153.             return "♫ "..args["{Artist}"]..' - '.. args["{Title}"]
  154.         end
  155.     end, 10)
  156.  
  157. -- {{{ Wibox
  158. -- Create a textclock widget
  159. mytextclock = awful.widget.textclock()
  160.  
  161. -- Clock showing only the time
  162. -- Initialize widget
  163. datewidget = wibox.widget.textbox()
  164. -- Register widget
  165. vicious.register(datewidget, vicious.widgets.date, " |%R| ", 1)
  166.  
  167. -- Separator between tags and tasks
  168. separator = wibox.widget.textbox()
  169. separator:set_text(" | ")
  170.  
  171.  
  172. -- Create a wibox for each screen and add it
  173. mywibox = {}
  174. mypromptbox = {}
  175. mylayoutbox = {}
  176.  
  177. mytaglist = {}
  178. mytaglist.buttons = awful.util.table.join(
  179.                     awful.button({ }, 1, awful.tag.viewonly),
  180.                     awful.button({ modkey }, 1, awful.client.movetotag),
  181.                     awful.button({ }, 3, awful.tag.viewtoggle),
  182.                     awful.button({ modkey }, 3, awful.client.toggletag),
  183.                     awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  184.                     awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  185.                     )
  186. mytasklist = {}
  187. mytasklist.buttons = awful.util.table.join(
  188.                      awful.button({ }, 1, function (c)
  189.                                               if c == client.focus then
  190.                                                   c.minimized = true
  191.                                               else
  192.                                                   -- Without this, the following
  193.                                                   -- :isvisible() makes no sense
  194.                                                   c.minimized = false
  195.                                                   if not c:isvisible() then
  196.                                                       awful.tag.viewonly(c:tags()[1])
  197.                                                   end
  198.                                                   -- This will also un-minimize
  199.                                                   -- the client, if needed
  200.                                                   client.focus = c
  201.                                                   c:raise()
  202.                                               end
  203.                                           end),
  204.                      awful.button({ }, 3, function ()
  205.                                               if instance then
  206.                                                   instance:hide()
  207.                                                   instance = nil
  208.                                               else
  209.                                                   instance = awful.menu.clients({
  210.                                                       theme = { width = 250 }
  211.                                                   })
  212.                                               end
  213.                                           end),
  214.                      awful.button({ }, 4, function ()
  215.                                               awful.client.focus.byidx(1)
  216.                                               if client.focus then client.focus:raise() end
  217.                                           end),
  218.                      awful.button({ }, 5, function ()
  219.                                               awful.client.focus.byidx(-1)
  220.                                               if client.focus then client.focus:raise() end
  221.                                           end))
  222.  
  223. for s = 1, screen.count() do
  224.     -- Create a promptbox for each screen
  225.     mypromptbox[s] = awful.widget.prompt()
  226.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  227.     -- We need one layoutbox per screen.
  228.     mylayoutbox[s] = awful.widget.layoutbox(s)
  229.     mylayoutbox[s]:buttons(awful.util.table.join(
  230.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  231.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  232.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  233.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  234.     -- Create a taglist widget
  235.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  236.  
  237.     -- Create a tasklist widget
  238.     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  239.  
  240.     -- Create the wibox
  241.     mywibox[s] = awful.wibox({ position = "top", height = "15", screen = s })
  242.  
  243.     -- Widgets that are aligned to the left
  244.     local left_layout = wibox.layout.fixed.horizontal()
  245.     -- Hide menu launcher    left_layout:add(mylauncher)
  246.     left_layout:add(mytaglist[s])
  247.     left_layout:add(separator)
  248.     left_layout:add(mypromptbox[s])
  249.  
  250.     -- Widgets that are aligned to the right
  251.     local right_layout = wibox.layout.fixed.horizontal()
  252.     -- if s == 1 then right_layout:add(wibox.widget.systray()) end
  253.     right_layout:add(mpdwidget)
  254.     right_layout:add(datewidget)
  255.     right_layout:add(mylayoutbox[s])
  256.  
  257.     -- Now bring it all together (with the tasklist in the middle)
  258.     local layout = wibox.layout.align.horizontal()
  259.     layout:set_left(left_layout)
  260.     layout:set_middle(mytasklist[s])
  261.     layout:set_right(right_layout)--]]
  262.  
  263.     mywibox[s]:set_widget(layout)
  264. end
  265. -- }}}
  266.  
  267. -- {{{ Mouse bindings
  268. root.buttons(awful.util.table.join(
  269.     awful.button({ }, 3, function () mymainmenu:toggle() end)))
  270. -- }}}
  271.  
  272. -- {{{ Key bindings
  273. globalkeys = awful.util.table.join(
  274.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  275.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  276.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  277.     awful.key({ modkey,       }, "e", revelation),
  278.  
  279.     awful.key({ modkey,           }, "j",
  280.         function ()
  281.             awful.client.focus.byidx( 1)
  282.             if client.focus then client.focus:raise() end
  283.         end),
  284.     awful.key({ modkey }, "b",
  285.         function ()
  286.             mywibox[mouse.screen].visible = not mywibox[mouse.screen].visible
  287.     end),
  288.     awful.key({ modkey,           }, "k",
  289.         function ()
  290.             awful.client.focus.byidx(-1)
  291.             if client.focus then client.focus:raise() end
  292.         end),
  293.     awful.key({ modkey,           }, "w", function () mymainmenu:show() end),
  294.  
  295.     -- Layout manipulation
  296.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  297.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  298.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  299.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  300.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  301.     awful.key({ modkey,           }, "Tab",
  302.         function ()
  303.             awful.client.focus.history.previous()
  304.             if client.focus then
  305.                 client.focus:raise()
  306.             end
  307.         end),
  308.  
  309.     -- Standard program
  310.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  311.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  312.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  313.  
  314.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  315.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  316.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  317.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  318.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  319.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  320.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  321.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  322.  
  323.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  324.  
  325.     -- Prompt
  326.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  327.  
  328.     awful.key({ modkey }, "x",
  329.               function ()
  330.                   awful.prompt.run({ prompt = "Run Lua code: " },
  331.                   mypromptbox[mouse.screen].widget,
  332.                   awful.util.eval, nil,
  333.                   awful.util.getdir("cache") .. "/history_eval")
  334.               end),
  335.     -- Menubar
  336.     awful.key({ modkey }, "p", function() menubar.show() end),
  337.     -- Print screen
  338.     awful.key({ }, "Print", function () awful.util.spawn("scrot -e 'mv $f ~/Screenshots/ 2>/dev/null'") end)
  339.    
  340. )
  341.  
  342. clientkeys = awful.util.table.join(
  343.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  344.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  345.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  346.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  347.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  348.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  349.     awful.key({ modkey,           }, "n",
  350.         function (c)
  351.             -- The client currently has the input focus, so it cannot be
  352.             -- minimized, since minimized clients can't have the focus.
  353.             c.minimized = true
  354.         end),
  355.     awful.key({ modkey,           }, "m",
  356.         function (c)
  357.             c.maximized_horizontal = not c.maximized_horizontal
  358.             c.maximized_vertical   = not c.maximized_vertical
  359.         end)
  360. )
  361.  
  362. -- Bind all key numbers to tags.
  363. -- Be careful: we use keycodes to make it works on any keyboard layout.
  364. -- This should map on the top row of your keyboard, usually 1 to 9.
  365. for i = 1, 9 do
  366.     globalkeys = awful.util.table.join(globalkeys,
  367.         -- View tag only.
  368.         awful.key({ modkey }, "#" .. i + 9,
  369.                   function ()
  370.                         local screen = mouse.screen
  371.                         local tag = awful.tag.gettags(screen)[i]
  372.                         if tag then
  373.                            awful.tag.viewonly(tag)
  374.                         end
  375.                   end),
  376.         -- Toggle tag.
  377.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  378.                   function ()
  379.                       local screen = mouse.screen
  380.                       local tag = awful.tag.gettags(screen)[i]
  381.                       if tag then
  382.                          awful.tag.viewtoggle(tag)
  383.                       end
  384.                   end),
  385.         -- Move client to tag.
  386.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  387.                   function ()
  388.                       if client.focus then
  389.                           local tag = awful.tag.gettags(client.focus.screen)[i]
  390.                           if tag then
  391.                               awful.client.movetotag(tag)
  392.                           end
  393.                      end
  394.                   end),
  395.         -- Toggle tag.
  396.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  397.                   function ()
  398.                       if client.focus then
  399.                           local tag = awful.tag.gettags(client.focus.screen)[i]
  400.                           if tag then
  401.                               awful.client.toggletag(tag)
  402.                           end
  403.                       end
  404.                   end))
  405. end
  406.  
  407. clientbuttons = awful.util.table.join(
  408.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  409.     awful.button({ modkey }, 1, awful.mouse.client.move),
  410.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  411.  
  412. -- Set keys
  413. root.keys(globalkeys)
  414. -- }}}
  415.  
  416. -- {{{ Rules
  417. -- Rules to apply to new clients (through the "manage" signal).
  418. awful.rules.rules = {
  419.     -- All clients will match this rule.
  420.     { rule = { },
  421.       properties = { border_width = beautiful.border_width,
  422.                      border_color = beautiful.border_normal,
  423.              -- size_hints_honor = false,
  424.                      focus = awful.client.focus.filter,
  425.                      raise = true,
  426.                      keys = clientkeys,
  427.                      buttons = clientbuttons } },
  428.     { rule = { class = "MPlayer" },
  429.       properties = { floating = true } },
  430.     { rule = { class = "pinentry" },
  431.       properties = { floating = true } },
  432.     { rule = { class = "gimp" },
  433.       properties = { floating = true } },
  434.     { rule = { class = "Wine" },
  435.       properties = { border_width = 0, floating = true } },
  436.     -- Set Firefox to always map on tags number 2 of screen 1.
  437.     -- { rule = { class = "Firefox" },
  438.     --   properties = { tag = tags[1][2] } },
  439. }
  440. -- }}}
  441.  
  442. -- {{{ Signals
  443. -- Signal function to execute when a new client appears.
  444. client.connect_signal("manage", function (c, startup)
  445.     -- Enable sloppy focus
  446.     c:connect_signal("mouse::enter", function(c)
  447.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  448.             and awful.client.focus.filter(c) then
  449.             client.focus = c
  450.         end
  451.     end)
  452.  
  453.     if not startup then
  454.         -- Set the windows at the slave,
  455.         -- i.e. put it at the end of others instead of setting it master.
  456.         -- awful.client.setslave(c)
  457.  
  458.         -- Put windows in a smart way, only if they does not set an initial position.
  459.         if not c.size_hints.user_position and not c.size_hints.program_position then
  460.             awful.placement.no_overlap(c)
  461.             awful.placement.no_offscreen(c)
  462.         end
  463.     end
  464.  
  465.     local titlebars_enabled = false
  466.     if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  467.         -- buttons for the titlebar
  468.         local buttons = awful.util.table.join(
  469.                 awful.button({ }, 1, function()
  470.                     client.focus = c
  471.                     c:raise()
  472.                     awful.mouse.client.move(c)
  473.                 end),
  474.                 awful.button({ }, 3, function()
  475.                     client.focus = c
  476.                     c:raise()
  477.                     awful.mouse.client.resize(c)
  478.                 end)
  479.                 )
  480.  
  481.         -- Widgets that are aligned to the left
  482.         local left_layout = wibox.layout.fixed.horizontal()
  483.         left_layout:add(awful.titlebar.widget.iconwidget(c))
  484.         left_layout:buttons(buttons)
  485.  
  486.         -- Widgets that are aligned to the right
  487.         local right_layout = wibox.layout.fixed.horizontal()
  488.         right_layout:add(awful.titlebar.widget.floatingbutton(c))
  489.         right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  490.         right_layout:add(awful.titlebar.widget.stickybutton(c))
  491.         right_layout:add(awful.titlebar.widget.ontopbutton(c))
  492.         right_layout:add(awful.titlebar.widget.closebutton(c))
  493.  
  494.         -- The title goes in the middle
  495.         local middle_layout = wibox.layout.flex.horizontal()
  496.         local title = awful.titlebar.widget.titlewidget(c)
  497.         title:set_align("center")
  498.         middle_layout:add(title)
  499.         middle_layout:buttons(buttons)
  500.  
  501.         -- Now bring it all together
  502.         local layout = wibox.layout.align.horizontal()
  503.         layout:set_left(left_layout)
  504.         layout:set_right(right_layout)
  505.         layout:set_middle(middle_layout)
  506.  
  507.         awful.titlebar(c):set_widget(layout)
  508.     end
  509. end)
  510.  
  511. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  512. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  513. -- }}}
  514.  
  515. mytextbox = wibox.widget.textbox()
  516. mytextbox:set_text("Hello, world!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement