eahil

rc.lua_in_question

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