From 2fcf932f3a7a0b79cfde60a2904c81e2433fb38a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 17 Nov 2026 21:26:28 +0100 Subject: [PATCH] Edit: take native focus while editing text Text fields only focused visually by the toolkit, but not by X11 underneath semantically, so the host can still consume Space and other shortcuts instead of letting them reach the field. Practically speaking, this means that if you type a space in the text field of A/B, it triggers start/stop in REAPER. Fix this by letting widgets say whether they need native focus, and update it when the focused widget changes. This depends on https://github.com/lsp-plugins/lsp-ws-lib/pull/8 --- include/lsp-plug.in/tk/widgets/base/Widget.h | 5 +++++ include/lsp-plug.in/tk/widgets/simple/Edit.h | 2 ++ src/main/widgets/base/Widget.cpp | 5 +++++ src/main/widgets/containers/Window.cpp | 4 ++++ src/main/widgets/simple/Edit.cpp | 5 +++++ 5 files changed, 21 insertions(+) diff --git a/include/lsp-plug.in/tk/widgets/base/Widget.h b/include/lsp-plug.in/tk/widgets/base/Widget.h index 74b6831a..5c9f5d55 100644 --- a/include/lsp-plug.in/tk/widgets/base/Widget.h +++ b/include/lsp-plug.in/tk/widgets/base/Widget.h @@ -347,6 +347,11 @@ namespace lsp */ bool has_focus() const; + /** Whether this widget needs native keyboard focus. + * @return true if host keyboard shortcuts must be bypassed + */ + virtual bool needs_input_focus() const; + /** * Make widget being focused * @return true if widget has been focused, false if widget already had focus or it is impossible diff --git a/include/lsp-plug.in/tk/widgets/simple/Edit.h b/include/lsp-plug.in/tk/widgets/simple/Edit.h index 9fd6ac3d..abb6cf2b 100644 --- a/include/lsp-plug.in/tk/widgets/simple/Edit.h +++ b/include/lsp-plug.in/tk/widgets/simple/Edit.h @@ -240,6 +240,8 @@ namespace lsp virtual status_t on_change(); virtual status_t on_before_popup(Menu *menu); virtual status_t on_popup(Menu *menu); + + virtual bool needs_input_focus() const override; }; } /* namespace tk */ diff --git a/src/main/widgets/base/Widget.cpp b/src/main/widgets/base/Widget.cpp index 772c0edd..d8b9d08e 100644 --- a/src/main/widgets/base/Widget.cpp +++ b/src/main/widgets/base/Widget.cpp @@ -833,6 +833,11 @@ namespace lsp return (wnd != NULL) ? wnd->check_focus(_this) : false; } + bool Widget::needs_input_focus() const + { + return false; + } + bool Widget::take_focus() { Window *wnd = widget_cast(toplevel()); diff --git a/src/main/widgets/containers/Window.cpp b/src/main/widgets/containers/Window.cpp index e14998b1..c2e4b470 100644 --- a/src/main/widgets/containers/Window.cpp +++ b/src/main/widgets/containers/Window.cpp @@ -1341,6 +1341,8 @@ namespace lsp ev.nType = ws::UIE_FOCUS_IN; w->handle_event(&ev); } + if (pWindow != NULL) + pWindow->set_input_focus((pFocused != NULL) && pFocused->needs_input_focus()); return true; } @@ -1363,6 +1365,8 @@ namespace lsp ev.nType = ws::UIE_FOCUS_OUT; w->handle_event(&ev); } + if (pWindow != NULL) + pWindow->set_input_focus(false); return true; } diff --git a/src/main/widgets/simple/Edit.cpp b/src/main/widgets/simple/Edit.cpp index b99e0636..43fea59a 100644 --- a/src/main/widgets/simple/Edit.cpp +++ b/src/main/widgets/simple/Edit.cpp @@ -1179,6 +1179,11 @@ namespace lsp return STATUS_OK; } + bool Edit::needs_input_focus() const + { + return true; + } + status_t Edit::slot_popup_cut_action(Widget *sender, void *ptr, void *data) { Edit *_this = widget_ptrcast(ptr);