Advertisement
Guest User

awesome // rc.lua

a guest
Dec 12th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.50 KB | None | 0 0
  1. -- Standard awesome library
  2. require("awful")
  3. require("awful.autofocus")
  4. require("awful.rules")
  5. -- Theme handling library
  6. require("beautiful")
  7. -- Notification library
  8. require("naughty")
  9. -- shifty - dynamic tagging library
  10. require("shifty")
  11.  
  12. -- {{{ Error handling
  13. -- Check if awesome encountered an error during startup and fell back to
  14. -- another config (This code will only ever execute for the fallback config)
  15. if awesome.startup_errors then
  16.     naughty.notify({ preset = naughty.config.presets.critical,
  17.                      title = "Oops, there were errors during startup!",
  18.                      text = awesome.startup_errors })
  19. end
  20.  
  21. -- Handle runtime errors after startup
  22. do
  23.     local in_error = false
  24.     awesome.add_signal("debug::error", function (err)
  25.         -- Make sure we don't go into an endless error loop
  26.         if in_error then return end
  27.         in_error = true
  28.  
  29.         naughty.notify({ preset = naughty.config.presets.critical,
  30.                          title = "Oops, an error happened!",
  31.                          text = err })
  32.         in_error = false
  33.     end)
  34. end
  35. -- }}}
  36.  
  37. -- useful for debugging, marks the beginning of rc.lua exec
  38. print("Entered rc.lua: " .. os.time())
  39.  
  40. -- {{{ Variable definitions
  41. -- Themes define colours, icons, and wallpapers
  42. beautiful.init(awful.util.getdir("config") .. "/themes/own/theme.lua")
  43.  
  44. -- This is used later as the default terminal and editor to run.
  45. terminal = "urxvt"
  46. editor = os.getenv("EDITOR") or "nano"
  47. editor_cmd = editor
  48. browser = os.getenv("BROWSER")
  49. mail = terminal .. " -e mutt"
  50. office = "soffice"
  51. screenlock = "slock"
  52. alsa_mute = "amixer -q set Master toggle"
  53. alsa_lower = "amixer -q set Master 5dB-"
  54. alsa_raise = "amixer -q set Master 5dB+"
  55. backlight_inc = "xbacklight -inc 10"
  56. backlight_dec = "xbacklight -dec 10"
  57.  
  58. -- Default modkey.
  59. -- Usually, Mod4 is the key with a logo between Control and Alt.
  60. -- If you do not like this or do not have such a key,
  61. -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
  62. -- However, you can use another modifier like Mod1, but it may interact with others.
  63. modkey = "Mod4"
  64.  
  65. -- Table of layouts to cover with awful.layout.inc, order matters.
  66. layouts =
  67. {
  68.     awful.layout.suit.floating,
  69.     awful.layout.suit.tile,
  70.     awful.layout.suit.tile.bottom,
  71.     awful.layout.suit.max,
  72.     awful.layout.suit.max.fullscreen,
  73. }
  74. -- }}}
  75.  
  76. -- Define if we want to use titlebar on all applications.
  77. use_titlebar = false
  78.  
  79. -- Shifty configured tags.
  80. shifty.config.tags = {
  81.     ["1:term"] = {
  82.         layout      = awful.layout.suit.tile.bottom,
  83.         mwfact      = 0.60,
  84.         position    = 1,
  85.         init        = true,
  86.         screen      = screen.count(),
  87.         spawn       = terminal,
  88.         exclusive   = true,
  89.     },
  90.     ["2:web"] = {
  91.         layout      = awful.layout.suit.max,
  92.         position    = 2,
  93.         screen      = 1,
  94.         spawn       = browser,
  95.         exclusive   = true,
  96.     },
  97.     ["3:view"] = {
  98.         layout      = awful.layout.suit.max,
  99.         position    = 3,
  100.         screen      = 1,
  101.         spawn       = "evince"
  102.     },
  103.     ["4:edit"] = {
  104.         layout      = awful.layout.suit.max,
  105.         position    = 4,
  106.         screen      = screen.count(),
  107.         spawn       = editor_cmd
  108.     },
  109.     ["5:office"] = {
  110.         layout      = awful.layout.suit.tile,
  111.         position    = 5,
  112.         screen      = screen.count(),
  113.         spawn       = office
  114.     },
  115.     ["6:dev"] = {
  116.         layout      = awful.layout.suit.max,
  117.         position    = 6,
  118.         screen      = screen.count(),
  119.     },
  120.     ["7:soc"] = {
  121.         layout      = awful.layout.suit.tile,
  122.         position    = 7,
  123.         screen      = screen.count(),
  124.     },
  125.     ["8:media"] = {
  126.         layout      = awful.layout.suit.tile,
  127.         position    = 8,
  128.         screen      = 1,
  129.     },
  130.     ["9:mail"] = {
  131.         layout      = awful.layout.suit.max,
  132.         position    = 9,
  133.         screen      = screen.count(),
  134.         spawn       = mail
  135.     },
  136. }
  137.  
  138. -- SHIFTY: application matching rules
  139. -- order here matters, early rules will be applied first
  140. shifty.config.apps = {
  141.     { match = { "XTerm", "URxvt" },
  142.         tag = "1:term",
  143.     },
  144.     { match = { "Firefox", "luakit", "Iceweasel", "Icedove", "uzbl", "dwb" },
  145.         tag = "2:web",
  146.         nopopup = true,
  147.     },
  148.     { match = { "Xpdf", "Okular", "XDvi", "Geeqie", "Apvlv", "Evince", "feh", "zathura" },
  149.         tag = "3:view",
  150.     },
  151.     { match = { "Gimp", "Scite", "Gvim", "Gview", "Zim", "jabref" },
  152.         tag = "4:edit",
  153.         max_clients = 1,
  154.     },
  155.     { match = { "LibreOffice*", "Calligra*" },
  156.         tag = "5:office",
  157.     },
  158.     { match = { "Codeblocks", "Texmaker" },
  159.         tag = "6:dev",
  160.     },
  161.     { match = { "Pidgin", "Skype", "Empathy", "Jitsi" },
  162.         tag = "7:soc",
  163.     },
  164.     { match = { "Vlc", "mplayer", "guayadeque" },
  165.         tag = "8:media",
  166.     },
  167.     { match = { "Icedove" },
  168.         tag = "9:mail",
  169.     },
  170.     { match = { name = { "Mutt" } },
  171.         tag = "9:mail",
  172.     },
  173.     {
  174.         match = {""},
  175.         buttons = awful.util.table.join(
  176.             awful.button({}, 1, function (c) client.focus = c; c:raise() end),
  177.             awful.button({modkey}, 1, function(c)
  178.                 client.focus = c
  179.                 c:raise()
  180.                 awful.mouse.client.move(c)
  181.                 end),
  182.             awful.button({modkey}, 3, awful.mouse.client.resize)
  183.             )
  184.     },
  185. }
  186.  
  187. -- SHIFTY: default tag creation rules
  188. -- parameter description
  189. --  * floatBars : if floating clients should always have a titlebar
  190. --  * guess_name : should shifty try and guess tag names when creating
  191. --                 new (unconfigured) tags?
  192. --  * guess_position: as above, but for position parameter
  193. --  * run : function to exec when shifty creates a new tag
  194. --  * all other parameters (e.g. layout, mwfact) follow awesome's tag API
  195. shifty.config.defaults = {
  196.     layout = awful.layout.suit.max,
  197.     ncol = 1,
  198.     mwfact = 0.60,
  199.     floatBars = true,
  200.     guess_name = true,
  201.     guess_position = true,
  202. }
  203. -- {{{ Wibox
  204.  
  205. -- Create a systray
  206. mysystray = widget({ type = "systray" })
  207.  
  208. -- Create a wibox for each screen and add it
  209. mywibox = {}
  210. myconkybox = {}
  211. mypromptbox = {}
  212. mylayoutbox = {}
  213. mytaglist = {}
  214. mytaglist.buttons = awful.util.table.join(
  215.                     awful.button({ }, 1, awful.tag.viewonly),
  216.                     awful.button({ modkey }, 1, awful.client.movetotag),
  217.                     awful.button({ }, 3, awful.tag.viewtoggle),
  218.                     awful.button({ modkey }, 3, awful.client.toggletag),
  219.                     awful.button({ }, 4, awful.tag.viewnext),
  220.                     awful.button({ }, 5, awful.tag.viewprev)
  221.                     )
  222. mytasklist = {}
  223. mytasklist.buttons = awful.util.table.join(
  224.                      awful.button({ }, 1, function (c)
  225.                                               if c == client.focus then
  226.                                                   c.minimized = true
  227.                                               else
  228.                                                   if not c:isvisible() then
  229.                                                       awful.tag.viewonly(c:tags()[1])
  230.                                                   end
  231.                                                   -- This will also un-minimize
  232.                                                   -- the client, if needed
  233.                                                   client.focus = c
  234.                                                   c:raise()
  235.                                               end
  236.                                           end),
  237.                      awful.button({ }, 3, function ()
  238.                                               if instance then
  239.                                                   instance:hide()
  240.                                                   instance = nil
  241.                                               else
  242.                                                   instance = awful.menu.clients({ width=250 })
  243.                                               end
  244.                                           end),
  245.                      awful.button({ }, 4, function ()
  246.                                               awful.client.focus.byidx(1)
  247.                                               if client.focus then client.focus:raise() end
  248.                                           end),
  249.                      awful.button({ }, 5, function ()
  250.                                               awful.client.focus.byidx(-1)
  251.                                               if client.focus then client.focus:raise() end
  252.                                           end))
  253.  
  254. for s = 1, screen.count() do
  255.     -- Create a promptbox for each screen
  256.     mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  257.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  258.     -- We need one layoutbox per screen.
  259.     mylayoutbox[s] = awful.widget.layoutbox(s)
  260.     -- Create a taglist widget
  261.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  262.  
  263.     -- Create a tasklist widget
  264.     mytasklist[s] = awful.widget.tasklist(function(c)
  265.                                               return awful.widget.tasklist.label.currenttags(c, s)
  266.                                           end, mytasklist.buttons)
  267.  
  268.     -- Create the wibox
  269.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  270.     myconkybox[s] = awful.wibox({ position = "bottom", screen = screen.count(), height = "15", width = "1", ontop = false })
  271.  
  272.     -- Add widgets to the wibox - order matters
  273.     mywibox[s].widgets = {
  274.         {
  275.             mylayoutbox[s],
  276.             mytaglist[s],
  277.             mypromptbox[s],
  278.             layout = awful.widget.layout.horizontal.leftright
  279.         },
  280.         s == 1 and mysystray or nil,
  281.         mytasklist[s],
  282.         layout = awful.widget.layout.horizontal.rightleft
  283.     }
  284. end
  285. -- }}}
  286.  
  287. -- SHIFTY: initialize shifty
  288. -- the assignment of shifty.taglist must always be after its actually
  289. -- initialized with awful.widget.taglist.new()
  290. shifty.taglist = mytaglist
  291. shifty.init()
  292.  
  293. -- {{{ Mouse bindings
  294. root.buttons(awful.util.table.join(
  295.     awful.button({ }, 4, awful.tag.viewnext),
  296.     awful.button({ }, 5, awful.tag.viewprev)
  297. ))
  298. -- }}}
  299.  
  300. -- {{{ Key bindings
  301. globalkeys = awful.util.table.join(
  302.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  303.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  304.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  305.     awful.key({ modkey,           }, "j",
  306.         function ()
  307.             awful.client.focus.byidx( 1)
  308.             if client.focus then client.focus:raise() end
  309.         end),
  310.     awful.key({ modkey,           }, "k",
  311.         function ()
  312.             awful.client.focus.byidx(-1)
  313.             if client.focus then client.focus:raise() end
  314.         end),
  315.  
  316.     -- Shifty: keybindings specific to shifty
  317.     awful.key({modkey, "Shift"  }, "d", shifty.del                      ), -- delete a tag
  318.     awful.key({modkey, "Shift"  }, "n", shifty.send_prev                ), -- client to prev tag
  319.     awful.key({modkey           }, "n", shifty.send_next                ), -- client to next tag
  320.     awful.key({modkey, "Control"}, "n",
  321.               function()
  322.                   local t = awful.tag.selected()
  323.                   if t ~= nil then
  324.                     local s = awful.util.cycle(screen.count(), t.screen + 1)
  325.                     awful.tag.history.restore()
  326.                     t = shifty.tagtoscr(s, t)
  327.                     awful.tag.viewonly(t)
  328.                   end
  329.               end),
  330.     awful.key({modkey           }, "a", shifty.add                      ), -- creat a new tag
  331.     awful.key({modkey           }, "r", shifty.rename                   ), -- rename a tag
  332.     awful.key({modkey, "Shift"  }, "a",                                    -- nopopup new tag
  333.         function()
  334.             shifty.add({nopopup = true})
  335.         end),
  336.  
  337.     -- Layout manipulation
  338.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  339.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  340.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  341.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  342.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  343.     awful.key({ modkey,           }, "Tab",
  344.         function ()
  345.             awful.client.focus.history.previous()
  346.             if client.focus then
  347.                 client.focus:raise()
  348.             end
  349.         end),
  350.  
  351.     -- Standard program
  352.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal)   end),
  353.     awful.key({ modkey, "Control" }, "r", awesome.restart                                  ),
  354.     awful.key({ modkey, "Shift"   }, "q", awesome.quit                                     ),
  355.  
  356.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  357.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  358.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  359.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  360.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  361.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  362.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  363.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  364.  
  365. --    awful.key({ modkey, "Control" }, "n", awful.client.restore                             ), -- used for shifty and does not work!
  366.  
  367.     -- Prompt
  368.     awful.key({ modkey },            "F1",    function () mypromptbox[screen.count()]:run() end),
  369.  
  370.     awful.key({ modkey }, "F4",
  371.               function ()
  372.                   awful.prompt.run({ prompt = "Run Lua code: " },
  373.                   mypromptbox[screen.count()].widget,
  374.                   awful.util.eval, nil,
  375.                   awful.util.getdir("cache") .. "/history_eval")
  376.               end),
  377.  
  378.     -- own keys
  379.     awful.key({ modkey,           }, "e",      function () awful.util.spawn(editor) end),
  380.     awful.key({                   }, "#160",   function () awful.util.spawn(screenlock) end),
  381.     awful.key({                   }, "#122",   function () awful.util.spawn(alsa_lower) end),
  382.     awful.key({                   }, "#123",   function () awful.util.spawn(alsa_raise) end),
  383.     awful.key({                   }, "#121",   function () awful.util.spawn(alsa_mute) end),
  384.     awful.key({                   }, "#158",   function () awful.util.spawn(browser) end),
  385.     awful.key({                   }, "#163",   function () awful.util.spawn(mail) end)--,
  386. --    awful.key({                   }, "#232",   function () awful.util.spawn(backlight_dec) end),
  387. --    awful.key({                   }, "#233",   function () awful.util.spawn(backlight_inc) end)
  388. )
  389.  
  390. clientkeys = awful.util.table.join(
  391.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  392.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  393.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  394.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  395.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  396.     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
  397.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  398.     awful.key({ modkey,           }, "n",
  399.         function (c)
  400.             -- The client currently has the input focus, so it cannot be
  401.             -- minimized, since minimized clients can't have the focus.
  402.             c.minimized = true
  403.         end),
  404.     awful.key({ modkey,           }, "m",
  405.         function (c)
  406.             c.maximized_horizontal = not c.maximized_horizontal
  407.             c.maximized_vertical   = not c.maximized_vertical
  408.         end)
  409. )
  410. -- SHIFTY: assign client keys to shifty for use in
  411. -- match() function(manage hook)
  412. shifty.config.clientkeys = clientkeys
  413. shifty.config.modkey = modkey
  414.  
  415. -- Compute the maximum number of digit we need, limited to 9
  416. for i = 1, (shifty.config.maxtags or 9) do
  417.     globalkeys = awful.util.table.join(globalkeys,
  418.         awful.key({modkey}, i, function()
  419.             local t = awful.tag.viewonly(shifty.getpos(i))
  420.             end),
  421.         awful.key({modkey, "Control"}, i, function()
  422.             local t = shifty.getpos(i)
  423.             t.selected = not t.selected
  424.             end),
  425.         awful.key({modkey, "Control", "Shift"}, i, function()
  426.             if client.focus then
  427.                 awful.client.toggletag(shifty.getpos(i))
  428.             end
  429.             end),
  430.         -- move clients to other tags
  431.         awful.key({modkey, "Shift"}, i, function()
  432.             if client.focus then
  433.                 t = shifty.getpos(i)
  434.                 awful.client.movetotag(t)
  435.                 awful.tag.viewonly(t)
  436.             end
  437.         end))
  438. end
  439.  
  440.  
  441. -- Set keys
  442. root.keys(globalkeys)
  443. -- }}}
  444.  
  445.  
  446. -- {{{ Signals
  447. -- Signal function to execute when a new client appears.
  448. client.add_signal("manage", function (c, startup)
  449.     -- Add a titlebar
  450.     -- awful.titlebar.add(c, { modkey = modkey })
  451.  
  452.     -- Enable sloppy focus
  453.     c:add_signal("mouse::enter", function(c)
  454.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  455.             and awful.client.focus.filter(c) then
  456.             client.focus = c
  457.         end
  458.     end)
  459.  
  460.     if not startup then
  461.         -- Set the windows at the slave,
  462.         -- i.e. put it at the end of others instead of setting it master.
  463.         -- awful.client.setslave(c)
  464.  
  465.         -- Put windows in a smart way, only if they does not set an initial position.
  466.         if not c.size_hints.user_position and not c.size_hints.program_position then
  467.             awful.placement.no_overlap(c)
  468.             awful.placement.no_offscreen(c)
  469.         end
  470.     end
  471. end)
  472.  
  473. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  474. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  475. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement