WIP refacto keyboard.c

This commit is contained in:
Stacy Harper 2021-08-26 09:16:47 +02:00 committed by John Sullivan
parent ff92a92086
commit e73316bd7c
5 changed files with 41 additions and 37 deletions

View File

@ -9,7 +9,7 @@ PKGS = wayland-client xkbcommon pangocairo
WVKBD_SOURCES += $(wildcard $(SRC)/*.c)
WVKBD_HEADERS += $(wildcard $(SRC)/*.h)
CFLAGS += -std=gnu99 -Wall -g -DWITH_WAYLAND_SHM -DLAYOUT=\"layout.${LAYOUT}.h\"
CFLAGS += -std=gnu99 -Wall -g -DWITH_WAYLAND_SHM -DLAYOUT=\"layout.${LAYOUT}.h\" -DKEYMAP=\"keymap.${LAYOUT}.h\"
CFLAGS += $(shell pkg-config --cflags $(PKGS))
LDFLAGS =$(shell pkg-config --libs $(PKGS)) -lm -lutil -lrt

View File

@ -3,5 +3,31 @@
static const char *default_font = "Monospace 15";
struct clr_scheme scheme = {
/* colors */
.bg = {.bgra = {15, 15, 15, 225}},
.fg = {.bgra = {45, 45, 45, 225}},
.high = {.bgra = {100, 100, 100, 225}},
.text = {.color = UINT32_MAX},
};
struct clr_scheme scheme1 = {
/* colors */
.bg = {.bgra = {15, 15, 15, 225}},
.fg = {.bgra = {32, 32, 32, 225}},
.high = {.bgra = {100, 100, 100, 225}},
.text = {.color = UINT32_MAX},
};
/* layers is an ordered list of layouts, used to cycle through */
static enum layout_id layers[] = {
Full, //First layout is the default layout on startup
Special,
Emoji,
Simple,
Cyrillic,
Arabic,
NumLayouts //signals the last item, may not be omitted
};
#endif // config_def_h_INCLUDED

View File

@ -13,6 +13,11 @@
fprintf(stderr, __VA_ARGS__); \
exit(1)
#ifndef KEYMAP
#error "make sure to define KEYMAP"
#endif
#include KEYMAP
void
kbd_switch_layout(struct kbd *kb, struct layout *l) {
kb->prevlayout = kb->layout;

View File

@ -9,8 +9,6 @@
/* spacing between keys */
#define KBD_KEY_BORDER 2
#include "keymap.mobintl.h"
/* layout declarations */
enum layout_id {
Full = 0,
@ -61,17 +59,6 @@ enum layout_id {
NumLayouts,
};
/* layers is an ordered list of layouts, used to cycle through */
static enum layout_id layers[] = {
Full, //First layout is the default layout on startup
Special,
Emoji,
Simple,
Cyrillic,
Arabic,
NumLayouts //signals the last item, may not be omitted
};
static struct key keys_full[], keys_special[], keys_simple[], keys_cyrillic[],
keys_arabic[],
keys_emoji[],
@ -138,28 +125,6 @@ static struct layout layouts[NumLayouts] = {
};
/* keyboard settings */
static struct kbd keyboard = {
/* default layout */
.layers = (enum layout_id *) &layers,
.layer_index = 0,
.scheme =
{
/* colors */
.bg = {.bgra = {15, 15, 15, 225}},
.fg = {.bgra = {45, 45, 45, 225}},
.high = {.bgra = {100, 100, 100, 225}},
.text = {.color = UINT32_MAX},
},
.scheme1 =
{
/* colors */
.bg = {.bgra = {15, 15, 15, 225}},
.fg = {.bgra = {32, 32, 32, 225}},
.high = {.bgra = {100, 100, 100, 225}},
.text = {.color = UINT32_MAX},
},
};
/* key layouts
*

10
main.c
View File

@ -8,7 +8,6 @@
#include <wayland-client.h>
#include <wchar.h>
#include "drw.h"
#include "keyboard.h"
#include "config.h"
@ -42,6 +41,7 @@ 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 struct kbd keyboard;
/* event handler prototypes */
static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
@ -333,6 +333,14 @@ main(int argc, char **argv) {
if ((tmp = getenv("WVKBD_HEIGHT")))
height = atoi(tmp);
/* keyboard settings */
keyboard.layers = (enum layout_id *) &layers;
keyboard.scheme = scheme;
keyboard.layer_index = 0;
keyboard.scheme1 = scheme1;
keyboard.scheme1 = scheme1;
int i;
for (i = 1; argv[i]; i++) {
if ((!strcmp(argv[i], "-v")) || (!strcmp(argv[i], "--version"))) {