wind: Stop tracking windows after they're closed

This commit is contained in:
apio 2023-09-16 11:45:51 +02:00
parent d3cc4d109b
commit fbfa5328d7
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 24 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include "IPC.h"
#include "Mouse.h"
#include "Screen.h"
#include <luna/Alignment.h>
#include <luna/String.h>
@ -129,6 +130,7 @@ static Result<void> 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 {};

View File

@ -7,6 +7,8 @@
static SharedPtr<ui::Image> 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; }
}

View File

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

View File

@ -179,6 +179,7 @@ Result<int> luna_main(int argc, char** argv)
if (window)
{
g_windows.remove(window);
mouse_pointer.window_did_close(window);
delete window;
}
}