summaryrefslogtreecommitdiff
path: root/WindowServer/WSWindowManager.h
blob: 9df93d8515f73df1ca58b123828aebc7a129bbb9 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once

#include <Widgets/Rect.h>
#include <Widgets/Color.h>
#include <Widgets/Painter.h>
#include <AK/HashTable.h>
#include <AK/InlineLinkedList.h>
#include <AK/WeakPtr.h>
#include <AK/Lock.h>
#include "WSEventReceiver.h"

class WSScreen;
class MouseEvent;
class PaintEvent;
class WSWindow;
class CharacterBitmap;
class GraphicsBitmap;

class WSWindowManager : public WSEventReceiver {
public:
    static WSWindowManager& the();
    void add_window(WSWindow&);
    void remove_window(WSWindow&);

    void notify_title_changed(WSWindow&);
    void notify_rect_changed(WSWindow&, const Rect& oldRect, const Rect& newRect);

    WSWindow* activeWindow() { return m_active_window.ptr(); }

    void move_to_front(WSWindow&);

    static void initialize();

    void draw_cursor();

    void invalidate(const WSWindow&);
    void invalidate(const WSWindow&, const Rect&);
    void invalidate(const Rect&);
    void invalidate();
    void flush(const Rect&);

private:
    WSWindowManager();
    virtual ~WSWindowManager() override;

    void process_mouse_event(MouseEvent&);
    void handle_titlebar_mouse_event(WSWindow&, MouseEvent&);

    void set_active_window(WSWindow*);
    
    virtual void event(WSEvent&) override;

    void compose();
    void paint_window_frame(WSWindow&);

    WSScreen& m_screen;
    Rect m_screen_rect;

    Color m_active_window_border_color;
    Color m_active_window_title_color;

    Color m_inactive_window_border_color;
    Color m_inactive_window_title_color;

    HashTable<WSWindow*> m_windows;
    InlineLinkedList<WSWindow> m_windows_in_order;

    WeakPtr<WSWindow> m_active_window;

    WeakPtr<WSWindow> m_dragWindow;

    Point m_drag_origin;
    Point m_drag_window_origin;
    Rect m_last_drag_rect;
    Rect m_drag_start_rect;
    Rect m_drag_end_rect;

    Rect m_last_cursor_rect;

    unsigned m_recompose_count { 0 };
    unsigned m_flush_count { 0 };

    RetainPtr<GraphicsBitmap> m_front_bitmap;
    RetainPtr<GraphicsBitmap> m_back_bitmap;

    Vector<Rect> m_invalidated_rects;

    bool m_pending_compose_event { false };

    RetainPtr<CharacterBitmap> m_cursor_bitmap_inner;
    RetainPtr<CharacterBitmap> m_cursor_bitmap_outer;

    OwnPtr<Painter> m_back_painter;
    OwnPtr<Painter> m_front_painter;

    mutable Lock m_lock;

    bool m_flash_flush { false };
};