Hyprland/src/Compositor.hpp

187 lines
8.9 KiB
C++
Raw Normal View History

2022-03-16 21:37:21 +01:00
#pragma once
#include <memory>
2022-03-17 16:56:33 +01:00
#include <deque>
2022-03-18 22:35:51 +01:00
#include <list>
2022-03-16 21:37:21 +01:00
#include "defines.hpp"
#include "debug/Log.hpp"
#include "events/Events.hpp"
2022-03-17 15:53:45 +01:00
#include "config/ConfigManager.hpp"
2022-03-18 20:03:39 +01:00
#include "managers/ThreadManager.hpp"
#include "managers/XWaylandManager.hpp"
2022-06-09 12:46:55 +02:00
#include "managers/input/InputManager.hpp"
#include "managers/LayoutManager.hpp"
2022-03-19 17:48:18 +01:00
#include "managers/KeybindManager.hpp"
2022-03-23 22:01:59 +01:00
#include "managers/AnimationManager.hpp"
#include "managers/EventManager.hpp"
2022-05-28 17:32:19 +02:00
#include "debug/HyprDebugOverlay.hpp"
2022-03-17 16:56:33 +01:00
#include "helpers/Monitor.hpp"
2022-03-20 15:55:47 +01:00
#include "helpers/Workspace.hpp"
2022-03-17 20:22:29 +01:00
#include "Window.hpp"
#include "render/Renderer.hpp"
2022-04-04 19:44:25 +02:00
#include "render/OpenGL.hpp"
#include "hyprerror/HyprError.hpp"
2022-03-20 15:55:47 +01:00
2022-03-16 21:37:21 +01:00
class CCompositor {
public:
CCompositor();
~CCompositor();
// ------------------ WLR BASICS ------------------ //
wl_display* m_sWLDisplay;
2022-07-13 18:18:23 +02:00
wl_event_loop* m_sWLEventLoop;
2022-03-16 21:37:21 +01:00
wlr_backend* m_sWLRBackend;
2022-07-13 18:18:23 +02:00
wlr_session* m_sWLRSession;
2022-03-16 21:37:21 +01:00
wlr_renderer* m_sWLRRenderer;
wlr_allocator* m_sWLRAllocator;
wlr_compositor* m_sWLRCompositor;
2022-03-17 19:03:15 +01:00
wlr_subcompositor* m_sWLRSubCompositor;
wlr_data_device_manager* m_sWLRDataDevMgr;
2022-03-16 21:37:21 +01:00
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;
2022-03-17 19:03:15 +01:00
wlr_scene* m_sWLRScene;
2022-03-22 18:29:13 +01:00
wlr_input_inhibit_manager* m_sWLRInhibitMgr;
wlr_keyboard_shortcuts_inhibit_manager_v1* m_sWLRKbShInhibitMgr;
2022-03-24 17:17:08 +01:00
wlr_egl* m_sWLREGL;
2022-04-04 19:44:25 +02:00
int m_iDRMFD;
wlr_ext_workspace_manager_v1* m_sWLREXTWorkspaceMgr;
2022-04-14 21:48:12 +02:00
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;
2022-05-12 12:13:02 +02:00
wlr_virtual_pointer_manager_v1* m_sWLRVirtPtrMgr;
2022-05-29 11:24:42 +02:00
wlr_foreign_toplevel_manager_v1* m_sWLRToplevelMgr;
wlr_tablet_manager_v2* m_sWLRTabletManager;
2022-06-29 22:23:51 +02:00
wlr_xdg_foreign_registry* m_sWLRForeignRegistry;
wlr_idle_inhibit_manager_v1* m_sWLRIdleInhibitMgr;
2022-07-07 11:52:12 +02:00
wlr_pointer_gestures_v1* m_sWLRPointerGestures;
2022-07-30 22:41:24 +02:00
wlr_output_power_manager_v1* m_sWLROutputPowerMgr;
2022-08-05 13:03:37 +02:00
wlr_input_method_manager_v2* m_sWLRIMEMgr;
wlr_text_input_manager_v3* m_sWLRTextInputMgr;
2022-03-16 21:37:21 +01:00
// ------------------------------------------------- //
const char* m_szWLDisplaySocket;
std::string m_szInstanceSignature = "";
2022-07-10 15:41:26 +02:00
std::string m_szCurrentSplash = "error";
2022-03-16 21:37:21 +01:00
2022-07-27 12:32:00 +02:00
std::vector<std::shared_ptr<CMonitor>> m_vMonitors;
std::vector<std::shared_ptr<CMonitor>> m_vRealMonitors; // for all monitors, even those turned off
2022-06-30 15:44:26 +02:00
std::vector<std::unique_ptr<CWindow>> m_vWindows;
std::deque<std::unique_ptr<CWindow>> m_dUnmanagedX11Windows;
std::vector<std::unique_ptr<SXDGPopup>> m_vXDGPopups;
std::vector<std::unique_ptr<CWorkspace>> m_vWorkspaces;
std::vector<std::unique_ptr<SSubsurface>> m_vSubsurfaces;
std::vector<CWindow*> m_vWindowsFadingOut;
std::vector<SLayerSurface*> m_vSurfacesFadingOut;
2022-03-17 16:56:33 +01:00
void startCompositor();
2022-07-13 18:18:23 +02:00
void cleanup();
2022-03-17 20:22:29 +01:00
2022-03-20 14:36:55 +01:00
wlr_surface* m_pLastFocus = nullptr;
2022-04-02 18:57:09 +02:00
CWindow* m_pLastWindow = nullptr;
2022-07-27 12:32:00 +02:00
CMonitor* m_pLastMonitor = nullptr;
2022-03-22 18:29:13 +01:00
SSeat m_sSeat;
2022-03-18 22:53:27 +01:00
bool m_bReadyToProcess = false;
2022-07-13 18:18:23 +02:00
bool m_bSessionActive = true;
2022-07-31 15:46:42 +02:00
bool m_bDPMSStateON = true;
2022-03-17 20:22:29 +01:00
// ------------------------------------------------- //
2022-07-27 12:32:00 +02:00
CMonitor* getMonitorFromID(const int&);
CMonitor* getMonitorFromName(const std::string&);
CMonitor* getMonitorFromCursor();
CMonitor* getMonitorFromVector(const Vector2D&);
2022-03-18 22:35:51 +01:00
void removeWindowFromVectorSafe(CWindow*);
2022-04-02 18:57:09 +02:00
void focusWindow(CWindow*, wlr_surface* pSurface = nullptr);
2022-04-02 13:02:16 +02:00
void focusSurface(wlr_surface*, CWindow* pWindowOwner = nullptr);
2022-03-18 22:53:27 +01:00
bool windowExists(CWindow*);
2022-03-18 23:16:15 +01:00
bool windowValidMapped(CWindow*);
2022-03-18 22:53:27 +01:00
CWindow* vectorToWindow(const Vector2D&);
CWindow* vectorToWindowIdeal(const Vector2D&); // used only for finding a window to focus on, basically a "findFocusableWindow"
2022-03-20 18:31:58 +01:00
CWindow* vectorToWindowTiled(const Vector2D&);
2022-07-23 15:48:08 +02:00
wlr_surface* vectorToLayerSurface(const Vector2D&, std::vector<std::unique_ptr<SLayerSurface>>*, Vector2D*, SLayerSurface**);
2022-04-02 13:02:16 +02:00
wlr_surface* vectorWindowToSurface(const Vector2D&, CWindow*, Vector2D& sl);
2022-03-19 20:30:21 +01:00
CWindow* windowFromCursor();
2022-03-20 11:14:24 +01:00
CWindow* windowFloatingFromCursor();
2022-07-27 12:32:00 +02:00
CMonitor* getMonitorFromOutput(wlr_output*);
2022-03-20 14:00:46 +01:00
CWindow* getWindowForPopup(wlr_xdg_popup*);
2022-03-20 14:36:55 +01:00
CWindow* getWindowFromSurface(wlr_surface*);
2022-03-20 15:55:47 +01:00
bool isWorkspaceVisible(const int&);
CWorkspace* getWorkspaceByID(const int&);
2022-04-21 16:38:48 +02:00
CWorkspace* getWorkspaceByName(const std::string&);
CWorkspace* getWorkspaceByString(const std::string&);
2022-03-20 15:55:47 +01:00
void sanityCheckWorkspaces();
2022-07-07 11:52:12 +02:00
void updateWorkspaceWindowDecos(const int&);
2022-03-20 15:55:47 +01:00
int getWindowsOnWorkspace(const int&);
CWindow* getFirstWindowOnWorkspace(const int&);
void fixXWaylandWindowsOnWorkspace(const int&);
2022-03-21 19:18:33 +01:00
CWindow* getFullscreenWindowOnWorkspace(const int&);
2022-03-22 18:29:13 +01:00
bool doesSeatAcceptInput(wlr_surface*);
2022-04-02 13:02:16 +02:00
bool isWindowActive(CWindow*);
2022-04-04 16:25:30 +02:00
void moveWindowToTop(CWindow*);
void cleanupFadingOut(const int& monid);
2022-04-09 13:26:55 +02:00
CWindow* getWindowInDirection(CWindow*, char);
2022-04-28 17:55:25 +02:00
void deactivateAllWLRWorkspaces(wlr_ext_workspace_handle_v1* exclude = nullptr);
2022-04-13 20:45:06 +02:00
CWindow* getNextWindowOnWorkspace(CWindow*);
2022-07-09 18:39:41 +02:00
CWindow* getPrevWindowOnWorkspace(CWindow*);
2022-04-21 16:38:48 +02:00
int getNextAvailableNamedWorkspace();
bool isPointOnAnyMonitor(const Vector2D&);
2022-04-25 13:40:46 +02:00
CWindow* getConstraintWindow(SMouse*);
2022-07-27 12:32:00 +02:00
CMonitor* getMonitorInDirection(const char&);
2022-07-12 13:40:55 +02:00
void updateAllWindowsAnimatedDecorationValues();
void updateWindowAnimatedDecorationValues(CWindow*);
2022-05-30 17:11:35 +02:00
void moveWindowToWorkspace(CWindow*, const std::string&);
int getNextAvailableMonitorID();
2022-07-27 12:32:00 +02:00
void moveWorkspaceToMonitor(CWorkspace*, CMonitor*);
bool workspaceIDOutOfBounds(const int&);
2022-06-26 12:12:29 +02:00
void setWindowFullscreen(CWindow*, bool, eFullscreenMode);
2022-06-30 15:44:26 +02:00
void moveUnmanagedX11ToWindows(CWindow*);
CWindow* getX11Parent(CWindow*);
2022-07-27 12:32:00 +02:00
void scheduleFrameForMonitor(CMonitor*);
void addToFadingOutSafe(SLayerSurface*);
void addToFadingOutSafe(CWindow*);
2022-07-26 17:30:30 +02:00
CWindow* getWindowByRegex(const std::string&);
2022-08-01 18:50:16 +02:00
void warpCursorTo(const Vector2D&);
2022-08-05 17:07:01 +02:00
SLayerSurface* getLayerSurfaceFromWlr(wlr_layer_surface_v1*);
2022-08-10 17:46:01 +02:00
SLayerSurface* getLayerSurfaceFromSurface(wlr_surface*);
void closeWindow(CWindow*);
2022-03-18 23:52:36 +01:00
std::string explicitConfigPath;
2022-07-31 00:27:32 +02:00
void startHyprCtlTick();
2022-03-18 23:52:36 +01:00
private:
void initAllSignals();
2022-07-31 00:27:32 +02:00
void setRandomSplash();
2022-03-16 21:37:21 +01:00
};
2022-03-20 13:37:07 +01:00
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")};