Skip to content

Commit 9387fe7

Browse files
committed
gg: fix .char event handling for backspace, delete, tab and enter for linux/x11 (send appropriate .char codes to the apps, similar to macos)
1 parent cab9789 commit 9387fe7

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎vlib/gg/gg.c.v‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,28 @@ fn gg_event_fn(ce voidptr, user_data voidptr) {
468468
// dump(e)
469469
}
470470
}
471+
$if linux {
472+
if e.typ == .key_down && e.key_code in [.backspace, .delete, .enter, .tab] {
473+
// with X11, sokol does not send .char events for some keys; we will emulate them for consistency here:
474+
e.char_code = match e.key_code {
475+
.backspace { u32(8) }
476+
.tab { 9 }
477+
.enter { 13 }
478+
.delete { 127 }
479+
else { u32(e.key_code) }
480+
}
481+
e.key_code = .invalid
482+
e.typ = .char
483+
if ctx.config.event_fn != unsafe { nil } {
484+
ctx.config.event_fn(e, ctx.config.user_data)
485+
} else if ctx.config.on_event != unsafe { nil } {
486+
ctx.config.on_event(ctx.config.user_data, e)
487+
}
488+
if ctx.config.char_fn != unsafe { nil } {
489+
ctx.config.char_fn(e.char_code, ctx.config.user_data)
490+
}
491+
}
492+
}
471493
}
472494

473495
fn gg_cleanup_fn(user_data voidptr) {

0 commit comments

Comments
 (0)