diff --git a/wind/IPC.cpp b/wind/IPC.cpp index 98d93d68..e04d0300 100644 --- a/wind/IPC.cpp +++ b/wind/IPC.cpp @@ -1,4 +1,5 @@ #include "IPC.h" +#include "Mouse.h" #include "Screen.h" #include #include @@ -129,6 +130,7 @@ static Result handle_close_window_message(Client& client) auto* window = client.windows[request.window]; client.windows[request.window] = nullptr; g_windows.remove(window); + Mouse::the().window_did_close(window); delete window; return {}; diff --git a/wind/Mouse.cpp b/wind/Mouse.cpp index 0ba7d1ea..125a37a7 100644 --- a/wind/Mouse.cpp +++ b/wind/Mouse.cpp @@ -7,6 +7,8 @@ static SharedPtr g_mouse_cursor; +static Mouse* s_mouse; + Mouse::Mouse(ui::Canvas& screen) { m_position.x = screen.width / 2; @@ -14,6 +16,14 @@ Mouse::Mouse(ui::Canvas& screen) m_screen_rect = screen.rect(); g_mouse_cursor = ui::Image::load("/usr/share/cursors/default.tga").value_or({}); + + s_mouse = this; +} + +Mouse& Mouse::the() +{ + check(s_mouse); + return *s_mouse; } void Mouse::draw(ui::Canvas& screen) @@ -110,3 +120,10 @@ void Mouse::update(const moon::MousePacket& packet) m_active_window = new_active_window; } } + +void Mouse::window_did_close(Window* window) +{ + if (m_dragging_window == window) { m_dragging_window = nullptr; } + + if (m_active_window == window) { m_active_window = nullptr; } +} diff --git a/wind/Mouse.h b/wind/Mouse.h index bee42f4c..3b068133 100644 --- a/wind/Mouse.h +++ b/wind/Mouse.h @@ -13,6 +13,10 @@ class Mouse void draw(ui::Canvas& screen); + void window_did_close(Window* window); + + static Mouse& the(); + private: ui::Point m_position; ui::Rect m_screen_rect; diff --git a/wind/main.cpp b/wind/main.cpp index d65dd551..b0b4930c 100644 --- a/wind/main.cpp +++ b/wind/main.cpp @@ -179,6 +179,7 @@ Result luna_main(int argc, char** argv) if (window) { g_windows.remove(window); + mouse_pointer.window_did_close(window); delete window; } }