X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=config%2Fawesome%2Frc.lua;h=2bcc47fbf4e1535dc337d834ff65a6c11cd2fae9;hb=1b0bfb33e57baf684511418a513b2003c46ad26f;hp=bf699297d400a783aab05bd3ec0d6dadcd9a2815;hpb=c4efffc9d1d55a6b2440bda809babf415f547120;p=~madcoder%2Fdotfiles.git diff --git a/config/awesome/rc.lua b/config/awesome/rc.lua index bf69929..2bcc47f 100644 --- a/config/awesome/rc.lua +++ b/config/awesome/rc.lua @@ -4,17 +4,18 @@ require("awful") require("awful.autofocus") require("awful.rules") -require("vicious") require("beautiful") +require("vicious") -terminal = "x-terminal-emulator" +terminal = "urxvtcd" lock = 'xscreensaver-command -lock' +lock = 'gnome-screensaver-command --lock' beautiful.init(awful.util.getdir("config").."/theme") -- {{{ Modkeys -modkey = "Mod4" -shift = "Shift" -alt = "Mod1" +modkey = "Mod4" +shift = "Shift" +alt = "Mod1" control = "Control" k_n = {} @@ -37,10 +38,6 @@ function fg(color, text) return ''..text..'' end -function heading(text) - return fg(beautiful.fg_focus, text) -end - -- }}} -- {{{ Tags @@ -185,21 +182,36 @@ end -- }}} -- {{{ Widgets -function make_imagebox(fname, w, h, bg) - local icon = image(fname) +local icondir = awful.util.getdir("config").."/icons/" + +function make_icon(fname, left, right, h, bg) + local icon = image(icondir..fname) local ib = widget { type = 'imagebox' } + local w = left + icon.width + right local i = image.argb32(w, h, nil) - if not bg then bg = beautiful.bg_normal end - - i:draw_rectangle(0, 0, w, h, true, bg) - i:insert(icon, math.floor((w - icon.width) / 2), - math.floor((h - icon.height) / 2)) + i:draw_rectangle(0, 0, w, h, true, beautiful.bg_normal) + i:insert(icon, left, math.floor((h - icon.height) / 2)) ib.image = i return ib end +function draw_dashes_h(img, x, y, on, off, len, color) + for i = 0, len, on + off do + img:draw_line(x + i, y, x + i + on - 1, y, color) + end +end + +function draw_dashes_v(img, x, y, on, off, len, color) + for i = 0, len, on + off do + img:draw_line(x, y + i, x, y + i + on - 1, color) + end +end + + +local mywidgets = {} + -- {{{ Taglist maintaglist = {} @@ -217,51 +229,56 @@ mypromptbox = awful.widget.prompt{ } -- }}} --- {{{ Load Average Widget - -loadwidget = widget({ type = 'textbox' }) -load_update = function() - -- Use /proc/loadavg to get the average system load on 1, 5 and 15 minute intervals - local f = io.open('/proc/loadavg') - local n = f:read() - f:close() - - -- Find the third space - local pos = n:find(' ', n:find(' ', n:find(' ')+1)+1) - - loadwidget.text = heading('Load')..': '..n:sub(1,pos-1) -end -load_update() +-- {{{ CPU Widgets -t = timer { timeout = 10 } -t:add_signal("timeout", load_update) -t:start() +local cpuwidgets = {} +for i = 1, io.popen("grep -c ^cpu /proc/stat"):read("*n") do + local cpu = {} --- }}} --- {{{ CPU Widgets + cpu.widget = widget{ type = 'imagebox' } + cpu.update = function(cpu, value) + local color -cpuiconwidget = nil --- make_imagebox(os.getenv("HOME")..'/tmp/famfamfam/computer.png', 18, 18) + if value < 25 then + color = beautiful.fg_focus + elseif value < 50 then + color = 'yellow' + elseif value < 75 then + color = 'orange' + else + color = 'red' + end -cputextwidget = widget({ type = 'textbox' }) + if cpu.color == color then return end + local img = image.argb32(11, 16, nil) + draw_dashes_h(img, 0, 4, 2, 1, 7, color) + draw_dashes_h(img, 0, 11, 2, 1, 7, color) + draw_dashes_v(img, 0, 4, 2, 1, 7, color) + draw_dashes_v(img, 7, 4, 2, 1, 7, color) + img:draw_rectangle(2, 6, 4, 4, true, color) + cpu.widget.image = img + cpu.percent = value + end + table.insert(mywidgets, cpu.widget) + cpuwidgets[i] = cpu +end -cpugraphwidget = awful.widget.graph{ - width = 40, height = 16, - layout = awful.widget.layout.horizontal.rightleft -} -cpugraphwidget:set_background_color('#333333') -cpugraphwidget:set_border_color('#0a0a0a') -cpugraphwidget:set_gradient_colors({ '#285577', '#285577', '#AEC6D8' }) +cputextwidget = widget{ type = 'textbox' } vicious.register(cputextwidget, vicious.widgets.cpu, function (widget, args) local r = tonumber(args[1]) local percent = args[1]..'%' + + for i = 1, #args do + cpuwidgets[i]:update(args[i]) + end + if r < 10 then percent = '0'..percent end if r < 25 then - percent = fg('green', percent) + percent = fg(beautiful.fg_focus, percent) elseif r < 50 then percent = fg('yellow', percent) elseif r < 75 then @@ -269,21 +286,18 @@ function (widget, args) else percent = fg('red', percent) end - for s = 1, screen.count() do - cpugraphwidget:add_value(r / 100) - end - return ' '..percent..' ' + return percent..' ' end, 2) +table.insert(mywidgets, cputextwidget) + -- }}} -- {{{ Memory Usage Widget -memiconwidget = nil --- make_imagebox(os.getenv("HOME")..'/tmp/famfamfam/bricks.png', 18, 18) +table.insert(mywidgets, make_icon('mem.png', 16, 4, 16)) -memtextwidget = widget({ type = 'textbox' }) +memtextwidget = widget{ type = 'textbox' } -memtextwidget.text = heading('MEM')..': ' vicious.register(memtextwidget, vicious.widgets.mem, function (widget, args) -- Add extra preceding zeroes when needed local r = tonumber(args[1]) @@ -292,54 +306,48 @@ vicious.register(memtextwidget, vicious.widgets.mem, function (widget, args) percent = '0'..percent end if r < 50 then - percent = fg('green', percent) + percent = fg(beautiful.fg_focus, percent) elseif r < 80 then percent = fg('orange', percent) else percent = fg('red', percent) end - return ' '..percent..' '..args[2]..'M' + return percent..' '..args[2]..'M' end, 2) --- }}} --- {{{ spacers - -rspacer = widget({ type = 'textbox' }) -rspacer.text = " │ " +table.insert(mywidgets, memtextwidget) -- }}} -- {{{ Clock -clockwidget = widget({ type = "textbox" }) +table.insert(mywidgets, make_icon('clock.png', 16, 4, 16)) + +clockwidget = widget{ type = "textbox" } vicious.register(clockwidget, vicious.widgets.date, - fg("#dddddd", "%a %d %b - %H:%M"), 10) + fg(theme.fg_focus, "%H:%M") .. " %a %d %b ", 10) + +table.insert(mywidgets, clockwidget) -- }}} -- {{{ Statusbar -mainstatusbar = {} -mysystray = widget({ type = "systray" }) - for s = 1, screen.count() do - local lr_layout = awful.widget.layout.horizontal.leftright - local rl_layout = awful.widget.layout.horizontal.rightleft - - mainstatusbar[s] = awful.wibox{ position = "top", height = 18, screen = s } - - mainstatusbar[s].widgets = { + local tab = { { awful.widget.taglist(s, maintaglist.label, maintaglist.buttons), mypromptbox.widget, - layout = lr_layout + layout = awful.widget.layout.horizontal.leftright }, - s == 1 and mysystray or nil, - s == 1 and rspacer or nil, - clockwidget, rspacer, - memtextwidget, memiconwidget, rspacer, - cpugraphwidget.widget, cputextwidget, cpuiconwidget, rspacer, - loadwidget, rspacer, - layout = awful.widget.layout.horizontal.rightleft } + + if (s == 1) then + table.insert(tab, widget{ type = 'systray' }) + end + for i = #mywidgets, 1, -1 do + table.insert(tab, mywidgets[i]) + end + tab["layout"] = awful.widget.layout.horizontal.rightleft + awful.wibox{ position = "top", height = 16, screen = s }.widgets = tab end -- }}} @@ -347,7 +355,6 @@ end -- {{{ Keys ---- {{{ Global keys -local hist = os.getenv("HOME") .. "/.cache/awesome/history" globalkeys = awful.util.table.join( -- Mod+{A/S}: Switch to prev/next tag awful.key(k_m, "Left", mtag.prev), @@ -359,14 +366,10 @@ globalkeys = awful.util.table.join( -- Mod+Shift_{E/D}: move window to next/prev screen awful.key(k_mc, "Right", function() - local s = mouse.screen + 1 - while s > screen.count() do s = s - screen.count() end - client.focus.screen = s + client.focus.screen = awful.util.cycle(screen.count(), mouse.screen + 1) end), awful.key(k_mc, "Left", function() - local s = mouse.screen - 1 - while s < 1 do s = s + screen.count() end - client.focus.screen = s + client.focus.screen = awful.util.cycle(screen.count(), mouse.screen - 1) end), @@ -387,11 +390,19 @@ globalkeys = awful.util.table.join( awful.key(k_ms, "k", function () awful.client.swap.byidx(-1) end), -- Mod+{E/D}: Switch to next/previous screen - awful.key(k_m, "Tab", function () awful.screen.focus_relative(1) end), - awful.key(k_ms, "Tab", function () awful.screen.focus_relative(-1) end), + awful.key(k_m, "Tab", function () + awful.screen.focus_relative(1) + coords = mouse.coords(); + mouse.coords({ x = coords.x + 5, y = coords.y + 5}, true) + end), + awful.key(k_ms, "Tab", function () + awful.screen.focus_relative(-1) + coords = mouse.coords() + mouse.coords({ x = coords.x + 5, y = coords.y + 5}, true) + end), -- Mod+Enter: Launch a new terminal - awful.key(k_m, "e", function() awful.util.spawn("firefox") end), + awful.key(k_m, "e", function() awful.util.spawn("chromium-browser") end), awful.key(k_m, "Return", function() awful.util.spawn(terminal) end), awful.key(k_ac, "r", awesome.restart), awful.key(k_m, "F12", function() awful.util.spawn(lock) end), @@ -455,7 +466,7 @@ local clientkeys = awful.util.table.join( if mypromptbox.widget.text then mypromptbox.widget.text = "" else - mypromptbox.widget.text = "Class: " .. c.class .. " Instance: ".. c.instance + mypromptbox.widget.text = "Class: " .. c.class .. " Instance: ".. c.instance .. " Name: " .. c.name end end), @@ -492,27 +503,17 @@ awful.rules.rules = { }, { rule = { class = "MPlayer" }, properties = { floating = true } }, { rule = { class = "pinentry" }, properties = { floating = true } }, - -- Set Firefox to always map on tags number 2 of screen 1. - -- { rule = { class = "Firefox" }, - -- properties = { tag = tags[1][2] } }, + { rule = { class = "Claws-mail", name = "[no subject] - Compose message" }, + properties = { maximized_vertical = true, floating = true, x = 0 } }, } -- }}} -- {{{ Signals -function warp_mouse(c) - local o = awful.mouse.client_under_pointer() - if not o or o ~= c then - local g = c:geometry() - mouse.coords({ x = g.x + 5, y = g.y + 5 }, true) - end -end - client.add_signal("focus", function (c) if not awful.client.ismarked(c) then c.border_color = beautiful.border_focus end - warp_mouse(c) end) client.add_signal("unfocus", function (c) @@ -525,14 +526,7 @@ client.add_signal("manage", function (c, startup) c:add_signal("mouse::enter", function(c) client.focus = c end) end) -for s = 1, screen.count() do - screen[s]:add_signal("arrange", function () - if client.focus and client.focus.screen == s then - warp_mouse(client.focus) - end - end) -end - -- }}} awful.util.spawn("xkbcomp -w 0 -R/usr/share/X11/xkb /home/madcoder/.Xkeyboard :0") +awful.util.spawn("xsetroot -cursor_name left_ptr")