initial commit
This commit is contained in:
commit
1c606d0274
36 changed files with 9908 additions and 0 deletions
121
main.c
Normal file
121
main.c
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Copyright (c) 2024, Richard Acayan. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "graphics.h"
|
||||
#include "input.h"
|
||||
#include "layout.h"
|
||||
#include "keymap.h"
|
||||
#include "parser.h"
|
||||
#include "ufkbd.h"
|
||||
|
||||
extern struct ufkbd_input_driver ufkbd_input_wayland;
|
||||
extern struct ufkbd_driver ufkbd_wayland;
|
||||
|
||||
static struct ufkbd_ctx *ufkbd = NULL;
|
||||
|
||||
void ufkbd_terminate(struct ufkbd_ctx *ctx)
|
||||
{
|
||||
if (ctx != NULL)
|
||||
ctx->terminate = true;
|
||||
}
|
||||
|
||||
static void sighandler(int sig)
|
||||
{
|
||||
ufkbd_terminate(ufkbd);
|
||||
}
|
||||
|
||||
static int parse_layout(struct ufkbd_keymap *keymap, struct ufkbd_layout *layout)
|
||||
{
|
||||
int ret, fd;
|
||||
|
||||
fd = open("/usr/share/unfettered-keyboard/layouts", O_DIRECTORY | O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror("layout: failed to open /usr/share/unfettered-keyboard/layouts");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = ufkbd_parser_parse(fd, "latn_qwerty_us.xml", keymap, layout);
|
||||
if (ret) {
|
||||
fprintf(stderr, "layout: failed to parse layout: %s\n",
|
||||
strerror(-ret));
|
||||
return 1;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct ufkbd_ctx *ctx;
|
||||
size_t i;
|
||||
int ret;
|
||||
|
||||
signal(SIGINT, sighandler);
|
||||
signal(SIGTERM, sighandler);
|
||||
|
||||
ctx = calloc(1, sizeof(*ctx));
|
||||
if (ctx == NULL)
|
||||
return 1;
|
||||
|
||||
ufkbd = ctx;
|
||||
|
||||
ctx->keymap = ufkbd_keymap_init();
|
||||
if (ctx->keymap == NULL)
|
||||
return 1;
|
||||
|
||||
ctx->layout = ufkbd_layout_init();
|
||||
if (ctx->layout == NULL)
|
||||
return 1;
|
||||
|
||||
ret = parse_layout(ctx->keymap, ctx->layout);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ufkbd_keymap_end(ctx->keymap);
|
||||
|
||||
ctx->graphics = ufkbd_graphics_init();
|
||||
if (ctx->graphics == NULL)
|
||||
return 1;
|
||||
|
||||
ctx->drv = &ufkbd_wayland;
|
||||
ctx->drv_data = ctx->drv->init(ctx);
|
||||
if (ctx->drv_data == NULL)
|
||||
return 1;
|
||||
|
||||
ctx->repeat_delay_ns = 600000000;
|
||||
ctx->repeat_interval_ns = 25000000;
|
||||
ctx->dist_squared = 1000;
|
||||
|
||||
for (i = 0; i < UFKBD_PRESS_MAX; i++)
|
||||
ctx->presses[i].key = NULL;
|
||||
|
||||
while (!ctx->terminate) {
|
||||
if (ctx->n_presses) {
|
||||
ctx->drv->listen_step(ctx->drv_data, 25);
|
||||
ufkbd_input_repeat_held(ctx);
|
||||
} else {
|
||||
ctx->drv->listen_step(ctx->drv_data, -1);
|
||||
}
|
||||
}
|
||||
|
||||
ctx->drv->uninit(ctx->drv_data);
|
||||
|
||||
ufkbd_graphics_uninit(ctx->graphics);
|
||||
ufkbd_layout_uninit(ctx->layout);
|
||||
ufkbd_keymap_uninit(ctx->keymap);
|
||||
|
||||
free(ctx);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue