Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <AK/Vector.h>
10#include <AK/WeakPtr.h>
11#include <LibCore/Object.h>
12#include <LibGfx/Forward.h>
13#include <LibGfx/Rect.h>
14
15namespace WindowServer {
16
17class KeyEvent;
18class Window;
19
20class WindowSwitcher final : public Core::Object {
21 C_OBJECT(WindowSwitcher)
22public:
23 enum class Mode {
24 ShowAllWindows,
25 ShowCurrentDesktop
26 };
27 static WindowSwitcher& the();
28
29 virtual ~WindowSwitcher() override = default;
30
31 bool is_visible() const { return m_visible; }
32 void set_visible(bool);
33
34 void show(Mode mode)
35 {
36 m_mode = mode;
37 set_visible(true);
38 }
39 void hide() { set_visible(false); }
40
41 void on_key_event(KeyEvent const&);
42
43 void refresh();
44 void refresh_if_needed();
45
46 void select_window(Window&);
47
48 Mode mode() const { return m_mode; }
49
50private:
51 WindowSwitcher();
52
53 int thumbnail_width() const { return 64; }
54 int thumbnail_height() const { return 64; }
55 int item_height() const { return 14 + thumbnail_height(); }
56 int padding() const { return 30; }
57 int item_padding() const { return 10; }
58
59 void draw();
60 void redraw();
61 void select_window_at_index(int index);
62 Gfx::IntRect item_rect(int index) const;
63 Window* selected_window();
64 void clear_hovered_index();
65
66 virtual void event(Core::Event&) override;
67
68 RefPtr<Window> m_switcher_window;
69 Mode m_mode { Mode::ShowCurrentDesktop };
70 Gfx::IntRect m_rect;
71 bool m_visible { false };
72 bool m_windows_on_multiple_stacks { false };
73 Vector<WeakPtr<Window>> m_windows;
74 int m_selected_index { 0 };
75 int m_hovered_index { -1 };
76};
77
78}