Guest User

Untitled

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