Files
wlgol/tests/test_config.c
T
arek d20f4d5481 fix(input): honor pointer entry position and make clear work
Pointer enter ignored the surface position, so the pattern preview
rendered at a stale cell until the first motion event. The clear
action only printed a message and toggle_grid had no default key
binding, leaving both unreachable without a hand-written config.

Set the cursor position from the enter event, implement clear via
grid_clear plus a dirty flag, and add g/c default bindings in both
the built-in table and the generated config template. Also defer
wl_buffer destruction on resize until the compositor releases it,
route pointer motion through a handler hook instead of reading
pointer_data directly, and clean up dead code (show_lines, unused
ternary, unchecked ftruncate, unfreed grid buffers). Fixes a
wl_callback proxy leak from frame-callback overwrite. Syncs the
keyboard-bindings and display-scaling specs and archives the
fix-review-findings change.
2026-11-11 18:04:50 +01:00

53 lines
1.7 KiB
C

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <xkbcommon/xkbcommon.h>
#include "config.h"
int main(void) {
uint32_t mods;
char *key = NULL;
assert(config_parse_mods("ctrl+q", &mods, &key) == 0);
assert(mods == MOD_CTRL);
assert(strcmp(key, "q") == 0);
free(key);
assert(config_parse_mods("space", &mods, &key) == 0);
assert(mods == 0);
assert(strcmp(key, "space") == 0);
free(key);
assert(config_parse_action("quit") == ACTION_QUIT);
assert(config_parse_action("select:glider") == ACTION_SELECT_GLIDER);
assert(config_parse_action("nope") == ACTION_NONE);
config_t cfg = config_defaults();
xkb_keysym_t one = xkb_keysym_from_name("1", XKB_KEYSYM_CASE_INSENSITIVE);
xkb_keysym_t space = xkb_keysym_from_name("space", XKB_KEYSYM_CASE_INSENSITIVE);
xkb_keysym_t g = xkb_keysym_from_name("g", XKB_KEYSYM_CASE_INSENSITIVE);
xkb_keysym_t c = xkb_keysym_from_name("c", XKB_KEYSYM_CASE_INSENSITIVE);
assert(config_lookup(&cfg, 0, one) == ACTION_SELECT_GLIDER);
assert(config_lookup(&cfg, 0, space) == ACTION_ROTATE);
assert(config_lookup(&cfg, 0, g) == ACTION_TOGGLE_GRID);
assert(config_lookup(&cfg, 0, c) == ACTION_CLEAR);
const char *path = "/tmp/opencode/test_keys.conf";
FILE *fp = fopen(path, "w");
assert(fp);
fputs("[bindings]\n\"1\" = \"quit\"\n", fp);
fclose(fp);
config_t cfg2 = config_load(path);
assert(config_lookup(&cfg2, 0, one) == ACTION_QUIT);
assert(config_lookup(&cfg2, 0, space) == ACTION_ROTATE);
config_free(&cfg);
config_free(&cfg2);
remove(path);
printf("config tests passed\n");
return 0;
}