summaryrefslogtreecommitdiff
path: root/Applications/Taskbar/WindowList.cpp
blob: f7f8278586be583cb758bb08827b0df597f5b556 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "WindowList.h"
#include <LibGUI/GWindowServerConnection.h>

WindowList& WindowList::the()
{
    static WindowList* s_the;
    if (!s_the)
        s_the = new WindowList;
    return *s_the;
}

Window* WindowList::window(const WindowIdentifier& identifier)
{
    auto it = m_windows.find(identifier);
    if (it != m_windows.end())
        return it->value;
    return nullptr;
}

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);
    window->set_button(aid_create_button(identifier));
    window->button()->on_click = [window = window.ptr(), identifier](auto&) {
        if (window->is_minimized() || !window->is_active()) {
            GWindowServerConnection::the().post_message(WindowServer::WM_SetActiveWindow(identifier.client_id(), identifier.window_id()));
        } else {
            GWindowServerConnection::the().post_message(WindowServer::WM_SetWindowMinimized(identifier.client_id(), identifier.window_id(), true));
        }
    };
    auto& window_ref = *window;
    m_windows.set(identifier, move(window));
    return window_ref;
}

void WindowList::remove_window(const WindowIdentifier& identifier)
{
    m_windows.remove(identifier);
}