initial commit
This commit is contained in:
commit
1c606d0274
36 changed files with 9908 additions and 0 deletions
113
include/ufkbd.h
Normal file
113
include/ufkbd.h
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
/*
|
||||
* Copyright (c) 2024, Richard Acayan. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef UFKBD_H
|
||||
#define UFKBD_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
#define UFKBD_PRESS_MAX 64
|
||||
#define UFKBD_MOD_MAX 4
|
||||
|
||||
struct ufkbd_ctx;
|
||||
struct ufkbd_graphics_ctx;
|
||||
struct ufkbd_graphics_driver;
|
||||
struct ufkbd_input_driver;
|
||||
|
||||
// These correspond to the key0..key8 properties in the layout definitions
|
||||
enum ufkbd_part {
|
||||
UFKBD_PART_CENTER,
|
||||
UFKBD_PART_TL,
|
||||
UFKBD_PART_TR,
|
||||
UFKBD_PART_BL,
|
||||
UFKBD_PART_BR,
|
||||
UFKBD_PART_LEFT,
|
||||
UFKBD_PART_RIGHT,
|
||||
UFKBD_PART_TOP,
|
||||
UFKBD_PART_BOTTOM,
|
||||
UFKBD_PART_MAX
|
||||
};
|
||||
|
||||
enum ufkbd_mod_state {
|
||||
UFKBD_MOD_RELEASED,
|
||||
UFKBD_MOD_PRESSED,
|
||||
UFKBD_MOD_LATCHED,
|
||||
UFKBD_MOD_LOCKED,
|
||||
};
|
||||
|
||||
enum ufkbd_modifier {
|
||||
UFKBD_MOD_SHIFT,
|
||||
UFKBD_MOD_CTRL,
|
||||
UFKBD_MOD_ALT,
|
||||
};
|
||||
|
||||
struct ufkbd_key {
|
||||
// Graphical parameters
|
||||
size_t presses[UFKBD_PART_MAX];
|
||||
void *labels_mask[UFKBD_PART_MAX * 2];
|
||||
void *labels_color[UFKBD_PART_MAX * 2];
|
||||
|
||||
int keyids[UFKBD_PART_MAX];
|
||||
xkb_keysym_t keysyms[UFKBD_PART_MAX];
|
||||
enum ufkbd_part lut[16];
|
||||
int latch_state;
|
||||
};
|
||||
|
||||
struct ufkbd_driver {
|
||||
void *(*init)(struct ufkbd_ctx *ufkbd);
|
||||
void (*uninit)(void *data);
|
||||
|
||||
// Deprecated
|
||||
void (*listen_one)(void *data, bool block);
|
||||
|
||||
void (*listen_step)(void *data, int timeout);
|
||||
int (*send_key)(void *data, int code, bool repeat);
|
||||
int (*send_mod)(void *data, enum ufkbd_modifier mod, bool pressed);
|
||||
|
||||
int (*draw_begin)(void *data, size_t *stride, void **ptr);
|
||||
void (*draw_touch)(void *data, int x, int y, int width, int height);
|
||||
void (*draw_end)(void *data);
|
||||
};
|
||||
|
||||
struct ufkbd_press {
|
||||
struct ufkbd_key *key;
|
||||
int xl, xr, yt, yb;
|
||||
|
||||
struct timespec repeat;
|
||||
|
||||
// Coordinates of starting and ending position of keypress
|
||||
int x1, y1, x2, y2;
|
||||
|
||||
// Cached section of the key that is pressed
|
||||
enum ufkbd_part part;
|
||||
};
|
||||
|
||||
struct ufkbd_ctx {
|
||||
struct ufkbd_keymap *keymap;
|
||||
struct ufkbd_layout *layout;
|
||||
|
||||
struct ufkbd_driver *drv;
|
||||
void *drv_data;
|
||||
|
||||
struct ufkbd_graphics_ctx *graphics;
|
||||
|
||||
// Settings
|
||||
int repeat_delay_ns;
|
||||
int repeat_interval_ns;
|
||||
int dist_squared;
|
||||
|
||||
uint32_t mods[(UFKBD_MOD_MAX + 15) / 16];
|
||||
|
||||
size_t n_presses;
|
||||
struct ufkbd_press presses[UFKBD_PRESS_MAX];
|
||||
|
||||
bool terminate;
|
||||
};
|
||||
|
||||
void ufkbd_terminate(struct ufkbd_ctx *ctx);
|
||||
|
||||
#endif /* UFKBD_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue