1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:57:35 +00:00

LibGUI+WindowServer+Applets+Taskbar: Remove active input concepts

and the CaptureInput mode. They are a source of unneeded complexity
in WindowServer and have proven prone to regressions, so this patch
replaces them with a simple input preemption scheme using Popups.

Popup windows now have ergonomics similar to menus: When open,
a popup preempts all mouse and key events for the entire window
stack; however, they are fragile and will close after WindowServer
swallows the first event outside them. This is similar to how combo
box windows and popups work in the classic Windows DE and has the
added benefit of letting the user click anywhere to dismiss a popup
without having to worry about unwanted interactions with other
widgets.
This commit is contained in:
thankyouverycool 2022-11-17 10:00:07 -05:00 committed by Andreas Kling
parent 35bd79701c
commit 24d299c9c8
17 changed files with 76 additions and 191 deletions

View file

@ -115,15 +115,6 @@ ComboBox::ComboBox()
m_list_window = add<Window>(window());
m_list_window->set_window_type(GUI::WindowType::Popup);
m_list_window->set_frameless(true);
m_list_window->set_window_mode(WindowMode::CaptureInput);
m_list_window->on_active_input_change = [this](bool is_active_input) {
if (!is_active_input) {
m_open_button->set_enabled(false);
close();
}
m_open_button->set_enabled(true);
};
m_list_view = m_list_window->set_main_widget<ListView>();
m_list_view->set_should_hide_unnecessary_scrollbars(true);

View file

@ -223,12 +223,6 @@ CommandPalette::CommandPalette(GUI::Window& parent_window, ScreenPosition screen
};
m_text_box->set_focus(true);
on_active_input_change = [this](bool is_active_input) {
if (!is_active_input)
close();
};
}
void CommandPalette::collect_actions(GUI::Window& parent_window)

View file

@ -202,7 +202,6 @@ NonnullRefPtr<Action> make_command_palette_action(Window* window)
{
auto action = Action::create("&Commands...", { Mod_Ctrl | Mod_Shift, Key_A }, MUST(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png"sv)), [=](auto&) {
auto command_palette = CommandPalette::construct(*window);
command_palette->set_window_mode(GUI::WindowMode::CaptureInput);
if (command_palette->exec() != GUI::Dialog::ExecResult::OK)
return;
auto* action = command_palette->selected_action();

View file

@ -170,7 +170,7 @@ static Action* action_for_shortcut(Window& window, Shortcut const& shortcut)
}
// NOTE: Application-global shortcuts are ignored while a blocking modal window is up.
if (!window.is_blocking() && !window.is_capturing_input()) {
if (!window.is_blocking() && !window.is_popup()) {
if (auto* action = Application::the()->action_for_shortcut(shortcut)) {
dbgln_if(KEYBOARD_SHORTCUTS_DEBUG, " > Asked application, got action: {} {} (enabled: {}, shortcut: {}, alt-shortcut: {})", action, action->text(), action->is_enabled(), action->shortcut().to_string(), action->alternate_shortcut().to_string());
return action;

View file

@ -100,7 +100,6 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
set_frameless(true);
set_blocks_emoji_input(true);
set_window_mode(GUI::WindowMode::CaptureInput);
resize(400, 300);
auto& scrollable_container = *main_widget.find_descendant_of_type_named<GUI::ScrollableContainerWidget>("scrollable_container"sv);
@ -139,11 +138,6 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
scrollable_container.horizontal_scrollbar().set_visible(false);
update_displayed_emoji();
on_active_input_change = [this](bool is_active_input) {
if (!is_active_input)
close();
};
m_search_box->on_change = [this]() {
update_displayed_emoji();
};

View file

@ -752,10 +752,7 @@ bool Widget::is_focused() const
auto* win = window();
if (!win)
return false;
// Capturing modals are not active despite being the active
// input window. So we can have focus if either we're the active
// input window or we're the active window
if (win->is_active_input() || win->is_active())
if (win->is_focusable())
return win->focused_widget() == this;
return false;
}

View file

@ -37,8 +37,8 @@ public:
bool is_modal() const { return m_window_mode != WindowMode::Modeless; }
bool is_blocking() const { return m_window_mode == WindowMode::Blocking; }
bool is_capturing_input() const { return m_window_mode == WindowMode::CaptureInput; }
bool is_popup() const { return m_window_type == WindowType::Popup; }
bool is_autocomplete() const { return m_window_type == WindowType::Autocomplete; }
bool is_fullscreen() const { return m_fullscreen; }
@ -96,7 +96,6 @@ public:
Function<void()> on_close;
Function<CloseRequestDecision()> on_close_request;
Function<void(bool is_active_input)> on_active_input_change;
Function<void(bool is_preempted)> on_input_preemption_change;
Function<void(bool is_active_window)> on_active_window_change;
@ -130,7 +129,7 @@ public:
bool is_visible() const;
bool is_active() const;
bool is_active_input() const { return m_is_active_input; }
bool is_focusable() const { return is_active() || is_popup() || is_autocomplete(); }
void show();
void hide();
@ -304,7 +303,6 @@ private:
WindowMode m_window_mode { WindowMode::Modeless };
AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> m_cursor { Gfx::StandardCursor::None };
AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> m_effective_cursor { Gfx::StandardCursor::None };
bool m_is_active_input { false };
bool m_has_alpha_channel { false };
bool m_double_buffering_enabled { true };
bool m_resizable { true };