mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2026-04-09 14:42:30 +02:00
Compare commits
9 Commits
v0.19.1
...
4fd182a583
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fd182a583 | ||
|
|
47dadbee23 | ||
|
|
7b782d8f7d | ||
|
|
e67a5afce9 | ||
|
|
4366d88eca | ||
|
|
1a60d1abed | ||
|
|
49d8a629a5 | ||
|
|
9fb1964f5d | ||
|
|
5b29d8c1a7 |
@@ -6,7 +6,7 @@ packages:
|
||||
- libxkbcommon-dev
|
||||
- pango-dev
|
||||
- scdoc
|
||||
- clang21-extra-tools # needed for formatting
|
||||
- clang22-extra-tools # needed for formatting
|
||||
sources:
|
||||
- https://git.sr.ht/~proycon/wvkbd
|
||||
triggers:
|
||||
|
||||
6
Makefile
6
Makefile
@@ -31,14 +31,12 @@ DOCS = wvkbd.1
|
||||
|
||||
all: ${BIN} ${DOCS}
|
||||
|
||||
$(BUILDDIR):
|
||||
$(BUILDDIR)/config.h:
|
||||
mkdir -p $(BUILDDIR)
|
||||
|
||||
$(BUILDDIR)/config.h: $(BUILDDIR)
|
||||
cp config.$(LAYOUT).h $@
|
||||
|
||||
$(BUILDDIR)/%.o: $(BUILDDIR)
|
||||
$(BUILDDIR)/%.o: %.c
|
||||
mkdir -p $(BUILDDIR)
|
||||
$(CC) -I $(CURDIR) -I $(CURDIR)/$(BUILDDIR) -c $(CFLAGS) -o $@ $<
|
||||
|
||||
proto/%-client-protocol.c: proto/%.xml
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
VERSION = 0.19.1
|
||||
VERSION = 0.20
|
||||
CFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=700
|
||||
PREFIX = /usr/local
|
||||
MANPREFIX = ${PREFIX}/share/man
|
||||
|
||||
@@ -14,6 +14,8 @@ struct clr_scheme schemes[] = {
|
||||
.high = {.bgra = {100, 100, 100, transparency}},
|
||||
.swipe = {.bgra = {100, 255, 100, 64}},
|
||||
.text = {.color = UINT32_MAX},
|
||||
.text_press = {.color = UINT32_MAX},
|
||||
.text_swipe = {.color = UINT32_MAX},
|
||||
.font = DEFAULT_FONT,
|
||||
.rounding = DEFAULT_ROUNDING,
|
||||
},
|
||||
@@ -23,6 +25,8 @@ struct clr_scheme schemes[] = {
|
||||
.fg = {.bgra = {32, 32, 32, transparency}},
|
||||
.high = {.bgra = {100, 100, 100, transparency}},
|
||||
.swipe = {.bgra = {100, 255, 100, 64}},
|
||||
.text_press = {.color = UINT32_MAX},
|
||||
.text_swipe = {.color = UINT32_MAX},
|
||||
.text = {.color = UINT32_MAX},
|
||||
.font = DEFAULT_FONT,
|
||||
.rounding = DEFAULT_ROUNDING,
|
||||
|
||||
75
keyboard.c
75
keyboard.c
@@ -38,7 +38,7 @@ kbd_switch_layout(struct kbd *kb, struct layout *l, size_t layer_index)
|
||||
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, kb->layout->keymap_name, 0, 0);
|
||||
create_and_upload_keymap(kb, kb->layout->keymap_name, 0);
|
||||
}
|
||||
kbd_draw_layout(kb);
|
||||
}
|
||||
@@ -198,7 +198,7 @@ kbd_init(struct kbd *kb, struct layout *layouts, char *layer_names_list,
|
||||
kb->last_abc_layout = &kb->layouts[layer];
|
||||
|
||||
/* upload keymap */
|
||||
create_and_upload_keymap(kb, kb->layout->keymap_name, 0, 0);
|
||||
create_and_upload_keymap(kb, kb->layout->keymap_name, 0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -304,9 +304,11 @@ kbd_unpress_key(struct kbd *kb, uint32_t time)
|
||||
unlatch_altgr = (kb->mods & AltGr) == AltGr;
|
||||
|
||||
if (kb->last_press->type == Copy) {
|
||||
if (kb->debug) fprintf(stderr, "release copy key (unlatch_shift=%d, mods=%d)\n", unlatch_shift, kb->mods);
|
||||
zwp_virtual_keyboard_v1_key(kb->vkbd, time, 127, // COMP key
|
||||
WL_KEYBOARD_KEY_STATE_RELEASED);
|
||||
} else {
|
||||
if (kb->debug) fprintf(stderr, "release key %d", kb->last_press->code);
|
||||
if ((kb->shift_space_is_tab) && (kb->last_press->code == KEY_SPACE) && (unlatch_shift)) {
|
||||
// shift + space is tab
|
||||
unlatch_shift = false;
|
||||
@@ -322,6 +324,7 @@ kbd_unpress_key(struct kbd *kb, uint32_t time)
|
||||
}
|
||||
|
||||
if (unlatch_shift) {
|
||||
if (kb->debug) fprintf(stderr, "unlatch shift");
|
||||
kb->mods ^= Shift;
|
||||
zwp_virtual_keyboard_v1_key_mods(kb->vkbd, time, Shift, WL_KEYBOARD_KEY_STATE_RELEASED);
|
||||
}
|
||||
@@ -460,8 +463,12 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time)
|
||||
case Mod:
|
||||
kb->mods ^= k->code;
|
||||
if (kb->mods & k->code) {
|
||||
if (kb->debug)
|
||||
fprintf(stderr, "mod pressed\n");
|
||||
zwp_virtual_keyboard_v1_key_mods(kb->vkbd, time, k->code, WL_KEYBOARD_KEY_STATE_PRESSED);
|
||||
} else {
|
||||
if (kb->debug)
|
||||
fprintf(stderr, "mod released\n");
|
||||
zwp_virtual_keyboard_v1_key_mods(kb->vkbd, time, k->code, WL_KEYBOARD_KEY_STATE_RELEASED);
|
||||
}
|
||||
if ((k->code == Shift) || (k->code == CapsLock)) {
|
||||
@@ -523,10 +530,15 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time)
|
||||
// copy code as unicode chr by setting a temporary keymap
|
||||
kb->last_swipe = kb->last_press = k;
|
||||
kbd_draw_key(kb, k, Press);
|
||||
if (kb->debug)
|
||||
fprintf(stderr, "pressing copy key\n");
|
||||
create_and_upload_keymap(kb, kb->layout->keymap_name, k->code,
|
||||
k->code_mod);
|
||||
if (kb->mods & Shift) {
|
||||
if (kb->debug)
|
||||
fprintf(stderr, "Pressing copy key (with shift)\n");
|
||||
create_and_upload_keymap(kb, kb->layout->keymap_name, k->code_mod);
|
||||
} else {
|
||||
if (kb->debug)
|
||||
fprintf(stderr, "Pressing copy key\n");
|
||||
create_and_upload_keymap(kb, kb->layout->keymap_name, k->code);
|
||||
}
|
||||
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0);
|
||||
zwp_virtual_keyboard_v1_key(kb->vkbd, time, 127, // COMP key
|
||||
WL_KEYBOARD_KEY_STATE_PRESSED);
|
||||
@@ -541,9 +553,13 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time)
|
||||
void
|
||||
kbd_print_key_stdout(struct kbd *kb, struct key *k)
|
||||
{
|
||||
/* printed keys may slightly differ from the actual output
|
||||
/* Printed keys may slightly differ from the actual output
|
||||
* we generally print what is on the key LABEL and only support the normal
|
||||
* and shift layers. Other modifiers produce no output (Ctrl,Alt)
|
||||
* and shift layers. Other modifiers produce no output (Ctrl,Alt).
|
||||
* If a label has more than one character,
|
||||
* only the first character is printed,
|
||||
* because downpipe programs otherwise have no way of differentiating a swipe
|
||||
* from a single keypress.
|
||||
* */
|
||||
|
||||
bool handled = true;
|
||||
@@ -572,13 +588,34 @@ kbd_print_key_stdout(struct kbd *kb, struct key *k)
|
||||
if (!handled) {
|
||||
if ((kb->mods & Shift) ||
|
||||
((kb->mods & CapsLock) & (strlen(k->label) == 1 && isalpha(k->label[0]))))
|
||||
printf("%s", k->shift_label);
|
||||
kbd_print_first_utf8_char_stdout(k->shift_label);
|
||||
else if (!(kb->mods & Ctrl) && !(kb->mods & Alt) && !(kb->mods & Super))
|
||||
printf("%s", k->label);
|
||||
kbd_print_first_utf8_char_stdout(k->label);
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void kbd_print_first_utf8_char_stdout(const char *str) {
|
||||
unsigned char c = (unsigned char)str[0];
|
||||
int len;
|
||||
|
||||
if ((c & 0x80) == 0) {
|
||||
len = 1;
|
||||
} else if ((c & 0xE0) == 0xC0) {
|
||||
len = 2;
|
||||
} else if ((c & 0xF0) == 0xE0) {
|
||||
len = 3;
|
||||
} else if ((c & 0xF8) == 0xF0) {
|
||||
len = 4;
|
||||
} else {
|
||||
len = 1; // Invalid UTF-8
|
||||
}
|
||||
|
||||
for (int i = 0; i < len && str[i] != '\0'; i++) {
|
||||
putchar(str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
kbd_clear_last_popup(struct kbd *kb)
|
||||
{
|
||||
@@ -604,19 +641,26 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
|
||||
case Unpress:
|
||||
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
||||
scheme->fg, scheme->rounding);
|
||||
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h,
|
||||
KBD_KEY_BORDER, label, scheme->font_description);
|
||||
break;
|
||||
case Press:
|
||||
draw_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
||||
scheme->high, scheme->rounding);
|
||||
drw_draw_text(kb->surf, scheme->text_press, k->x, k->y, k->w, k->h,
|
||||
KBD_KEY_BORDER, label, scheme->font_description);
|
||||
break;
|
||||
case Swipe:
|
||||
draw_over_inset(kb->surf, k->x, k->y, k->w, k->h, KBD_KEY_BORDER,
|
||||
scheme->swipe, scheme->rounding);
|
||||
drw_draw_text(kb->surf, scheme->text_swipe, k->x, k->y, k->w, k->h,
|
||||
KBD_KEY_BORDER, label, scheme->font_description);
|
||||
break;
|
||||
default:
|
||||
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h,
|
||||
KBD_KEY_BORDER, label, scheme->font_description);
|
||||
}
|
||||
|
||||
drw_draw_text(kb->surf, scheme->text, k->x, k->y, k->w, k->h,
|
||||
KBD_KEY_BORDER, label, scheme->font_description);
|
||||
|
||||
if (type == Press || type == Unpress) {
|
||||
kbd_clear_last_popup(kb);
|
||||
@@ -630,7 +674,7 @@ kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type type)
|
||||
kb->last_popup_y, k->w, k->h, scheme->rounding);
|
||||
draw_inset(kb->popup_surf, k->x, kb->last_popup_y, k->w, k->h,
|
||||
KBD_KEY_BORDER, scheme->high, scheme->rounding);
|
||||
drw_draw_text(kb->popup_surf, scheme->text, k->x, kb->last_popup_y,
|
||||
drw_draw_text(kb->popup_surf, scheme->text_press, k->x, kb->last_popup_y,
|
||||
k->w, k->h, KBD_KEY_BORDER, label,
|
||||
scheme->font_description);
|
||||
}
|
||||
@@ -699,8 +743,7 @@ draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
|
||||
}
|
||||
|
||||
void
|
||||
create_and_upload_keymap(struct kbd *kb, const char *name, uint32_t comp_unichr,
|
||||
uint32_t comp_shift_unichr)
|
||||
create_and_upload_keymap(struct kbd *kb, const char *name, uint32_t comp_unichr)
|
||||
{
|
||||
int keymap_index = -1;
|
||||
for (int i = 0; i < NUMKEYMAPS; i++) {
|
||||
@@ -715,7 +758,7 @@ create_and_upload_keymap(struct kbd *kb, const char *name, uint32_t comp_unichr,
|
||||
const char *keymap_template = keymaps[keymap_index];
|
||||
size_t keymap_size = strlen(keymap_template) + 64;
|
||||
char *keymap_str = malloc(keymap_size);
|
||||
sprintf(keymap_str, keymap_template, comp_unichr, comp_shift_unichr);
|
||||
sprintf(keymap_str, keymap_template, comp_unichr, comp_unichr);
|
||||
keymap_size = strlen(keymap_str);
|
||||
int keymap_fd = os_create_anonymous_file(keymap_size);
|
||||
if (keymap_fd < 0) {
|
||||
|
||||
@@ -54,6 +54,8 @@ struct clr_scheme {
|
||||
Color high;
|
||||
Color swipe;
|
||||
Color text;
|
||||
Color text_press;
|
||||
Color text_swipe;
|
||||
char *font;
|
||||
int rounding;
|
||||
PangoFontDescription *font_description;
|
||||
@@ -139,6 +141,7 @@ void kbd_release_key(struct kbd *kb, uint32_t time);
|
||||
void kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y);
|
||||
void kbd_press_key(struct kbd *kb, struct key *k, uint32_t time);
|
||||
void kbd_print_key_stdout(struct kbd *kb, struct key *k);
|
||||
void kbd_print_first_utf8_char_stdout(const char *str);
|
||||
void kbd_clear_last_popup(struct kbd *kb);
|
||||
void kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type);
|
||||
void kbd_draw_layout(struct kbd *kb);
|
||||
@@ -148,8 +151,7 @@ double kbd_get_row_length(struct key *k);
|
||||
void kbd_next_layer(struct kbd *kb, struct key *k, bool invert);
|
||||
void kbd_switch_layout(struct kbd *kb, struct layout *l, size_t layer_index);
|
||||
|
||||
void create_and_upload_keymap(struct kbd *kb, const char *name,
|
||||
uint32_t comp_unichr, uint32_t comp_shift_unichr);
|
||||
void create_and_upload_keymap(struct kbd *kb, const char *name, uint32_t comp_unichr);
|
||||
|
||||
#ifndef LAYOUT
|
||||
#error "make sure to define LAYOUT"
|
||||
|
||||
36
main.c
36
main.c
@@ -618,6 +618,14 @@ usage(char *argv0)
|
||||
fprintf(stderr, " --text [rrggbb|aa] - Set color of text on keys\n");
|
||||
fprintf(stderr,
|
||||
" --text-sp [rrggbb|aa] - Set color of text on special keys\n");
|
||||
fprintf(stderr,
|
||||
" --text-press [rrggbb|aa] - Set color of text on pressed keys\n");
|
||||
fprintf(stderr,
|
||||
" --text-press-sp [rrggbb|aa] - Set color of text on pressed special keys\n");
|
||||
fprintf(stderr,
|
||||
" --text-swipe [rrggbb|aa] - Set color of text on swiped keys\n");
|
||||
fprintf(stderr,
|
||||
" --text-swipe-sp [rrggbb|aa] - Set color of text on swiped special keys\n");
|
||||
fprintf(stderr,
|
||||
" --list-layers - Print the list of available layers\n");
|
||||
fprintf(stderr,
|
||||
@@ -902,6 +910,34 @@ main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
set_kbd_colors(keyboard.schemes[1].text.bgra, argv[++i]);
|
||||
} else if ((!strcmp(argv[i], "-text-press")) ||
|
||||
(!strcmp(argv[i], "--text-press"))) {
|
||||
if (i >= argc - 1) {
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
set_kbd_colors(keyboard.schemes[0].text_press.bgra, argv[++i]);
|
||||
} else if ((!strcmp(argv[i], "-text-press-sp")) ||
|
||||
(!strcmp(argv[i], "--text-press-sp"))) {
|
||||
if (i >= argc - 1) {
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
set_kbd_colors(keyboard.schemes[1].text_press.bgra, argv[++i]);
|
||||
} else if ((!strcmp(argv[i], "-text-swipe")) ||
|
||||
(!strcmp(argv[i], "--text-swipe"))) {
|
||||
if (i >= argc - 1) {
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
set_kbd_colors(keyboard.schemes[0].text_swipe.bgra, argv[++i]);
|
||||
} else if ((!strcmp(argv[i], "-text-swipe-sp")) ||
|
||||
(!strcmp(argv[i], "--text-swipe-sp"))) {
|
||||
if (i >= argc - 1) {
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
set_kbd_colors(keyboard.schemes[1].text_swipe.bgra, argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-H")) {
|
||||
if (i >= argc - 1) {
|
||||
usage(argv[0]);
|
||||
|
||||
Reference in New Issue
Block a user