diff --git a/setup-gnome.cpp b/setup-gnome.cpp index c8b2553..7588176 100644 --- a/setup-gnome.cpp +++ b/setup-gnome.cpp @@ -28,7 +28,10 @@ using std::cerr; using std::endl; -static int lockfile = -1; +static int lockfile; +static GSettings *touchpad_settings = NULL; +static GDBusProxy *session_manager_properties = NULL; +static GDBusProxy *display_config_properties = NULL; static void send_events_handler(GSettings *settings, const char* key, __attribute__((unused)) gpointer user_data) { const gchar *send_events_string = g_settings_get_string(settings, key); @@ -90,7 +93,7 @@ int setup_gnome(int lockfile_arg) { lockfile = lockfile_arg; // get a new glib settings context to read the touchpad configuration of the current user - GSettings *touchpad_settings = g_settings_new("org.gnome.desktop.peripherals.touchpad"); + touchpad_settings = g_settings_new("org.gnome.desktop.peripherals.touchpad"); if (!touchpad_settings) { cerr << "main(...): g_settings_new(...) failed." << endl; return EXIT_FAILURE; @@ -140,3 +143,9 @@ int setup_gnome(int lockfile_arg) { return EXIT_SUCCESS; } + +void clean_gnome() { + g_clear_object(&session_manager_properties); + g_clear_object(&display_config_properties); + g_clear_object(&touchpad_settings); +} diff --git a/setup-gnome.h b/setup-gnome.h index deeee2d..2df16ce 100644 --- a/setup-gnome.h +++ b/setup-gnome.h @@ -18,3 +18,4 @@ #pragma once int setup_gnome(int lockfile); +void clean_gnome(); diff --git a/setup-kde.cpp b/setup-kde.cpp index 0a029fb..903096f 100644 --- a/setup-kde.cpp +++ b/setup-kde.cpp @@ -31,6 +31,8 @@ using std::endl; int lockfile; gboolean isMousePluggedInPrev; gboolean isEnabledSave; +GDBusProxy *kded5_modules_touchpad = NULL; +GDBusProxy *solid_power_management = NULL; static void kded5_modules_touchpad_handler(GDBusProxy *proxy, __attribute__((unused)) char *sender_name, char *signal_name, GVariant *parameters, __attribute__((unused)) gpointer user_data) { if (!strcmp("enabledChanged", signal_name) && g_variant_is_of_type(parameters, (const GVariantType *)"(b)") && g_variant_n_children(parameters)) { @@ -53,7 +55,7 @@ static void kded5_modules_touchpad_handler(GDBusProxy *proxy, __attribute__((unu GVariant *isMousePluggedInParam = g_dbus_proxy_call_sync(proxy, "isMousePluggedIn", NULL, G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, NULL); if (isMousePluggedInParam != NULL && g_variant_is_of_type(isMousePluggedInParam, (const GVariantType *)"(b)") && g_variant_n_children(isMousePluggedInParam)) { GVariant *isMousePluggedIn = g_variant_get_child_value(isMousePluggedInParam, 0); - if (!g_variant_get_boolean(isMousePluggedIn)) { + if (isMousePluggedInPrev && !g_variant_get_boolean(isMousePluggedIn)) { if (set_touchpad_state(1)) { cerr << "kded5_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl; } @@ -61,7 +63,7 @@ static void kded5_modules_touchpad_handler(GDBusProxy *proxy, __attribute__((unu cerr << "kded5_modules_touchpad_handler(...): flock(...) failed." << endl; } } - else if (!isMousePluggedInPrev) { + else if (!isMousePluggedInPrev && g_variant_get_boolean(isMousePluggedIn)) { if (flock(lockfile, LOCK_EX)) { cerr << "kded5_modules_touchpad_handler(...): flock(...) failed." << endl; } @@ -199,3 +201,8 @@ int setup_kde(int lockfile_arg) { return EXIT_SUCCESS; } + +void clean_kde() { + g_clear_object(&kded5_modules_touchpad); + g_clear_object(&solid_power_management); +} diff --git a/setup-kde.h b/setup-kde.h index e95e6a5..e89ba04 100644 --- a/setup-kde.h +++ b/setup-kde.h @@ -18,3 +18,4 @@ #pragma once int setup_kde(int lockfile); +void clean_kde(); diff --git a/tuxedo-touchpad-switch.cpp b/tuxedo-touchpad-switch.cpp index fe35252..6ada49c 100644 --- a/tuxedo-touchpad-switch.cpp +++ b/tuxedo-touchpad-switch.cpp @@ -38,6 +38,10 @@ static int lockfile = -1; static void gracefull_exit(int signum = 0) { int result = EXIT_SUCCESS; + + clean_gnome(); + clean_kde(); + if (signum < 0) { result = EXIT_FAILURE; } @@ -108,6 +112,7 @@ int main() { g_main_loop_run(app); // g_main_loop_run only returns on error + g_clear_object(&app); cerr << "main(...): g_main_loop_run(...) failed." << endl; gracefull_exit(-EXIT_FAILURE); }