Advertisement
Shlomo

r.lua

Mar 11th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.06 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. vicious = require("vicious")
  14. require("volume")
  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("/usr/share/awesome/themes/default/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 = 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.  
  57. -- paths
  58. local icons = os.getenv("HOME") .. "/dotfiles/icons/light-blue/"
  59.  
  60.  
  61.  
  62. -- Table of layouts to cover with awful.layout.inc, order matters.
  63. local layouts =
  64. {
  65.     awful.layout.suit.floating,
  66.     awful.layout.suit.tile,
  67.     awful.layout.suit.tile.left,
  68.     awful.layout.suit.tile.bottom,
  69.     awful.layout.suit.tile.top,
  70.     awful.layout.suit.fair,
  71.     awful.layout.suit.fair.horizontal,
  72.     awful.layout.suit.spiral,
  73.     awful.layout.suit.spiral.dwindle,
  74.     awful.layout.suit.max,
  75.     awful.layout.suit.max.fullscreen,
  76.     awful.layout.suit.magnifier
  77. }
  78. -- }}}
  79.  
  80. -- {{{ Wallpaper
  81. if beautiful.wallpaper then
  82.     for s = 1, screen.count() do
  83.         gears.wallpaper.maximized(beautiful.wallpaper, s, true)
  84.     end
  85. end
  86. -- }}}
  87.  
  88. -- {{{ Tags
  89. -- Define a tag table which hold all screen tags.
  90. tags = {}
  91. for s = 1, screen.count() do
  92.     -- Each screen has its own tag table.
  93.     tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
  94. end
  95. -- }}}
  96.  
  97. -- {{{ Menu
  98. -- Create a laucher widget and a main menu
  99. myawesomemenu = {
  100.    { "manual", terminal .. " -e man awesome" },
  101.    { "edit config", editor_cmd .. " " .. awesome.conffile },
  102.    { "restart", awesome.restart },
  103.    { "quit", awesome.quit }
  104. }
  105.  
  106. require("menu")
  107. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  108.                                     { "application",xdgmenu, beautiful.awesome_icon },
  109.                                     { "firefox", firefox },
  110.                                     { "open terminal", terminal }
  111.                                   }
  112.                         })
  113.  
  114. mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
  115.                                      menu = mymainmenu })
  116.  
  117. -- Menubar configuration
  118. menubar.utils.terminal = terminal -- Set the terminal for applications that require it
  119. -- }}}
  120.  
  121.  
  122. -- {{{ Wibox
  123. -- Create a textclock widget
  124.  
  125.  
  126.  
  127. --kbdwidget = wibox.widget.textbox()
  128. --kbdwidget:set_markup(" En ")
  129. --dbus.request_name("session", "ru.gentoo.kbdd")
  130. --dbus.add_match("session", "interface='ru.gentoo.kbdd',member='layoutChanged'")
  131. --dbus.connect_signal("ru.gentoo.kbdd", function(...)
  132.     --local data = {...}
  133.     --local layout = data[2]
  134.     --lts = {[0] = " En ", [1] = " Il ", [2] = " Ru "}
  135.     --kbdwidget:set_markup(" " .. lts[layout])
  136.     --end
  137.  
  138.  
  139.  
  140. -- network usage
  141. --netwidget = wibox.widget.textbox()
  142. --vicious.register(netwidget, vicious.widgets.net, '<span color="#CC9090">⇩${wlp2s0 down_kb}</span> <span color="#7F9F7F">⇧${wlp2s0 up_kb}</span>', 3)
  143.  
  144. -- Battery Widget
  145. batwidget = awful.widget.progressbar()
  146. batwidget:set_width(8)
  147. batwidget:set_height(10)
  148. batwidget:set_vertical(true)
  149. batwidget:set_background_color("#494B4F")
  150. batwidget:set_border_color(nil)
  151. batwidget:set_color({type="linear", from = {0, 0}, to = {0, 20}, stops = { {0, "#AECF96"}, {0.5, "#88A175"}, {1.0, "#FF5656"} } })
  152. vicious.register(batwidget, vicious.widgets.bat, "$2", 61, "BAT0")
  153.  
  154. -- wifi icon
  155. --wifiicon = wibox.widget.imagebox()
  156. --wifiicon:set_image(icons .. "wifi.png")
  157.  
  158. -- Wifi Widget
  159. wifiwidget = wibox.widget.textbox()
  160. vicious.register(wifiwidget, vicious.widgets.wifi, '  ${ssid}' , 11, "wlp2s0")
  161.  
  162.  
  163.  
  164. mytextclock = awful.widget.textclock()
  165.  
  166.  
  167. -- Create a wibox for each screen and add it
  168. mywibox = {}
  169. mypromptbox = {}
  170. mylayoutbox = {}
  171. mytaglist = {}
  172. mytaglist.buttons = awful.util.table.join(
  173.                     awful.button({ }, 1, awful.tag.viewonly),
  174.                     awful.button({ modkey }, 1, awful.client.movetotag),
  175.                     awful.button({ }, 3, awful.tag.viewtoggle),
  176.                     awful.button({ modkey }, 3, awful.client.toggletag),
  177.                     awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
  178.                     awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
  179.                     )
  180. mytasklist = {}
  181. mytasklist.buttons = awful.util.table.join(
  182.                      awful.button({ }, 1, function (c)
  183.                                               if c == client.focus then
  184.                                                   c.minimized = true
  185.                                               else
  186.                                                   -- Without this, the following
  187.                                                   -- :isvisible() makes no sense
  188.                                                   c.minimized = false
  189.                                                   if not c:isvisible() then
  190.                                                       awful.tag.viewonly(c:tags()[1])
  191.                                                   end
  192.                                                   -- This will also un-minimize
  193.                                                   -- the client, if needed
  194.                                                   client.focus = c
  195.                                                   c:raise()
  196.                                               end
  197.                                           end),
  198.                      awful.button({ }, 3, function ()
  199.                                               if instance then
  200.                                                   instance:hide()
  201.                                                   instance = nil
  202.                                               else
  203.                                                   instance = awful.menu.clients({ width=250 })
  204.                                               end
  205.                                           end),
  206.                      awful.button({ }, 4, function ()
  207.                                               awful.client.focus.byidx(1)
  208.                                               if client.focus then client.focus:raise() end
  209.                                           end),
  210.                      awful.button({ }, 5, function ()
  211.                                               awful.client.focus.byidx(-1)
  212.                                               if client.focus then client.focus:raise() end
  213.                                           end))
  214.  
  215. for s = 1, screen.count() do
  216.     -- Create a promptbox for each screen
  217.     mypromptbox[s] = awful.widget.prompt()
  218.     -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  219.     -- We need one layoutbox per screen.
  220.     mylayoutbox[s] = awful.widget.layoutbox(s)
  221.     mylayoutbox[s]:buttons(awful.util.table.join(
  222.                            awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  223.                            awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  224.                            awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  225.                            awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  226.     -- Create a taglist widget
  227.     mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
  228.  
  229.     -- Create a tasklist widget
  230.     mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
  231.  
  232.     -- Create the wibox
  233.     mywibox[s] = awful.wibox({ position = "top", screen = s })
  234.  
  235. -- network usage
  236. --netwidget = wibox.widget.textbox()
  237. --vicious.register(netwidget, vicious.widgets.net, '<span color="#CC9090">⇩${eth0 down_kb}</span> <span color="#7F9F7F">⇧${eth0 up_kb}</span>', 3)
  238.  
  239.  
  240.     -- Widgets that are aligned to the left
  241.     local left_layout = wibox.layout.fixed.horizontal()
  242.     left_layout:add(mylauncher)
  243.     left_layout:add(mytaglist[s])
  244.     left_layout:add(mypromptbox[s])
  245.     --left_layout:add(volume_widget)
  246.     -- Widgets that are aligned to the right
  247.     local right_layout = wibox.layout.fixed.horizontal()
  248.     if s == 1 then right_layout:add(wibox.widget.systray()) end
  249.     --right_layout:add(netwidget)
  250.     right_layout:add(wifiwidget)
  251.     --right_layout:add(volume_widget)
  252.     right_layout:add(batwidget)
  253.     --right_layout:add(kbdwidget)
  254.     right_layout:add(mytextclock)
  255.     right_layout:add(mylayoutbox[s])
  256.     --right_layout:add(awful.titlebar.widget.closebutton(c))
  257.  
  258.    
  259.     -- Now bring it all together (with the tasklist in the middle)
  260.     local layout = wibox.layout.align.horizontal()
  261.     layout:set_left(left_layout)
  262.     layout:set_middle(mytasklist[s])
  263.     layout:set_right(right_layout)
  264.  
  265.     mywibox[s]:set_widget(layout)
  266. end
  267. -- }}}
  268.  
  269.  
  270.  
  271. -- Initialize widget
  272. memwidget = awful.widget.progressbar()
  273. -- Progressbar properties
  274. memwidget:set_width(8)
  275. memwidget:set_height(10)
  276. memwidget:set_vertical(true)
  277. memwidget:set_background_color("#494B4F")
  278. memwidget:set_border_color(nil)
  279. memwidget:set_color({ type = "linear", from = { 0, 0 }, to = { 10,0 }, stops = { {0, "#AECF96"}, {0.5, "#88A175"},
  280.                     {1, "#FF5656"}}})
  281. -- Register widget
  282. vicious.register(memwidget, vicious.widgets.mem, "$1", 13)
  283.  
  284.  
  285.  
  286.  
  287. -- {{{ Mouse bindings
  288. root.buttons(awful.util.table.join(
  289.     awful.button({ }, 3, function () mymainmenu:toggle() end),
  290.     awful.button({ }, 4, awful.tag.viewnext),
  291.     awful.button({ }, 5, awful.tag.viewprev)
  292. ))
  293. -- }}}
  294.  
  295. -- {{{ Key bindings
  296. globalkeys = awful.util.table.join(
  297.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  298.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  299.     awful.key({ modkey,           }, "Escape", awful.tag.history.restore),
  300.  
  301.     awful.key({ modkey,           }, "j",
  302.         function ()
  303.             awful.client.focus.byidx( 1)
  304.             if client.focus then client.focus:raise() end
  305.         end),
  306.     awful.key({ modkey,           }, "k",
  307.         function ()
  308.             awful.client.focus.byidx(-1)
  309.             if client.focus then client.focus:raise() end
  310.         end),
  311.     awful.key({ modkey,           }, "w", function () mymainmenu:show() end),
  312.  
  313.     -- Layout manipulation
  314.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  315.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  316.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  317.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  318.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  319.     awful.key({ modkey,           }, "Tab",
  320.         function ()
  321.             awful.client.focus.history.previous()
  322.             if client.focus then
  323.                 client.focus:raise()
  324.             end
  325.         end),
  326.  
  327.     -- Standard program
  328.     awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
  329.     awful.key({ modkey, "Control" }, "r", awesome.restart),
  330.     awful.key({ modkey, "Shift"   }, "q", awesome.quit),
  331.  
  332.     awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  333.     awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  334.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  335.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  336.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  337.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  338.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  339.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  340.  
  341.     awful.key({ modkey, "Control" }, "n", awful.client.restore),
  342.  
  343.     -- Prompt
  344.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  345.  
  346.     awful.key({ modkey }, "x",
  347.               function ()
  348.                   awful.prompt.run({ prompt = "Run Lua code: " },
  349.                   mypromptbox[mouse.screen].widget,
  350.                   awful.util.eval, nil,
  351.                   awful.util.getdir("cache") .. "/history_eval")
  352.               end),
  353.     -- Menubar
  354.     awful.key({ modkey }, "p", function() menubar.show() end)
  355. )
  356.  
  357. clientkeys = awful.util.table.join(
  358.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  359.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  360.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  361.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  362.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  363.     awful.key({ modkey,           }, "t",      function (c) c.ontop = not c.ontop            end),
  364.     awful.key({ modkey,           }, "n",
  365.         function (c)
  366.             -- The client currently has the input focus, so it cannot be
  367.             -- minimized, since minimized clients can't have the focus.
  368.             c.minimized = true
  369.         end),
  370.     awful.key({ modkey,           }, "m",
  371.         function (c)
  372.             c.maximized_horizontal = not c.maximized_horizontal
  373.             c.maximized_vertical   = not c.maximized_vertical
  374.         end)
  375. )
  376.  
  377. -- Compute the maximum number of digit we need, limited to 9
  378. keynumber = 0
  379. for s = 1, screen.count() do
  380.    keynumber = math.min(9, math.max(#tags[s], keynumber))
  381. end
  382.  
  383. -- Bind all key numbers to tags.
  384. -- Be careful: we use keycodes to make it works on any keyboard layout.
  385. -- This should map on the top row of your keyboard, usually 1 to 9.
  386. for i = 1, keynumber do
  387.     globalkeys = awful.util.table.join(globalkeys,
  388.         awful.key({ modkey }, "#" .. i + 9,
  389.                   function ()
  390.                         local screen = mouse.screen
  391.                         if tags[screen][i] then
  392.                             awful.tag.viewonly(tags[screen][i])
  393.                         end
  394.                   end),
  395.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  396.                   function ()
  397.                       local screen = mouse.screen
  398.                       if tags[screen][i] then
  399.                           awful.tag.viewtoggle(tags[screen][i])
  400.                       end
  401.                   end),
  402.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  403.                   function ()
  404.                       if client.focus and tags[client.focus.screen][i] then
  405.                           awful.client.movetotag(tags[client.focus.screen][i])
  406.                       end
  407.                   end),
  408.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  409.                   function ()
  410.                       if client.focus and tags[client.focus.screen][i] then
  411.                           awful.client.toggletag(tags[client.focus.screen][i])
  412.                       end
  413.                   end))
  414. end
  415.  
  416. clientbuttons = awful.util.table.join(
  417.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  418.     awful.button({ modkey }, 1, awful.mouse.client.move),
  419.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  420.  
  421. -- Set keys
  422. root.keys(globalkeys)
  423. -- }}}
  424.  
  425. -- {{{ Rules
  426. awful.rules.rules = {
  427.     -- All clients will match this rule.
  428.     { rule = { },
  429.       properties = { border_width = beautiful.border_width,
  430.                      border_color = beautiful.border_normal,
  431.                      focus = awful.client.focus.filter,
  432.                      keys = clientkeys,
  433.                      buttons = clientbuttons } },
  434.     { rule = { class = "MPlayer" },
  435.       properties = { floating = true } },
  436.     { rule = { class = "pinentry" },
  437.       properties = { floating = true } },
  438.     { rule = { class = "gimp" },
  439.       properties = { floating = true } },
  440.     -- Set Firefox to always map on tags number 2 of screen 1.
  441.     -- { rule = { class = "Firefox" },
  442.     --   properties = { tag = tags[1][2] } },
  443. }
  444. -- }}}
  445.  
  446. -- {{{ Signals
  447. -- Signal function to execute when a new client appears.
  448. client.connect_signal("manage", function (c, startup)
  449.     -- Enable sloppy focus
  450.     c:connect_signal("mouse::enter", function(c)
  451.         if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  452.             and awful.client.focus.filter(c) then
  453.             client.focus = c
  454.         end
  455.     end)
  456.  
  457.     if not startup then
  458.         -- Set the windows at the slave,
  459.         -- i.e. put it at the end of others instead of setting it master.
  460.         -- awful.client.setslave(c)
  461.  
  462.         -- Put windows in a smart way, only if they does not set an initial position.
  463.         if not c.size_hints.user_position and not c.size_hints.program_position then
  464.             awful.placement.no_overlap(c)
  465.             awful.placement.no_offscreen(c)
  466.         end
  467.     end
  468.  
  469.     local titlebars_enabled = false
  470.     if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
  471.         -- Widgets that are aligned to the left
  472.         local left_layout = wibox.layout.fixed.horizontal()
  473.         left_layout:add(awful.titlebar.widget.iconwidget(c))
  474.  
  475.         -- Widgets that are aligned to the right
  476.         local right_layout = wibox.layout.fixed.horizontal()
  477.         right_layout:add(awful.titlebar.widget.floatingbutton(c))
  478.         right_layout:add(awful.titlebar.widget.maximizedbutton(c))
  479.         right_layout:add(awful.titlebar.widget.stickybutton(c))
  480.         right_layout:add(awful.titlebar.widget.ontopbutton(c))
  481.         right_layout:add(awful.titlebar.widget.closebutton(c))
  482.  
  483.         -- The title goes in the middle
  484.         local title = awful.titlebar.widget.titlewidget(c)
  485.         title:buttons(awful.util.table.join(
  486.                 awful.button({ }, 1, function()
  487.                     client.focus = c
  488.                     c:raise()
  489.                     awful.mouse.client.move(c)
  490.                 end),
  491.                 awful.button({ }, 3, function()
  492.                     client.focus = c
  493.                     c:raise()
  494.                     awful.mouse.client.resize(c)
  495.                 end)
  496.                 ))
  497.  
  498.         -- Now bring it all together
  499.         local layout = wibox.layout.align.horizontal()
  500.         layout:set_left(left_layout)
  501.         layout:set_right(right_layout)
  502.         layout:set_middle(title)
  503.  
  504.         awful.titlebar(c):set_widget(layout)
  505.     end
  506. end)
  507.  
  508. client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  509. client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  510. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement