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.
This commit is contained in:
thankyouverycool 2022-08-12 19:34:04 -04:00 committed by Andreas Kling
parent db058a22ae
commit 9bcd7dc0ce
Notes: sideshowbarker 2024-07-17 08:12:16 +09:00
4 changed files with 6 additions and 2 deletions

View File

@ -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));

View File

@ -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,

View File

@ -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;

View File

@ -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;