Hide module if UPower service isn't running
parent
0140606226
commit
e0f0931e2d
|
@ -34,6 +34,10 @@ class UPower : public AModule {
|
||||||
const gchar *object_path, const gchar *interface_name,
|
const gchar *object_path, const gchar *interface_name,
|
||||||
const gchar *signal_name, GVariant *parameters,
|
const gchar *signal_name, GVariant *parameters,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
static void upowerAppear(GDBusConnection *conn, const gchar *name, const gchar *name_owner,
|
||||||
|
gpointer data);
|
||||||
|
static void upowerDisappear(GDBusConnection *connection, const gchar *name, gpointer user_data);
|
||||||
|
|
||||||
void removeDevice(const gchar *objectPath);
|
void removeDevice(const gchar *objectPath);
|
||||||
void addDevice(UpDevice *device);
|
void addDevice(UpDevice *device);
|
||||||
void setDisplayDevice();
|
void setDisplayDevice();
|
||||||
|
@ -67,6 +71,8 @@ class UPower : public AModule {
|
||||||
UPowerTooltip *upower_tooltip;
|
UPowerTooltip *upower_tooltip;
|
||||||
std::string lastStatus;
|
std::string lastStatus;
|
||||||
bool showAltText;
|
bool showAltText;
|
||||||
|
bool upowerRunning;
|
||||||
|
guint upowerWatcher_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::upower
|
} // namespace waybar::modules::upower
|
||||||
|
|
|
@ -68,6 +68,14 @@ UPower::UPower(const std::string& id, const Json::Value& config)
|
||||||
box_.signal_query_tooltip().connect(sigc::mem_fun(*this, &UPower::show_tooltip_callback));
|
box_.signal_query_tooltip().connect(sigc::mem_fun(*this, &UPower::show_tooltip_callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upowerWatcher_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
|
||||||
|
"org.freedesktop.UPower",
|
||||||
|
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
||||||
|
upowerAppear,
|
||||||
|
upowerDisappear,
|
||||||
|
this,
|
||||||
|
NULL);
|
||||||
|
|
||||||
GError* error = NULL;
|
GError* error = NULL;
|
||||||
client = up_client_new_full(NULL, &error);
|
client = up_client_new_full(NULL, &error);
|
||||||
if (client == NULL) {
|
if (client == NULL) {
|
||||||
|
@ -106,6 +114,7 @@ UPower::~UPower() {
|
||||||
g_dbus_connection_signal_unsubscribe(login1_connection, login1_id);
|
g_dbus_connection_signal_unsubscribe(login1_connection, login1_id);
|
||||||
login1_id = 0;
|
login1_id = 0;
|
||||||
}
|
}
|
||||||
|
g_bus_unwatch_name(upowerWatcher_id);
|
||||||
removeDevices();
|
removeDevices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +151,17 @@ void UPower::prepareForSleep_cb(GDBusConnection* system_bus, const gchar* sender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void UPower::upowerAppear(GDBusConnection* conn, const gchar* name, const gchar* name_owner,
|
||||||
|
gpointer data) {
|
||||||
|
UPower* up = static_cast<UPower*>(data);
|
||||||
|
up->upowerRunning = true;
|
||||||
|
up->dp.emit();
|
||||||
|
}
|
||||||
|
void UPower::upowerDisappear(GDBusConnection* conn, const gchar* name, gpointer data) {
|
||||||
|
UPower* up = static_cast<UPower*>(data);
|
||||||
|
up->upowerRunning = false;
|
||||||
|
up->dp.emit();
|
||||||
|
}
|
||||||
|
|
||||||
void UPower::removeDevice(const gchar* objectPath) {
|
void UPower::removeDevice(const gchar* objectPath) {
|
||||||
std::lock_guard<std::mutex> guard(m_Mutex);
|
std::lock_guard<std::mutex> guard(m_Mutex);
|
||||||
|
@ -261,6 +281,14 @@ std::string UPower::timeToString(gint64 time) {
|
||||||
auto UPower::update() -> void {
|
auto UPower::update() -> void {
|
||||||
std::lock_guard<std::mutex> guard(m_Mutex);
|
std::lock_guard<std::mutex> guard(m_Mutex);
|
||||||
|
|
||||||
|
// Hide everything if the UPower service is not running
|
||||||
|
if (!upowerRunning) {
|
||||||
|
event_box_.set_visible(false);
|
||||||
|
// Call parent update
|
||||||
|
AModule::update();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
UpDeviceKind kind;
|
UpDeviceKind kind;
|
||||||
UpDeviceState state;
|
UpDeviceState state;
|
||||||
double percentage;
|
double percentage;
|
||||||
|
|
Loading…
Reference in New Issue