From 897cce324138bccc48156336b97249064291d0b5 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 8 Sep 2022 00:17:01 +1000 Subject: [PATCH] import --- battery-caution-charging.svg | 324 +++++++++++++++++++++++++ battery-caution.svg | 367 ++++++++++++++++++++++++++++ battery-empty-charging.svg | 310 ++++++++++++++++++++++++ battery-empty.svg | 453 +++++++++++++++++++++++++++++++++++ battery-full-charging.svg | 265 ++++++++++++++++++++ battery-full.svg | 257 ++++++++++++++++++++ battery-good-charging.svg | 316 ++++++++++++++++++++++++ battery-good.svg | 373 ++++++++++++++++++++++++++++ battery-low-charging.svg | 306 +++++++++++++++++++++++ battery-low.svg | 339 ++++++++++++++++++++++++++ init.lua | 117 +++++++++ 11 files changed, 3427 insertions(+) create mode 100644 battery-caution-charging.svg create mode 100644 battery-caution.svg create mode 100644 battery-empty-charging.svg create mode 100644 battery-empty.svg create mode 100644 battery-full-charging.svg create mode 100644 battery-full.svg create mode 100644 battery-good-charging.svg create mode 100644 battery-good.svg create mode 100644 battery-low-charging.svg create mode 100644 battery-low.svg create mode 100644 init.lua diff --git a/battery-caution-charging.svg b/battery-caution-charging.svg new file mode 100644 index 0000000..e221b53 --- /dev/null +++ b/battery-caution-charging.svg @@ -0,0 +1,324 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/battery-caution.svg b/battery-caution.svg new file mode 100644 index 0000000..762b5f9 --- /dev/null +++ b/battery-caution.svg @@ -0,0 +1,367 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/battery-empty-charging.svg b/battery-empty-charging.svg new file mode 100644 index 0000000..63cb55e --- /dev/null +++ b/battery-empty-charging.svg @@ -0,0 +1,310 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/battery-empty.svg b/battery-empty.svg new file mode 100644 index 0000000..cb8a2f9 --- /dev/null +++ b/battery-empty.svg @@ -0,0 +1,453 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/battery-full-charging.svg b/battery-full-charging.svg new file mode 100644 index 0000000..a5df1c3 --- /dev/null +++ b/battery-full-charging.svg @@ -0,0 +1,265 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/battery-full.svg b/battery-full.svg new file mode 100644 index 0000000..37806b8 --- /dev/null +++ b/battery-full.svg @@ -0,0 +1,257 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/battery-good-charging.svg b/battery-good-charging.svg new file mode 100644 index 0000000..36c1856 --- /dev/null +++ b/battery-good-charging.svg @@ -0,0 +1,316 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/battery-good.svg b/battery-good.svg new file mode 100644 index 0000000..56dcb60 --- /dev/null +++ b/battery-good.svg @@ -0,0 +1,373 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/battery-low-charging.svg b/battery-low-charging.svg new file mode 100644 index 0000000..c662b12 --- /dev/null +++ b/battery-low-charging.svg @@ -0,0 +1,306 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/battery-low.svg b/battery-low.svg new file mode 100644 index 0000000..df5628f --- /dev/null +++ b/battery-low.svg @@ -0,0 +1,339 @@ + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..3102677 --- /dev/null +++ b/init.lua @@ -0,0 +1,117 @@ +local awful = require("awful") +local wibox = require("wibox") +local gears = require("gears") +local beautiful = require("beautiful") +local menubar = require("menubar") +local cairo = require("lgi").cairo +local Rsvg = require("lgi").Rsvg +local longpress = require("awesome-longpress") +local posix = require "posix" +local batterystat = { + batteries = {}, + iconSize = 96, + iconPath = os.getenv("HOME") .. "/.config/awesome/awesome-batterystat/" +--iconPath = gears.filesystem.get_configuration_dir() .. "/awesome-batterystat/" +} + +local iconNames = { +["battery-full"] = 95, +["battery-good"] = 70, +["battery-low"] = 40, +["battery-caution"] = 20, +["battery-empty"] = 0} +local function chooseIcon(status,percent) + local bestIcon,bestPercent = "", -1 + for k,v in pairs(iconNames) do + if v > bestPercent and percent >= v then + bestIcon, bestPercent = k, v + end + end + if status == "Charging" then + return bestIcon.."-charging" + end + return bestIcon +end + +-- preload icon widgets to avoid loading them on every update +local icons = {} +for k,v in pairs(iconNames) do + icons[k] = wibox.widget{ + widget = wibox.widget.imagebox, + forced_height = batterystat.iconSize, + forced_width = batterystat.iconSize, + image = string.format("%s/%s.svg",batterystat.iconPath,k) + } + icons[k.."-charging"] = wibox.widget{ + widget = wibox.widget.imagebox, + forced_height = batterystat.iconSize, + forced_width = batterystat.iconSize, + image = string.format("%s/%s-charging.svg",batterystat.iconPath,k) + } +end + +local function getBatteryState(path) + local state, percent + local f = io.open(string.format("%s/status",path),"r") + if f then + state = f:read("*a"):match("%S+") + f:close() + end + local f = io.open(string.format("%s/capacity",path),"r") + if f then + percent = tonumber(f:read("*a"):match("%S+")) + f:close() + end + return state, percent +end + +function batterystat.scan() + for _,d in pairs(posix.dir("/sys/class/power_supply")) do + local f = io.open(string.format("/sys/class/power_supply/%s/type",d)) + if f then + local ptype = f:read("*a"):match("%S+") + if ptype == "Battery" then + batterystat.batteries[#batterystat.batteries+1] = string.format("/sys/class/power_supply/%s/",d) + end + f:close() + end + end +end + +local function bwidgetUpdate(self) + self:reset() + for k,v in pairs(batterystat.batteries) do + local name = v:match("/([^/]+)/$") + local state, percent = getBatteryState(v) + local colour = (state == "Charging") and "lime" or "red" + local sbwidget = (wibox.widget{ + layout = wibox.layout.stack, + forced_width = batterystat.iconSize, + icons[chooseIcon(state,percent)], + wibox.widget{ + widget = wibox.widget.textbox, + align = "center", + valign = "top", + text = name + }, + wibox.widget{ + widget = wibox.widget.textbox, + align = "right", + valign = "bottom", + markup = string.format('%d%%',colour,percent) + } + }) + self:add(sbwidget) + end +end + +function batterystat.new() + local bwidget = wibox.widget{ + layout = wibox.layout.grid.horizontal, + update = bwidgetUpdate + } + batterystat.scan() + return bwidget +end + +return batterystat