From 808ca2028981247bf697b8df5902ffe7c3e50b3f Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Mon, 3 May 2021 14:30:13 +0300 Subject: Window: Dispatch key events only to the root with key focus --- src/ui/widget.c | 1 + src/ui/window.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/ui/widget.c b/src/ui/widget.c index 62112e86..00fe0f5f 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c @@ -879,6 +879,7 @@ iBool dispatchEvent_Widget(iWidget *d, const SDL_Event *ev) { printf("[%p] %s:'%s' ate the key\n", child, class_Widget(child)->name, cstr_String(id_Widget(child))); + identify_Widget(child); fflush(stdout); } #endif diff --git a/src/ui/window.c b/src/ui/window.c index 39adba83..577caa4c 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -941,6 +941,10 @@ iBool dispatchEvent_Window(iWindow *d, const SDL_Event *ev) { if (isCommand_SDLEvent(ev) && ev->user.data2 && ev->user.data2 != root) { continue; /* Not meant for this root. */ } + else if ((ev->type == SDL_KEYDOWN || ev->type == SDL_KEYUP || ev->type == SDL_TEXTINPUT) + && d->keyRoot != root) { + continue; /* Key events go only to the root with keyboard focus. */ + } setCurrent_Root(root); const iBool wasUsed = dispatchEvent_Widget(root->widget, ev); if (wasUsed) { -- cgit v1.2.3