Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
add battery panel
Browse files Browse the repository at this point in the history
  • Loading branch information
RMTT committed Sep 28, 2020
1 parent eb12e6e commit 7c021b6
Showing 1 changed file with 67 additions and 5 deletions.
72 changes: 67 additions & 5 deletions theme/fly/widget/battery.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,52 @@ local icons = require("theme.assets.icons")
local wibox = require("wibox")
local awful = require("awful")
local sig = require("theme.fly.signal")
local beautiful = require("beautiful")
local constants = require("utils.constants")

local battery = {}

local have_moved = false

local items = {}
local progressbars = {}

function battery:init(config)
self.widget = wibox.widget {
image = icons.fly.battery_unknown,
resize = true,
forced_height = config.height,
forced_width = config.width,
widget = wibox.widget.imagebox
widget = wibox.widget.imagebox,
}

self.panel_content = wibox.widget {
spacing = 5,
layout = wibox.layout.fixed.vertical
}

self.panel = awful.popup {
widget = {
{

},
self.panel_content,
margins = 5,
widget = wibox.container.margin
}
},
preferred_positions = "bottom",
preferred_anchors = "middle",
bg = beautiful.startup_bg,
visible = false,
ontop = true
}

self.widget:connect_signal("button::press", function(geo, lx, ly, button, mods, w)
if not have_moved then
battery.panel:move_next_to(w)
have_moved = true
else
battery.panel.visible = not battery.panel.visible
end
end)

awesome.connect_signal(sig.battery_manager.update_device, function(data)
if data.type == constants.BATTERY_DEVICE_DISPLAY then
if data.state == constants.BATTERY_DEVICE_STATE_UNKNOWN then
Expand All @@ -46,6 +71,43 @@ function battery:init(config)
end
end
else
if items[data.path] then
if progressbars[data.path] then
progressbars[data.path].value = data.percentage
end
else
local markup = data.model
if data.device_type == constants.BATTERY_DEVICE_TYPE_BATTERY then
markup = "Battery"
end

progressbars[data.path] = wibox.widget {
max_value = 100,
value = data.percentage,
forced_height = 15,
forced_width = 100,
paddings = 1,
border_width = 1,
border_color = beautiful.border_color,
widget = wibox.widget.progressbar,
}

items[data.path] = wibox.widget {
{
wibox.widget {
markup = markup,
align = 'center',
valign = 'center',
widget = wibox.widget.textbox
},
progressbars[data.path],
layout = wibox.layout.align.vertical
},
widget = wibox.container.margin
}

battery.panel_content:add(items[data.path])
end
end
end)
end
Expand Down

0 comments on commit 7c021b6

Please sign in to comment.