gg: fix .char event handling for backspace, delete, tab and enter for linux/x11 (send appropriate .char codes to the apps, similar to macos)

This commit is contained in:
Delyan Angelov 2025-06-18 21:41:20 +03:00
parent cab97894ae
commit 9387fe73e3
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -468,6 +468,28 @@ fn gg_event_fn(ce voidptr, user_data voidptr) {
// dump(e)
}
}
$if linux {
if e.typ == .key_down && e.key_code in [.backspace, .delete, .enter, .tab] {
// with X11, sokol does not send .char events for some keys; we will emulate them for consistency here:
e.char_code = match e.key_code {
.backspace { u32(8) }
.tab { 9 }
.enter { 13 }
.delete { 127 }
else { u32(e.key_code) }
}
e.key_code = .invalid
e.typ = .char
if ctx.config.event_fn != unsafe { nil } {
ctx.config.event_fn(e, ctx.config.user_data)
} else if ctx.config.on_event != unsafe { nil } {
ctx.config.on_event(ctx.config.user_data, e)
}
if ctx.config.char_fn != unsafe { nil } {
ctx.config.char_fn(e.char_code, ctx.config.user_data)
}
}
}
}
fn gg_cleanup_fn(user_data voidptr) {