feat: implement keyboard and mouse input, pattern placement, and HiDPI scaling

Add configurable key bindings (TOML), modifier-aware dispatch, mouse-driven
pattern placement with preview and rotation, cell grid storage/rendering,
and fractional/integer HiDPI scaling. Archive the input-and-placement change
and sync its specs to main specs.

Tests: Hashtable, Config, Grid, Pattern (4/4 pass).
This commit is contained in:
2026-11-08 14:46:04 +01:00
parent 5e7abfb56b
commit 7874a5f7c6
31 changed files with 4081 additions and 96 deletions
+49
View File
@@ -0,0 +1,49 @@
#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);
assert(config_lookup(&cfg, 0, one) == ACTION_SELECT_GLIDER);
assert(config_lookup(&cfg, 0, space) == ACTION_ROTATE);
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;
}