This repository has been archived by the owner on Dec 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
local DBus = require("utils.dbus_wrapper.bus") | ||
local Call = require("utils.dbus_wrapper.call") | ||
local sig = require("theme.fly.signal") | ||
local lgi = require("lgi") | ||
local Gio = lgi.Gio | ||
local GLib = lgi.GLib | ||
local constants = require("utils.constants") | ||
|
||
local battery_manager = {} | ||
local bus | ||
|
||
local function get_display_device() | ||
local call = Call.new() | ||
call.name = "org.freedesktop.UPower" | ||
call.path = "/org/freedesktop/UPower" | ||
call.interface = "org.freedesktop.UPower" | ||
call.member = "GetDisplayDevice" | ||
call.timeout = -1 | ||
call.args = nil | ||
local f, body = call(bus) | ||
|
||
if f then | ||
return body[1] | ||
else | ||
return nil | ||
end | ||
end | ||
|
||
local function parse_device(path, display) | ||
local call = Call.new() | ||
call.name = "org.freedesktop.UPower" | ||
call.path = path | ||
call.interface = "org.freedesktop.DBus.Properties" | ||
call.member = "GetAll" | ||
call.timeout = -1 | ||
call.args = GLib.Variant("(s)", { "org.freedesktop.UPower.Device" }) | ||
local f, body = call(bus) | ||
|
||
local data = body.value[1] | ||
local type = constants.BATTERY_DEVICE_OTHER | ||
if display then | ||
type = constants.BATTERY_DEVICE_DISPLAY | ||
end | ||
|
||
if data["Type"] ~= constants.BATTERY_DEVICE_TYPE_LINE_POWER then | ||
awesome.emit_signal(sig.battery_manager.update_device, { | ||
type = type, | ||
path = path, | ||
device_type = data["Type"], | ||
state = data["State"], | ||
percentage = data["Percentage"], | ||
model = data["Model"] | ||
}) | ||
end | ||
end | ||
|
||
local function get_devices() | ||
local call = Call.new() | ||
call.name = "org.freedesktop.UPower" | ||
call.path = "/org/freedesktop/UPower" | ||
call.interface = "org.freedesktop.UPower" | ||
call.member = "EnumerateDevices" | ||
call.timeout = -1 | ||
call.args = nil | ||
local f, body = call(bus) | ||
|
||
local res = {} | ||
if f then | ||
for i = 1, #body[1] do | ||
table.insert(res, body[1][i]) | ||
end | ||
end | ||
return res | ||
end | ||
|
||
local function device_added(path) | ||
print("device: ", path) | ||
end | ||
|
||
local function device_removed(path) end | ||
|
||
function battery_manager:init(config) | ||
Gio.Async.call(function() | ||
bus = DBus.new(Gio.BusType.SYSTEM) | ||
|
||
-- get display device | ||
local display_device = get_display_device() | ||
|
||
parse_device(display_device, true) | ||
|
||
-- enumerate device | ||
local devices = get_devices() | ||
for i = 1, #devices do | ||
parse_device(devices[i]) | ||
end | ||
|
||
bus:signal_subscribe("org.freedesktop.UPower", "org.freedesktop.UPower", "DeviceAdded", | ||
nil, nil, Gio.DBusSignalFlags.NONE, device_added) | ||
|
||
bus:signal_subscribe("org.freedesktop.UPower", "org.freedesktop.UPower", "DeviceRemoved", | ||
nil, nil, Gio.DBusSignalFlags.NONE, device_removed) | ||
end)() | ||
end | ||
|
||
return battery_manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,53 @@ | ||
local icons = require("theme.assets.icons") | ||
local wibox = require("wibox") | ||
local awful = require("awful") | ||
local sig = require("theme.fly.signal") | ||
local constants = require("utils.constants") | ||
|
||
local battery = {} | ||
|
||
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 | ||
} | ||
|
||
self.panel = awful.popup { | ||
widget = { | ||
{ | ||
|
||
}, | ||
widget = wibox.container.margin | ||
} | ||
} | ||
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 | ||
battery.widget:set_image(icons.fly.battery_unknown) | ||
elseif data.state == constants.BATTERY_DEVICE_STATE_CHARGING then | ||
battery.widet:set_image(icons.fly.battery_charging) | ||
elseif data.state == constants.BATTERY_DEVICE_STATE_EMPTY then | ||
battery.widget:set_image(icons.fly.battery_empty) | ||
elseif data.state == constants.BATTERY_DEVICE_STATE_FULL_CHARGED then | ||
battery.widget:set_image(icons.fly.battery_full) | ||
else | ||
local percentage = data.percentage | ||
if percentage > 0 and percentage < 25 then | ||
battery.widget:set_image(icons.fly.battery_step_one) | ||
elseif percentage >= 25 and percentage < 50 then | ||
battery.widget:set_image(icons.fly.battery_step_two) | ||
elseif percentage >= 50 and percentage < 75 then | ||
battery.widget:set_image(icons.fly.battery_step_three) | ||
elseif percentage >= 75 and percentage < 100 then | ||
battery.widget:set_image(icons.fly.battery_step_four) | ||
end | ||
end | ||
else | ||
end | ||
end) | ||
end | ||
|
||
return battery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters