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>
2024-06-19 18:36:40 +02:00
# include <sys/resource.h>
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"
2022-03-19 15:59:53 +01:00
# 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"
2022-05-24 19:42:43 +02:00
# include "managers/EventManager.hpp"
2022-12-05 18:05:15 +01:00
# include "managers/ProtocolManager.hpp"
2023-02-03 12:58:55 +01:00
# include "managers/SessionLockManager.hpp"
2023-02-19 21:54:53 +01:00
# include "managers/HookSystemManager.hpp"
2022-05-28 17:32:19 +02:00
# include "debug/HyprDebugOverlay.hpp"
2023-02-27 13:32:38 +01:00
# include "debug/HyprNotificationOverlay.hpp"
2022-03-17 16:56:33 +01:00
# include "helpers/Monitor.hpp"
2024-02-29 14:03:38 +01:00
# include "desktop/Workspace.hpp"
2024-03-20 02:44:51 +01:00
# include "desktop/Window.hpp"
2022-03-17 20:22:29 +01:00
# include "render/Renderer.hpp"
2022-04-04 19:44:25 +02:00
# include "render/OpenGL.hpp"
2022-04-08 21:40:41 +02:00
# include "hyprerror/HyprError.hpp"
2023-02-27 13:32:38 +01:00
# include "plugins/PluginSystem.hpp"
2023-09-29 17:38:13 +02:00
# include "helpers/Watchdog.hpp"
2022-03-20 15:55:47 +01:00
2024-07-21 13:09:54 +02:00
# include <aquamarine/backend/Backend.hpp>
# include <aquamarine/output/Output.hpp>
2024-06-08 10:07:59 +02:00
class CWLSurfaceResource ;
2023-12-06 23:54:56 +01:00
enum eManagersInitStage {
2023-03-05 14:37:21 +01:00
STAGE_PRIORITY = 0 ,
2024-06-08 10:07:59 +02:00
STAGE_BASICINIT ,
2023-03-05 14:37:21 +01:00
STAGE_LATE
} ;
2022-03-16 21:37:21 +01:00
class CCompositor {
2022-12-16 18:17:31 +01:00
public :
2022-03-16 21:37:21 +01:00
CCompositor ( ) ;
~ CCompositor ( ) ;
2024-07-21 13:09:54 +02:00
wl_display * m_sWLDisplay ;
wl_event_loop * m_sWLEventLoop ;
int m_iDRMFD = - 1 ;
bool m_bInitialized = false ;
SP < Aquamarine : : CBackend > m_pAqBackend ;
2022-03-16 21:37:21 +01:00
2024-04-28 23:25:24 +02:00
std : : string m_szHyprTempDataRoot = " " ;
2022-12-16 18:17:31 +01:00
std : : string m_szWLDisplaySocket = " " ;
std : : string m_szInstanceSignature = " " ;
2024-04-28 23:25:24 +02:00
std : : string m_szInstancePath = " " ;
2022-12-16 18:17:31 +01:00
std : : string m_szCurrentSplash = " error " ;
2022-03-16 21:37:21 +01:00
2024-04-27 13:43:12 +02:00
std : : vector < SP < CMonitor > > m_vMonitors ;
std : : vector < SP < CMonitor > > m_vRealMonitors ; // for all monitors, even those turned off
std : : vector < PHLWINDOW > m_vWindows ;
2024-05-09 22:47:21 +02:00
std : : vector < PHLLS > m_vLayers ;
2024-04-02 21:32:39 +02:00
std : : vector < PHLWORKSPACE > m_vWorkspaces ;
2024-04-27 13:43:12 +02:00
std : : vector < PHLWINDOWREF > m_vWindowsFadingOut ;
2024-04-30 03:41:27 +02:00
std : : vector < PHLLSREF > m_vSurfacesFadingOut ;
2022-03-16 21:37:21 +01:00
2023-07-24 18:50:17 +02:00
std : : unordered_map < std : : string , uint64_t > m_mMonitorIDMap ;
2023-07-09 23:08:40 +02:00
2024-07-22 13:16:25 +02:00
void initServer ( std : : string socketName , int socketFd ) ;
void startCompositor ( ) ;
2024-07-24 19:07:36 +02:00
void stopCompositor ( ) ;
2022-12-16 18:17:31 +01:00
void cleanup ( ) ;
2023-08-08 16:16:34 +02:00
void createLockFile ( ) ;
void removeLockFile ( ) ;
2024-06-19 18:36:40 +02:00
void bumpNofile ( ) ;
void restoreNofile ( ) ;
2022-03-17 16:56:33 +01:00
2024-06-08 10:07:59 +02:00
WP < CWLSurfaceResource > m_pLastFocus ;
2024-04-27 13:43:12 +02:00
PHLWINDOWREF m_pLastWindow ;
2024-05-05 23:18:10 +02:00
WP < CMonitor > m_pLastMonitor ;
2022-03-17 20:22:29 +01:00
2024-04-27 13:43:12 +02:00
std : : vector < PHLWINDOWREF > m_vWindowFocusHistory ; // first element is the most recently focused.
2023-01-20 19:15:15 +01:00
2022-12-16 18:17:31 +01:00
bool m_bReadyToProcess = false ;
bool m_bSessionActive = true ;
bool m_bDPMSStateON = true ;
2024-07-21 13:09:54 +02:00
bool m_bUnsafeState = false ; // unsafe state is when there is no monitors.
bool m_bNextIsUnsafe = false ;
2023-11-01 19:53:36 +01:00
CMonitor * m_pUnsafeOutput = nullptr ; // fallback output for the unsafe state
2022-12-16 18:17:31 +01:00
bool m_bIsShuttingDown = false ;
2022-04-28 17:57:24 +02:00
2022-03-17 20:22:29 +01:00
// ------------------------------------------------- //
2024-06-08 10:07:59 +02:00
CMonitor * getMonitorFromID ( const int & ) ;
CMonitor * getMonitorFromName ( const std : : string & ) ;
CMonitor * getMonitorFromDesc ( const std : : string & ) ;
CMonitor * getMonitorFromCursor ( ) ;
CMonitor * getMonitorFromVector ( const Vector2D & ) ;
void removeWindowFromVectorSafe ( PHLWINDOW ) ;
void focusWindow ( PHLWINDOW , SP < CWLSurfaceResource > pSurface = nullptr ) ;
void focusSurface ( SP < CWLSurfaceResource > , PHLWINDOW pWindowOwner = nullptr ) ;
bool monitorExists ( CMonitor * ) ;
PHLWINDOW vectorToWindowUnified ( const Vector2D & , uint8_t properties , PHLWINDOW pIgnoreWindow = nullptr ) ;
SP < CWLSurfaceResource > vectorToLayerSurface ( const Vector2D & , std : : vector < PHLLSREF > * , Vector2D * , PHLLS * ) ;
SP < CWLSurfaceResource > vectorToLayerPopupSurface ( const Vector2D & , CMonitor * monitor , Vector2D * , PHLLS * ) ;
SP < CWLSurfaceResource > vectorWindowToSurface ( const Vector2D & , PHLWINDOW , Vector2D & sl ) ;
Vector2D vectorToSurfaceLocal ( const Vector2D & , PHLWINDOW , SP < CWLSurfaceResource > ) ;
2024-07-21 13:09:54 +02:00
CMonitor * getMonitorFromOutput ( SP < Aquamarine : : IOutput > ) ;
CMonitor * getRealMonitorFromOutput ( SP < Aquamarine : : IOutput > ) ;
2024-06-08 10:07:59 +02:00
PHLWINDOW getWindowFromSurface ( SP < CWLSurfaceResource > ) ;
PHLWINDOW getWindowFromHandle ( uint32_t ) ;
bool isWorkspaceVisible ( PHLWORKSPACE ) ;
2024-06-11 22:56:35 +02:00
bool isWorkspaceVisibleNotCovered ( PHLWORKSPACE ) ;
2024-06-08 10:07:59 +02:00
PHLWORKSPACE getWorkspaceByID ( const int & ) ;
PHLWORKSPACE getWorkspaceByName ( const std : : string & ) ;
PHLWORKSPACE getWorkspaceByString ( const std : : string & ) ;
void sanityCheckWorkspaces ( ) ;
void updateWorkspaceWindowDecos ( const int & ) ;
2024-07-11 16:10:42 +02:00
void updateWorkspaceWindowData ( const int & ) ;
2024-06-08 10:07:59 +02:00
int getWindowsOnWorkspace ( const int & id , std : : optional < bool > onlyTiled = { } , std : : optional < bool > onlyVisible = { } ) ;
int getGroupsOnWorkspace ( const int & id , std : : optional < bool > onlyTiled = { } , std : : optional < bool > onlyVisible = { } ) ;
PHLWINDOW getUrgentWindow ( ) ;
bool hasUrgentWindowOnWorkspace ( const int & ) ;
PHLWINDOW getFirstWindowOnWorkspace ( const int & ) ;
PHLWINDOW getTopLeftWindowOnWorkspace ( const int & ) ;
PHLWINDOW getFullscreenWindowOnWorkspace ( const int & ) ;
bool isWindowActive ( PHLWINDOW ) ;
void changeWindowZOrder ( PHLWINDOW , bool ) ;
void cleanupFadingOut ( const int & monid ) ;
PHLWINDOW getWindowInDirection ( PHLWINDOW , char ) ;
PHLWINDOW getNextWindowOnWorkspace ( PHLWINDOW , bool focusableOnly = false , std : : optional < bool > floating = { } ) ;
PHLWINDOW getPrevWindowOnWorkspace ( PHLWINDOW , bool focusableOnly = false , std : : optional < bool > floating = { } ) ;
int getNextAvailableNamedWorkspace ( ) ;
bool isPointOnAnyMonitor ( const Vector2D & ) ;
bool isPointOnReservedArea ( const Vector2D & point , const CMonitor * monitor = nullptr ) ;
CMonitor * getMonitorInDirection ( const char & ) ;
CMonitor * getMonitorInDirection ( CMonitor * , const char & ) ;
void updateAllWindowsAnimatedDecorationValues ( ) ;
void updateWorkspaceWindows ( const int64_t & id ) ;
void updateWindowAnimatedDecorationValues ( PHLWINDOW ) ;
int getNextAvailableMonitorID ( std : : string const & name ) ;
void moveWorkspaceToMonitor ( PHLWORKSPACE , CMonitor * , bool noWarpCursor = false ) ;
void swapActiveWorkspaces ( CMonitor * , CMonitor * ) ;
CMonitor * getMonitorFromString ( const std : : string & ) ;
bool workspaceIDOutOfBounds ( const int64_t & ) ;
void setWindowFullscreen ( PHLWINDOW , bool , eFullscreenMode mode = FULLSCREEN_INVALID ) ;
void updateFullscreenFadeOnWorkspace ( PHLWORKSPACE ) ;
PHLWINDOW getX11Parent ( PHLWINDOW ) ;
2024-07-21 13:09:54 +02:00
void scheduleFrameForMonitor ( CMonitor * , Aquamarine : : IOutput : : scheduleFrameReason reason = Aquamarine : : IOutput : : AQ_SCHEDULE_CLIENT_UNKNOWN ) ;
2024-06-08 10:07:59 +02:00
void addToFadingOutSafe ( PHLLS ) ;
2024-06-12 22:57:06 +02:00
void removeFromFadingOutSafe ( PHLLS ) ;
2024-06-08 10:07:59 +02:00
void addToFadingOutSafe ( PHLWINDOW ) ;
PHLWINDOW getWindowByRegex ( const std : : string & ) ;
void warpCursorTo ( const Vector2D & , bool force = false ) ;
PHLLS getLayerSurfaceFromSurface ( SP < CWLSurfaceResource > ) ;
void closeWindow ( PHLWINDOW ) ;
Vector2D parseWindowVectorArgsRelative ( const std : : string & , const Vector2D & ) ;
void forceReportSizesToWindowsOnWorkspace ( const int & ) ;
PHLWORKSPACE createNewWorkspace ( const int & , const int & , const std : : string & name = " " , bool isEmtpy = true ) ; // will be deleted next frame if left empty and unfocused!
void renameWorkspace ( const int & , const std : : string & name = " " ) ;
void setActiveMonitor ( CMonitor * ) ;
bool isWorkspaceSpecial ( const int & ) ;
int getNewSpecialID ( ) ;
void performUserChecks ( ) ;
void moveWindowToWorkspaceSafe ( PHLWINDOW pWindow , PHLWORKSPACE pWorkspace ) ;
PHLWINDOW getForceFocus ( ) ;
void arrangeMonitors ( ) ;
void enterUnsafeState ( ) ;
void leaveUnsafeState ( ) ;
void setPreferredScaleForSurface ( SP < CWLSurfaceResource > pSurface , double scale ) ;
void setPreferredTransformForSurface ( SP < CWLSurfaceResource > pSurface , wl_output_transform transform ) ;
void updateSuspendedStates ( ) ;
PHLWINDOW windowForCPointer ( CWindow * ) ;
2024-07-21 13:09:54 +02:00
void onNewMonitor ( SP < Aquamarine : : IOutput > output ) ;
2024-06-08 10:07:59 +02:00
std : : string explicitConfigPath ;
2022-12-16 18:17:31 +01:00
private :
2024-06-06 20:27:09 +02:00
void initAllSignals ( ) ;
void removeAllSignals ( ) ;
void cleanEnvironment ( ) ;
void setRandomSplash ( ) ;
void initManagers ( eManagersInitStage stage ) ;
void prepareFallbackOutput ( ) ;
2024-06-19 18:36:40 +02:00
uint64_t m_iHyprlandPID = 0 ;
wl_event_source * m_critSigSource = nullptr ;
rlimit m_sOriginalNofile = { 0 } ;
2022-03-16 21:37:21 +01:00
} ;
2022-03-20 13:37:07 +01:00
inline std : : unique_ptr < CCompositor > g_pCompositor ;