Advertisement
timcowchip

rc.lua with launchbar

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