mirror of
https://github.com/jjsullivan5196/wvkbd.git
synced 2025-03-13 10:52:47 +01:00
implemented printing to stdout
This commit is contained in:
parent
2fd0cfc89c
commit
da06f514df
45
keyboard.h
45
keyboard.h
@ -96,6 +96,7 @@ static void kbd_init_layout(struct layout *l, uint32_t width, uint32_t height);
|
|||||||
static struct key *kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y);
|
static struct key *kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y);
|
||||||
static void kbd_unpress_key(struct kbd *kb, uint32_t time);
|
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_press_key(struct kbd *kb, struct key *k, uint32_t time);
|
||||||
|
static void kbd_print_key_stdout(struct kbd *kb, struct key *k);
|
||||||
static void kbd_draw_key(struct kbd *kb, struct key *k, bool pressed);
|
static void kbd_draw_key(struct kbd *kb, struct key *k, bool pressed);
|
||||||
static void kbd_draw_layout(struct kbd *kb);
|
static void kbd_draw_layout(struct kbd *kb);
|
||||||
static void kbd_resize(struct kbd *kb, uint32_t w, uint32_t h,
|
static void kbd_resize(struct kbd *kb, uint32_t w, uint32_t h,
|
||||||
@ -256,6 +257,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
|||||||
kbd_draw_key(kb, k, true);
|
kbd_draw_key(kb, k, true);
|
||||||
zwp_virtual_keyboard_v1_key(kb->vkbd, time, kb->last_press->code,
|
zwp_virtual_keyboard_v1_key(kb->vkbd, time, kb->last_press->code,
|
||||||
WL_KEYBOARD_KEY_STATE_PRESSED);
|
WL_KEYBOARD_KEY_STATE_PRESSED);
|
||||||
|
if (kb->print)
|
||||||
|
kbd_print_key_stdout(kb, k);
|
||||||
if (compose) {
|
if (compose) {
|
||||||
fprintf(stderr, "pressing composed key\n");
|
fprintf(stderr, "pressing composed key\n");
|
||||||
compose++;
|
compose++;
|
||||||
@ -304,6 +307,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
|||||||
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0);
|
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0);
|
||||||
zwp_virtual_keyboard_v1_key(kb->vkbd, time, 127, // COMP key
|
zwp_virtual_keyboard_v1_key(kb->vkbd, time, 127, // COMP key
|
||||||
WL_KEYBOARD_KEY_STATE_PRESSED);
|
WL_KEYBOARD_KEY_STATE_PRESSED);
|
||||||
|
if (kb->print)
|
||||||
|
kbd_print_key_stdout(kb, k);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -312,6 +317,46 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
|
|||||||
kb->surf->dirty = true;
|
kb->surf->dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
kbd_print_key_stdout(struct kbd *kb, struct key *k) {
|
||||||
|
/* 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)
|
||||||
|
* */
|
||||||
|
|
||||||
|
bool handled = true;
|
||||||
|
if (k->type == Code) {
|
||||||
|
switch (k->code) {
|
||||||
|
case KEY_SPACE:
|
||||||
|
printf(" ");
|
||||||
|
break;
|
||||||
|
case KEY_ENTER:
|
||||||
|
printf("\n");
|
||||||
|
break;
|
||||||
|
case KEY_BACKSPACE:
|
||||||
|
printf("\b");
|
||||||
|
break;
|
||||||
|
case KEY_TAB:
|
||||||
|
printf("\t");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
handled = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (k->type != Copy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!handled) {
|
||||||
|
if ((kb->mods & Shift) || (kb->mods & CapsLock))
|
||||||
|
printf("%s", k->shift_label);
|
||||||
|
else if (!(kb->mods & Ctrl) && !(kb->mods & Alt) && (!kb->mods & Super))
|
||||||
|
printf("%s", k->label);
|
||||||
|
}
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
kbd_draw_key(struct kbd *kb, struct key *k, bool pressed) {
|
kbd_draw_key(struct kbd *kb, struct key *k, bool pressed) {
|
||||||
struct drwsurf *d = kb->surf;
|
struct drwsurf *d = kb->surf;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user