/* Host UI input: compile with only the public header and sqs_map dynamic library. */
#include "sqs_map.h"
#include <stdio.h>
#include <string.h>
int main(void) {
    if (!(sqsm_map_runtime_flags() & SQSM_MAP_POINTER_INPUT)) return 2;
    sqsm_map_t map = 0;
    sqsm_map_bytes_t event = {NULL, 0, 0}, notices = {NULL, 0, 0};
    if (sqsm_map_create(128, 96, &map) != SQSM_MAP_OK) return 3;
    /* A real UI calls this on the creation thread with logical viewport pixels. */
    const char *input = "{\"type\":\"click\",\"point\":{\"x\":64,\"y\":48},\"shiftKey\":true}";
    int status = sqsm_map_pointer_json(map, (const uint8_t *)input, strlen(input), &event);
    if (status == SQSM_MAP_OK) {
        fwrite(event.data, 1, (size_t)event.len, stdout);
        sqsm_map_bytes_free(event.allocation);
        status = sqsm_map_poll_events_json(map, &notices);
        if (status == SQSM_MAP_OK) sqsm_map_bytes_free(notices.allocation);
    }
    sqsm_map_destroy(map);
    return status == SQSM_MAP_OK ? 0 : 1;
}
