summaryrefslogtreecommitdiff
path: root/tests/x11/test_state.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 17:08:48 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 17:08:48 +0300
commitac6f9f5e7711521455b83ceb843a25e091646d43 (patch)
tree0dfd5fc46a605cd4980ef3c9131ddbaa2270c78a /tests/x11/test_state.c
parentd4d13e616cb15ef22479d9cb97922af93317a01a (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/x11/test_state.c')
-rw-r--r--tests/x11/test_state.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/x11/test_state.c b/tests/x11/test_state.c
index abdda95..abc0851 100644
--- a/tests/x11/test_state.c
+++ b/tests/x11/test_state.c
@@ -36,8 +36,63 @@ static void state_changed(struct yasl_surface *surface, uint32_t state, void *ud
notifications++;
}
+/* Build an XSETTINGS blob in either byte order. */
+struct blob {
+ unsigned char bytes[256];
+ size_t len;
+ bool msb;
+};
+
+static void put(struct blob *b, uint32_t v, int size)
+{
+ for (int i = 0; i < size; i++)
+ b->bytes[b->len++] = (unsigned char)(v >> (8 * (b->msb ? size - 1 - i : i)));
+}
+
+static void put_name(struct blob *b, unsigned type, const char *name)
+{
+ size_t n = strlen(name);
+ b->bytes[b->len++] = (unsigned char)type;
+ b->bytes[b->len++] = 0;
+ put(b, (uint32_t)n, 2);
+ memcpy(b->bytes + b->len, name, n);
+ b->len += (n + 3) & ~(size_t)3;
+ put(b, 7, 4); /* Last-change serial. */
+}
+
+static void test_xsettings(void)
+{
+ for (int order = 0; order < 2; order++) {
+ struct blob b = {.msb = order == 1};
+ b.bytes[0] = b.msb ? MSBFirst : LSBFirst;
+ b.len = 4;
+ put(&b, 1, 4);
+ put(&b, 4, 4);
+ put_name(&b, 1, "Net/ThemeName");
+ put(&b, 5, 4);
+ memcpy(b.bytes + b.len, "Adwai", 5);
+ b.len += 8;
+ put_name(&b, 2, "Net/Color");
+ put(&b, 0x1111, 2); put(&b, 0x2222, 2); put(&b, 0x3333, 2); put(&b, 0xffff, 2);
+ put_name(&b, 0, "Net/DoubleClickTimeX");
+ put(&b, 999, 4);
+ put_name(&b, 0, "Net/DoubleClickTime");
+ put(&b, 250, 4);
+
+ int32_t ms = 0;
+ assert(xsettings_int(b.bytes, b.len, "Net/DoubleClickTime", &ms) && ms == 250);
+ assert(!xsettings_int(b.bytes, b.len, "Net/DoubleClick", &ms));
+ /* A string with that name is not an integer setting. */
+ assert(!xsettings_int(b.bytes, b.len, "Net/ThemeName", &ms));
+ /* The value is last, so any truncation fails cleanly. */
+ for (size_t len = 0; len < b.len; len++)
+ assert(!xsettings_int(b.bytes, len, "Net/DoubleClickTime", &ms));
+ }
+}
+
int main(void)
{
+ test_xsettings();
struct x11_display display = {.base.ops = &yasl_x11_backend,
.net_state = 10, .fullscreen = 20, .maximized_h = 21, .maximized_v = 22};
display.native = (Display *)&display;