Change setting on xsession switch

pull/3/head
Werner Sembach 4 years ago
parent 085b4d9bb6
commit a59369fe43

@ -145,6 +145,25 @@ void send_events_handler(GSettings *settings, const char* key, __attribute__((un
}
}
void properties_changed_handler(__attribute__((unused)) GDBusProxy *proxy, GVariant *changed_properties, __attribute__((unused)) GStrv invalidated_properties, __attribute__((unused)) gpointer user_data) {
if (g_variant_is_of_type(changed_properties, G_VARIANT_TYPE_VARDICT)) {
GVariantDict changed_properties_dict;
gboolean sessionIsActive;
g_variant_dict_init (&changed_properties_dict, changed_properties);
if (g_variant_dict_lookup (&changed_properties_dict, "SessionIsActive", "b", &sessionIsActive)) {
if (sessionIsActive) {
GSettings *touchpad_settings = g_settings_new("org.gnome.desktop.peripherals.touchpad");
if (!touchpad_settings) {
cerr << "properties_changed_handler(...): g_settings_new(...) failed." << endl;
return;
}
send_events_handler(touchpad_settings, "send-events", NULL);
}
}
}
}
int main() {
// Currently this programm works on desktop environments using Gnome settings only (Gnome/Budgie/Cinnamon/etc.).
// A KDE configuration version will be developt once this works flawless.
@ -158,26 +177,43 @@ int main() {
return EXIT_FAILURE;
}
// sync on config change
if (g_signal_connect(touchpad_settings, "changed::send-events", G_CALLBACK(send_events_handler), NULL) < 1) {
cerr << "main(...): g_signal_connect(...) failed." << endl;
return EXIT_FAILURE;
}
// sync on start
send_events_handler(touchpad_settings, "send-events", NULL);
// TODO sync on xsession change
// sync on xsession change
GDBusProxy *session_manager_properties = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager", NULL, NULL);
if (session_manager_properties == NULL) {
cerr << "main(...): g_dbus_proxy_new_for_bus_sync(...) failed." << endl;
return EXIT_FAILURE;
}
if (g_signal_connect(session_manager_properties, "g-properties-changed", G_CALLBACK(properties_changed_handler), NULL) < 1) {
cerr << "main(...): g_signal_connect(...) failed." << endl;
g_object_unref(session_manager_properties);
return EXIT_FAILURE;
}
// start empty glib mainloop, required for glib signals to be catched
GMainLoop *app = g_main_loop_new(NULL, TRUE);
if (!app) {
cerr << "main(...): g_main_loop_new(...) failed." << endl;
g_object_unref(session_manager_properties);
return EXIT_FAILURE;
}
g_main_loop_run(app);
// g_main_loop_run should not return
cerr << "main(...): g_main_loop_run(...) failed." << endl;
g_object_unref(session_manager_properties);
return EXIT_FAILURE;
}

Loading…
Cancel
Save