mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Moved upower into its own directory
This commit is contained in:
parent
2b2ac311d5
commit
14a2a7027f
@ -43,7 +43,7 @@
|
|||||||
#include "modules/keyboard_state.hpp"
|
#include "modules/keyboard_state.hpp"
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_UPOWER
|
#ifdef HAVE_UPOWER
|
||||||
#include "modules/upower.hpp"
|
#include "modules/upower/upower.hpp"
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBPULSE
|
#ifdef HAVE_LIBPULSE
|
||||||
#include "modules/pulseaudio.hpp"
|
#include "modules/pulseaudio.hpp"
|
||||||
|
@ -19,9 +19,9 @@ class UPower : public AModule {
|
|||||||
~UPower();
|
~UPower();
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
|
|
||||||
private:
|
|
||||||
typedef std::unordered_map<std::string, UpDevice *> Devices;
|
typedef std::unordered_map<std::string, UpDevice *> Devices;
|
||||||
|
|
||||||
|
private:
|
||||||
static void deviceAdded_cb(UpClient *client, UpDevice *device, gpointer data);
|
static void deviceAdded_cb(UpClient *client, UpDevice *device, gpointer data);
|
||||||
static void deviceRemoved_cb(UpClient *client, const gchar *objectPath, gpointer data);
|
static void deviceRemoved_cb(UpClient *client, const gchar *objectPath, gpointer data);
|
||||||
static void deviceNotify_cb(UpDevice *device, GParamSpec *pspec, gpointer user_data);
|
static void deviceNotify_cb(UpDevice *device, GParamSpec *pspec, gpointer user_data);
|
||||||
@ -30,9 +30,10 @@ class UPower : public AModule {
|
|||||||
const gchar *signal_name, GVariant *parameters,
|
const gchar *signal_name, GVariant *parameters,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
void removeDevice(const gchar *objectPath);
|
void removeDevice(const gchar *objectPath);
|
||||||
void addDevice(UpDevice *device, bool lockMutex = true);
|
void addDevice(UpDevice *device);
|
||||||
void setDisplayDevice();
|
void setDisplayDevice();
|
||||||
void resetDevices();
|
void resetDevices();
|
||||||
|
void removeDevices();
|
||||||
|
|
||||||
Gtk::Box box_;
|
Gtk::Box box_;
|
||||||
Gtk::Image icon_;
|
Gtk::Image icon_;
|
@ -206,7 +206,7 @@ endif
|
|||||||
|
|
||||||
if (upower_glib.found() and giounix.found() and not get_option('logind').disabled())
|
if (upower_glib.found() and giounix.found() and not get_option('logind').disabled())
|
||||||
add_project_arguments('-DHAVE_UPOWER', language: 'cpp')
|
add_project_arguments('-DHAVE_UPOWER', language: 'cpp')
|
||||||
src_files += 'src/modules/upower.cpp'
|
src_files += 'src/modules/upower/upower.cpp'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if libpulse.found()
|
if libpulse.found()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "modules/upower.hpp"
|
#include "modules/upower/upower.hpp"
|
||||||
|
|
||||||
#include "gtkmm/icontheme.h"
|
#include "gtkmm/icontheme.h"
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ void UPower::removeDevice(const gchar* objectPath) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UPower::addDevice(UpDevice* device, bool lockMutex) {
|
void UPower::addDevice(UpDevice* device) {
|
||||||
if (G_IS_OBJECT(device)) {
|
if (G_IS_OBJECT(device)) {
|
||||||
const gchar* objectPath = up_device_get_object_path(device);
|
const gchar* objectPath = up_device_get_object_path(device);
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ void UPower::addDevice(UpDevice* device, bool lockMutex) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lockMutex) std::lock_guard<std::mutex> guard(m_Mutex);
|
std::lock_guard<std::mutex> guard(m_Mutex);
|
||||||
|
|
||||||
if (devices.find(objectPath) != devices.end()) {
|
if (devices.find(objectPath) != devices.end()) {
|
||||||
UpDevice* device = devices[objectPath];
|
UpDevice* device = devices[objectPath];
|
||||||
@ -144,10 +144,8 @@ void UPower::setDisplayDevice() {
|
|||||||
g_signal_connect(displayDevice, "notify", G_CALLBACK(deviceNotify_cb), this);
|
g_signal_connect(displayDevice, "notify", G_CALLBACK(deviceNotify_cb), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Removes all devices and adds the current devices */
|
void UPower::removeDevices() {
|
||||||
void UPower::resetDevices() {
|
|
||||||
std::lock_guard<std::mutex> guard(m_Mutex);
|
std::lock_guard<std::mutex> guard(m_Mutex);
|
||||||
// Removes all devices
|
|
||||||
if (!devices.empty()) {
|
if (!devices.empty()) {
|
||||||
auto it = devices.cbegin();
|
auto it = devices.cbegin();
|
||||||
while (it != devices.cend()) {
|
while (it != devices.cend()) {
|
||||||
@ -157,12 +155,18 @@ void UPower::resetDevices() {
|
|||||||
devices.erase(it++);
|
devices.erase(it++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes all devices and adds the current devices */
|
||||||
|
void UPower::resetDevices() {
|
||||||
|
// Removes all devices
|
||||||
|
removeDevices();
|
||||||
|
|
||||||
// Adds all devices
|
// Adds all devices
|
||||||
GPtrArray* newDevices = up_client_get_devices2(client);
|
GPtrArray* newDevices = up_client_get_devices2(client);
|
||||||
for (guint i = 0; i < newDevices->len; i++) {
|
for (guint i = 0; i < newDevices->len; i++) {
|
||||||
UpDevice* device = (UpDevice*)g_ptr_array_index(newDevices, i);
|
UpDevice* device = (UpDevice*)g_ptr_array_index(newDevices, i);
|
||||||
if (device) addDevice(device, false);
|
if (device && G_IS_OBJECT(device)) addDevice(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the widget
|
// Update the widget
|
||||||
@ -209,6 +213,17 @@ auto UPower::update() -> void {
|
|||||||
event_box_.set_visible(true);
|
event_box_.set_visible(true);
|
||||||
|
|
||||||
// TODO: Tooltip
|
// TODO: Tooltip
|
||||||
|
if (!devices.empty()) {
|
||||||
|
for (auto& e : devices) {
|
||||||
|
const gchar* objectPath = up_device_get_object_path(e.second);
|
||||||
|
double percentage;
|
||||||
|
g_object_get(e.second, "percentage", &percentage, NULL);
|
||||||
|
printf("Device: %s, VALID: %f\n", objectPath, percentage);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("No devices\n");
|
||||||
|
}
|
||||||
|
// box_.set_tooltip
|
||||||
|
|
||||||
// Set percentage
|
// Set percentage
|
||||||
if (displayDeviceValid) {
|
if (displayDeviceValid) {
|
Loading…
Reference in New Issue
Block a user