diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2022-09-09 07:21:31 -0400 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-09-09 11:27:38 -0400 |
commit | f8e65d24cf2b0dc83ff6ec47e33f1a4ffd4b56db (patch) | |
tree | 50dc23cf7a6a5b1253da6ff82049faf622ed022f | |
parent | bfcb4d88cfe1c01dd7e7ce28ea7c4bdeedaef73c (diff) | |
download | serenity-f8e65d24cf2b0dc83ff6ec47e33f1a4ffd4b56db.zip |
LibGUI: Allow blocking CommandPalette/EmojiInput on a per Window basis
Instead of having to negate every focusable widget or textbox, let
windows override all their widgets. These two Dialogs now block
themselves and each other.
-rw-r--r-- | Userland/Libraries/LibGUI/CommandPalette.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/EmojiInputDialog.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/TextEditor.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Window.h | 8 |
5 files changed, 20 insertions, 3 deletions
diff --git a/Userland/Libraries/LibGUI/CommandPalette.cpp b/Userland/Libraries/LibGUI/CommandPalette.cpp index 000d6e2ad8..1a96dbf0e8 100644 --- a/Userland/Libraries/LibGUI/CommandPalette.cpp +++ b/Userland/Libraries/LibGUI/CommandPalette.cpp @@ -176,6 +176,8 @@ CommandPalette::CommandPalette(GUI::Window& parent_window, ScreenPosition screen : GUI::Dialog(&parent_window, screen_position) { set_frameless(true); + set_blocks_command_palette(true); + set_blocks_emoji_input(true); resize(450, 300); collect_actions(parent_window); diff --git a/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp b/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp index 6ff7976458..2a1ad4805b 100644 --- a/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp +++ b/Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp @@ -193,7 +193,7 @@ void ConnectionToWindowServer::key_down(i32 window_id, u32 code_point, u32 key, } bool focused_widget_accepts_emoji_input = window->focused_widget() && window->focused_widget()->accepts_emoji_input(); - if (focused_widget_accepts_emoji_input && (modifiers == (Mod_Ctrl | Mod_Alt)) && key == Key_Space) { + if (!window->blocks_emoji_input() && focused_widget_accepts_emoji_input && (modifiers == (Mod_Ctrl | Mod_Alt)) && key == Key_Space) { auto emoji_input_dialog = EmojiInputDialog::construct(window); emoji_input_dialog->set_window_mode(GUI::WindowMode::Passive); if (emoji_input_dialog->exec() != EmojiInputDialog::ExecResult::OK) @@ -207,8 +207,8 @@ void ConnectionToWindowServer::key_down(i32 window_id, u32 code_point, u32 key, key_event->m_code_point = emoji_code_point; } - bool accepts_command_palette = true; - if (window->focused_widget()) + bool accepts_command_palette = !window->blocks_command_palette(); + if (accepts_command_palette && window->focused_widget()) accepts_command_palette = window->focused_widget()->accepts_command_palette(); // FIXME: This shortcut should be configurable. diff --git a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp index f9981b7026..62d2c03741 100644 --- a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp +++ b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp @@ -53,6 +53,8 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window) VERIFY_NOT_REACHED(); set_frameless(true); + set_blocks_command_palette(true); + set_blocks_emoji_input(true); resize(400, 300); auto& scrollable_container = *main_widget.find_descendant_of_type_named<GUI::ScrollableContainerWidget>("scrollable_container"sv); diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index dc9a006017..3d5352f2d8 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -775,6 +775,9 @@ void TextEditor::select_all() void TextEditor::insert_emoji() { + if (!accepts_emoji_input() || window()->blocks_emoji_input()) + return; + auto emoji_input_dialog = EmojiInputDialog::construct(window()); emoji_input_dialog->set_window_mode(GUI::WindowMode::Passive); if (emoji_input_dialog->exec() != EmojiInputDialog::ExecResult::OK) @@ -1722,6 +1725,8 @@ void TextEditor::context_menu_event(ContextMenuEvent& event) if (is_displayonly()) return; + m_insert_emoji_action->set_enabled(accepts_emoji_input() && !window()->blocks_emoji_input()); + if (!m_context_menu) { m_context_menu = Menu::construct(); m_context_menu->add_action(undo_action()); diff --git a/Userland/Libraries/LibGUI/Window.h b/Userland/Libraries/LibGUI/Window.h index 9cefef3136..fddab1f195 100644 --- a/Userland/Libraries/LibGUI/Window.h +++ b/Userland/Libraries/LibGUI/Window.h @@ -225,6 +225,12 @@ public: Menubar& menubar() { return *m_menubar; } Menubar const& menubar() const { return *m_menubar; } + void set_blocks_command_palette(bool b) { m_blocks_command_palette = b; } + bool blocks_command_palette() const { return m_blocks_command_palette; } + + void set_blocks_emoji_input(bool b) { m_blocks_emoji_input = b; } + bool blocks_emoji_input() const { return m_blocks_emoji_input; } + protected: Window(Core::Object* parent = nullptr); virtual void wm_event(WMEvent&); @@ -307,6 +313,8 @@ private: bool m_visible_for_timer_purposes { true }; bool m_visible { false }; bool m_moved_by_client { false }; + bool m_blocks_command_palette { false }; + bool m_blocks_emoji_input { false }; }; } |