summaryrefslogtreecommitdiff
path: root/Userland/Services/Taskbar/WindowList.cpp
blob: 0af99bf5b085346b0270514ecf56fb6d8ff273be (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
43
44
45
46
47
48
49
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include "WindowList.h"

WindowList& WindowList::the()
{
    static WindowList s_the;
    return s_the;
}

Window* WindowList::find_parent(const Window& window)
{
    if (!window.parent_identifier().is_valid())
        return nullptr;
    for (auto& it : m_windows) {
        auto& w = *it.value;
        if (w.identifier() == window.parent_identifier())
            return &w;
    }
    return nullptr;
}

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);
    auto& window_ref = *window;
    m_windows.set(identifier, move(window));
    return window_ref;
}

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