Skip to content

Commit

Permalink
Watch for local.org_kde_powerdevil dbus service to come online
Browse files Browse the repository at this point in the history
Before we were just checking once at launch which meant if the service wasn't up by that time, we weren't able to control brightness on KDE.
Now we watch when it comes online and offline.
  • Loading branch information
jmanc3 committed Oct 3, 2021
1 parent f735e12 commit 24323aa
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/simple_dbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ bool registered_object_path = false;
*
*************************************************/

static double max_kde_brightness = 0;

void remove_service(const std::string &service) {
for (int i = 0; i < running_dbus_services.size(); i++) {
if (running_dbus_services[i] == service) {
if (running_dbus_services[i] == "local.org_kde_powerdevil")
max_kde_brightness = 0;
running_dbus_services.erase(running_dbus_services.begin() + i);
return;
}
Expand All @@ -48,6 +51,8 @@ void remove_service(const std::string &service) {

DBusHandlerResult handle_message_cb(DBusConnection *connection, DBusMessage *message, void *userdata);

static bool dbus_kde_max_brightness();

static DBusHandlerResult signal_handler(DBusConnection *connection,
DBusMessage *message, void *user_data) {
if (dbus_message_is_signal(message, "org.freedesktop.DBus",
Expand All @@ -67,6 +72,8 @@ static DBusHandlerResult signal_handler(DBusConnection *connection,

if (strcmp(old_owner, "") == 0) {
running_dbus_services.emplace_back(name);
if (std::string(name) == "local.org_kde_powerdevil")
dbus_kde_max_brightness();
} else if (strcmp(new_owner, "") == 0) {
remove_service(name);
}
Expand Down Expand Up @@ -140,6 +147,8 @@ static void dbus_reply_to_list_names_request(DBusPendingCall *call, void *data)
//
for (char *name = *args; name; name = *++args) {
running_dbus_services.emplace_back(name);
if (std::string(name) == "local.org_kde_powerdevil")
dbus_kde_max_brightness();
}

// Register some signals that we are interested in hearing about "NameOwnerChanged", "NameAcquired", "NameLost"
Expand Down Expand Up @@ -337,8 +346,6 @@ bool dbus_gnome_show_overview() {
return true;
}

static double max_kde_brightness = 0;

static void dbus_kde_max_brightness_response(DBusPendingCall *call, void *data) {
#ifdef TRACY_ENABLE
ZoneScoped;
Expand All @@ -355,7 +362,7 @@ static void dbus_kde_max_brightness_response(DBusPendingCall *call, void *data)
}
}

bool dbus_kde_max_brightness() {
static bool dbus_kde_max_brightness() {
if (!dbus_connection) return false;

DBusMessage *dbus_msg = dbus_message_new_method_call("local.org_kde_powerdevil", "/org/kde/Solid/PowerManagement/Actions/BrightnessControl",
Expand Down Expand Up @@ -385,7 +392,7 @@ double dbus_get_kde_max_brightness() {
}

double dbus_get_kde_current_brightness() {
if (!dbus_connection) return false;
if (!dbus_connection) return 0;

DBusMessage *dbus_msg = dbus_message_new_method_call("local.org_kde_powerdevil", "/org/kde/Solid/PowerManagement/Actions/BrightnessControl",
"org.kde.Solid.PowerManagement.Actions.BrightnessControl",
Expand Down Expand Up @@ -750,8 +757,6 @@ void dbus_start() {

dbus_poll_wakeup(nullptr, 0);
}

dbus_kde_max_brightness();
}

void dbus_end() {
Expand Down

0 comments on commit 24323aa

Please sign in to comment.