From 277953065ab591c83f17bcfa5c19c20e57964330 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 4 Aug 2023 13:08:48 +0200 Subject: [PATCH] wind: Reorder drag sequence --- wind/Mouse.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/wind/Mouse.cpp b/wind/Mouse.cpp index b807e5c1..bc1a3461 100644 --- a/wind/Mouse.cpp +++ b/wind/Mouse.cpp @@ -20,21 +20,7 @@ void Mouse::update(const moon::MousePacket& packet) m_position.y -= packet.ydelta; m_position = m_screen_rect.normalize(m_position); - if ((packet.buttons & moon::MouseButton::Left) && !m_dragging_window) - { - g_windows.for_each_reversed([this](Window* window) { - if (!this->m_dragging_window && window->surface.contains(this->m_position)) - { - this->m_dragging_window = window; - this->m_initial_drag_position = ui::Point { this->m_position.x - window->surface.pos.x, - this->m_position.y - window->surface.pos.y }; - os::println("Started drag: window at (%d,%d,%d,%d) with offset (%d,%d)", window->surface.pos.x, - window->surface.pos.y, window->surface.width, window->surface.height, - this->m_initial_drag_position.x, this->m_initial_drag_position.y); - } - }); - } - else if (m_dragging_window && !(packet.buttons & moon::MouseButton::Left)) + if (m_dragging_window && !(packet.buttons & moon::MouseButton::Left)) { os::println("Stopped drag: window at (%d,%d,%d,%d) with offset (%d,%d)", m_dragging_window->surface.pos.x, m_dragging_window->surface.pos.y, m_dragging_window->surface.width, @@ -48,6 +34,21 @@ void Mouse::update(const moon::MousePacket& packet) m_dragging_window->surface.pos = ui::Point { m_position.x - m_initial_drag_position.x, m_position.y - m_initial_drag_position.y }; m_dragging_window->surface = m_dragging_window->surface.absolute(); - m_dragging_window->focus(); + } + + else if ((packet.buttons & moon::MouseButton::Left) && !m_dragging_window) + { + g_windows.for_each_reversed([this](Window* window) { + if (!this->m_dragging_window && window->surface.contains(this->m_position)) + { + this->m_dragging_window = window; + this->m_initial_drag_position = ui::Point { this->m_position.x - window->surface.pos.x, + this->m_position.y - window->surface.pos.y }; + os::println("Started drag: window at (%d,%d,%d,%d) with offset (%d,%d)", window->surface.pos.x, + window->surface.pos.y, window->surface.width, window->surface.height, + this->m_initial_drag_position.x, this->m_initial_drag_position.y); + window->focus(); + } + }); } }