From c1e6f7f09b37e4ece220822887ad80cd6055dfbd Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 16 Dec 2016 22:01:26 +0100 Subject: add a battery widget --- config/awesome/battery.lua | 53 +++++++++++++++++++++++++++++++++++++++++ config/awesome/rc.lua | 31 +++++++++++++++++------- config/awesome/weasel-rules.lua | 20 +++++++++------- 3 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 config/awesome/battery.lua diff --git a/config/awesome/battery.lua b/config/awesome/battery.lua new file mode 100644 index 0000000..988f9fa --- /dev/null +++ b/config/awesome/battery.lua @@ -0,0 +1,53 @@ +function batteryInfoUpdate(adapter, warn, widget) + spacer = " " + local fcap = io.open("/sys/class/power_supply/"..adapter.."/capacity") + local fsta = io.open("/sys/class/power_supply/"..adapter.."/status") + local cap = fcap:read() + local sta = fsta:read() + fcap:close() + fsta:close() + + if sta:match("Charging") then + state = 1 + icon = "▴" + else + state = -1 + icon = "▾" + end + + if tonumber(cap) < 10 and warn then + naughty.notify({ title = "Battery Warning", + text = "Battery "..adapter.." low at "..cap.."%!", + timeout = 15, + position = "top_right", + fg = beautiful.fg_focus, + bg = beautiful.bg_focus, + }) + end + if tonumber(cap) < 10 then + color='red' + elseif tonumber(cap) < 25 then + color='orange' + else + color='green' + end + + widget:set_markup(spacer..""..icon..cap..'%'..spacer) +end + +local wibox = require("wibox") + +bat0_widget = wibox.widget.textbox() +bat0_widget:set_align("right") + +bat1_widget = wibox.widget.textbox() +bat1_widget:set_align("right") + +battery_timer = timer({timeout = 20}) +battery_timer:connect_signal("timeout", function() + batteryInfoUpdate("BAT0", true, bat0_widget) + batteryInfoUpdate("BAT1", false, bat1_widget) +end) +battery_timer:start() + +-- vim:set softtabstop=4:ts=4:shiftwidth=4:et=1: diff --git a/config/awesome/rc.lua b/config/awesome/rc.lua index b26cdeb..d10ada6 100644 --- a/config/awesome/rc.lua +++ b/config/awesome/rc.lua @@ -14,6 +14,7 @@ local menubar = require("menubar") -- Load Debian menu entries require("debian.menu") require("volume") +require("battery") require("weasel-rules") -- require("revelation") @@ -71,10 +72,10 @@ local layouts = -- awful.layout.suit.fair.horizontal, -- awful.layout.suit.spiral, -- awful.layout.suit.spiral.dwindle, - awful.layout.suit.max, + -- awful.layout.suit.max, -- awful.layout.suit.max.fullscreen, -- awful.layout.suit.magnifier - awful.layout.suit.floating, + -- awful.layout.suit.floating, } -- }}} @@ -206,6 +207,8 @@ for s = 1, screen.count() do local right_layout = wibox.layout.fixed.horizontal() if s == 1 then right_layout:add(wibox.widget.systray()) end right_layout:add(volume_widget) + right_layout:add(bat0_widget) + right_layout:add(bat1_widget) right_layout:add(mytextclock) right_layout:add(mylayoutbox[s]) @@ -270,8 +273,20 @@ globalkeys = awful.util.table.join( awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end), awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end), awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end), - awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end), - awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end), + awful.key({ modkey, }, "space", function () + if awful.util.table.hasitem(layouts, awful.layout.get() ) then + awful.layout.inc(layouts, 1) + else + awful.layout.set(layouts[1]) + end + end), + awful.key({ modkey, "Shift" }, "space", function () + if awful.util.table.hasitem(layouts, awful.layout.get() ) then + awful.layout.inc(layouts, -1) + else + awful.layout.set(layouts[1]) + end + end), -- awful.key({ modkey, "Control" }, "n", awful.client.restore), @@ -390,7 +405,7 @@ clientkeys = awful.util.table.join( awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ), awful.key({ modkey, }, "Return", function (c) c:swap(awful.client.getmaster()) end), awful.key({ modkey, }, "o", awful.client.movetoscreen ), - -- awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end), + awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end), -- weasel awful.key({ "Mod1" }, "q", function (c) @@ -561,11 +576,11 @@ client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_n -- }}} terminal = "urxvt" -awful.util.spawn("nm-applet") -awful.util.spawn("klipper") +awful.util.spawn_with_shell("pkill -x -f nm-applet; nm-applet") +--awful.util.spawn_with_shell("pkill -x -f klipper; klipper") -- awful.util.spawn("xscreensaver -no-splash") --KDE--awful.util.spawn("X-screensaver") ---KDE--awful.util.spawn_with_shell("pkill -x -f clipit; clipit") +awful.util.spawn_with_shell("pkill -x -f clipit; clipit") awful.util.spawn_with_shell("pkill -x -f 'alsa-volume-monitor hw:0'; alsa-volume-monitor hw:0") -- vim:set softtabstop=4:ts=4:shiftwidth=4:et=1: diff --git a/config/awesome/weasel-rules.lua b/config/awesome/weasel-rules.lua index b645df3..ed659bf 100644 --- a/config/awesome/weasel-rules.lua +++ b/config/awesome/weasel-rules.lua @@ -1,30 +1,32 @@ function get_weasel_rules() local sn = screen.count() + local browser_screen = 1 + local im_screen = 1 local rules = { { rule = { class = "URxvt" , name = "FURxvt" }, properties = { floating = true } }, { rule = { class = "Firefox" , name = "Mozilla Firefox" }, - properties = { tag = tags[sn][6] } }, + properties = { tag = tags[browser_screen][6] } }, { rule = { class = "Firefox" }, - properties = { tag = tags[sn][6] } }, + properties = { tag = tags[browser_screen][6] } }, { rule = { class = "chromium" , name = "New Tab - Chromium" }, - properties = { tag = tags[sn][7] } }, + properties = { tag = tags[browser_screen][7] } }, { rule = { class = "Tor Browser" , name = "Tor Browser" }, - properties = { tag = tags[sn][8], floating = true } }, + properties = { tag = tags[browser_screen][8], floating = true } }, { rule = { class = "Tor Browser" }, - properties = { tag = tags[sn][8], floating = true } }, + properties = { tag = tags[browser_screen][8], floating = true } }, { rule = { class = "URxvt" , name = "IRC" }, - properties = { tag = tags[sn][11] } }, + properties = { tag = tags[im_screen][11] } }, { rule = { class = "URxvt" , name = "Mail" }, - properties = { tag = tags[sn][12] } }, + properties = { tag = tags[im_screen][12] } }, { rule = { class = "URxvt" , name = "Mail COSY" }, - properties = { tag = tags[sn][12] } }, + properties = { tag = tags[im_screen][12] } }, { rule = { class = "chromium" , name = "Signal Private Messenger" }, - properties = { tag = tags[sn][13] } }, + properties = { tag = tags[im_screen][13] } }, --{ rule = { maximized_horizontal = true }, -- these two should remove window borders from maximized windows because they get in the way -- properties = { border_width = 0 } }, -- cgit v1.2.3