diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2022-08-12 19:34:04 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-16 16:43:27 +0200 |
commit | 9bcd7dc0ce9ceae1808072921653430011f4b2fc (patch) | |
tree | ac4da4a6cb48518d963608bf3f7192d0e2c99e45 /Userland | |
parent | db058a22aeeadc22539e3e1efd9216970eebdd19 (diff) | |
download | serenity-9bcd7dc0ce9ceae1808072921653430011f4b2fc.zip |
WindowServer: Don't start a drag and drop unless holding Primary mouse
Adds a member to record the last processed mouse buttons. If they
do not include MouseButton::Primary, return early before creating
a new drag and drop client. This fixes race conditions in which
MouseUp events canceling or completing a drop could be swallowed
by Overlay creation or postponed by an executing DragOperation,
leaving the operation in limbo.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/WindowServer/ConnectionFromClient.cpp | 2 | ||||
-rw-r--r-- | Userland/Services/WindowServer/Event.h | 2 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowManager.cpp | 1 | ||||
-rw-r--r-- | Userland/Services/WindowServer/WindowManager.h | 3 |
4 files changed, 6 insertions, 2 deletions
diff --git a/Userland/Services/WindowServer/ConnectionFromClient.cpp b/Userland/Services/WindowServer/ConnectionFromClient.cpp index 4a547f9df5..04a03cc8c3 100644 --- a/Userland/Services/WindowServer/ConnectionFromClient.cpp +++ b/Userland/Services/WindowServer/ConnectionFromClient.cpp @@ -817,7 +817,7 @@ void ConnectionFromClient::start_window_resize(i32 window_id) Messages::WindowServer::StartDragResponse ConnectionFromClient::start_drag(String const& text, HashMap<String, ByteBuffer> const& mime_data, Gfx::ShareableBitmap const& drag_bitmap) { auto& wm = WindowManager::the(); - if (wm.dnd_client()) + if (wm.dnd_client() || !(wm.last_processed_buttons() & MouseButton::Primary)) return false; wm.start_dnd_drag(*this, text, drag_bitmap.bitmap(), Core::MimeData::construct(mime_data)); diff --git a/Userland/Services/WindowServer/Event.h b/Userland/Services/WindowServer/Event.h index 6ab2bc59b4..f3fb5ebab1 100644 --- a/Userland/Services/WindowServer/Event.h +++ b/Userland/Services/WindowServer/Event.h @@ -48,7 +48,7 @@ public: bool is_key_event() const { return type() == KeyUp || type() == KeyDown; } }; -enum class MouseButton : u8 { +enum MouseButton : u8 { None = 0, Primary = 1, Secondary = 2, diff --git a/Userland/Services/WindowServer/WindowManager.cpp b/Userland/Services/WindowServer/WindowManager.cpp index 0d46f9a98e..f3359c8b27 100644 --- a/Userland/Services/WindowServer/WindowManager.cpp +++ b/Userland/Services/WindowServer/WindowManager.cpp @@ -1459,6 +1459,7 @@ void WindowManager::event(Core::Event& event) m_previous_event_was_super_keydown = false; process_mouse_event(mouse_event); + m_last_processed_buttons = mouse_event.buttons(); // TODO: handle transitioning between two stacks set_hovered_window(current_window_stack().window_at(mouse_event.position(), WindowStack::IncludeWindowFrame::No)); return; diff --git a/Userland/Services/WindowServer/WindowManager.h b/Userland/Services/WindowServer/WindowManager.h index 3a5459c911..2d69e85fca 100644 --- a/Userland/Services/WindowServer/WindowManager.h +++ b/Userland/Services/WindowServer/WindowManager.h @@ -347,6 +347,8 @@ public: Window const* automatic_cursor_tracking_window() const { return m_automatic_cursor_tracking_window; } void set_automatic_cursor_tracking_window(Window* window) { m_automatic_cursor_tracking_window = window; } + u8 last_processed_buttons() { return m_last_processed_buttons; } + private: explicit WindowManager(Gfx::PaletteImpl const&); @@ -469,6 +471,7 @@ private: ResizeDirection m_resize_direction { ResizeDirection::None }; u8 m_keyboard_modifiers { 0 }; + u8 m_last_processed_buttons { MouseButton::None }; NonnullRefPtr<WindowSwitcher> m_switcher; NonnullRefPtr<KeymapSwitcher> m_keymap_switcher; |