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;
}
+25
View File
@@ -0,0 +1,25 @@
#include <assert.h>
#include <stdio.h>
#include "grid.h"
int main(void) {
grid_t g;
grid_init(&g, 4, 4);
assert(grid_get(&g, 0, 0) == 0);
grid_set(&g, 1, 2, 1);
assert(grid_get(&g, 1, 2) == 1);
assert(grid_get(&g, -1, 0) == 0);
assert(grid_get(&g, 4, 4) == 0);
grid_set(&g, 0, 0, 1);
grid_resize(&g, 6, 2);
assert(grid_get(&g, 0, 0) == 1);
assert(grid_get(&g, 1, 2) == 0);
grid_clear(&g);
assert(grid_get(&g, 0, 0) == 0);
grid_free(&g);
printf("grid tests passed\n");
return 0;
}
+28
View File
@@ -0,0 +1,28 @@
#include <assert.h>
#include <stdio.h>
#include "pattern.h"
int main(void) {
assert(pattern_count() == 4);
const void *p = pattern_get(0);
(void)p;
int dx[16], dy[16];
int n = pattern_rotated_offsets(0, 0, dx, dy);
assert(n == 5);
int w, h;
pattern_bounds(0, 1, &w, &h);
assert(w == 3 && h == 3);
int dx2[16], dy2[16];
pattern_rotated_offsets(0, 1, dx2, dy2);
int same = 1;
for (int i = 0; i < n; i++) {
if (dx[i] != dx2[i] || dy[i] != dy2[i]) same = 0;
}
assert(!same);
printf("pattern tests passed\n");
return 0;
}