mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2025-04-15 13:26:49 +02:00
ran make format
This commit is contained in:
parent
878b16b997
commit
07f153fe32
52
keyboard.h
52
keyboard.h
@ -42,16 +42,19 @@ struct key {
|
||||
const double width; // relative width (1.0)
|
||||
const enum key_type type;
|
||||
|
||||
const uint32_t code; /* code: key scancode or modifier name (see
|
||||
const uint32_t
|
||||
code; /* code: key scancode or modifier name (see
|
||||
* `/usr/include/linux/input-event-codes.h` for scancode names, and
|
||||
* `keyboard.h` for modifiers)
|
||||
* XKB keycodes are +8 */
|
||||
struct layout *layout; //pointer back to the parent layout that holds this key
|
||||
struct layout *layout; // pointer back to the parent layout that holds this
|
||||
// key
|
||||
const uint32_t code_mod; /* modifier to force when this key is pressed */
|
||||
uint8_t scheme; // index of the scheme to use
|
||||
bool reset_mod; /* reset modifiers when clicked */
|
||||
|
||||
//actual coordinates on the surface (pixels), will be computed automatically for all keys
|
||||
// actual coordinates on the surface (pixels), will be computed automatically
|
||||
// for all keys
|
||||
uint32_t x, y, w, h;
|
||||
};
|
||||
|
||||
@ -85,11 +88,13 @@ static void kbd_unpress_key(struct kbd *kb, uint32_t time);
|
||||
static void kbd_press_key(struct kbd *kb, struct key *k, uint32_t time);
|
||||
static void kbd_draw_key(struct kbd *kb, struct key *k, bool pressed);
|
||||
static void kbd_draw_layout(struct kbd *kb);
|
||||
static void kbd_resize(struct kbd *kb, uint32_t w, uint32_t h, struct layout * layouts, uint8_t layoutcount);
|
||||
static void kbd_resize(struct kbd *kb, uint32_t w, uint32_t h,
|
||||
struct layout *layouts, uint8_t layoutcount);
|
||||
static uint8_t kbd_get_rows(struct layout *l);
|
||||
static double kbd_get_row_length(struct key *k);
|
||||
|
||||
uint8_t kbd_get_rows(struct layout *l) {
|
||||
uint8_t
|
||||
kbd_get_rows(struct layout *l) {
|
||||
uint8_t rows = 0;
|
||||
struct key *k = l->keys;
|
||||
while (k->type != Last) {
|
||||
@ -119,7 +124,8 @@ kbd_init_layout(struct layout *l, uint32_t width, uint32_t height) {
|
||||
} else if (k->width > 0) {
|
||||
k->x = x;
|
||||
k->y = y;
|
||||
fprintf(stderr, "(%d/%f)*%f -> %s\n",width,rowlength,k->width, k->label);
|
||||
fprintf(stderr, "(%d/%f)*%f -> %s\n", width, rowlength, k->width,
|
||||
k->label);
|
||||
k->w = ((double)width / rowlength) * k->width;
|
||||
x += k->w;
|
||||
}
|
||||
@ -144,7 +150,8 @@ kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y) {
|
||||
struct key *k = l->keys;
|
||||
fprintf(stderr, "get key: +%d+%d\n", x, y);
|
||||
while (k->type != Last) {
|
||||
if ((k->type != EndRow) && (k->type != Pad) && (k->type != Pad) && (x >= k->x) && (y >= k->y) && (x < k->x + k->w) && (y < k->y + k->h)) {
|
||||
if ((k->type != EndRow) && (k->type != Pad) && (k->type != Pad) &&
|
||||
(x >= k->x) && (y >= k->y) && (x < k->x + k->w) && (y < k->y + k->h)) {
|
||||
return k;
|
||||
}
|
||||
k++;
|
||||
@ -167,14 +174,15 @@ kbd_unpress_key(struct kbd *kb, uint32_t time) {
|
||||
}
|
||||
kb->last_press = NULL;
|
||||
|
||||
|
||||
if (compose >= 2) {
|
||||
compose = 0;
|
||||
if ((!kb->prevlayout) || (strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
|
||||
if ((!kb->prevlayout) ||
|
||||
(strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
|
||||
create_and_upload_keymap(kb->layout->keymap_name, 0, 0);
|
||||
}
|
||||
kb->layout = kb->prevlayout;
|
||||
if ((kb->mods & Shift) == Shift) kb->mods ^= Shift;
|
||||
if ((kb->mods & Shift) == Shift)
|
||||
kb->mods ^= Shift;
|
||||
kbd_draw_layout(kb);
|
||||
} else if ((kb->mods & Shift) == Shift) {
|
||||
kb->mods ^= Shift;
|
||||
@ -185,10 +193,12 @@ kbd_unpress_key(struct kbd *kb, uint32_t time) {
|
||||
|
||||
void
|
||||
kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
||||
if ((compose == 1) && (k->type != Compose) && (k->type != Mod) && (k->layout)) {
|
||||
if ((compose == 1) && (k->type != Compose) && (k->type != Mod) &&
|
||||
(k->layout)) {
|
||||
compose++;
|
||||
fprintf(stderr, "showing compose %d\n", compose);
|
||||
if ((!kb->prevlayout) || (strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
|
||||
if ((!kb->prevlayout) ||
|
||||
(strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
|
||||
create_and_upload_keymap(kb->layout->keymap_name, 0, 0);
|
||||
}
|
||||
kb->prevlayout = kb->layout;
|
||||
@ -204,7 +214,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
||||
if (k->reset_mod) {
|
||||
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, k->code_mod, 0, 0, 0);
|
||||
} else {
|
||||
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods ^ k->code_mod, 0, 0, 0);
|
||||
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods ^ k->code_mod, 0,
|
||||
0, 0);
|
||||
}
|
||||
} else {
|
||||
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0);
|
||||
@ -236,7 +247,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
||||
break;
|
||||
case Layout:
|
||||
kb->layout = k->layout;
|
||||
if ((!kb->prevlayout) || (strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
|
||||
if ((!kb->prevlayout) ||
|
||||
(strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
|
||||
fprintf(stderr, "Switching to keymap %s\n", kb->layout->keymap_name);
|
||||
create_and_upload_keymap(kb->layout->keymap_name, 0, 0);
|
||||
}
|
||||
@ -262,14 +274,15 @@ void
|
||||
kbd_draw_key(struct kbd *kb, struct key *k, bool pressed) {
|
||||
struct drwsurf *d = kb->surf;
|
||||
const char *label = (kb->mods & Shift) ? k->shift_label : k->label;
|
||||
fprintf(stderr, "Draw key +%d+%d %dx%d -> %s\n", k->x, k->y, k->w, k->h, k->label);
|
||||
fprintf(stderr, "Draw key +%d+%d %dx%d -> %s\n", k->x, k->y, k->w, k->h,
|
||||
k->label);
|
||||
struct clr_scheme *scheme = (k->scheme == 0) ? &(kb->scheme) : &(kb->scheme1);
|
||||
Color *fill = pressed ? &scheme->high : &scheme->fg;
|
||||
draw_inset(d, k->x, k->y, k->w, k->h, KBD_KEY_BORDER, fill->color);
|
||||
uint32_t xoffset = k->w / (strlen(label) + 2);
|
||||
fprintf(stderr, " xoffset=%d\n", xoffset);
|
||||
wld_draw_text(d->render, d->ctx->font, scheme->text.color,
|
||||
k->x + xoffset, k->y + (k->h / 2), label, -1, NULL);
|
||||
wld_draw_text(d->render, d->ctx->font, scheme->text.color, k->x + xoffset,
|
||||
k->y + (k->h / 2), label, -1, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
@ -293,7 +306,8 @@ kbd_draw_layout(struct kbd *kb) {
|
||||
}
|
||||
|
||||
void
|
||||
kbd_resize(struct kbd *kb, uint32_t w, uint32_t h, struct layout * layouts, uint8_t layoutcount) {
|
||||
kbd_resize(struct kbd *kb, uint32_t w, uint32_t h, struct layout *layouts,
|
||||
uint8_t layoutcount) {
|
||||
struct drwsurf *d = kb->surf;
|
||||
|
||||
kb->w = w;
|
||||
@ -316,5 +330,3 @@ draw_inset(struct drwsurf *d, uint32_t x, uint32_t y, uint32_t width,
|
||||
wld_fill_rectangle(d->render, color, x + border, y + border, width - border,
|
||||
height - border);
|
||||
}
|
||||
|
||||
|
||||
|
9
keymap.h
9
keymap.h
@ -1,4 +1,5 @@
|
||||
static const char * get_keymap(const char * name, uint32_t comp_unichr, uint32_t comp_shift_unichr) {
|
||||
static const char *
|
||||
get_keymap(const char *name, uint32_t comp_unichr, uint32_t comp_shift_unichr) {
|
||||
char *keymap = malloc(65000);
|
||||
if (strcmp(name, "latin") == 0) {
|
||||
sprintf(keymap, "xkb_keymap {\
|
||||
@ -1463,7 +1464,8 @@ xkb_symbols \"(unnamed)\" {\
|
||||
};\
|
||||
\
|
||||
};\
|
||||
", comp_unichr, comp_shift_unichr);
|
||||
",
|
||||
comp_unichr, comp_shift_unichr);
|
||||
return keymap;
|
||||
} else if (strcmp("name", "cyrillic")) {
|
||||
sprintf(keymap, "xkb_keymap {\
|
||||
@ -2927,7 +2929,8 @@ xkb_symbols \"(unnamed)\" {\
|
||||
};\
|
||||
\
|
||||
};\
|
||||
", comp_unichr, comp_shift_unichr);
|
||||
",
|
||||
comp_unichr, comp_shift_unichr);
|
||||
return keymap;
|
||||
} else {
|
||||
fprintf(stderr, "No such keymap: %s", name);
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include "keyboard.h"
|
||||
|
||||
|
||||
/* font (see `man fonts-conf` for instructions) */
|
||||
static const char *fc_font_pattern =
|
||||
"Monospace:size=16:antialias=true:hinting=true";
|
||||
@ -64,49 +63,18 @@ enum layout_names {
|
||||
NumLayouts,
|
||||
};
|
||||
|
||||
static struct key keys_full[],
|
||||
keys_special[],
|
||||
keys_simple[],
|
||||
keys_cyrillic[],
|
||||
keys_compose_a[],
|
||||
keys_compose_e[],
|
||||
keys_compose_y[],
|
||||
keys_compose_u[],
|
||||
keys_compose_i[],
|
||||
keys_compose_o[],
|
||||
keys_compose_q[],
|
||||
keys_compose_w[],
|
||||
keys_compose_r[],
|
||||
keys_compose_t[],
|
||||
keys_compose_p[],
|
||||
keys_compose_s[],
|
||||
keys_compose_d[],
|
||||
keys_compose_f[],
|
||||
keys_compose_g[],
|
||||
keys_compose_h[],
|
||||
keys_compose_j[],
|
||||
keys_compose_k[],
|
||||
keys_compose_l[],
|
||||
keys_compose_z[],
|
||||
keys_compose_x[],
|
||||
keys_compose_c[],
|
||||
keys_compose_v[],
|
||||
keys_compose_b[],
|
||||
keys_compose_n[],
|
||||
keys_compose_m[],
|
||||
keys_compose_math[],
|
||||
keys_compose_punctuation[],
|
||||
keys_compose_bracket[],
|
||||
keys_compose_cyr_i[],
|
||||
keys_compose_cyr_j[],
|
||||
keys_compose_cyr_e[],
|
||||
keys_compose_cyr_u[],
|
||||
keys_compose_cyr_l[],
|
||||
keys_compose_cyr_n[],
|
||||
keys_compose_cyr_tse[],
|
||||
keys_compose_cyr_che[],
|
||||
keys_compose_cyr_g[],
|
||||
keys_compose_cyr_k[];
|
||||
static struct key keys_full[], keys_special[], keys_simple[], keys_cyrillic[],
|
||||
keys_compose_a[], keys_compose_e[], keys_compose_y[], keys_compose_u[],
|
||||
keys_compose_i[], keys_compose_o[], keys_compose_q[], keys_compose_w[],
|
||||
keys_compose_r[], keys_compose_t[], keys_compose_p[], keys_compose_s[],
|
||||
keys_compose_d[], keys_compose_f[], keys_compose_g[], keys_compose_h[],
|
||||
keys_compose_j[], keys_compose_k[], keys_compose_l[], keys_compose_z[],
|
||||
keys_compose_x[], keys_compose_c[], keys_compose_v[], keys_compose_b[],
|
||||
keys_compose_n[], keys_compose_m[], keys_compose_math[],
|
||||
keys_compose_punctuation[], keys_compose_bracket[], keys_compose_cyr_i[],
|
||||
keys_compose_cyr_j[], keys_compose_cyr_e[], keys_compose_cyr_u[],
|
||||
keys_compose_cyr_l[], keys_compose_cyr_n[], keys_compose_cyr_tse[],
|
||||
keys_compose_cyr_che[], keys_compose_cyr_g[], keys_compose_cyr_k[];
|
||||
|
||||
static struct layout layouts[NumLayouts] = {
|
||||
[Full] = {keys_full, "latin"}, // third parameter is the keymap name
|
||||
@ -156,7 +124,6 @@ static struct layout layouts[NumLayouts] = {
|
||||
|
||||
const enum layout_names DefaultLayout = Full;
|
||||
|
||||
|
||||
/* keyboard settings */
|
||||
static struct kbd keyboard = {
|
||||
/* default layout */
|
||||
@ -278,7 +245,6 @@ static struct key keys_full[] = {
|
||||
{".", "?", 1.0, Code, KEY_DOT},
|
||||
{"Entr", "Entr", 2.0, Code, KEY_ENTER, .scheme = 1},
|
||||
|
||||
|
||||
/* end of layout */
|
||||
{"", "", 0.0, Last},
|
||||
};
|
||||
@ -332,7 +298,8 @@ static struct key keys_special[] = {
|
||||
{"⌫", "⌫", 1.0, Code, KEY_BACKSPACE, .scheme = 1},
|
||||
{"", "", 0.0, EndRow},
|
||||
|
||||
{"Abc", "Abc", 1.0, Layout, 0, &layouts[(DefaultLayout == Simple) ? Full : Simple] , .scheme=1},
|
||||
{"Abc", "Abc", 1.0, Layout, 0,
|
||||
&layouts[(DefaultLayout == Simple) ? Full : Simple], .scheme = 1},
|
||||
{"Alt", "Alt", 1.0, Mod, Alt, .scheme = 1},
|
||||
{",", "'", 1.0, Code, KEY_COMMA},
|
||||
{"", "", 4.0, Code, KEY_SPACE},
|
||||
@ -381,7 +348,8 @@ static struct key keys_simple[] = {
|
||||
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
|
||||
{"", "", 0.0, EndRow},
|
||||
|
||||
{"Abc", "Abc", 1.0, Layout, 0, &layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme=1 },
|
||||
{"Abc", "Abc", 1.0, Layout, 0,
|
||||
&layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme = 1},
|
||||
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
|
||||
{",", "'", 1.0, Code, KEY_COMMA, &layouts[ComposeMath]},
|
||||
{"", "", 4.0, Code, KEY_SPACE},
|
||||
@ -447,14 +415,14 @@ static struct key keys_cyrillic[] = {
|
||||
|
||||
{"", "", 0.0, EndRow},
|
||||
|
||||
{"Abc", "Abc", 1.0, Layout, 0, &layouts[(DefaultLayout == Cyrillic) ? Full : DefaultLayout] , .scheme=1},
|
||||
{"Abc", "Abc", 1.0, Layout, 0,
|
||||
&layouts[(DefaultLayout == Cyrillic) ? Full : DefaultLayout], .scheme = 1},
|
||||
{"Cmp", "Cmp", 1.0, Compose, .scheme = 1},
|
||||
{",", "'", 1.0, Code, KEY_EQUAL},
|
||||
{"", "", 4.0, Code, KEY_SPACE},
|
||||
{".", "?", 1.0, Code, KEY_SLASH},
|
||||
{"Entr", "Entr", 2.0, Code, KEY_ENTER, .scheme = 1},
|
||||
|
||||
|
||||
/* end of layout */
|
||||
{"", "", 0.0, Last},
|
||||
};
|
||||
@ -662,7 +630,6 @@ static struct key keys_compose_q[] = {
|
||||
{"", "", 0.0, Last},
|
||||
};
|
||||
|
||||
|
||||
static struct key keys_compose_w[] = {
|
||||
{"ŵ", "Ŵ", 1.0, Copy, 0x0175, 0, 0x0174},
|
||||
{"", "", 9.0, Pad},
|
||||
@ -746,7 +713,6 @@ static struct key keys_compose_p[] = {
|
||||
{"", "", 0.0, Last},
|
||||
};
|
||||
|
||||
|
||||
static struct key keys_compose_s[] = {
|
||||
{"ś", "Ś", 1.0, Copy, 0x015B, 0, 0x015A},
|
||||
{"ŝ", "Ŝ", 1.0, Copy, 0x015D, 0, 0x015C},
|
||||
@ -1136,7 +1102,6 @@ static struct key keys_compose_cyr_u[] = {
|
||||
{"", "", 0.0, Last},
|
||||
};
|
||||
|
||||
|
||||
static struct key keys_compose_cyr_l[] = {
|
||||
{"љ", "Љ", 1.0, Copy, 0x0459, 0, 0x0409},
|
||||
{"", "", 9.0, Pad},
|
||||
@ -1270,7 +1235,8 @@ static struct key keys_compose_math[] = {
|
||||
{"_", "_", 1, Code, KEY_MINUS, 0, Shift},
|
||||
{"", "", 2, Pad},
|
||||
{"", "", 0.0, EndRow},
|
||||
{"Abc", "Abc", 1.0, Layout, 0, &layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme=1 },
|
||||
{"Abc", "Abc", 1.0, Layout, 0,
|
||||
&layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme = 1},
|
||||
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
|
||||
{",", "'", 1.0, Code, KEY_COMMA, &layouts[ComposeMath]},
|
||||
{"", "", 4.0, Code, KEY_SPACE},
|
||||
@ -1300,7 +1266,8 @@ static struct key keys_compose_punctuation[] = {
|
||||
{",", ",", 1, Code, KEY_COMMA},
|
||||
{"", "", 2, Pad},
|
||||
{"", "", 0.0, EndRow},
|
||||
{"Abc", "Abc", 1.0, Layout, 0, &layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme=1 },
|
||||
{"Abc", "Abc", 1.0, Layout, 0,
|
||||
&layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme = 1},
|
||||
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
|
||||
{",", "'", 1.0, Code, KEY_COMMA, &layouts[ComposeMath]},
|
||||
{"", "", 4.0, Code, KEY_SPACE},
|
||||
@ -1326,7 +1293,8 @@ static struct key keys_compose_bracket[] = {
|
||||
{"⇧", "⇧", 2, Mod, Shift, .scheme = 1},
|
||||
{"", "", 8, Pad},
|
||||
{"", "", 0.0, EndRow},
|
||||
{"Abc", "Abc", 1.0, Layout, 0, &layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme=1 },
|
||||
{"Abc", "Abc", 1.0, Layout, 0,
|
||||
&layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme = 1},
|
||||
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
|
||||
{",", "'", 1.0, Code, KEY_COMMA, &layouts[ComposeMath]},
|
||||
{"", "", 4.0, Code, KEY_SPACE},
|
||||
|
8
main.c
8
main.c
@ -6,9 +6,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <sys/mman.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include "drw.h"
|
||||
#include "keymap.h"
|
||||
@ -94,7 +94,8 @@ 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);
|
||||
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 = {
|
||||
@ -277,7 +278,8 @@ layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) {
|
||||
}
|
||||
|
||||
void
|
||||
create_and_upload_keymap(const char * name, uint32_t comp_unichr, uint32_t comp_shift_unichr) {
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user