From fbf824a50feb88b54617ae7b7f977cc1a0b45fc3 Mon Sep 17 00:00:00 2001 From: Rob Ryan Date: Sun, 15 Aug 2021 15:40:08 +1000 Subject: [PATCH] LibGUI: Allow widgets to make themselves non-auto-focusable This patchs adds a way for widgets exclude themselves from being a focus candidate in Window::focus_a_widget_if_possible(). This is to allow the URL box to not get auto-focused when the browser is loaded. --- Userland/Libraries/LibGUI/Widget.h | 4 ++++ Userland/Libraries/LibGUI/Window.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Userland/Libraries/LibGUI/Widget.h b/Userland/Libraries/LibGUI/Widget.h index a46a735e89..86b353b5a0 100644 --- a/Userland/Libraries/LibGUI/Widget.h +++ b/Userland/Libraries/LibGUI/Widget.h @@ -114,6 +114,9 @@ public: String tooltip() const { return m_tooltip; } void set_tooltip(String); + bool is_auto_focusable() const { return m_auto_focusable; } + void set_auto_focusable(bool auto_focusable) { m_auto_focusable = auto_focusable; } + bool is_enabled() const { return m_enabled; } void set_enabled(bool); @@ -357,6 +360,7 @@ private: bool m_fill_with_background_color { false }; bool m_visible { true }; bool m_greedy_for_hits { false }; + bool m_auto_focusable { true }; bool m_enabled { true }; bool m_updates_enabled { true }; bool m_accepts_emoji_input { false }; diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index 526bce67c9..92d6dd570a 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -947,6 +947,8 @@ Vector Window::focusable_widgets(FocusSource source) const return IterationDecision::Continue; if (!child.is_enabled()) return IterationDecision::Continue; + if (!child.is_auto_focusable()) + return IterationDecision::Continue; collect_focusable_widgets(child); return IterationDecision::Continue; });