Advertisement
Guest User

rc.lua by unlogic

a guest
Jul 29th, 2011
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 33.47 KB | None | 0 0
  1. require("awful")
  2. require("awful.autofocus")
  3. require("awful.rules")
  4. require("beautiful")
  5. require("naughty")
  6. require("vicious")
  7. require("debian.menu")
  8. require("awesompd")
  9. require("obvious.popup_run_prompt")
  10. require("orglendar")
  11. require("org-awesome")
  12.  
  13. -- Useful functions and tools
  14.  
  15. function run_once(program)
  16.    local bin = program
  17.    --local _, _, bin = string.find(program, "([^ ]+).*")
  18.    local bus = io.popen("ps aux | grep '" .. bin .. "' | wc -l")
  19.    local pcount = bus:read("*line")
  20.    print("Pcount : " .. pcount)
  21.    bus:close()
  22.    if tonumber(pcount) < 3 then
  23.       awful.util.spawn(program)
  24.    end
  25. end
  26.  
  27. function repeat_every(func, seconds)
  28.    func()
  29.    local t = timer({ timeout = seconds })
  30.    t:add_signal("timeout", func)
  31.    t:start()
  32. end
  33.  
  34. function pop_spaces(s1,s2,maxsize)
  35.    local sps = ""
  36.    for i = 1, maxsize-string.len(s1)-string.len(s2) do
  37.       sps = sps .. " "
  38.    end
  39.    return s1 .. sps .. s2
  40. end
  41.  
  42. -- Autorun programs
  43. autorun = true
  44.  
  45. autorunApps =  
  46.    {
  47.    "setxkbmap -layout 'us,ua,ru' -variant ',winkeys,winkeys' -option grp:alt_shift_toggle -option compose:ralt -option terminate:ctrl_alt_bksp",
  48.    "kbdd"
  49. }
  50.  
  51. runOnceApps = {
  52.    "emacs --daemon",
  53.    "thunderbird",
  54.    "xscreensaver -nosplash"
  55. }
  56.  
  57. if autorun then
  58.    for app = 1, #autorunApps do
  59.       awful.util.spawn(autorunApps[app])
  60.    end
  61.    for app = 1, #runOnceApps do
  62.       run_once(runOnceApps[app])
  63.    end
  64. end
  65.  
  66. -- {{{ Variable definitions
  67. -- Themes define colours, icons, and wallpapers
  68. beautiful.init("/home/unlogic/.config/awesome/themes/nice-and-clean-theme/theme.lua")
  69.  
  70. -- This is used later as the default terminal and editor to run.
  71. --terminal = "urxvt -fn 'xft:droid sans mono:pixelsize=14'"
  72. terminal = "urxvt"
  73. editor = os.getenv("EDITOR") or "editor"
  74. editor_cmd = terminal .. " -e "  .. editor
  75.  
  76. -- Default modkey.
  77. modkey = "Mod4"
  78.  
  79. -- Table of layouts to cover with awful.layout.inc, order matters.
  80. layouts =
  81.    {
  82.    awful.layout.suit.floating,          -- 1
  83.    awful.layout.suit.tile,      -- 2
  84.    awful.layout.suit.tile.bottom,   -- 3
  85.    awful.layout.suit.spiral,        -- 4
  86.    awful.layout.suit.max,       -- 5
  87.    awful.layout.suit.magnifier      -- 6
  88. }
  89. -- }}}
  90.  
  91. -- {{{ Tags
  92. -- Define a tag table which hold all screen tags.
  93. tags = {}
  94. for s = 1, screen.count() do
  95.    --    -- Each screen has its own tag table.
  96.    tags[s] = awful.tag({ "☯", "⚑", "☎", "☉", "☻", "⌥"}, s, {layouts[1], layouts[5], layouts[1], layouts[2], layouts[1], layouts[1]})
  97. end--
  98. -- }}}
  99.  
  100. -- {{{ Menu
  101. -- Create a laucher widget and a main menu
  102. myawesomemenu = {
  103.    { "restart", awesome.restart },
  104.    { "quit", awesome.quit }
  105. }
  106.  
  107. sshmenu = {
  108.    { "ssh delice", terminal .. " -e conserv" },
  109.    { "ssh emera", terminal .. " -e conwork" }
  110. }
  111.  
  112. mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
  113.                                     { "software", debian.menu.Debian_menu.Debian },
  114.                     { "connect to", sshmenu}
  115.                  }
  116.                })
  117.  
  118. mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
  119.                                      menu = mymainmenu })
  120. -- }}}
  121.  
  122.  
  123. -- {{{ Wibox
  124. -- *** MyMPDWidget Init ***
  125.  
  126. musicwidget = awesompd:create() -- Create awesompd widget
  127. musicwidget.font = "Liberation Mono" -- Set widget font
  128. musicwidget.scrolling = true -- If true, the text in the widget will be scrolled
  129. musicwidget.output_size = 30 -- Set the size of widget in symbols
  130. musicwidget.update_interval = 10 -- Set the update interval in seconds
  131. musicwidget.path_to_icons = "/home/unlogic/.config/awesome/iconsg"
  132. musicwidget.debug_mode = true
  133. musicwidget.jamendo_format = awesompd.FORMAT_MP3 -- or you can use FORMAT_MP3
  134. instance.show_jamendo_album_covers = true
  135. instance.album_cover_size = 50
  136. musicwidget.ldecorator = "| "
  137. musicwidget.rdecorator = " |"
  138.  
  139. -- Set all the servers to work with
  140. musicwidget.servers = {
  141.    { server = "localhost",
  142.      port = 6600 },
  143.    { server = "192.168.0.72",
  144.      port = 6600 }
  145. }
  146.  
  147. --Set the buttons of the widget
  148. musicwidget:register_buttons({ { "", awesompd.MOUSE_LEFT, musicwidget:command_toggle() },
  149.                    { "Control", awesompd.MOUSE_SCROLL_UP, musicwidget:command_prev_track() },
  150.                    { "Control", awesompd.MOUSE_SCROLL_DOWN, musicwidget:command_next_track() },
  151.                    { "", awesompd.MOUSE_SCROLL_UP, musicwidget:command_volume_up() },
  152.                    { "", awesompd.MOUSE_SCROLL_DOWN, musicwidget:command_volume_down() },
  153.                    { "", awesompd.MOUSE_RIGHT, musicwidget:command_show_menu() } })
  154.  
  155.  
  156. musicwidget:run()
  157. -- *** MyMPDWidget End
  158.  
  159.  
  160. -- Create a textclock widget
  161. mytextclock = awful.widget.textclock({ align = "right" })
  162.  
  163. -- Create a systray
  164. mysystray = widget({ type = "systray" })
  165.  
  166. -- MEMWIDGET
  167. memwidget = widget({ type = "textbox" })
  168. vicious.register(memwidget, vicious.widgets.mem, function (widget, args)
  169.                                                     infojets.update_ram(args[2], args[4])
  170.                                                     return " ♻ " ..args[1].."% | "
  171.                                                  end, 13)
  172. -- CPU WIDGET.TEXT
  173. cpuwidget = widget({ type = "textbox" })
  174. vicious.register(cpuwidget, vicious.widgets.cpu,
  175.          function (widget, args)
  176.                     infojets.update_cpu(args[1])
  177.             if string.len(args[1]) == 1 then
  178.                return " ☢  " .. args[1] .. "% "
  179.             else
  180.                return " ☢ " .. args[1] .. "% "
  181.             end
  182.          end)
  183. cpuwidget:buttons(
  184.    awful.util.table.join(awful.button({ }, 1,
  185.                       function ()
  186.                      awful.util.spawn(terminal .. " -e htop")
  187.                       end)))
  188. -- CPUTEMP WIDGET
  189. cputempwidget = widget({ type = "textbox" })
  190. vicious.register(cputempwidget, vicious.widgets.thermal,
  191.          function (widget, args)
  192.                     infojets.update_temp(args[1])
  193.             return args[1] .. "°C |"
  194.          end, 19, "thermal_zone0" )
  195.  
  196. -- Battery widget
  197. batwidget = widget({ type = "textbox" })
  198.  
  199. function getBattery(widg)
  200.    local fst = io.popen("cat /sys/class/power_supply/BAT0/status")
  201.    local fch = io.popen("cat /sys/class/power_supply/BAT0/energy_now")
  202.    local fmax = io.popen("cat /sys/class/power_supply/BAT0/energy_full")
  203.    local st = fst:read("*all")
  204.    local ch = fch:read("*all")
  205.    local max = fmax:read("*all")
  206.    local battery = math.floor(ch * 100 / max)
  207.    if st:match("Charging") then
  208.       dir = "% ▲"
  209.    elseif st:match("Discharging") then
  210.       dir = "% ▼"
  211.       if tonumber(battery) <= 10 then
  212.      naughty.notify({ title      = "Battery Warning"
  213.               , text       = "Battery low! " .. battery .."%" .. " left!"
  214.               , timeout    = 5
  215.               , position   = "top_right"
  216.                })
  217.       end
  218.    else
  219.       dir = "% ◆"
  220.    end
  221.    widg.text = " ⚡ " .. battery .. dir .. " |"
  222.    fst:close()
  223.    fch:close()
  224.    fmax:close()
  225. end
  226.  
  227. getBattery(batwidget)
  228. repeat_every(function () getBattery(batwidget) end, 10)
  229.  
  230. -- Time widget
  231. timewidget = widget({ type = "textbox", name = "org_widget" })
  232.  
  233. repeat_every(function()
  234.                 timewidget.text = os.date("%H:%M")
  235.                 if infojets and infojets.update_clock then
  236.                    infojets.update_clock()
  237.                    infojets.update_date()
  238.                 end
  239.              end, 10)
  240. -- function timeUpdate()
  241. --    local fd = io.popen("date | grep -o -e '..:..'")
  242. --    local tm = fd:read("*all")
  243. --    fd:close()
  244. --    infojets.update_clock()
  245. --    infojets.update_date()
  246. --    timewidget.text = tm
  247. -- end
  248.  
  249. --timeUpdate()
  250. --awful.hooks.timer.register(5, function () timeUpdate() end)
  251.  
  252. -- Quick launch bar widget BEGINS
  253.  
  254. function getValue(t, key)
  255.    _, _, res = string.find(t, key .. " *= *([^%c]+)%c")
  256.    return res
  257. end
  258.  
  259. function split (s,t)
  260.    local l = {n=0}
  261.    local f = function (s)
  262.         l.n = l.n + 1
  263.         l[l.n] = s
  264.          end
  265.    local p = "%s*(.-)%s*"..t.."%s*"
  266.    s = string.gsub(s,p,f)
  267.    l.n = l.n + 1
  268.    return l
  269. end
  270.  
  271. launchbar = { layout = awful.widget.layout.horizontal.leftright }
  272. filedir = "/home/unlogic/.config/awesome/launchbar/" -- Specify your folder with shortcuts here
  273. files = split(io.popen("ls " .. filedir .. "*.desktop"):read("*all"),"\n")
  274. for i = 1, table.getn(files) do
  275.    local t = io.open(files[i]):read("*all")
  276.    launchbar[i] = { image = image(getValue(t,"Icon")),
  277.                     command = getValue(t,"Exec"),
  278.                     position = tonumber(getValue(t,"Position")) or 255 }
  279. end
  280. table.sort(launchbar, function(a,b) return a.position < b.position end)
  281. for i = 1, table.getn(launchbar) do
  282.    launchbar[i] = awful.widget.launcher(launchbar[i])
  283. end
  284.  
  285. -- Quick launch bar widget ENDS
  286.  
  287. recurse = true
  288. client.add_signal("new", function(c)
  289.    c:add_signal("property::icon", function()
  290.                                      -- Make sure we aren't going into an endless loop when changing the icon
  291.                                      print(c.icon)
  292.       if not recurse then return end
  293. --      if not client.icon then return end
  294.       -- Here you can do something with c.icon, e.g.:
  295.       c.icon:save("/tmp/icon.png")
  296.       local h =
  297.          io.popen("convert -colorspace Gray /tmp/icon.png /tmp/icon2.png"):read("*all")
  298.       recurse = false
  299.       c.icon = image("/tmp/icon2.png")
  300.       recurse = true
  301.    end)
  302. end)
  303.  
  304. -- *** Internal calc function *** ---
  305. function calc(result)
  306.    naughty.notify( { title = "Awesome calc",
  307.                      text = "Result: " .. result,
  308.                      timeout = 5})
  309. end
  310.  
  311. -- *** Debug pring function *** ---
  312. function nprint(s)
  313.    naughty.notify( { title = "Debug print",
  314.                      text = tostring(s),
  315.                      timeout = 5})
  316. end
  317.  
  318. -- *** Calendar widget
  319.  
  320. orglendar.files = { "/home/unlogic/Documents/Notes/edu.org" }
  321. orglendar.register(timewidget)
  322. -- work_file = "/home/unlogic/Documents/Notes/edu.org"
  323. -- timewidget:add_signal("mouse::enter", function() org.naughty_open(0) end)
  324. -- timewidget:add_signal("mouse::leave", org.naughty_close)
  325.  
  326. -- timewidget:buttons(awful.util.table.join(
  327. --                       awful.button({ }, 1, function () awful.util.spawn("emacs " .. work_file) end),
  328. --                       awful.button({ }, 3, function () org.update() end),
  329. --                       awful.button({ }, 4, function()
  330. --                                               org.naughty_open(-1)
  331. --                                            end),
  332. --                       awful.button({ }, 5, function()
  333. --                                               org.naughty_open(1)
  334. --                                            end)))
  335. -- org.register(timewidget, { work_file })
  336.            
  337. -- *** Calendar widget end
  338.  
  339.  
  340. -- *** Keyboard widget
  341. kbdwidget = widget({type = "textbox", name = "kbdwidget"})
  342. kbdwidget.text = " ✡ US |"
  343. dbus.request_name("session", "ru.gentoo.kbdd")
  344. dbus.add_match("session", "interface='ru.gentoo.kbdd',member='layoutChanged'")
  345. dbus.add_signal("ru.gentoo.kbdd", function(...)
  346.     local data = {...}
  347.     local layout = data[2]
  348.     lts = {[0] = "✡ US", [1] = "★ UA", [2] = "☭ RU"}
  349.     kbdwidget.text = " "..lts[layout].." |"
  350.     end
  351. )
  352.  
  353. -- Volume widget
  354. cardid  = 0
  355. channel = "Master"
  356. function volume (mode, widget)
  357.    if mode == "update" then
  358.       local fd = io.popen("amixer -c " .. cardid .. " -- sget " .. channel)
  359.       local status = fd:read("*all")
  360.       fd:close()
  361.      
  362.       local volume = string.match(status, "(%d?%d?%d)%%")
  363.       volume = string.format("% 3d", volume)
  364.      
  365.       status = string.match(status, "%[(o[^%]]*)%]")
  366.      
  367.       if string.find(status, "on", 1, true) then
  368.      volume = "♫" .. volume .. "% |"
  369.       else
  370.      volume = "♫" .. volume .. "M |"
  371.       end
  372.       widget.text = volume
  373.    elseif mode == "up" then
  374.       io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%+"):read("*all")
  375.       volume("update", widget)
  376.    elseif mode == "down" then
  377.       io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%-"):read("*all")
  378.       volume("update", widget)
  379.    else
  380.       io.popen("amixer -c " .. cardid .. " sset " .. channel .. " toggle"):read("*all")
  381.       volume("update", widget)
  382.    end
  383. end
  384.  
  385. tb_volume = widget({ type = "textbox", name = "tb_volume", align = "right" })
  386. tb_volume:buttons(awful.util.table.join(
  387.              awful.button({ }, 3, function ()  awful.util.spawn("gnome-volume-control") end),
  388.              awful.button({ }, 4, function () volume("up", tb_volume) end),
  389.              awful.button({ }, 5, function () volume("down", tb_volume) end),
  390.              awful.button({ }, 1, function () volume("mute", tb_volume) end)
  391.            ))
  392.  
  393. repeat_every(function() volume("update", tb_volume) end, 10)
  394.  
  395. -- Wierd - wicd widget for awesome
  396.  
  397. wierd = {}
  398.  
  399. function wierd.update_widget()
  400.    local bus = io.popen("wicd-cli -yd", "r")
  401.    local line = bus:read("*line")
  402.    if not string.find(line,"^Invalid") then
  403.       while line do
  404.          for key, value in pairs(wierd.properties) do
  405.             local _, matches, result = string.find(line, "^" .. value .. "(.*)")
  406.             if matches then
  407.                wierd.values[key] = result
  408.             end
  409.          end
  410.          line = bus:read("*line")
  411.       end
  412.       local text = wierd.format
  413.       for key, value in pairs(wierd.values) do
  414.          text = text.gsub(text,key,value)
  415.       end
  416.       wierd.widget.text = text
  417.    else
  418.       local text = " ⚠ OFF |"
  419.       wierd.widget.text = text
  420.    end
  421. end
  422.  
  423. function wierd.pop_spaces(s1,s2,maxsize)
  424.    local sps = ""
  425.    for i = 1, maxsize-string.len(s1)-string.len(s2) do
  426.       sps = sps .. " "
  427.    end
  428.    return s1 .. sps .. s2
  429. end
  430.  
  431. wierd.widget = widget({ type = "textbox" })
  432. wierd.format = " ⚚ $QUALITY% |"
  433. wierd.properties = {}
  434. wierd.values = {}
  435. wierd.properties["$ESSID"] = "Essid: "
  436. wierd.properties["$IP"] = "IP: "
  437. wierd.properties["$ENC_METHOD"] = "Encryption Method: "
  438. wierd.properties["$QUALITY"] = "Quality: "
  439. wierd.properties["$SPEED"] = "Bit Rates: "
  440. wierd.update_widget_timer = timer({ timeout = 10 })
  441. wierd.update_widget_timer:add_signal("timeout", function () wierd.update_widget() end)
  442. wierd.update_widget_timer:start()
  443. wierd.update_widget()
  444.  
  445. wierd.widget:add_signal("mouse::enter",
  446.                         function()
  447.                            local result = ""
  448.                            for key, value in pairs(wierd.values) do
  449.                               if key ~= "$ESSID" and key ~= "$QUALITY" then
  450.                                  result = result .. wierd.pop_spaces(wierd.properties[key],value,23) .. "\n"
  451.                               end
  452.                            end
  453.                            result = '<span font="monospace">' .. string.sub(result,1,string.len(result)-1) .. "</span>"
  454.                            wierd.popup = naughty.notify(
  455.                               { title = "Connected to " .. wierd.values["$ESSID"]
  456.                                 .. " at " .. wierd.values["$QUALITY"] .. "%",
  457.                              text = result, timeout = 0 })
  458.                         end)
  459. wierd.widget:add_signal("mouse::leave", function()
  460.                                      if wierd.popup ~= nil then
  461.                                         naughty.destroy(wierd.popup)
  462.                                         wierd.popup = nil
  463.                                      end
  464.                                   end)
  465. wierd.widget:buttons(awful.util.table.join(
  466.                         awful.button({ }, 1, function ()  awful.util.spawn(terminal .. " -e wicd-curses") end)))
  467.  
  468. -- Mailsome widget
  469.  
  470. mailsome_timer = timer({ timeout = 10 })
  471. mailsome_timer:add_signal("timeout", function ()
  472.                                            local mailbus = io.open("/tmp/mailsome")
  473.                                            if mailbus then
  474.                                               local mailtext = mailbus:read("*all")
  475.                                               mailtext = string.sub(mailtext,1,string.len(mailtext)-1)
  476.                                               naughty.notify( { title = "Mailsome notification",
  477.                                                                 text = mailtext, timeout = 0 })
  478.                                               awful.util.spawn("rm /tmp/mailsome")
  479.                                            end
  480.                                         end)
  481. mailsome_timer:start()
  482. -- Guake-like console
  483. -- This function is for awesome versions prior to 3.4
  484. -- This function is for awesome versions prior to 3.4
  485.  
  486. dropdown = {}
  487.  
  488. function dropdown_toggle(prog, height, s)
  489.    if s == nil then s = mouse.screen end
  490.    if height == nil then height = 0.2 end
  491.    
  492.    if not dropdown[prog] then
  493.       -- Create table
  494.       dropdown[prog] = {}
  495.      
  496.       -- Add unmanage hook for dropdown programs
  497.       awful.hooks.unmanage.register(function (c)
  498.                                        for scr, cl in pairs(dropdown[prog]) do
  499.                                           if cl == c then
  500.                                              dropdown[prog][scr] = nil
  501.                                           end
  502.                                        end
  503.                                     end)
  504.    end
  505.    
  506.    if not dropdown[prog][s] then
  507.       spawnw = function (c)
  508.                   -- Store client
  509.                   dropdown[prog][s] = c
  510.                  
  511.                   -- Float client
  512.                   awful.client.floating.set(c, true)
  513.                  
  514.                   -- Get screen geometry
  515.                   screengeom = screen[s].workarea
  516.                  
  517.                   -- Calculate height
  518.                   if height < 1 then
  519.                      height = screengeom.height*height
  520.                   end
  521.  
  522.                   -- I like a different border with for the popup window
  523.                   -- So I don't confuse it with terminals in the layout
  524.                   bw = 2
  525.  
  526.                   -- Resize client
  527.                   c:geometry({
  528.                                 x = screengeom.x,
  529.                                 y = screengeom.y - 1000,
  530.                                 width = screengeom.width - bw,
  531.                                 height = height - bw
  532.                              })
  533.  
  534.                   -- Mark terminal as ontop
  535.                   --            c.ontop = true
  536.                   --            c.above = true
  537.                   c.border_width = bw
  538.  
  539.                   -- Focus and raise client
  540.                   c:raise()
  541.                   client.focus = c
  542.  
  543.                   -- Remove hook
  544.                   awful.hooks.manage.unregister(spawnw)
  545.                end
  546.  
  547.       -- Add hook
  548.       awful.hooks.manage.register(spawnw)
  549.  
  550.       -- Spawn program
  551.       awful.util.spawn(prog)
  552.  
  553.       dropdown.currtag = awful.tag.selected(s)
  554.    else
  555.       -- Get client
  556.       c = dropdown[prog][s]
  557.      
  558.       -- Switch the client to the current workspace
  559.  
  560.       -- Focus and raise if not hidden
  561.       if c.hidden then
  562.          awful.client.movetotag(awful.tag.selected(s), c)
  563.          c.hidden = false
  564.          c:raise()
  565.          client.focus = c
  566.       else
  567.          if awful.tag.selected(s) == dropdown.currtag then
  568.             c.hidden = true
  569.             local ctags = c:tags()
  570.             for i, t in pairs(ctags) do
  571.                ctags[i] = nil
  572.             end
  573.             c:tags(ctags)
  574.          else
  575.             awful.client.movetotag(awful.tag.selected(s), c)
  576.             c:raise()
  577.             client.focus = c
  578.          end
  579.       end
  580.       dropdown.currtag = awful.tag.selected(s)
  581.    end
  582. end
  583.  
  584. -- Create a wibox for each screen and add it
  585. mywibox = {}
  586. mydownbox = {}
  587. mypromptbox = {}
  588. musicwidget.promptbox = mypromptbox
  589. mylayoutbox = {}
  590. mytaglist = {}
  591. mytaglist.buttons = awful.util.table.join(
  592.    awful.button({ }, 1, awful.tag.viewonly),
  593.    awful.button({ modkey }, 1, awful.client.movetotag),
  594.    awful.button({ }, 3, awful.tag.viewtoggle),
  595.    awful.button({ modkey }, 3, awful.client.toggletag),
  596.    awful.button({ }, 4, awful.tag.viewnext),
  597.    awful.button({ }, 5, awful.tag.viewprev)
  598. )
  599. mytasklist = {}
  600. mytasklist.buttons = awful.util.table.join(
  601.    awful.button({ }, 1, function (c)
  602.                if not c:isvisible() then
  603.                   awful.tag.viewonly(c:tags()[1])
  604.                end
  605.                client.focus = c
  606.                c:raise()
  607.             end),
  608.    awful.button({ }, 3, function ()
  609.                if instance then
  610.                   instance:hide()
  611.                   instance = nil
  612.                else
  613.                   instance = awful.menu.clients({ width=250 })
  614.                end
  615.             end),
  616.    awful.button({ }, 4, function ()
  617.                awful.client.focus.byidx(1)
  618.                if client.focus then client.focus:raise() end
  619.             end),
  620.    awful.button({ }, 5, function ()
  621.                awful.client.focus.byidx(-1)
  622.                if client.focus then client.focus:raise() end
  623.             end))
  624.  
  625. for s = 1, screen.count() do
  626.    -- Create a promptbox for each screen
  627.    mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
  628.    -- Create an imagebox widget which will contains an icon indicating which layout we're using.
  629.    -- We need one layoutbox per screen.
  630.    mylayoutbox[s] = awful.widget.layoutbox(s)
  631.    mylayoutbox[s]:buttons(awful.util.table.join(
  632.                              awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
  633.                              awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
  634.                              awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
  635.                              awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
  636.    -- Create a taglist widget
  637.    mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
  638.    
  639.    -- Create a tasklist widget
  640.    mytasklist[s] = awful.widget.tasklist(function(c)
  641.                                             return awful.widget.tasklist.label.currenttags(c, s)
  642.                                          end, mytasklist.buttons)
  643.    -- Create separator
  644.    separator = widget({ type = "textbox" })
  645.    separator.text = " | "
  646.  
  647.    -- Create the wibox
  648.    mywibox[s] = awful.wibox({ position = "top", screen = s })
  649.    -- Add widgets to the wibox - order matters
  650.    mywibox[s].widgets = {
  651.       {
  652.          mylauncher,
  653.          mytaglist[s],        
  654.          separator,
  655.          launchbar,
  656.          separator,
  657.          s == 1 and mysystray or nil,
  658.          separator,
  659.          mypromptbox[s],
  660.          layout = awful.widget.layout.horizontal.leftright
  661.       },
  662.       mylayoutbox[s],
  663.       timewidget,
  664.       batwidget,
  665.       tb_volume,   
  666.       memwidget,
  667.       cputempwidget,
  668.       cpuwidget,
  669.       wierd.widget,
  670.       kbdwidget,
  671.       musicwidget.widget,
  672.       mytasklist[s],
  673.       layout = awful.widget.layout.horizontal.rightleft
  674.    }
  675.    
  676. end
  677.  
  678. function delay_s(delay)
  679. delay = delay or 1
  680. local time_to = os.time() + delay
  681. while os.time() < time_to do end
  682. end
  683.  
  684. --shifty.taglist = mytaglist
  685.  
  686. -- }}}
  687.  
  688. -- {{{ Mouse bindings
  689. root.buttons(awful.util.table.join(
  690. --    awful.button({ }, 3, function () mymainmenu:toggle() end),
  691.     awful.button({ }, 4, awful.tag.viewnext),
  692.     awful.button({ }, 5, awful.tag.viewprev)
  693. ))
  694. -- }}}
  695.  
  696. ------- MARK FUNCTIONALITY -----------
  697.  
  698. -- iterator: cycle over a table starting from the next element
  699. local function cycle(t, item)
  700.     local index = awful.util.table.hasitem(t, item)
  701.     local size  = table.getn(t)
  702.     local count = 0
  703.     return function ()
  704.         index = next(t, index) or 1; count = count + 1
  705.         if not (count > size) then return t[index] end
  706.     end
  707. end
  708.  
  709. -- cycle through marked clients
  710. function cycle_marked()
  711.     local clients = client.get(mouse.screen)
  712.     local focused = awful.client.next(0)
  713.     cycle(clients,focused)
  714.     for c in cycle(clients, focused) do
  715.         if awful.client.ismarked(c) then
  716.             local ctags = c:tags()
  717.             if table.getn(ctags) == 0 then
  718.                 -- not on any tag, show client on current tag
  719.                 awful.client.movetotag(awful.tag.selected(), c)
  720.             else
  721.                 -- else, pop to first tag client is visible on
  722.                 awful.tag.viewonly(ctags[1])
  723.             end
  724.             -- And then focus the client
  725.             client.focus = c
  726.             c:raise()
  727.             return
  728.         end
  729.     end
  730. end
  731.  
  732. -- {{{ Key bindings
  733. globalkeys = awful.util.table.join(
  734.     awful.key({ modkey,           }, "Left",   awful.tag.viewprev       ),
  735.     awful.key({ modkey,           }, "Right",  awful.tag.viewnext       ),
  736.     awful.key({ modkey,           }, "Tab", awful.tag.history.restore),
  737.  
  738.     awful.key({ modkey,           }, "Up",
  739.         function ()
  740.             awful.client.focus.byidx( 1)
  741.             if client.focus then client.focus:raise() end
  742.         end),
  743.     awful.key({ modkey,           }, "Down",
  744.         function ()
  745.             awful.client.focus.byidx(-1)
  746.             if client.focus then client.focus:raise() end
  747.         end),
  748.  
  749.     -- Layout manipulation
  750.     awful.key({ modkey, "Shift"   }, "j", function () awful.client.swap.byidx(  1)    end),
  751.     awful.key({ modkey, "Shift"   }, "k", function () awful.client.swap.byidx( -1)    end),
  752.     awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
  753.     awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
  754.     awful.key({ modkey,           }, "a", cycle_marked ),
  755.     awful.key({ modkey,           }, "t", function()
  756.                                              awful.client.togglemarked()
  757.                                              naughty.notify({text = "placeholder"})
  758.                                           end),
  759.     awful.key({ modkey,           }, "u", awful.client.urgent.jumpto),
  760.     awful.key({ modkey,           }, "Tab",
  761.         function ()
  762.             awful.client.focus.history.previous()
  763.             if client.focus then
  764.                 client.focus:raise()
  765.             end
  766.         end),
  767.  
  768. --    awful.key({ "Shift" }, "Alt_L", function () kbdcfg.switch() end),
  769.     -- Standard program
  770.     awful.key({ modkey,           }, "Return", function () dropdown_toggle("urxvt -pe tabbed", 0.5) end),
  771.     awful.key({ modkey            }, "l", function ()
  772.                          awful.util.spawn("xscreensaver-command -lock")
  773.                          delay_s(10)
  774.                          awful.util.spawn("xset dpms force off")
  775.                       end),
  776.     awful.key({ modkey }, "z",  function()
  777.                    naughty.notify({ title = "Debug stug",
  778.                             text = "Some text may appear here someday",
  779.                             timeout = 3, hover_timeout = 0.5,
  780.                             width = 160})
  781. --                 obvious.popup_run_prompt.run_prompt()
  782.                 end),
  783. --    awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),
  784. --    awful.key({ modkey,           }, "h",     function () awful.tag.incmwfact(-0.05)    end),
  785.     awful.key({ modkey, "Shift"   }, "h",     function () awful.tag.incnmaster( 1)      end),
  786.     awful.key({ modkey, "Shift"   }, "l",     function () awful.tag.incnmaster(-1)      end),
  787.     awful.key({ modkey, "Control" }, "h",     function () awful.tag.incncol( 1)         end),
  788.     awful.key({ modkey, "Control" }, "l",     function () awful.tag.incncol(-1)         end),
  789.     awful.key({ modkey,           }, "space", function () awful.layout.inc(layouts,  1) end),
  790.     awful.key({ modkey, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),
  791.     awful.key({ }, "Print", function () awful.util.spawn("gnome-screenshot") end),
  792. --    awful.key({ modkey }, "q", function () awful.util.spawn("gnome-screenshot -a") end),
  793.  
  794.     -- Prompt
  795.     awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),
  796.  
  797.     awful.key({ modkey }, "x",
  798.               function ()
  799.                   awful.prompt.run({ prompt = "Run Lua code: " },
  800.                   mypromptbox[mouse.screen].widget,
  801.                   awful.util.eval, nil,
  802.                   awful.util.getdir("cache") .. "/history_eval")
  803.               end)
  804. )
  805.  
  806. clientkeys = awful.util.table.join(
  807.     awful.key({ modkey,           }, "f",      function (c) c.fullscreen = not c.fullscreen  end),
  808.     awful.key({ modkey, "Shift"   }, "c",      function (c) c:kill()                         end),
  809.     awful.key({ modkey, "Control" }, "space",  awful.client.floating.toggle                     ),
  810.     awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
  811.     awful.key({ modkey,           }, "o",      awful.client.movetoscreen                        ),
  812.     awful.key({ modkey, "Shift"   }, "r",      function (c) c:redraw()                       end),
  813.     awful.key({ modkey,           }, "n",      function (c) c.minimized = not c.minimized    end),
  814.     awful.key({ modkey }, "b", function ()
  815.                   mywibox[mouse.screen].visible = not mywibox[mouse.screen].visible
  816.                    end),
  817.     awful.key({ modkey,           }, "m",
  818.           function (c)
  819.          c.maximized_horizontal = not c.maximized_horizontal
  820.          c.maximized_vertical   = not c.maximized_vertical
  821.           end)
  822.  )
  823.  
  824. -- Compute the maximum number of digit we need, limited to 9
  825. keynumber = 0
  826. for s = 1, screen.count() do
  827.    keynumber = math.min(9, math.max(#tags[s], keynumber));
  828. end
  829.  
  830. -- Bind all key numbers to tags.
  831. -- Be careful: we use keycodes to make it works on any keyboard layout.
  832. -- This should map on the top row of your keyboard, usually 1 to 9.
  833. for i = 1, keynumber do
  834.     globalkeys = awful.util.table.join(globalkeys,
  835.         awful.key({ modkey }, "#" .. i + 9,
  836.                   function ()
  837.                         local screen = mouse.screen
  838.                         if tags[screen][i] then
  839.                             awful.tag.viewonly(tags[screen][i])
  840.                         end
  841.                   end),
  842.         awful.key({ modkey, "Control" }, "#" .. i + 9,
  843.                   function ()
  844.                       local screen = mouse.screen
  845.                       if tags[screen][i] then
  846.                           awful.tag.viewtoggle(tags[screen][i])
  847.                       end
  848.                   end),
  849.         awful.key({ modkey, "Shift" }, "#" .. i + 9,
  850.                   function ()
  851.                       if client.focus and tags[client.focus.screen][i] then
  852.                           awful.client.movetotag(tags[client.focus.screen][i])
  853.                       end
  854.                   end),
  855.         awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
  856.                   function ()
  857.                       if client.focus and tags[client.focus.screen][i] then
  858.                           awful.client.toggletag(tags[client.focus.screen][i])
  859.                       end
  860.                   end))
  861. end
  862.  
  863. clientbuttons = awful.util.table.join(
  864.     awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
  865.     awful.button({ modkey }, 1, awful.mouse.client.move),
  866.     awful.button({ modkey }, 3, awful.mouse.client.resize))
  867.  
  868. -- Set keys
  869. root.keys(globalkeys)
  870. --shifty.config.globalkeys = globalkeys
  871. --shifty.config.clientkeys = clientkeys
  872.  
  873. -- }}}
  874.  
  875. -- {{{ Rules
  876. awful.rules.rules = {
  877.     -- All clients will match this rule.
  878.     { rule = { },
  879.       properties = { border_width = beautiful.border_width,
  880.                      border_color = beautiful.border_normal,
  881.                      focus = true,
  882.                      keys = clientkeys,
  883.                      buttons = clientbuttons } },
  884.     { rule = { class = "MPlayer" },
  885.       properties = { floating = true } },
  886.     { rule = { class = "pinentry" },
  887.       properties = { floating = true } },
  888.     { rule = { class = "gimp" },
  889.       properties = { floating = true } },
  890.     -- Set Firefox to always map on tags number 2 of screen 1.
  891.     { rule = { class = "Firefox" },
  892.       properties = { tag = tags[1][2] } },
  893.     { rule = { class = "Iceweasel" },
  894.       properties = { tag = tags[1][2] } },
  895.     { rule = { class = "FreeMind" },
  896.       properties = { tag = tags[1][1] } },
  897.     { rule = { class = "Thunderbird" },
  898.       properties = { tag = tags[1][2] } },
  899.     { rule = { class = "Pidgin" },
  900.       properties = { tag = tags[1][3], floating = true } },
  901. }
  902. -- }}}
  903.  
  904. -- {{{ Signals
  905. -- Signal function to execute when a new client appears.
  906. client.add_signal("manage", function (c, startup)
  907.                                -- Add a titlebar
  908.                                -- awful.titlebar.add(c, { modkey = modkey })
  909.                                
  910.                                -- Enable sloppy focus
  911.                                c:add_signal("mouse::enter", function(c)
  912.                                                                if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
  913.                                                                and awful.client.focus.filter(c) then
  914.                                                                client.focus = c
  915.                                                             end
  916.                                                          end)
  917.                                
  918.                                if not startup then
  919.                                   -- Set the windows at the slave,
  920.                                   -- i.e. put it at the end of others instead of setting it master.
  921.                                   -- awful.client.setslave(c)
  922.                                  
  923.                                   -- Put windows in a smart way, only if they does not set an initial position.
  924.                                   if not c.size_hints.user_position and not c.size_hints.program_position then
  925.                                      awful.placement.no_overlap(c)
  926.                                      awful.placement.no_offscreen(c)
  927.                                   end
  928.                                end
  929.                                c.size_hints_honor = false
  930.                             end)
  931.  
  932. client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
  933. client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
  934. -- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement