diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 17:08:48 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 17:08:48 +0300 |
| commit | ac6f9f5e7711521455b83ceb843a25e091646d43 (patch) | |
| tree | 0dfd5fc46a605cd4980ef3c9131ddbaa2270c78a /tests/common/test_desktop.c | |
| parent | d4d13e616cb15ef22479d9cb97922af93317a01a (diff) | |
Report the system double-click interval
wsap_term hardcodes 400 ms in three places to count clicks.
yasl_display_double_click_ms() reads the interval from the system. X11
parses Net/DoubleClickTime from the XSETTINGS owner's property. Wayland
has no protocol for it, so it asks the Settings portal for KDE's
DoubleClickInterval, which KDE sends as a string and which exists only
when the user set it, then GNOME's double-click. X11 without XSETTINGS
asks the portal too. Cocoa reads NSEvent.doubleClickInterval. Missing or
implausible values give YASL_DOUBLE_CLICK_MS_DEFAULT, 400 ms.
The X11 state test covers the XSETTINGS parser in both byte orders and
with truncation. The Xwayland test owns the settings selection. The
desktop test serves both portal keys. The Cocoa path is not built or run
here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/common/test_desktop.c')
| -rw-r--r-- | tests/common/test_desktop.c | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/tests/common/test_desktop.c b/tests/common/test_desktop.c index f65a9cd..89760fe 100644 --- a/tests/common/test_desktop.c +++ b/tests/common/test_desktop.c @@ -1,5 +1,6 @@ #define _GNU_SOURCE #include "common/backend.h" +#include "platform/freedesktop/dbus.h" #include "yasl/desktop.h" #include <assert.h> @@ -142,6 +143,8 @@ static void test_open_uri(const char *dir) static void test_appearance_fallback(void) { + assert(yasl_display_double_click_ms(NULL) == YASL_DOUBLE_CLICK_MS_DEFAULT); + assert(portal_double_click_ms() == 0); struct yasl_display display = {0}; assert(yasl_display_appearance(NULL) == 0); unsetenv("GTK_THEME"); @@ -160,6 +163,8 @@ static void test_appearance_fallback(void) } #if YASL_HAS_DBUS +static dbus_int32_t fake_slot = -1; + /* A fake notification server and Settings portal on a private bus. */ struct fake_bus { DBusConnection *conn; @@ -167,6 +172,7 @@ struct fake_bus { char app[64], title[64], body[64], entry[64]; int notifications; bool read_one; + bool kde; _Atomic bool stop; }; @@ -175,14 +181,28 @@ static void reply_setting(DBusConnection *c, DBusMessage *msg, bool nested) const char *ns = NULL, *key = NULL; dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &ns, DBUS_TYPE_STRING, &key, DBUS_TYPE_INVALID); - dbus_uint32_t value; - if (ns && key && strcmp(ns, "org.freedesktop.appearance") == 0 && - strcmp(key, "color-scheme") == 0) { - value = 1; - } else if (ns && key && strcmp(ns, "org.freedesktop.appearance") == 0 && - strcmp(key, "contrast") == 0) { - value = 1; + struct fake_bus *fb = dbus_connection_get_data(c, fake_slot); + dbus_uint32_t value = 1; + dbus_int32_t gnome_ms = 333; + const char *kde_ms = "250"; + int type = DBUS_TYPE_UINT32; + const void *data = &value; + if (!ns || !key) { + type = DBUS_TYPE_INVALID; + } else if (strcmp(ns, "org.freedesktop.appearance") == 0 && + (strcmp(key, "color-scheme") == 0 || strcmp(key, "contrast") == 0)) { + } else if (strcmp(ns, "org.gnome.desktop.peripherals.mouse") == 0 && + strcmp(key, "double-click") == 0) { + type = DBUS_TYPE_INT32; + data = &gnome_ms; + } else if (fb->kde && strcmp(ns, "org.kde.kdeglobals.KDE") == 0 && + strcmp(key, "DoubleClickInterval") == 0) { + type = DBUS_TYPE_STRING; + data = &kde_ms; } else { + type = DBUS_TYPE_INVALID; + } + if (type == DBUS_TYPE_INVALID) { DBusMessage *err = dbus_message_new_error(msg, "org.freedesktop.portal.Error.NotFound", "Requested setting not found"); dbus_connection_send(c, err, NULL); @@ -191,16 +211,17 @@ static void reply_setting(DBusConnection *c, DBusMessage *msg, bool nested) } DBusMessage *reply = dbus_message_new_method_return(msg); DBusMessageIter it, outer, inner; + const char signature[2] = {(char)type, '\0'}; dbus_message_iter_init_append(reply, &it); if (nested) { dbus_message_iter_open_container(&it, DBUS_TYPE_VARIANT, "v", &outer); - dbus_message_iter_open_container(&outer, DBUS_TYPE_VARIANT, "u", &inner); - dbus_message_iter_append_basic(&inner, DBUS_TYPE_UINT32, &value); + dbus_message_iter_open_container(&outer, DBUS_TYPE_VARIANT, signature, &inner); + dbus_message_iter_append_basic(&inner, type, data); dbus_message_iter_close_container(&outer, &inner); dbus_message_iter_close_container(&it, &outer); } else { - dbus_message_iter_open_container(&it, DBUS_TYPE_VARIANT, "u", &outer); - dbus_message_iter_append_basic(&outer, DBUS_TYPE_UINT32, &value); + dbus_message_iter_open_container(&it, DBUS_TYPE_VARIANT, signature, &outer); + dbus_message_iter_append_basic(&outer, type, data); dbus_message_iter_close_container(&it, &outer); } dbus_connection_send(c, reply, NULL); @@ -280,6 +301,8 @@ static void test_bus(const char *address) pthread_mutex_init(&fb.lock, NULL); fb.conn = dbus_connection_open_private(address, &err); assert(fb.conn && dbus_bus_register(fb.conn, &err)); + assert(dbus_connection_allocate_data_slot(&fake_slot)); + assert(dbus_connection_set_data(fb.conn, fake_slot, &fb, NULL)); assert(dbus_bus_request_name(fb.conn, "org.freedesktop.Notifications", 0, &err) == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER); assert(dbus_bus_request_name(fb.conn, "org.freedesktop.portal.Desktop", 0, &err) == @@ -311,10 +334,18 @@ static void test_bus(const char *address) assert(yasl_display_appearance(&display) == want); unsetenv("GTK_THEME"); + /* A KDE value, sent as a string, wins over the GNOME key. */ + assert(portal_double_click_ms() == 333); + fb.kde = true; + assert(portal_double_click_ms() == 250); + fb.read_one = true; + assert(portal_double_click_ms() == 250); + fb.stop = true; pthread_join(thread, NULL); dbus_connection_close(fb.conn); dbus_connection_unref(fb.conn); + dbus_connection_free_data_slot(&fake_slot); pthread_mutex_destroy(&fb.lock); } #endif |
