2019-04-03 20:44:35 -03:00
|
|
|
#include "WindowList.h"
|
2019-11-08 07:39:45 -03:00
|
|
|
#include <LibGUI/GWindowServerConnection.h>
|
2019-04-03 20:44:35 -03:00
|
|
|
|
2019-04-23 18:14:14 -03:00
|
|
|
WindowList& WindowList::the()
|
|
|
|
|
{
|
|
|
|
|
static WindowList* s_the;
|
|
|
|
|
if (!s_the)
|
|
|
|
|
s_the = new WindowList;
|
|
|
|
|
return *s_the;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 19:39:11 -03:00
|
|
|
Window* WindowList::window(const WindowIdentifier& identifier)
|
|
|
|
|
{
|
|
|
|
|
auto it = m_windows.find(identifier);
|
|
|
|
|
if (it != m_windows.end())
|
|
|
|
|
return it->value;
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-03 20:44:35 -03:00
|
|
|
Window& WindowList::ensure_window(const WindowIdentifier& identifier)
|
|
|
|
|
{
|
|
|
|
|
auto it = m_windows.find(identifier);
|
|
|
|
|
if (it != m_windows.end())
|
|
|
|
|
return *it->value;
|
|
|
|
|
auto window = make<Window>(identifier);
|
2019-04-23 18:14:14 -03:00
|
|
|
window->set_button(aid_create_button(identifier));
|
2019-12-02 05:33:37 -03:00
|
|
|
window->button()->on_click = [window = window.ptr(), identifier](auto&) {
|
2019-04-23 21:48:02 -03:00
|
|
|
if (window->is_minimized() || !window->is_active()) {
|
2019-12-02 05:33:37 -03:00
|
|
|
GWindowServerConnection::the().post_message(WindowServer::WM_SetActiveWindow(identifier.client_id(), identifier.window_id()));
|
2019-04-23 21:48:02 -03:00
|
|
|
} else {
|
2019-12-02 05:33:37 -03:00
|
|
|
GWindowServerConnection::the().post_message(WindowServer::WM_SetWindowMinimized(identifier.client_id(), identifier.window_id(), true));
|
2019-04-23 21:48:02 -03:00
|
|
|
}
|
2019-04-04 09:38:53 -03:00
|
|
|
};
|
2019-04-03 20:44:35 -03:00
|
|
|
auto& window_ref = *window;
|
|
|
|
|
m_windows.set(identifier, move(window));
|
|
|
|
|
return window_ref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WindowList::remove_window(const WindowIdentifier& identifier)
|
|
|
|
|
{
|
|
|
|
|
m_windows.remove(identifier);
|
|
|
|
|
}
|