mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2025-07-13 14:34:36 +02:00
WIP: refactorise keyboard.c
This commit is contained in:
committed by
John Sullivan
parent
5fb98bd005
commit
b5ec768822
34
main.c
34
main.c
@ -9,7 +9,8 @@
|
||||
#include <wchar.h>
|
||||
|
||||
#include "drw.h"
|
||||
#include "os-compatibility.h"
|
||||
#include "keyboard.h"
|
||||
#include "config.h"
|
||||
|
||||
/* lazy die macro */
|
||||
#define die(...) \
|
||||
@ -41,7 +42,6 @@ static uint32_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM |
|
||||
/* application state */
|
||||
static bool run_display = true;
|
||||
static int cur_x = -1, cur_y = -1;
|
||||
static int compose = 0;
|
||||
|
||||
/* event handler prototypes */
|
||||
static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
|
||||
@ -88,8 +88,6 @@ static void layer_surface_configure(void *data,
|
||||
uint32_t serial, uint32_t w, uint32_t h);
|
||||
static void layer_surface_closed(void *data,
|
||||
struct zwlr_layer_surface_v1 *surface);
|
||||
static void create_and_upload_keymap(const char *name, uint32_t comp_unichr,
|
||||
uint32_t comp_shift_unichr);
|
||||
|
||||
/* event handlers */
|
||||
static const struct wl_pointer_listener pointer_listener = {
|
||||
@ -124,13 +122,7 @@ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
|
||||
.closed = layer_surface_closed,
|
||||
};
|
||||
|
||||
bool debug = false;
|
||||
|
||||
/* configuration, allows nested code to access above variables */
|
||||
#ifndef LAYOUT
|
||||
#error "make sure to define LAYOUT"
|
||||
#endif
|
||||
#include LAYOUT
|
||||
|
||||
char *
|
||||
estrdup(const char *s)
|
||||
@ -316,26 +308,6 @@ layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) {
|
||||
run_display = false;
|
||||
}
|
||||
|
||||
void
|
||||
create_and_upload_keymap(const char *name, uint32_t comp_unichr,
|
||||
uint32_t comp_shift_unichr) {
|
||||
const char *keymap_str = get_keymap(name, comp_unichr, comp_shift_unichr);
|
||||
size_t keymap_size = strlen(keymap_str) + 1;
|
||||
int keymap_fd = os_create_anonymous_file(keymap_size);
|
||||
if (keymap_fd < 0) {
|
||||
die("could not create keymap fd\n");
|
||||
}
|
||||
void *ptr =
|
||||
mmap(NULL, keymap_size, PROT_READ | PROT_WRITE, MAP_SHARED, keymap_fd, 0);
|
||||
if (ptr == (void *)-1) {
|
||||
die("could not map keymap data\n");
|
||||
}
|
||||
strcpy(ptr, keymap_str);
|
||||
zwp_virtual_keyboard_v1_keymap(
|
||||
keyboard.vkbd, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymap_fd, keymap_size);
|
||||
free((void *)keymap_str);
|
||||
}
|
||||
|
||||
void
|
||||
usage(char *argv0)
|
||||
{
|
||||
@ -384,7 +356,7 @@ main(int argc, char **argv) {
|
||||
}
|
||||
height = atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-D")) {
|
||||
debug = true;
|
||||
keyboard.debug = true;
|
||||
} else if ((!strcmp(argv[i], "-fn")) || (!strcmp(argv[i], "--fn"))) {
|
||||
fc_font_pattern = estrdup(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-o")) {
|
||||
|
Reference in New Issue
Block a user