Fix Window CLOSED event when using more than one window
Fixed an issue where if there were more than one window, when they were closed, the CLOSED event would trigger but the window count did not decrease. This happened because after the window was destroyed the DestroyNotify event was triggered, which when looked up in the m_windows map, reinserted itself with default initialization.
This commit is contained in:
@@ -59,15 +59,19 @@ void X11WindowDriver::poll_events() {
|
|||||||
XEvent event;
|
XEvent event;
|
||||||
XNextEvent(m_display, &event);
|
XNextEvent(m_display, &event);
|
||||||
|
|
||||||
X11::Window handle = event.xany.window;
|
auto iter = m_windows.find(event.xany.window);
|
||||||
Nova::Window& window = m_windows[handle];
|
if (iter == m_windows.end()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowID window = iter->second;
|
||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case ConfigureNotify: {
|
case ConfigureNotify: {
|
||||||
XConfigureEvent xce = event.xconfigure;
|
XConfigureEvent xce = event.xconfigure;
|
||||||
if (xce.width != window.width || xce.height != window.height) {
|
if (xce.width != window->width || xce.height != window->height) {
|
||||||
window.width = xce.width;
|
window->width = xce.width;
|
||||||
window.height = xce.height;
|
window->height = xce.height;
|
||||||
NOVA_DEBUG("Window event: RESIZED ({}x{})", xce.width, xce.height);
|
NOVA_DEBUG("Window event: RESIZED ({}x{})", xce.width, xce.height);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -75,7 +79,7 @@ void X11WindowDriver::poll_events() {
|
|||||||
case ClientMessage: {
|
case ClientMessage: {
|
||||||
if (event.xclient.data.l[0] == static_cast<long>(m_window_close_atom)) {
|
if (event.xclient.data.l[0] == static_cast<long>(m_window_close_atom)) {
|
||||||
NOVA_DEBUG("Window event: CLOSED");
|
NOVA_DEBUG("Window event: CLOSED");
|
||||||
destroy_window(&window);
|
destroy_window(window);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -105,10 +109,10 @@ WindowID X11WindowDriver::create_window(const std::string_view p_title, const u3
|
|||||||
|
|
||||||
X11::Window handle = XCreateSimpleWindow(m_display, DefaultRootWindow(m_display), 0, 0, p_width, p_height, 0, 0, 0);
|
X11::Window handle = XCreateSimpleWindow(m_display, DefaultRootWindow(m_display), 0, 0, p_width, p_height, 0, 0, 0);
|
||||||
|
|
||||||
Nova::Window& window = m_windows[handle];
|
Window* window = new Window();
|
||||||
window.width = p_width;
|
window->width = p_width;
|
||||||
window.height = p_height;
|
window->height = p_height;
|
||||||
window.handle = handle;
|
window->handle = handle;
|
||||||
|
|
||||||
XSetWMProtocols(m_display, handle, &m_window_close_atom, 1);
|
XSetWMProtocols(m_display, handle, &m_window_close_atom, 1);
|
||||||
XSelectInput(m_display, handle, StructureNotifyMask);
|
XSelectInput(m_display, handle, StructureNotifyMask);
|
||||||
@@ -116,7 +120,8 @@ WindowID X11WindowDriver::create_window(const std::string_view p_title, const u3
|
|||||||
XMapWindow(m_display, handle);
|
XMapWindow(m_display, handle);
|
||||||
XFlush(m_display);
|
XFlush(m_display);
|
||||||
|
|
||||||
return &window;
|
m_windows[handle] = window;
|
||||||
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
void X11WindowDriver::destroy_window(WindowID p_window) {
|
void X11WindowDriver::destroy_window(WindowID p_window) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace Nova {
|
|||||||
private:
|
private:
|
||||||
X11::Display* m_display = nullptr;
|
X11::Display* m_display = nullptr;
|
||||||
X11::Atom m_window_close_atom = 0;
|
X11::Atom m_window_close_atom = 0;
|
||||||
std::unordered_map<X11::Window, Nova::Window> m_windows;
|
std::unordered_map<X11::Window, WindowID> m_windows;
|
||||||
};
|
};
|
||||||
} // namespace Nova
|
} // namespace Nova
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user