diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-04 01:44:35 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-04 01:44:35 +0200 |
commit | 96104b55249ad0201b1be805e1874c759fdd0ac9 (patch) | |
tree | e56bc509d217f8e618a729b835ebd92b8bb6c16c /Applications/Taskbar/WindowList.h | |
parent | ea801a99dcd2f00e048f107e89d29fd07d7f018b (diff) | |
download | serenity-96104b55249ad0201b1be805e1874c759fdd0ac9.zip |
Taskbar: More bringup work. We now see a basic window list.
Diffstat (limited to 'Applications/Taskbar/WindowList.h')
-rw-r--r-- | Applications/Taskbar/WindowList.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/Applications/Taskbar/WindowList.h b/Applications/Taskbar/WindowList.h new file mode 100644 index 0000000000..7f5484376b --- /dev/null +++ b/Applications/Taskbar/WindowList.h @@ -0,0 +1,80 @@ +#pragma once + +#include <AK/AKString.h> +#include <AK/HashMap.h> +#include <AK/Traits.h> +#include <SharedGraphics/Rect.h> +#include <LibGUI/GButton.h> + +class WindowIdentifier { +public: + WindowIdentifier(int client_id, int window_id) + : m_client_id(client_id) + , m_window_id(window_id) + { + } + + int client_id() const { return m_client_id; } + int window_id() const { return m_window_id; } + + bool operator==(const WindowIdentifier& other) const + { + return m_client_id == other.m_client_id && m_window_id == other.m_window_id; + } +private: + int m_client_id { -1 }; + int m_window_id { -1 }; +}; + +namespace AK { +template<> +struct Traits<WindowIdentifier> { + static unsigned hash(const WindowIdentifier& w) { return pair_int_hash(w.client_id(), w.window_id()); } + static void dump(const WindowIdentifier& w) { kprintf("WindowIdentifier(%d, %d)", w.client_id(), w.window_id()); } +}; +} + +class Window { +public: + explicit Window(const WindowIdentifier& identifier) + : m_identifier(identifier) + { + } + + ~Window() + { + delete m_button; + } + + WindowIdentifier identifier() const { return m_identifier; } + + String title() const { return m_title; } + void set_title(const String& title) { m_title = title; } + + Rect rect() const { return m_rect; } + void set_rect(const Rect& rect) { m_rect = rect; } + + GButton* button() { return m_button; } + void set_button(GButton* button) { m_button = button; } + +private: + WindowIdentifier m_identifier; + String m_title; + Rect m_rect; + GButton* m_button { nullptr }; +}; + +class WindowList { +public: + template<typename Callback> void for_each_window(Callback callback) + { + for (auto& it : m_windows) + callback(*it.value); + } + + Window& ensure_window(const WindowIdentifier&); + void remove_window(const WindowIdentifier&); + +private: + HashMap<WindowIdentifier, OwnPtr<Window>> m_windows; +}; |