Add Plasma 6 support

master
Werner Sembach 6 months ago
parent edf029bbd0
commit 87487eb7a6

@ -31,22 +31,22 @@ using std::endl;
int lockfile; int lockfile;
gboolean isMousePluggedInPrev; gboolean isMousePluggedInPrev;
gboolean isEnabledSave; gboolean isEnabledSave;
GDBusProxy *kded5_modules_touchpad = NULL; GDBusProxy *kded_modules_touchpad = NULL;
GDBusProxy *solid_power_management = 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) { static void kded_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)) { if (!strcmp("enabledChanged", signal_name) && g_variant_is_of_type(parameters, (const GVariantType *)"(b)") && g_variant_n_children(parameters)) {
GVariant *enabledChanged = g_variant_get_child_value(parameters, 0); GVariant *enabledChanged = g_variant_get_child_value(parameters, 0);
isEnabledSave = g_variant_get_boolean(enabledChanged); isEnabledSave = g_variant_get_boolean(enabledChanged);
if (isEnabledSave) { if (isEnabledSave) {
if (set_touchpad_state(1)) { if (set_touchpad_state(1)) {
cerr << "kded5_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl;
} }
} }
else { else {
if (set_touchpad_state(0)) { if (set_touchpad_state(0)) {
cerr << "kded5_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl;
} }
} }
g_variant_unref(enabledChanged); g_variant_unref(enabledChanged);
@ -57,18 +57,18 @@ static void kded5_modules_touchpad_handler(GDBusProxy *proxy, __attribute__((unu
GVariant *isMousePluggedIn = g_variant_get_child_value(isMousePluggedInParam, 0); GVariant *isMousePluggedIn = g_variant_get_child_value(isMousePluggedInParam, 0);
if (isMousePluggedInPrev && !g_variant_get_boolean(isMousePluggedIn)) { if (isMousePluggedInPrev && !g_variant_get_boolean(isMousePluggedIn)) {
if (set_touchpad_state(1)) { if (set_touchpad_state(1)) {
cerr << "kded5_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl;
} }
if (flock(lockfile, LOCK_UN)) { if (flock(lockfile, LOCK_UN)) {
cerr << "kded5_modules_touchpad_handler(...): flock(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): flock(...) failed." << endl;
} }
} }
else if (!isMousePluggedInPrev && g_variant_get_boolean(isMousePluggedIn)) { else if (!isMousePluggedInPrev && g_variant_get_boolean(isMousePluggedIn)) {
if (flock(lockfile, LOCK_EX)) { if (flock(lockfile, LOCK_EX)) {
cerr << "kded5_modules_touchpad_handler(...): flock(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): flock(...) failed." << endl;
} }
if (set_touchpad_state(isEnabledSave)) { if (set_touchpad_state(isEnabledSave)) {
cerr << "kded5_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl;
} }
} }
isMousePluggedInPrev = g_variant_get_boolean(isMousePluggedIn); isMousePluggedInPrev = g_variant_get_boolean(isMousePluggedIn);
@ -76,7 +76,7 @@ static void kded5_modules_touchpad_handler(GDBusProxy *proxy, __attribute__((unu
g_variant_unref(isMousePluggedInParam); g_variant_unref(isMousePluggedInParam);
} }
else { else {
cerr << "kded5_modules_touchpad_handler(...): g_dbus_proxy_call_sync(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): g_dbus_proxy_call_sync(...) failed." << endl;
} }
} }
} }
@ -84,23 +84,23 @@ static void kded5_modules_touchpad_handler(GDBusProxy *proxy, __attribute__((unu
static void solid_power_management_handler(__attribute__((unused)) GDBusProxy *proxy, __attribute__((unused)) char *sender_name, char *signal_name, __attribute__((unused)) GVariant *parameters, __attribute__((unused)) gpointer user_data) { static void solid_power_management_handler(__attribute__((unused)) GDBusProxy *proxy, __attribute__((unused)) char *sender_name, char *signal_name, __attribute__((unused)) GVariant *parameters, __attribute__((unused)) gpointer user_data) {
if (!strcmp("aboutToSuspend", signal_name)) { if (!strcmp("aboutToSuspend", signal_name)) {
if (set_touchpad_state(1)) { if (set_touchpad_state(1)) {
cerr << "kded5_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl;
} }
if (flock(lockfile, LOCK_UN)) { if (flock(lockfile, LOCK_UN)) {
cerr << "kded5_modules_touchpad_handler(...): flock(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): flock(...) failed." << endl;
} }
} }
else if (!strcmp("resumingFromSuspend", signal_name)) { else if (!strcmp("resumingFromSuspend", signal_name)) {
if (flock(lockfile, LOCK_EX)) { if (flock(lockfile, LOCK_EX)) {
cerr << "kded5_modules_touchpad_handler(...): flock(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): flock(...) failed." << endl;
} }
if (set_touchpad_state(isEnabledSave)) { if (set_touchpad_state(isEnabledSave)) {
cerr << "kded5_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl;
} }
} }
} }
static int kded5_modules_touchpad_init(GDBusProxy *proxy) { static int kded_modules_touchpad_init(GDBusProxy *proxy) {
GVariant *isEnabledParam = g_dbus_proxy_call_sync(proxy, "isEnabled", NULL, G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, NULL); GVariant *isEnabledParam = g_dbus_proxy_call_sync(proxy, "isEnabled", NULL, G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, NULL);
if (isEnabledParam != NULL && g_variant_is_of_type(isEnabledParam, (const GVariantType *)"(b)") && g_variant_n_children(isEnabledParam)) { if (isEnabledParam != NULL && g_variant_is_of_type(isEnabledParam, (const GVariantType *)"(b)") && g_variant_n_children(isEnabledParam)) {
GVariant *isEnabled = g_variant_get_child_value(isEnabledParam, 0); GVariant *isEnabled = g_variant_get_child_value(isEnabledParam, 0);
@ -109,13 +109,13 @@ static int kded5_modules_touchpad_init(GDBusProxy *proxy) {
isEnabledSave = g_variant_get_boolean(isEnabled); isEnabledSave = g_variant_get_boolean(isEnabled);
if (isEnabledSave) { if (isEnabledSave) {
if (set_touchpad_state(1)) { if (set_touchpad_state(1)) {
cerr << "kded5_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
else { else {
if (set_touchpad_state(0)) { if (set_touchpad_state(0)) {
cerr << "kded5_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
@ -124,7 +124,7 @@ static int kded5_modules_touchpad_init(GDBusProxy *proxy) {
g_variant_unref(isEnabledParam); g_variant_unref(isEnabledParam);
} }
else { else {
cerr << "kded5_modules_touchpad_handler(...): g_dbus_proxy_call_sync(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): g_dbus_proxy_call_sync(...) failed." << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -138,11 +138,11 @@ static int kded5_modules_touchpad_init(GDBusProxy *proxy) {
// isMousePluggedInPrev just got init so it holds the current value // isMousePluggedInPrev just got init so it holds the current value
if (!isMousePluggedInPrev) { if (!isMousePluggedInPrev) {
if (set_touchpad_state(1)) { if (set_touchpad_state(1)) {
cerr << "kded5_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): set_touchpad_state(...) failed." << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (flock(lockfile, LOCK_UN)) { if (flock(lockfile, LOCK_UN)) {
cerr << "kded5_modules_touchpad_handler(...): flock(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): flock(...) failed." << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
@ -151,7 +151,7 @@ static int kded5_modules_touchpad_init(GDBusProxy *proxy) {
g_variant_unref(isMousePluggedInParam); g_variant_unref(isMousePluggedInParam);
} }
else { else {
cerr << "kded5_modules_touchpad_handler(...): g_dbus_proxy_call_sync(...) failed." << endl; cerr << "kded_modules_touchpad_handler(...): g_dbus_proxy_call_sync(...) failed." << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -160,65 +160,59 @@ static int kded5_modules_touchpad_init(GDBusProxy *proxy) {
int setup_kde(int lockfile_arg) { int setup_kde(int lockfile_arg) {
lockfile = lockfile_arg; lockfile = lockfile_arg;
const char *object_path = NULL;
kded_modules_touchpad = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
GDBusProxy *kded5 = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL,
G_DBUS_PROXY_FLAGS_NONE, NULL, "org.kde.kded6",
"org.kde.kded5", "/modules/kded_touchpad",
"/kded", "org.kde.touchpad",
"org.kde.kded5", NULL, NULL);
NULL, NULL); // call a random method to check if object exists
if (kded5 == NULL) { GVariant *isMousePluggedInParam = g_dbus_proxy_call_sync(kded_modules_touchpad,
cerr << "setup_kde(...): g_dbus_proxy_new_for_bus_sync(...) failed." << endl; "isMousePluggedIn",
return EXIT_FAILURE; NULL, G_DBUS_CALL_FLAGS_NONE,
} G_MAXINT, NULL, NULL);
GVariant *loadedModulesParam = g_dbus_proxy_call_sync(kded5, "loadedModules", NULL, G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, NULL); if (isMousePluggedInParam == NULL) {
if (loadedModulesParam != NULL && g_variant_is_of_type(loadedModulesParam, (const GVariantType *)"(as)") && g_variant_n_children(loadedModulesParam) ) { g_object_unref(kded_modules_touchpad);
GVariant *loadedModules = g_variant_get_child_value(loadedModulesParam, 0); g_variant_unref(isMousePluggedInParam);
GVariantIter *iter; kded_modules_touchpad = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
gchar *str; G_DBUS_PROXY_FLAGS_NONE, NULL,
"org.kde.kded5",
g_variant_get(loadedModules, "as", &iter); "/modules/kded_touchpad",
while (g_variant_iter_loop(iter, "s", &str)) { "org.kde.touchpad",
if (strcmp(str, "kded_touchpad") == 0) { NULL, NULL);
object_path = "/modules/kded_touchpad"; // call a random method to check if object exists
g_free(str); // g_variant_iter_loop needs freeing when break is used isMousePluggedInParam = g_dbus_proxy_call_sync(kded_modules_touchpad,
break; "isMousePluggedIn",
} NULL, G_DBUS_CALL_FLAGS_NONE,
if (strcmp(str, "touchpad") == 0) { G_MAXINT, NULL, NULL);
object_path = "/modules/touchpad"; if (isMousePluggedInParam == NULL) {
g_free(str); // g_variant_iter_loop needs freeing when break is used g_object_unref(kded_modules_touchpad);
break; g_variant_unref(isMousePluggedInParam);
kded_modules_touchpad = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE, NULL,
"org.kde.kded5",
"/modules/touchpad",
"org.kde.touchpad",
NULL, NULL);
// call a random method to check if object exists
isMousePluggedInParam = g_dbus_proxy_call_sync(kded_modules_touchpad,
"isMousePluggedIn",
NULL, G_DBUS_CALL_FLAGS_NONE,
G_MAXINT, NULL, NULL);
if (isMousePluggedInParam == NULL) {
g_clear_object(&kded_modules_touchpad);
g_variant_unref(isMousePluggedInParam);
cerr << "setup_kde(...): g_dbus_proxy_new_for_bus_sync(...) failed." << endl;
return EXIT_FAILURE;
} }
} }
g_variant_iter_free(iter);
g_variant_unref(loadedModules);
g_variant_unref(loadedModulesParam);
} else {
g_object_unref(kded5); // not needed anymore
cerr << "setup_kde(...): g_dbus_proxy_call_sync(...) failed." << endl;
return EXIT_FAILURE;
}
g_object_unref(kded5); // not needed anymore
if (object_path == NULL) {
cerr << "setup_kde(...): Could not find touchpad module in kded." << endl;
return EXIT_FAILURE;
} }
g_variant_unref(isMousePluggedInParam);
// sync on config and xsession change if (g_signal_connect(kded_modules_touchpad, "g-signal", G_CALLBACK(kded_modules_touchpad_handler), NULL) < 1) {
kded5_modules_touchpad = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE, NULL,
"org.kde.kded5",
object_path,
"org.kde.touchpad",
NULL, NULL);
if (kded5_modules_touchpad == NULL) {
cerr << "setup_kde(...): g_dbus_proxy_new_for_bus_sync(...) failed." << endl;
return EXIT_FAILURE;
}
if (g_signal_connect(kded5_modules_touchpad, "g-signal", G_CALLBACK(kded5_modules_touchpad_handler), NULL) < 1) {
cerr << "setup_kde(...): g_signal_connect(...) failed." << endl; cerr << "setup_kde(...): g_signal_connect(...) failed." << endl;
g_clear_object(&kded_modules_touchpad);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -231,16 +225,19 @@ int setup_kde(int lockfile_arg) {
NULL, NULL); NULL, NULL);
if (solid_power_management == NULL) { if (solid_power_management == NULL) {
cerr << "setup_kde(...): g_dbus_proxy_new_for_bus_sync(...) failed." << endl; cerr << "setup_kde(...): g_dbus_proxy_new_for_bus_sync(...) failed." << endl;
g_clear_object(&kded_modules_touchpad);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (g_signal_connect(solid_power_management, "g-signal", G_CALLBACK(solid_power_management_handler), NULL) < 1) { if (g_signal_connect(solid_power_management, "g-signal", G_CALLBACK(solid_power_management_handler), NULL) < 1) {
cerr << "setup_kde(...): g_signal_connect(...) failed." << endl; cerr << "setup_kde(...): g_signal_connect(...) failed." << endl;
clean_kde();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// sync on start // sync on start
if (kded5_modules_touchpad_init(kded5_modules_touchpad) == EXIT_FAILURE) { if (kded_modules_touchpad_init(kded_modules_touchpad) == EXIT_FAILURE) {
cerr << "setup_kde(...): kded5_modules_touchpad_init(...) failed." << endl; cerr << "setup_kde(...): kded_modules_touchpad_init(...) failed." << endl;
clean_kde();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -248,6 +245,6 @@ int setup_kde(int lockfile_arg) {
} }
void clean_kde() { void clean_kde() {
g_clear_object(&kded5_modules_touchpad); g_clear_object(&kded_modules_touchpad);
g_clear_object(&solid_power_management); g_clear_object(&solid_power_management);
} }

@ -32,7 +32,6 @@
#include <libudev.h> #include <libudev.h>
using std::cout;
using std::cerr; using std::cerr;
using std::endl; using std::endl;
@ -141,7 +140,7 @@ int set_touchpad_state(int enabled) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (touchpad_count == 0) { if (touchpad_count == 0) {
cout << "No compatible touchpads found." << endl; cerr << "No compatible touchpads found." << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }

Loading…
Cancel
Save