aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Compositor.hpp
blob: d2839103c22651ead61b3a920f8aa5de42730637 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#pragma once

#include <memory>
#include <deque>
#include <list>

#include "defines.hpp"
#include "debug/Log.hpp"
#include "events/Events.hpp"
#include "config/ConfigManager.hpp"
#include "managers/ThreadManager.hpp"
#include "managers/XWaylandManager.hpp"
#include "managers/InputManager.hpp"
#include "managers/LayoutManager.hpp"
#include "managers/KeybindManager.hpp"
#include "managers/AnimationManager.hpp"
#include "managers/EventManager.hpp"
#include "debug/HyprDebugOverlay.hpp"
#include "helpers/Monitor.hpp"
#include "helpers/Workspace.hpp"
#include "Window.hpp"
#include "render/Renderer.hpp"
#include "render/OpenGL.hpp"
#include "hyprerror/HyprError.hpp"

class CCompositor {
public:
    CCompositor();
    ~CCompositor();

    // ------------------ WLR BASICS ------------------ //
    wl_display*                      m_sWLDisplay;
    wlr_backend*                     m_sWLRBackend;
    wlr_renderer*                    m_sWLRRenderer;
    wlr_allocator*                   m_sWLRAllocator;
    wlr_compositor*                  m_sWLRCompositor;
    wlr_subcompositor*               m_sWLRSubCompositor;
    wlr_data_device_manager*         m_sWLRDataDevMgr;
    wlr_xdg_activation_v1*           m_sWLRXDGActivation;
    wlr_output_layout*               m_sWLROutputLayout;
    wlr_idle*                        m_sWLRIdle;
    wlr_layer_shell_v1*              m_sWLRLayerShell;
    wlr_xdg_shell*                   m_sWLRXDGShell;
    wlr_cursor*                      m_sWLRCursor;
    wlr_xcursor_manager*             m_sWLRXCursorMgr;
    wlr_virtual_keyboard_manager_v1* m_sWLRVKeyboardMgr;
    wlr_output_manager_v1*           m_sWLROutputMgr;
    wlr_presentation*                m_sWLRPresentation;
    wlr_scene*                       m_sWLRScene;
    wlr_input_inhibit_manager*       m_sWLRInhibitMgr;
    wlr_keyboard_shortcuts_inhibit_manager_v1* m_sWLRKbShInhibitMgr;
    wlr_egl*                         m_sWLREGL;
    int                              m_iDRMFD;
    wlr_ext_workspace_manager_v1*    m_sWLREXTWorkspaceMgr;
    wlr_linux_dmabuf_v1*             m_sWLRDmabuf;
    wlr_pointer_constraints_v1*      m_sWLRPointerConstraints;
    wlr_relative_pointer_manager_v1* m_sWLRRelPointerMgr;
    wlr_server_decoration_manager*   m_sWLRServerDecoMgr;
    wlr_xdg_decoration_manager_v1*   m_sWLRXDGDecoMgr;
    wlr_virtual_pointer_manager_v1*  m_sWLRVirtPtrMgr;
    wlr_foreign_toplevel_manager_v1* m_sWLRToplevelMgr;
    // ------------------------------------------------- //


    const char*             m_szWLDisplaySocket;

    std::list<SMonitor>     m_lMonitors;
    std::list<CWindow>      m_lWindows;
    std::list<SXDGPopup>    m_lXDGPopups;
    std::list<CWorkspace>   m_lWorkspaces;
    std::list<SSubsurface>  m_lSubsurfaces;
    std::list<CWindow*>     m_lWindowsFadingOut;
    std::list<SLayerSurface*> m_lSurfacesFadingOut;

    void                    startCompositor(); 
    void                    cleanupExit();

    wlr_surface*            m_pLastFocus = nullptr;
    CWindow*                m_pLastWindow = nullptr;
    SMonitor*               m_pLastMonitor = nullptr;
    
    SSeat                   m_sSeat;

    bool                    m_bReadyToProcess = false;

    // ------------------------------------------------- //

    SMonitor*               getMonitorFromID(const int&);
    SMonitor*               getMonitorFromName(const std::string&);
    SMonitor*               getMonitorFromCursor();
    SMonitor*               getMonitorFromVector(const Vector2D&);
    void                    removeWindowFromVectorSafe(CWindow*);
    void                    focusWindow(CWindow*, wlr_surface* pSurface = nullptr);
    void                    focusSurface(wlr_surface*, CWindow* pWindowOwner = nullptr);
    bool                    windowExists(CWindow*);
    bool                    windowValidMapped(CWindow*);
    CWindow*                vectorToWindow(const Vector2D&);
    CWindow*                vectorToWindowIdeal(const Vector2D&);
    CWindow*                vectorToWindowTiled(const Vector2D&);
    wlr_surface*            vectorToLayerSurface(const Vector2D&, std::list<SLayerSurface*>*, Vector2D*);
    wlr_surface*            vectorWindowToSurface(const Vector2D&, CWindow*, Vector2D& sl);
    CWindow*                windowFromCursor();
    CWindow*                windowFloatingFromCursor();
    SMonitor*               getMonitorFromOutput(wlr_output*);
    CWindow*                getWindowForPopup(wlr_xdg_popup*);
    CWindow*                getWindowFromSurface(wlr_surface*);
    bool                    isWorkspaceVisible(const int&);
    CWorkspace*             getWorkspaceByID(const int&);
    CWorkspace*             getWorkspaceByName(const std::string&);
    CWorkspace*             getWorkspaceByString(const std::string&);
    void                    sanityCheckWorkspaces();
    int                     getWindowsOnWorkspace(const int&);
    CWindow*                getFirstWindowOnWorkspace(const int&);
    void                    fixXWaylandWindowsOnWorkspace(const int&);
    CWindow*                getFullscreenWindowOnWorkspace(const int&);
    bool                    doesSeatAcceptInput(wlr_surface*);
    bool                    isWindowActive(CWindow*);
    void                    moveWindowToTop(CWindow*);
    void                    cleanupFadingOut();
    CWindow*                getWindowInDirection(CWindow*, char);
    void                    deactivateAllWLRWorkspaces(wlr_ext_workspace_handle_v1* exclude = nullptr);
    CWindow*                getNextWindowOnWorkspace(CWindow*);
    int                     getNextAvailableNamedWorkspace();
    bool                    isPointOnAnyMonitor(const Vector2D&);
    CWindow*                getConstraintWindow(SMouse*);
    SMonitor*               getMonitorInDirection(const char&);
    void                    updateAllWindowsBorders();
    void                    updateWindowBorderColor(CWindow*);

private:
    void                    initAllSignals();
};


inline std::unique_ptr<CCompositor> g_pCompositor;

// For XWayland
inline std::map<std::string, xcb_atom_t> HYPRATOMS = {
    HYPRATOM("_NET_WM_WINDOW_TYPE"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_NORMAL"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_DOCK"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_DIALOG"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_UTILITY"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_TOOLBAR"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_SPLASH"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_MENU"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_POPUP_MENU"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_TOOLTIP"),
    HYPRATOM("_NET_WM_WINDOW_TYPE_NOTIFICATION")};