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

Commit

Permalink
subscribe signals for battery
Browse files Browse the repository at this point in the history
  • Loading branch information
RMTT committed Sep 29, 2020
1 parent 8f9b5f8 commit bf6f660
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions theme/fly/module/battery_manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local GLib = lgi.GLib
local constants = require("utils.constants")

local battery_manager = {}
local devices_type = {}
local bus

local function get_display_device()
Expand Down Expand Up @@ -41,22 +42,18 @@ local function parse_device(path, display)
if display then
type = constants.BATTERY_DEVICE_DISPLAY
end
devices_type[path] = data["Type"]

if data["Type"] ~= constants.BATTERY_DEVICE_TYPE_LINE_POWER then
if devices_type[path] ~= constants.BATTERY_DEVICE_TYPE_LINE_POWER then
awesome.emit_signal(sig.battery_manager.update_device, {
type = type,
path = path,
device_type = data["Type"],
device_type = devices_type[path],
state = data["State"],
percentage = data["Percentage"],
model = data["Model"]
})
end

bus:signal_subscribe("org.freedesktop.UPower", "org.freedesktop.DBus.Properties", "PropertiesChanged",
nil, nil, Gio.DBusSignalFlags.NONE, function(conn, sender, object_path, interface_name, signal_name, user_data)
print(object_path)
end)
end

local function get_devices()
Expand All @@ -79,10 +76,12 @@ local function get_devices()
end

local function device_added(path)
print("device: ", path)
parse_device(path, false)
end

local function device_removed(path) end
local function device_removed(path)
awesome.emit_signal(sig.battery_manager.remove_device, path)
end

function battery_manager:init(config)
Gio.Async.call(function()
Expand All @@ -99,6 +98,28 @@ function battery_manager:init(config)
parse_device(devices[i])
end

bus:signal_subscribe("org.freedesktop.UPower", "org.freedesktop.DBus.Properties", "PropertiesChanged",
nil, nil, Gio.DBusSignalFlags.NONE, function(conn, sender, path, interface_name, signal_name, user_data)
local data = user_data.value[2]
if user_data.value[1] == "org.freedesktop.UPower.Device" then
local type = constants.BATTERY_DEVICE_OTHER
if path == display_device then
type = constants.BATTERY_DEVICE_DISPLAY
end

if devices_type[path] ~= constants.BATTERY_DEVICE_TYPE_LINE_POWER then
awesome.emit_signal(sig.battery_manager.update_device, {
type = type,
path = path,
device_type = devices_type[path],
state = data["State"],
percentage = data["Percentage"],
model = data["Model"]
})
end
end
end)

bus:signal_subscribe("org.freedesktop.UPower", "org.freedesktop.UPower", "DeviceAdded",
nil, nil, Gio.DBusSignalFlags.NONE, device_added)

Expand Down

0 comments on commit bf6f660

Please sign in to comment.