From f510c10a03c1b5835f36481bd5383192e2eecf79 Mon Sep 17 00:00:00 2001 From: brainpower Date: Thu, 17 Feb 2022 18:40:21 +0100 Subject: [PATCH] autodetect correct kded touchpad module plasma 5.24 renamed the "touchpad" kded module to "kded_touchpad". fix this by listing all loaded modules in kded and look for the correct module name to use. Otherwise it would try to use the wrong one, fail to initialize, and not re-enable the touchpad after resuming after suspend leaving the user with an unusable touchpad and no easy way to enable it. This now also gives an error message and exits, if no touchpad module is loaded. Fixes: #9 --- setup-kde.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/setup-kde.cpp b/setup-kde.cpp index 903096f..609a233 100644 --- a/setup-kde.cpp +++ b/setup-kde.cpp @@ -160,12 +160,55 @@ static int kded5_modules_touchpad_init(GDBusProxy *proxy) { int setup_kde(int lockfile_arg) { lockfile = lockfile_arg; - + const char *object_path = NULL; + + GDBusProxy *kded5 = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, NULL, + "org.kde.kded5", + "/kded", + "org.kde.kded5", + NULL, NULL); + if (kded5 == NULL) { + cerr << "main(...): g_dbus_proxy_new_for_bus_sync(...) failed." << endl; + return EXIT_FAILURE; + } + GVariant *loadedModulesParam = g_dbus_proxy_call_sync(kded5, "loadedModules", NULL, G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, NULL); + if (loadedModulesParam != NULL && g_variant_is_of_type(loadedModulesParam, (const GVariantType *)"(as)") && g_variant_n_children(loadedModulesParam) ) { + GVariant *loadedModules = g_variant_get_child_value(loadedModulesParam, 0); + GVariantIter *iter; + gchar *str; + + g_variant_get(loadedModules, "as", &iter); + while (g_variant_iter_loop(iter, "s", &str)) { + if (strcmp(str, "kded_touchpad") == 0) { + object_path = "/modules/kded_touchpad"; + break; // break is fine here, we dont need to free unpacked strings + } + if (strcmp(str, "touchpad") == 0) { + object_path = "/modules/touchpad"; + break; // break is fine here, we dont need to free unpacked strings + } + } + + g_variant_iter_free(iter); + g_variant_unref(loadedModules); + g_variant_unref(loadedModulesParam); + } else { + g_object_unref(kded5); // not needed anymore + cerr << "main(...): g_dbus_proxy_call_sync(...) failed." << endl; + return EXIT_FAILURE; + } + g_object_unref(kded5); // not needed anymore + if (object_path == NULL) { + cerr << "main(...): Could not find touchpad module in kded. Is it disabled?" << endl; + return EXIT_FAILURE; + } + // sync on config and xsession change GDBusProxy *kded5_modules_touchpad = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.kde.kded5", - "/modules/touchpad", + object_path, "org.kde.touchpad", NULL, NULL); if (kded5_modules_touchpad == NULL) {