2022-03-21 15:17:04 +01:00
# include "Events.hpp"
# include "../Compositor.hpp"
# include "../helpers/WLClasses.hpp"
2022-06-09 12:46:55 +02:00
# include "../managers/input/InputManager.hpp"
2022-03-21 15:17:04 +01:00
# include "../render/Renderer.hpp"
// ------------------------------------------------------------ //
// __ _______ _ _ _____ ______ _______ //
// \ \ / /_ _| \ | | __ \ / __ \ \ / / ____| //
// \ \ /\ / / | | | \| | | | | | | \ \ /\ / / (___ //
// \ \/ \/ / | | | . ` | | | | | | |\ \/ \/ / \___ \ //
// \ /\ / _| |_| |\ | |__| | |__| | \ /\ / ____) | //
// \/ \/ |_____|_| \_|_____/ \____/ \/ \/ |_____/ //
// //
// ------------------------------------------------------------ //
2022-03-27 21:46:27 +02:00
void addViewCoords ( void * pWindow , int * x , int * y ) {
const auto PWINDOW = ( CWindow * ) pWindow ;
2022-04-23 14:35:34 +02:00
* x + = PWINDOW - > m_vRealPosition . goalv ( ) . x ;
* y + = PWINDOW - > m_vRealPosition . goalv ( ) . y ;
2022-06-22 15:45:56 +02:00
2022-12-08 19:52:48 +01:00
if ( ! PWINDOW - > m_bIsX11 & & PWINDOW - > m_bIsMapped ) {
2022-06-22 15:45:56 +02:00
wlr_box geom ;
wlr_xdg_surface_get_geometry ( PWINDOW - > m_uSurface . xdg , & geom ) ;
* x - = geom . x ;
* y - = geom . y ;
}
2022-03-27 21:46:27 +02:00
}
2022-12-09 16:00:58 +01:00
void setAnimToMove ( void * data ) {
2022-12-16 18:17:31 +01:00
auto * const PANIMCFG = g_pConfigManager - > getAnimationPropertyConfig ( " windowsMove " ) ;
2022-07-28 13:28:43 +02:00
2022-12-09 16:00:58 +01:00
CAnimatedVariable * animvar = ( CAnimatedVariable * ) data ;
2022-07-28 13:28:43 +02:00
2022-12-09 16:00:58 +01:00
animvar - > setConfig ( PANIMCFG ) ;
2022-07-28 13:28:43 +02:00
}
2022-03-28 22:31:39 +02:00
void Events : : listener_mapWindow ( void * owner , void * data ) {
2022-12-16 18:17:31 +01:00
CWindow * PWINDOW = ( CWindow * ) owner ;
2023-04-12 14:38:15 +02:00
static auto * const PINACTIVEALPHA = & g_pConfigManager - > getConfigValuePtr ( " decoration:inactive_opacity " ) - > floatValue ;
static auto * const PACTIVEALPHA = & g_pConfigManager - > getConfigValuePtr ( " decoration:active_opacity " ) - > floatValue ;
static auto * const PDIMSTRENGTH = & g_pConfigManager - > getConfigValuePtr ( " decoration:dim_strength " ) - > floatValue ;
static auto * const PSWALLOW = & g_pConfigManager - > getConfigValuePtr ( " misc:enable_swallow " ) - > intValue ;
static auto * const PSWALLOWREGEX = & g_pConfigManager - > getConfigValuePtr ( " misc:swallow_regex " ) - > strValue ;
static auto * const PSWALLOWEXREGEX = & g_pConfigManager - > getConfigValuePtr ( " misc:swallow_exception_regex " ) - > strValue ;
2023-10-02 17:27:32 +02:00
static auto * const PNEWTAKESOVERFS = & g_pConfigManager - > getConfigValuePtr ( " misc:new_window_takes_over_fullscreen " ) - > intValue ;
2022-12-16 18:17:31 +01:00
auto PMONITOR = g_pCompositor - > m_pLastMonitor ;
const auto PWORKSPACE =
PMONITOR - > specialWorkspaceID ? g_pCompositor - > getWorkspaceByID ( PMONITOR - > specialWorkspaceID ) : g_pCompositor - > getWorkspaceByID ( PMONITOR - > activeWorkspace ) ;
PWINDOW - > m_iMonitorID = PMONITOR - > ID ;
PWINDOW - > m_bMappedX11 = true ;
PWINDOW - > m_iWorkspaceID = PMONITOR - > specialWorkspaceID ? PMONITOR - > specialWorkspaceID : PMONITOR - > activeWorkspace ;
PWINDOW - > m_bIsMapped = true ;
2022-04-10 11:17:06 +02:00
PWINDOW - > m_bReadyToDelete = false ;
2022-12-16 18:17:31 +01:00
PWINDOW - > m_bFadingOut = false ;
PWINDOW - > m_szTitle = g_pXWaylandManager - > getTitle ( PWINDOW ) ;
2023-02-03 22:21:14 +01:00
PWINDOW - > m_iX11Type = PWINDOW - > m_bIsX11 ? ( PWINDOW - > m_uSurface . xwayland - > override_redirect ? 2 : 1 ) : 1 ;
2023-05-24 19:23:07 +02:00
PWINDOW - > m_bFirstMap = true ;
2022-03-21 15:17:04 +01:00
2023-01-11 18:38:54 +01:00
if ( g_pInputManager - > m_bLastFocusOnLS ) // waybar fix
g_pInputManager - > releaseAllMouseButtons ( ) ;
2022-06-06 19:43:44 +02:00
// Set all windows tiled regardless of anything
g_pXWaylandManager - > setWindowStyleTiled ( PWINDOW , WLR_EDGE_LEFT | WLR_EDGE_RIGHT | WLR_EDGE_TOP | WLR_EDGE_BOTTOM ) ;
2022-05-29 11:24:42 +02:00
// Foreign Toplevel
2022-08-06 20:57:38 +02:00
PWINDOW - > createToplevelHandle ( ) ;
2022-05-29 11:24:42 +02:00
2023-03-30 00:44:25 +02:00
// checks if the window wants borders and sets the appropriate flag
2022-03-22 21:28:57 +01:00
g_pXWaylandManager - > checkBorders ( PWINDOW ) ;
2022-11-04 16:56:31 +01:00
// registers the animated vars and stuff
PWINDOW - > onMap ( ) ;
2023-03-20 16:00:58 +01:00
const auto PWINDOWSURFACE = PWINDOW - > m_pWLSurface . wlr ( ) ;
2022-03-21 17:00:17 +01:00
if ( ! PWINDOWSURFACE ) {
2022-06-30 15:44:26 +02:00
g_pCompositor - > removeWindowFromVectorSafe ( PWINDOW ) ;
2022-03-21 17:00:17 +01:00
return ;
}
2022-05-26 19:05:32 +02:00
if ( g_pXWaylandManager - > shouldBeFloated ( PWINDOW ) ) {
2022-12-16 18:17:31 +01:00
PWINDOW - > m_bIsFloating = true ;
2022-05-26 19:05:32 +02:00
PWINDOW - > m_bRequestsFloat = true ;
}
2023-02-21 21:47:02 +01:00
PWINDOW - > m_bX11ShouldntFocus =
PWINDOW - > m_bX11ShouldntFocus | | ( PWINDOW - > m_bIsX11 & & PWINDOW - > m_iX11Type = = 2 & & ! wlr_xwayland_or_surface_wants_focus ( PWINDOW - > m_uSurface . xwayland ) ) ;
2022-08-20 18:00:50 +02:00
2022-05-26 19:05:32 +02:00
if ( PWORKSPACE - > m_bDefaultFloating )
PWINDOW - > m_bIsFloating = true ;
if ( PWORKSPACE - > m_bDefaultPseudo ) {
PWINDOW - > m_bIsPseudotiled = true ;
2023-11-04 18:03:05 +01:00
CBox desiredGeometry = { 0 } ;
2022-05-26 19:05:32 +02:00
g_pXWaylandManager - > getGeometryForWindow ( PWINDOW , & desiredGeometry ) ;
PWINDOW - > m_vPseudoSize = Vector2D ( desiredGeometry . width , desiredGeometry . height ) ;
}
2022-03-24 18:22:01 +01:00
// window rules
2022-12-16 18:17:31 +01:00
const auto WINDOWRULES = g_pConfigManager - > getMatchingRules ( PWINDOW ) ;
2022-06-01 21:04:06 +02:00
std : : string requestedWorkspace = " " ;
2022-12-16 18:17:31 +01:00
bool workspaceSilent = false ;
bool requestsFullscreen = PWINDOW - > m_bWantsInitialFullscreen | |
( ! PWINDOW - > m_bIsX11 & & PWINDOW - > m_uSurface . xdg - > role = = WLR_XDG_SURFACE_ROLE_TOPLEVEL & & PWINDOW - > m_uSurface . xdg - > toplevel - > requested . fullscreen ) | |
( PWINDOW - > m_bIsX11 & & PWINDOW - > m_uSurface . xwayland - > fullscreen ) ;
2023-04-19 14:26:27 +02:00
bool requestsFakeFullscreen = false ;
2023-04-18 22:59:08 +02:00
bool requestsMaximize = false ;
2023-07-23 19:47:41 +02:00
bool overridingNoFullscreen = false ;
bool overridingNoMaximize = false ;
2022-03-24 18:22:01 +01:00
2023-04-03 20:16:51 +02:00
PWINDOW - > m_szInitialTitle = g_pXWaylandManager - > getTitle ( PWINDOW ) ;
PWINDOW - > m_szInitialClass = g_pXWaylandManager - > getAppIDClass ( PWINDOW ) ;
2022-03-24 18:22:01 +01:00
for ( auto & r : WINDOWRULES ) {
2023-10-15 20:07:23 +02:00
if ( r . szRule . starts_with ( " monitor " ) ) {
2022-03-24 18:22:01 +01:00
try {
2023-05-03 15:58:48 +02:00
const auto MONITORSTR = removeBeginEndSpacesTabs ( r . szRule . substr ( r . szRule . find ( ' ' ) ) ) ;
2022-03-24 18:22:01 +01:00
2022-06-01 21:04:06 +02:00
if ( MONITORSTR = = " unset " ) {
PWINDOW - > m_iMonitorID = PMONITOR - > ID ;
} else {
2023-03-18 02:33:48 +01:00
if ( isNumber ( MONITORSTR ) ) {
const long int MONITOR = std : : stoi ( MONITORSTR ) ;
if ( ! g_pCompositor - > getMonitorFromID ( MONITOR ) )
PWINDOW - > m_iMonitorID = 0 ;
else
PWINDOW - > m_iMonitorID = MONITOR ;
} else {
const auto PMONITOR = g_pCompositor - > getMonitorFromName ( MONITORSTR ) ;
if ( PMONITOR )
PWINDOW - > m_iMonitorID = PMONITOR - > ID ;
else {
2023-09-06 21:45:37 +02:00
Debug : : log ( ERR , " No monitor in monitor {} rule " , MONITORSTR ) ;
2023-03-18 02:33:48 +01:00
continue ;
}
}
2022-06-01 21:04:06 +02:00
}
2022-03-24 18:22:01 +01:00
2023-08-25 18:05:08 +02:00
const auto PMONITORFROMID = g_pCompositor - > getMonitorFromID ( PWINDOW - > m_iMonitorID ) ;
2022-11-26 16:41:08 +01:00
if ( PWINDOW - > m_iMonitorID ! = PMONITOR - > ID ) {
g_pKeybindManager - > m_mDispatchers [ " focusmonitor " ] ( std : : to_string ( PWINDOW - > m_iMonitorID ) ) ;
2023-08-25 18:05:08 +02:00
PMONITOR = PMONITORFROMID ;
2022-11-26 16:41:08 +01:00
}
2023-09-03 17:23:13 +02:00
PWINDOW - > m_iWorkspaceID = PMONITOR - > specialWorkspaceID ? PMONITOR - > specialWorkspaceID : PMONITOR - > activeWorkspace ;
2022-03-24 19:05:25 +01:00
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Rule monitor, applying to {:mw} " , PWINDOW ) ;
2023-09-06 21:45:37 +02:00
} catch ( std : : exception & e ) { Debug : : log ( ERR , " Rule monitor failed, rule: {} -> {} | err: {} " , r . szRule , r . szValue , e . what ( ) ) ; }
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " workspace " ) ) {
2022-06-01 21:04:06 +02:00
// check if it isnt unset
const auto WORKSPACERQ = r . szRule . substr ( r . szRule . find_first_of ( ' ' ) + 1 ) ;
2022-04-21 17:17:47 +02:00
2022-06-01 21:04:06 +02:00
if ( WORKSPACERQ = = " unset " ) {
requestedWorkspace = " " ;
} else {
requestedWorkspace = WORKSPACERQ ;
}
2022-04-21 17:17:47 +02:00
2022-12-15 18:36:34 +01:00
const auto JUSTWORKSPACE = WORKSPACERQ . contains ( ' ' ) ? WORKSPACERQ . substr ( 0 , WORKSPACERQ . find_first_of ( ' ' ) ) : WORKSPACERQ ;
if ( JUSTWORKSPACE = = PWORKSPACE - > m_szName | | JUSTWORKSPACE = = " name: " + PWORKSPACE - > m_szName )
2022-10-13 16:19:30 +02:00
requestedWorkspace = " " ;
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Rule workspace matched by {}, {} applied. " , PWINDOW , r . szValue ) ;
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " float " ) ) {
2022-03-24 18:22:01 +01:00
PWINDOW - > m_bIsFloating = true ;
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " tile " ) ) {
2022-03-24 18:22:01 +01:00
PWINDOW - > m_bIsFloating = false ;
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " pseudo " ) ) {
2022-04-02 20:04:32 +02:00
PWINDOW - > m_bIsPseudotiled = true ;
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " nofocus " ) ) {
2022-05-14 14:37:57 +02:00
PWINDOW - > m_bNoFocus = true ;
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " noinitialfocus " ) ) {
2023-04-28 16:36:08 +02:00
PWINDOW - > m_bNoInitialFocus = true ;
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " nofullscreenrequest " ) ) {
2022-11-26 21:44:40 +01:00
PWINDOW - > m_bNoFullscreenRequest = true ;
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " nomaximizerequest " ) ) {
2023-07-23 19:47:41 +02:00
PWINDOW - > m_bNoMaximizeRequest = true ;
2022-06-26 12:12:29 +02:00
} else if ( r . szRule = = " fullscreen " ) {
2023-07-23 19:47:41 +02:00
requestsFullscreen = true ;
overridingNoFullscreen = true ;
2023-04-18 22:59:08 +02:00
} else if ( r . szRule = = " fakefullscreen " ) {
requestsFakeFullscreen = true ;
2022-10-20 23:38:49 +02:00
} else if ( r . szRule = = " windowdance " ) {
PWINDOW - > m_sAdditionalConfigData . windowDanceCompat = true ;
2022-12-07 17:08:44 +01:00
} else if ( r . szRule = = " nomaxsize " ) {
PWINDOW - > m_sAdditionalConfigData . noMaxSize = true ;
2022-08-27 13:01:55 +02:00
} else if ( r . szRule = = " forceinput " ) {
PWINDOW - > m_sAdditionalConfigData . forceAllowsInput = true ;
2022-09-10 13:11:02 +02:00
} else if ( r . szRule = = " pin " ) {
PWINDOW - > m_bPinned = true ;
2022-12-23 20:34:28 +01:00
} else if ( r . szRule = = " maximize " ) {
2023-07-23 19:47:41 +02:00
requestsMaximize = true ;
overridingNoMaximize = true ;
2023-07-04 12:05:25 +02:00
} else if ( r . szRule = = " stayfocused " ) {
PWINDOW - > m_bStayFocused = true ;
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " group " ) ) {
2023-09-22 01:42:00 +02:00
if ( PWINDOW - > m_eGroupRules & GROUP_OVERRIDE )
continue ;
// `group` is a shorthand of `group set`
if ( removeBeginEndSpacesTabs ( r . szRule ) = = " group " ) {
PWINDOW - > m_eGroupRules | = GROUP_SET ;
continue ;
}
CVarList vars ( r . szRule , 0 , ' s ' ) ;
std : : string vPrev = " " ;
for ( auto const & v : vars ) {
if ( v = = " group " )
continue ;
if ( v = = " set " ) {
PWINDOW - > m_eGroupRules | = GROUP_SET ;
} else if ( v = = " new " ) {
// shorthand for `group barred set`
PWINDOW - > m_eGroupRules | = ( GROUP_SET | GROUP_BARRED ) ;
} else if ( v = = " lock " ) {
PWINDOW - > m_eGroupRules | = GROUP_LOCK ;
} else if ( v = = " invade " ) {
PWINDOW - > m_eGroupRules | = GROUP_INVADE ;
} else if ( v = = " barred " ) {
PWINDOW - > m_eGroupRules | = GROUP_BARRED ;
} else if ( v = = " deny " ) {
PWINDOW - > m_sGroupData . deny = true ;
} else if ( v = = " override " ) {
// Clear existing rules
PWINDOW - > m_eGroupRules = GROUP_OVERRIDE ;
} else if ( v = = " unset " ) {
// Clear existing rules and stop processing
PWINDOW - > m_eGroupRules = GROUP_OVERRIDE ;
break ;
} else if ( v = = " always " ) {
if ( vPrev = = " set " | | vPrev = = " group " )
PWINDOW - > m_eGroupRules | = GROUP_SET_ALWAYS ;
else if ( vPrev = = " lock " )
PWINDOW - > m_eGroupRules | = GROUP_LOCK_ALWAYS ;
else
Debug : : log ( ERR , " windowrule `group` does not support `{} always` " , vPrev ) ;
}
vPrev = v ;
}
2022-03-24 18:22:01 +01:00
}
2022-11-15 11:21:26 +01:00
PWINDOW - > applyDynamicRule ( r ) ;
2022-03-24 18:22:01 +01:00
}
2023-08-17 10:13:19 +02:00
PWINDOW - > updateSpecialRenderData ( ) ;
2022-09-10 13:11:02 +02:00
// disallow tiled pinned
if ( PWINDOW - > m_bPinned & & ! PWINDOW - > m_bIsFloating )
PWINDOW - > m_bPinned = false ;
2023-09-12 17:50:07 +02:00
const CVarList WORKSPACEARGS = CVarList ( requestedWorkspace , 0 , ' ' ) ;
2022-08-25 16:47:28 +02:00
2023-09-02 20:41:02 +02:00
if ( ! WORKSPACEARGS [ 0 ] . empty ( ) ) {
2023-10-15 20:07:23 +02:00
if ( WORKSPACEARGS [ WORKSPACEARGS . size ( ) - 1 ] . starts_with ( " silent " ) )
2023-09-12 17:50:07 +02:00
workspaceSilent = true ;
2022-06-01 21:04:06 +02:00
2023-09-15 13:05:21 +02:00
std : : string requestedWorkspaceName ;
const int REQUESTEDWORKSPACEID = getWorkspaceIDFromString ( WORKSPACEARGS . join ( " " , 0 , workspaceSilent ? WORKSPACEARGS . size ( ) - 1 : 0 ) , requestedWorkspaceName ) ;
2022-11-26 16:41:08 +01:00
2023-11-12 14:34:42 +01:00
if ( REQUESTEDWORKSPACEID ! = WORKSPACE_INVALID ) {
2023-09-02 20:41:02 +02:00
auto pWorkspace = g_pCompositor - > getWorkspaceByID ( REQUESTEDWORKSPACEID ) ;
2022-06-01 21:04:06 +02:00
2023-09-02 20:41:02 +02:00
if ( ! pWorkspace )
pWorkspace = g_pCompositor - > createNewWorkspace ( REQUESTEDWORKSPACEID , PWINDOW - > m_iMonitorID , requestedWorkspaceName ) ;
2022-10-24 19:36:31 +02:00
2023-09-02 20:41:02 +02:00
PWINDOW - > m_iWorkspaceID = pWorkspace - > m_iID ;
PWINDOW - > m_iMonitorID = pWorkspace - > m_iMonitorID ;
2022-10-24 19:36:31 +02:00
2023-09-03 17:23:13 +02:00
if ( g_pCompositor - > getMonitorFromID ( PWINDOW - > m_iMonitorID ) - > specialWorkspaceID & & ! pWorkspace - > m_bIsSpecialWorkspace )
workspaceSilent = true ;
2023-09-02 20:41:02 +02:00
if ( ! workspaceSilent ) {
if ( pWorkspace - > m_bIsSpecialWorkspace )
g_pCompositor - > getMonitorFromID ( pWorkspace - > m_iMonitorID ) - > setSpecialWorkspace ( pWorkspace ) ;
else
g_pKeybindManager - > m_mDispatchers [ " workspace " ] ( requestedWorkspaceName ) ;
2022-11-13 20:33:13 +01:00
2023-09-02 20:41:02 +02:00
PMONITOR = g_pCompositor - > m_pLastMonitor ;
2022-10-24 19:36:31 +02:00
}
2023-09-12 17:50:07 +02:00
} else
workspaceSilent = false ;
2022-10-24 19:36:31 +02:00
}
2022-03-24 18:22:01 +01:00
if ( PWINDOW - > m_bIsFloating ) {
g_pLayoutManager - > getCurrentLayout ( ) - > onWindowCreatedFloating ( PWINDOW ) ;
2022-03-30 20:16:23 +02:00
PWINDOW - > m_bCreatedOverFullscreen = true ;
2022-03-24 18:22:01 +01:00
// size and move rules
for ( auto & r : WINDOWRULES ) {
2023-10-15 20:07:23 +02:00
if ( r . szRule . starts_with ( " size " ) ) {
2022-03-24 18:22:01 +01:00
try {
2022-12-16 18:17:31 +01:00
const auto VALUE = r . szRule . substr ( r . szRule . find ( ' ' ) + 1 ) ;
const auto SIZEXSTR = VALUE . substr ( 0 , VALUE . find ( ' ' ) ) ;
const auto SIZEYSTR = VALUE . substr ( VALUE . find ( ' ' ) + 1 ) ;
2022-04-22 14:31:14 +02:00
2022-09-22 19:12:25 +02:00
const auto MAXSIZE = g_pXWaylandManager - > getMaxSizeForWindow ( PWINDOW ) ;
2022-12-16 18:17:31 +01:00
const auto SIZEX = SIZEXSTR = = " max " ?
std : : clamp ( MAXSIZE . x , 20.0 , PMONITOR - > vecSize . x ) :
2022-12-22 00:18:42 +01:00
( ! SIZEXSTR . contains ( ' % ' ) ? std : : stoi ( SIZEXSTR ) : std : : stof ( SIZEXSTR . substr ( 0 , SIZEXSTR . length ( ) - 1 ) ) * 0.01 * PMONITOR - > vecSize . x ) ;
2022-12-16 18:17:31 +01:00
const auto SIZEY = SIZEYSTR = = " max " ?
std : : clamp ( MAXSIZE . y , 20.0 , PMONITOR - > vecSize . y ) :
2022-12-22 00:18:42 +01:00
( ! SIZEYSTR . contains ( ' % ' ) ? std : : stoi ( SIZEYSTR ) : std : : stof ( SIZEYSTR . substr ( 0 , SIZEYSTR . length ( ) - 1 ) ) * 0.01 * PMONITOR - > vecSize . y ) ;
2022-03-24 18:22:01 +01:00
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Rule size, applying to {} " , PWINDOW ) ;
2022-03-24 18:22:01 +01:00
2022-04-23 14:16:02 +02:00
PWINDOW - > m_vRealSize = Vector2D ( SIZEX , SIZEY ) ;
2022-04-23 14:35:34 +02:00
g_pXWaylandManager - > setWindowSize ( PWINDOW , PWINDOW - > m_vRealSize . goalv ( ) ) ;
2022-07-30 12:42:27 +02:00
2022-10-14 21:46:32 +02:00
PWINDOW - > setHidden ( false ) ;
2023-09-06 21:45:37 +02:00
} catch ( . . . ) { Debug : : log ( LOG , " Rule size failed, rule: {} -> {} " , r . szRule , r . szValue ) ; }
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " minsize " ) ) {
2022-10-06 10:09:58 +02:00
try {
2022-12-16 18:17:31 +01:00
const auto VALUE = r . szRule . substr ( r . szRule . find ( ' ' ) + 1 ) ;
const auto SIZEXSTR = VALUE . substr ( 0 , VALUE . find ( ' ' ) ) ;
const auto SIZEYSTR = VALUE . substr ( VALUE . find ( ' ' ) + 1 ) ;
2022-10-06 10:09:58 +02:00
2022-12-16 18:17:31 +01:00
const auto SIZE =
Vector2D ( std : : max ( ( double ) std : : stoll ( SIZEXSTR ) , PWINDOW - > m_vRealSize . goalv ( ) . x ) , std : : max ( ( double ) std : : stoll ( SIZEYSTR ) , PWINDOW - > m_vRealSize . goalv ( ) . y ) ) ;
2022-10-06 10:09:58 +02:00
PWINDOW - > m_vRealSize = SIZE ;
g_pXWaylandManager - > setWindowSize ( PWINDOW , PWINDOW - > m_vRealSize . goalv ( ) ) ;
2022-10-14 21:46:32 +02:00
PWINDOW - > setHidden ( false ) ;
2023-09-06 21:45:37 +02:00
} catch ( . . . ) { Debug : : log ( LOG , " Rule minsize failed, rule: {} -> {} " , r . szRule , r . szValue ) ; }
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " maxsize " ) ) {
2022-10-15 17:04:57 +02:00
try {
2022-12-16 18:17:31 +01:00
const auto VALUE = r . szRule . substr ( r . szRule . find ( ' ' ) + 1 ) ;
const auto SIZEXSTR = VALUE . substr ( 0 , VALUE . find ( ' ' ) ) ;
const auto SIZEYSTR = VALUE . substr ( VALUE . find ( ' ' ) + 1 ) ;
2022-10-15 17:04:57 +02:00
2022-12-16 18:17:31 +01:00
const auto SIZE =
Vector2D ( std : : min ( ( double ) std : : stoll ( SIZEXSTR ) , PWINDOW - > m_vRealSize . goalv ( ) . x ) , std : : min ( ( double ) std : : stoll ( SIZEYSTR ) , PWINDOW - > m_vRealSize . goalv ( ) . y ) ) ;
2022-10-15 17:04:57 +02:00
PWINDOW - > m_vRealSize = SIZE ;
g_pXWaylandManager - > setWindowSize ( PWINDOW , PWINDOW - > m_vRealSize . goalv ( ) ) ;
PWINDOW - > setHidden ( false ) ;
2023-09-06 21:45:37 +02:00
} catch ( . . . ) { Debug : : log ( LOG , " Rule maxsize failed, rule: {} -> {} " , r . szRule , r . szValue ) ; }
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " move " ) ) {
2022-03-24 18:22:01 +01:00
try {
2022-12-16 18:17:31 +01:00
auto value = r . szRule . substr ( r . szRule . find ( ' ' ) + 1 ) ;
2022-11-10 17:59:08 +01:00
2023-10-15 20:07:23 +02:00
const bool ONSCREEN = value . starts_with ( " onscreen " ) ;
2023-09-12 10:56:20 +02:00
if ( ONSCREEN )
value = value . substr ( value . find_first_of ( ' ' ) + 1 ) ;
2023-10-15 20:07:23 +02:00
const bool CURSOR = value . starts_with ( " cursor " ) ;
2022-11-10 17:59:08 +01:00
if ( CURSOR )
value = value . substr ( value . find_first_of ( ' ' ) + 1 ) ;
2022-12-16 18:17:31 +01:00
const auto POSXSTR = value . substr ( 0 , value . find ( ' ' ) ) ;
const auto POSYSTR = value . substr ( value . find ( ' ' ) + 1 ) ;
2022-04-22 14:31:14 +02:00
2022-12-16 18:17:31 +01:00
int posX = 0 ;
int posY = 0 ;
2022-10-26 13:34:26 +02:00
2023-10-15 20:07:23 +02:00
if ( POSXSTR . starts_with ( " 100%- " ) ) {
2023-09-12 10:56:20 +02:00
const auto POSXRAW = POSXSTR . substr ( 5 ) ;
2022-12-16 18:17:31 +01:00
posX =
2022-12-22 00:18:42 +01:00
PMONITOR - > vecSize . x - ( ! POSXRAW . contains ( ' % ' ) ? std : : stoi ( POSXRAW ) : std : : stof ( POSXRAW . substr ( 0 , POSXRAW . length ( ) - 1 ) ) * 0.01 * PMONITOR - > vecSize . x ) ;
2022-11-10 17:59:08 +01:00
if ( CURSOR )
Debug : : log ( ERR , " Cursor is not compatible with 100%-, ignoring cursor! " ) ;
} else if ( ! CURSOR ) {
2022-12-22 00:18:42 +01:00
posX = ! POSXSTR . contains ( ' % ' ) ? std : : stoi ( POSXSTR ) : std : : stof ( POSXSTR . substr ( 0 , POSXSTR . length ( ) - 1 ) ) * 0.01 * PMONITOR - > vecSize . x ;
2022-11-10 17:59:08 +01:00
} else {
// cursor
if ( POSXSTR = = " cursor " ) {
posX = g_pInputManager - > getMouseCoordsInternal ( ) . x - PMONITOR - > vecPosition . x ;
} else {
2022-12-16 18:17:31 +01:00
posX = g_pInputManager - > getMouseCoordsInternal ( ) . x - PMONITOR - > vecPosition . x +
2022-12-22 00:18:42 +01:00
( ! POSXSTR . contains ( ' % ' ) ? std : : stoi ( POSXSTR ) : std : : stof ( POSXSTR . substr ( 0 , POSXSTR . length ( ) - 1 ) ) * 0.01 * PWINDOW - > m_vRealSize . goalv ( ) . x ) ;
2022-11-10 17:59:08 +01:00
}
2022-10-26 13:34:26 +02:00
}
2023-10-15 20:07:23 +02:00
if ( POSYSTR . starts_with ( " 100%- " ) ) {
2023-09-12 10:56:20 +02:00
const auto POSYRAW = POSYSTR . substr ( 5 ) ;
2022-12-16 18:17:31 +01:00
posY =
2022-12-22 00:18:42 +01:00
PMONITOR - > vecSize . y - ( ! POSYRAW . contains ( ' % ' ) ? std : : stoi ( POSYRAW ) : std : : stof ( POSYRAW . substr ( 0 , POSYRAW . length ( ) - 1 ) ) * 0.01 * PMONITOR - > vecSize . y ) ;
2022-11-10 17:59:08 +01:00
if ( CURSOR )
Debug : : log ( ERR , " Cursor is not compatible with 100%-, ignoring cursor! " ) ;
} else if ( ! CURSOR ) {
2022-12-22 00:18:42 +01:00
posY = ! POSYSTR . contains ( ' % ' ) ? std : : stoi ( POSYSTR ) : std : : stof ( POSYSTR . substr ( 0 , POSYSTR . length ( ) - 1 ) ) * 0.01 * PMONITOR - > vecSize . y ;
2022-11-10 17:59:08 +01:00
} else {
// cursor
if ( POSYSTR = = " cursor " ) {
posY = g_pInputManager - > getMouseCoordsInternal ( ) . y - PMONITOR - > vecPosition . y ;
} else {
2022-12-16 18:17:31 +01:00
posY = g_pInputManager - > getMouseCoordsInternal ( ) . y - PMONITOR - > vecPosition . y +
2022-12-22 00:18:42 +01:00
( ! POSYSTR . contains ( ' % ' ) ? std : : stoi ( POSYSTR ) : std : : stof ( POSYSTR . substr ( 0 , POSYSTR . length ( ) - 1 ) ) * 0.01 * PWINDOW - > m_vRealSize . goalv ( ) . y ) ;
2022-11-10 17:59:08 +01:00
}
2022-10-26 13:34:26 +02:00
}
2022-03-24 18:22:01 +01:00
2023-09-12 10:56:20 +02:00
if ( ONSCREEN ) {
int borderSize = PWINDOW - > getRealBorderSize ( ) ;
posX = std : : clamp ( posX , ( int ) ( PMONITOR - > vecReservedTopLeft . x + borderSize ) ,
( int ) ( PMONITOR - > vecSize . x - PMONITOR - > vecReservedBottomRight . x - PWINDOW - > m_vRealSize . goalv ( ) . x - borderSize ) ) ;
posY = std : : clamp ( posY , ( int ) ( PMONITOR - > vecReservedTopLeft . y + borderSize ) ,
( int ) ( PMONITOR - > vecSize . y - PMONITOR - > vecReservedBottomRight . y - PWINDOW - > m_vRealSize . goalv ( ) . y - borderSize ) ) ;
}
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Rule move, applying to {} " , PWINDOW ) ;
2022-03-24 18:22:01 +01:00
2022-10-26 13:34:26 +02:00
PWINDOW - > m_vRealPosition = Vector2D ( posX , posY ) + PMONITOR - > vecPosition ;
2022-07-30 12:42:27 +02:00
2022-10-14 21:46:32 +02:00
PWINDOW - > setHidden ( false ) ;
2023-09-06 21:45:37 +02:00
} catch ( . . . ) { Debug : : log ( LOG , " Rule move failed, rule: {} -> {} " , r . szRule , r . szValue ) ; }
2023-10-15 20:07:23 +02:00
} else if ( r . szRule . starts_with ( " center " ) ) {
2023-08-15 20:09:32 +02:00
auto RESERVEDOFFSET = Vector2D ( ) ;
const auto ARGS = CVarList ( r . szRule , 2 , ' ' ) ;
2023-08-11 16:54:16 +02:00
if ( ARGS [ 1 ] = = " 1 " )
RESERVEDOFFSET = ( PMONITOR - > vecReservedTopLeft - PMONITOR - > vecReservedBottomRight ) / 2.f ;
2023-09-11 11:09:34 +02:00
PWINDOW - > m_vRealPosition = PMONITOR - > middle ( ) - PWINDOW - > m_vRealSize . goalv ( ) / 2.f + RESERVEDOFFSET ;
2022-03-24 18:22:01 +01:00
}
}
2022-04-02 20:04:32 +02:00
// set the pseudo size to the GOAL of our current size
// because the windows are animated on RealSize
2022-04-23 14:35:34 +02:00
PWINDOW - > m_vPseudoSize = PWINDOW - > m_vRealSize . goalv ( ) ;
2022-10-01 19:25:02 +02:00
2023-09-21 23:18:26 +02:00
g_pCompositor - > changeWindowZOrder ( PWINDOW , true ) ;
2022-10-24 19:36:31 +02:00
} else {
2022-03-21 15:17:04 +01:00
g_pLayoutManager - > getCurrentLayout ( ) - > onWindowCreated ( PWINDOW ) ;
2022-03-24 18:22:01 +01:00
2022-04-02 20:04:32 +02:00
// Set the pseudo size here too so that it doesnt end up being 0x0
2022-12-16 18:17:31 +01:00
PWINDOW - > m_vPseudoSize = PWINDOW - > m_vRealSize . goalv ( ) - Vector2D ( 10 , 10 ) ;
2022-04-02 20:04:32 +02:00
}
2022-03-24 18:22:01 +01:00
2022-08-26 00:38:20 +02:00
const auto PFOCUSEDWINDOWPREV = g_pCompositor - > m_pLastWindow ;
2022-08-27 13:01:55 +02:00
if ( PWINDOW - > m_sAdditionalConfigData . forceAllowsInput ) {
2022-12-16 18:17:31 +01:00
PWINDOW - > m_bNoFocus = false ;
PWINDOW - > m_bNoInitialFocus = false ;
2022-08-27 13:01:55 +02:00
PWINDOW - > m_bX11ShouldntFocus = false ;
}
2022-12-02 21:10:15 +01:00
// check LS focus grab
2023-07-04 12:05:25 +02:00
const auto PFORCEFOCUS = g_pCompositor - > getForceFocus ( ) ;
2022-12-02 21:10:15 +01:00
const auto PLSFROMFOCUS = g_pCompositor - > getLayerSurfaceFromSurface ( g_pCompositor - > m_pLastFocus ) ;
if ( PLSFROMFOCUS & & PLSFROMFOCUS - > layerSurface - > current . keyboard_interactive )
PWINDOW - > m_bNoInitialFocus = true ;
2023-10-27 13:45:14 +02:00
if ( PWORKSPACE - > m_bHasFullscreenWindow & & ! requestsFullscreen & & ! PWINDOW - > m_bIsFloating ) {
2023-10-02 17:27:32 +02:00
if ( * PNEWTAKESOVERFS = = 0 )
PWINDOW - > m_bNoInitialFocus = true ;
2023-10-04 16:00:24 +02:00
else if ( * PNEWTAKESOVERFS = = 2 )
g_pCompositor - > setWindowFullscreen ( g_pCompositor - > getFullscreenWindowOnWorkspace ( PWORKSPACE - > m_iID ) , false , FULLSCREEN_INVALID ) ;
2023-10-17 12:41:27 +02:00
else if ( PWORKSPACE - > m_efFullscreenMode = = FULLSCREEN_MAXIMIZED )
requestsMaximize = true ;
2023-10-02 17:27:32 +02:00
else
requestsFullscreen = true ;
}
2022-12-02 21:10:15 +01:00
2023-02-21 21:47:02 +01:00
if ( ! PWINDOW - > m_bNoFocus & & ! PWINDOW - > m_bNoInitialFocus & &
2023-07-04 12:05:25 +02:00
( PWINDOW - > m_iX11Type ! = 2 | | ( PWINDOW - > m_bIsX11 & & wlr_xwayland_or_surface_wants_focus ( PWINDOW - > m_uSurface . xwayland ) ) ) & & ! workspaceSilent & &
( ! PFORCEFOCUS | | PFORCEFOCUS = = PWINDOW ) ) {
2022-05-14 14:37:57 +02:00
g_pCompositor - > focusWindow ( PWINDOW ) ;
2022-07-12 13:40:55 +02:00
PWINDOW - > m_fActiveInactiveAlpha . setValueAndWarp ( * PACTIVEALPHA ) ;
2023-05-31 21:11:20 +02:00
PWINDOW - > m_fDimPercent . setValueAndWarp ( PWINDOW - > m_sAdditionalConfigData . forceNoDim ? 0.f : * PDIMSTRENGTH ) ;
2022-08-30 12:46:17 +02:00
} else {
2022-07-12 13:40:55 +02:00
PWINDOW - > m_fActiveInactiveAlpha . setValueAndWarp ( * PINACTIVEALPHA ) ;
2022-08-30 12:46:17 +02:00
PWINDOW - > m_fDimPercent . setValueAndWarp ( 0 ) ;
}
2022-03-21 15:17:04 +01:00
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " Window got assigned a surfaceTreeNode {:x} " , ( uintptr_t ) PWINDOW - > m_pSurfaceTree ) ;
2022-03-28 21:16:23 +02:00
2022-03-28 17:51:03 +02:00
if ( ! PWINDOW - > m_bIsX11 ) {
2022-03-28 22:31:39 +02:00
PWINDOW - > hyprListener_commitWindow . initCallback ( & PWINDOW - > m_uSurface . xdg - > surface - > events . commit , & Events : : listener_commitWindow , PWINDOW , " XDG Window Late " ) ;
2022-09-25 20:07:48 +02:00
PWINDOW - > hyprListener_setTitleWindow . initCallback ( & PWINDOW - > m_uSurface . xdg - > toplevel - > events . set_title , & Events : : listener_setTitleWindow , PWINDOW , " XDG Window Late " ) ;
2022-03-28 22:31:39 +02:00
PWINDOW - > hyprListener_newPopupXDG . initCallback ( & PWINDOW - > m_uSurface . xdg - > events . new_popup , & Events : : listener_newPopupXDG , PWINDOW , " XDG Window Late " ) ;
2022-12-16 18:17:31 +01:00
PWINDOW - > hyprListener_requestMaximize . initCallback ( & PWINDOW - > m_uSurface . xdg - > toplevel - > events . request_maximize , & Events : : listener_requestMaximize , PWINDOW ,
" XDG Window Late " ) ;
PWINDOW - > hyprListener_requestMinimize . initCallback ( & PWINDOW - > m_uSurface . xdg - > toplevel - > events . request_minimize , & Events : : listener_requestMinimize , PWINDOW ,
" XDG Window Late " ) ;
2022-07-16 00:11:21 +02:00
PWINDOW - > hyprListener_requestMove . initCallback ( & PWINDOW - > m_uSurface . xdg - > toplevel - > events . request_move , & Events : : listener_requestMove , PWINDOW , " XDG Window Late " ) ;
PWINDOW - > hyprListener_requestResize . initCallback ( & PWINDOW - > m_uSurface . xdg - > toplevel - > events . request_resize , & Events : : listener_requestResize , PWINDOW , " XDG Window Late " ) ;
2022-12-16 18:17:31 +01:00
PWINDOW - > hyprListener_fullscreenWindow . initCallback ( & PWINDOW - > m_uSurface . xdg - > toplevel - > events . request_fullscreen , & Events : : listener_fullscreenWindow , PWINDOW ,
" XDG Window Late " ) ;
2023-11-09 23:43:52 +01:00
PWINDOW - > hyprListener_ackConfigure . initCallback ( & PWINDOW - > m_uSurface . xdg - > events . ack_configure , & Events : : listener_ackConfigure , PWINDOW , " XDG Window Late " ) ;
2022-03-28 17:51:03 +02:00
} else {
2022-12-16 18:17:31 +01:00
PWINDOW - > hyprListener_fullscreenWindow . initCallback ( & PWINDOW - > m_uSurface . xwayland - > events . request_fullscreen , & Events : : listener_fullscreenWindow , PWINDOW ,
" XWayland Window Late " ) ;
2022-03-28 22:31:39 +02:00
PWINDOW - > hyprListener_activateX11 . initCallback ( & PWINDOW - > m_uSurface . xwayland - > events . request_activate , & Events : : listener_activateX11 , PWINDOW , " XWayland Window Late " ) ;
PWINDOW - > hyprListener_setTitleWindow . initCallback ( & PWINDOW - > m_uSurface . xwayland - > events . set_title , & Events : : listener_setTitleWindow , PWINDOW , " XWayland Window Late " ) ;
2022-12-16 18:17:31 +01:00
PWINDOW - > hyprListener_requestMinimize . initCallback ( & PWINDOW - > m_uSurface . xwayland - > events . request_minimize , & Events : : listener_requestMinimize , PWINDOW ,
" Xwayland Window Late " ) ;
2023-07-04 22:03:19 +02:00
PWINDOW - > hyprListener_requestMaximize . initCallback ( & PWINDOW - > m_uSurface . xwayland - > events . request_maximize , & Events : : listener_requestMaximize , PWINDOW ,
2022-12-16 18:17:31 +01:00
" Xwayland Window Late " ) ;
2022-09-25 20:07:48 +02:00
2022-07-08 11:24:07 +02:00
if ( PWINDOW - > m_iX11Type = = 2 )
2022-12-16 18:17:31 +01:00
PWINDOW - > hyprListener_setGeometryX11U . initCallback ( & PWINDOW - > m_uSurface . xwayland - > events . set_geometry , & Events : : listener_unmanagedSetGeometry , PWINDOW ,
" XWayland Window Late " ) ;
2022-03-28 17:51:03 +02:00
}
2023-07-23 19:47:41 +02:00
if ( ( requestsFullscreen & & ( ! PWINDOW - > m_bNoFullscreenRequest | | overridingNoFullscreen ) ) | | ( requestsMaximize & & ( ! PWINDOW - > m_bNoMaximizeRequest | | overridingNoMaximize ) ) | |
requestsFakeFullscreen ) {
2022-06-27 20:11:09 +02:00
// fix fullscreen on requested (basically do a switcheroo)
if ( PWORKSPACE - > m_bHasFullscreenWindow ) {
const auto PFULLWINDOW = g_pCompositor - > getFullscreenWindowOnWorkspace ( PWORKSPACE - > m_iID ) ;
2022-09-20 13:17:34 +02:00
g_pCompositor - > setWindowFullscreen ( PFULLWINDOW , false , FULLSCREEN_FULL ) ;
2022-06-27 20:11:09 +02:00
}
2023-04-18 22:59:08 +02:00
if ( requestsFakeFullscreen & & ! PWINDOW - > m_bFakeFullscreenState ) {
PWINDOW - > m_bFakeFullscreenState = ! PWINDOW - > m_bFakeFullscreenState ;
g_pXWaylandManager - > setWindowFullscreen ( PWINDOW , true ) ;
} else {
2023-07-23 19:47:41 +02:00
overridingNoFullscreen = false ;
overridingNoMaximize = false ;
2023-04-18 22:59:08 +02:00
PWINDOW - > m_vRealPosition . warp ( ) ;
PWINDOW - > m_vRealSize . warp ( ) ;
g_pCompositor - > setWindowFullscreen ( PWINDOW , true , requestsFullscreen ? FULLSCREEN_FULL : FULLSCREEN_MAXIMIZED ) ;
}
2022-06-26 12:12:29 +02:00
}
2022-07-06 15:42:37 +02:00
// recheck idle inhibitors
g_pInputManager - > recheckIdleInhibitorStatus ( ) ;
2023-03-20 16:00:58 +01:00
PWINDOW - > m_pSurfaceTree = SubsurfaceTree : : createTreeRoot ( PWINDOW - > m_pWLSurface . wlr ( ) , addViewCoords , PWINDOW , PWINDOW ) ;
2022-06-28 14:09:14 +02:00
2022-08-06 20:57:38 +02:00
PWINDOW - > updateToplevel ( ) ;
2023-09-02 20:41:02 +02:00
if ( workspaceSilent ) {
2022-08-26 01:08:11 +02:00
if ( g_pCompositor - > windowValidMapped ( PFOCUSEDWINDOWPREV ) ) {
2022-08-26 00:38:20 +02:00
g_pCompositor - > focusWindow ( PFOCUSEDWINDOWPREV ) ;
2022-08-26 01:08:11 +02:00
PFOCUSEDWINDOWPREV - > updateWindowDecos ( ) ; // need to for some reason i cba to find out why
} else if ( ! PFOCUSEDWINDOWPREV )
2022-08-26 00:38:20 +02:00
g_pCompositor - > focusWindow ( nullptr ) ;
}
2022-10-01 20:19:15 +02:00
// verify swallowing
2023-04-15 20:15:59 +02:00
if ( * PSWALLOW & & * PSWALLOWREGEX ! = STRVAL_EMPTY ) {
2022-10-07 10:46:01 +02:00
// don't swallow ourselves
std : : regex rgx ( * PSWALLOWREGEX ) ;
if ( ! std : : regex_match ( g_pXWaylandManager - > getAppIDClass ( PWINDOW ) , rgx ) ) {
// check parent
int ppid = getPPIDof ( PWINDOW - > getPID ( ) ) ;
2022-10-01 20:19:15 +02:00
2022-10-07 10:46:01 +02:00
int curppid = 0 ;
2022-10-01 20:19:15 +02:00
2022-10-07 10:46:01 +02:00
for ( int i = 0 ; i < 5 ; + + i ) {
curppid = getPPIDof ( ppid ) ;
2022-10-01 20:19:15 +02:00
2022-10-07 10:46:01 +02:00
if ( curppid < 10 ) {
break ;
2022-10-01 20:19:15 +02:00
}
2022-10-07 10:46:01 +02:00
ppid = curppid ;
2022-10-01 20:19:15 +02:00
}
2022-10-07 10:46:01 +02:00
if ( ppid ) {
// get window by pid
std : : vector < CWindow * > found ;
2022-12-16 18:17:31 +01:00
CWindow * finalFound = nullptr ;
2022-10-07 10:46:01 +02:00
for ( auto & w : g_pCompositor - > m_vWindows ) {
2022-10-14 21:46:32 +02:00
if ( ! w - > m_bIsMapped | | w - > isHidden ( ) )
2022-10-07 10:46:01 +02:00
continue ;
if ( w - > getPID ( ) = = ppid ) {
found . push_back ( w . get ( ) ) ;
2022-10-04 11:17:03 +02:00
}
}
2022-10-07 10:46:01 +02:00
if ( found . size ( ) > 1 ) {
2022-10-04 11:17:03 +02:00
for ( auto & w : found ) {
2022-10-07 10:46:01 +02:00
// try get the focus, otherwise we'll ignore to avoid swallowing incorrect windows
if ( w = = PFOCUSEDWINDOWPREV ) {
2022-10-04 11:17:03 +02:00
finalFound = w ;
break ;
}
}
2022-10-07 10:46:01 +02:00
} else if ( found . size ( ) = = 1 ) {
2022-10-04 11:17:03 +02:00
finalFound = found [ 0 ] ;
}
2022-10-07 10:46:01 +02:00
if ( finalFound ) {
2023-04-15 20:15:59 +02:00
bool valid = std : : regex_match ( g_pXWaylandManager - > getAppIDClass ( finalFound ) , rgx ) ;
if ( * PSWALLOWEXREGEX ! = STRVAL_EMPTY ) {
std : : regex exc ( * PSWALLOWEXREGEX ) ;
valid = valid & & ! std : : regex_match ( g_pXWaylandManager - > getTitle ( finalFound ) , exc ) ;
}
2023-04-12 14:38:15 +02:00
// check if it's the window we want & not exempt from getting swallowed
2023-04-15 20:15:59 +02:00
if ( valid ) {
2022-10-07 10:46:01 +02:00
// swallow
PWINDOW - > m_pSwallowed = finalFound ;
2022-10-01 20:19:15 +02:00
2022-10-07 10:46:01 +02:00
g_pLayoutManager - > getCurrentLayout ( ) - > onWindowRemoved ( finalFound ) ;
2022-10-01 20:19:15 +02:00
2022-10-14 21:46:32 +02:00
finalFound - > setHidden ( true ) ;
2023-09-16 19:40:54 +02:00
g_pLayoutManager - > getCurrentLayout ( ) - > recalculateMonitor ( PWINDOW - > m_iMonitorID ) ;
2022-10-07 10:46:01 +02:00
}
2022-10-01 20:19:15 +02:00
}
}
}
}
2023-05-24 19:23:07 +02:00
PWINDOW - > m_bFirstMap = false ;
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Map request dispatched, monitor {}, window pos: {:5j}, window size: {:5j} " , PMONITOR - > szName , PWINDOW - > m_vRealPosition . goalv ( ) , PWINDOW - > m_vRealSize . goalv ( ) ) ;
2022-09-25 20:07:48 +02:00
auto workspaceID = requestedWorkspace ! = " " ? requestedWorkspace : PWORKSPACE - > m_szName ;
2023-09-20 17:25:03 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " openwindow " , std : : format ( " {:x},{},{},{} " , PWINDOW , workspaceID , g_pXWaylandManager - > getAppIDClass ( PWINDOW ) , PWINDOW - > m_szTitle ) } ) ;
2023-02-19 21:54:53 +01:00
EMIT_HOOK_EVENT ( " openWindow " , PWINDOW ) ;
2022-11-02 16:15:39 +01:00
2023-12-10 17:28:12 +01:00
// apply data from default decos. Borders, shadows.
g_pDecorationPositioner - > forceRecalcFor ( PWINDOW ) ;
PWINDOW - > updateWindowDecos ( ) ;
g_pLayoutManager - > getCurrentLayout ( ) - > recalculateWindow ( PWINDOW ) ;
// do animations
g_pAnimationManager - > onWindowPostCreateClose ( PWINDOW , false ) ;
PWINDOW - > m_fAlpha . setValueAndWarp ( 0.f ) ;
PWINDOW - > m_fAlpha = 1.f ;
PWINDOW - > m_vRealPosition . setCallbackOnEnd ( setAnimToMove ) ;
PWINDOW - > m_vRealSize . setCallbackOnEnd ( setAnimToMove ) ;
2022-11-02 16:15:39 +01:00
// recalc the values for this window
g_pCompositor - > updateWindowAnimatedDecorationValues ( PWINDOW ) ;
2023-10-02 17:22:39 +02:00
// avoid this window being visible
if ( PWORKSPACE - > m_bHasFullscreenWindow & & ! PWINDOW - > m_bIsFullscreen & & ! PWINDOW - > m_bIsFloating )
PWINDOW - > m_fAlpha . setValueAndWarp ( 0.f ) ;
2023-01-20 19:44:30 +01:00
2023-10-22 17:58:06 +02:00
g_pCompositor - > setPreferredScaleForSurface ( PWINDOW - > m_pWLSurface . wlr ( ) , PMONITOR - > scale ) ;
g_pCompositor - > setPreferredTransformForSurface ( PWINDOW - > m_pWLSurface . wlr ( ) , PMONITOR - > transform ) ;
2023-11-01 20:50:32 +01:00
2023-11-02 22:36:16 +01:00
if ( g_pCompositor - > vectorToWindowIdeal ( g_pInputManager - > getMouseCoordsInternal ( ) ) = = g_pCompositor - > m_pLastWindow )
g_pInputManager - > simulateMouseMovement ( ) ;
2023-11-03 23:47:12 +01:00
// fix some xwayland apps that don't behave nicely
2023-11-05 15:12:55 +01:00
PWINDOW - > m_vReportedSize = PWINDOW - > m_vPendingReportedSize ;
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events : : listener_unmapWindow ( void * owner , void * data ) {
CWindow * PWINDOW = ( CWindow * ) owner ;
2022-03-21 15:17:04 +01:00
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " {:c} unmapped " , PWINDOW ) ;
2022-09-25 20:07:48 +02:00
2023-03-28 21:17:47 +02:00
if ( ! PWINDOW - > m_pWLSurface . exists ( ) | | ! PWINDOW - > m_bIsMapped ) {
2023-09-20 17:25:03 +02:00
Debug : : log ( WARN , " {} unmapped without being mapped?? " , PWINDOW ) ;
2023-03-28 21:17:47 +02:00
PWINDOW - > m_bFadingOut = false ;
return ;
}
2023-11-11 16:18:04 +01:00
const auto PMONITOR = g_pCompositor - > getMonitorFromID ( PWINDOW - > m_iMonitorID ) ;
if ( PMONITOR ) {
PWINDOW - > m_vOriginalClosedPos = PWINDOW - > m_vRealPosition . vec ( ) - PMONITOR - > vecPosition ;
PWINDOW - > m_vOriginalClosedSize = PWINDOW - > m_vRealSize . vec ( ) ;
PWINDOW - > m_eOriginalClosedExtents = PWINDOW - > getFullWindowExtents ( ) ;
}
2023-09-20 17:25:03 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " closewindow " , std : : format ( " {:x} " , PWINDOW ) } ) ;
2023-02-19 21:54:53 +01:00
EMIT_HOOK_EVENT ( " closeWindow " , PWINDOW ) ;
2022-03-24 21:34:24 +01:00
2022-12-05 18:05:15 +01:00
g_pProtocolManager - > m_pToplevelExportProtocolManager - > onWindowUnmap ( PWINDOW ) ;
2022-03-28 17:51:03 +02:00
if ( ! PWINDOW - > m_bIsX11 ) {
2022-07-26 21:41:29 +02:00
Debug : : log ( LOG , " Unregistered late callbacks XDG " ) ;
2022-03-28 22:31:39 +02:00
PWINDOW - > hyprListener_commitWindow . removeCallback ( ) ;
PWINDOW - > hyprListener_setTitleWindow . removeCallback ( ) ;
PWINDOW - > hyprListener_newPopupXDG . removeCallback ( ) ;
2022-07-16 00:11:21 +02:00
PWINDOW - > hyprListener_requestMaximize . removeCallback ( ) ;
PWINDOW - > hyprListener_requestMinimize . removeCallback ( ) ;
PWINDOW - > hyprListener_requestMove . removeCallback ( ) ;
PWINDOW - > hyprListener_requestResize . removeCallback ( ) ;
2022-08-22 11:35:46 +02:00
PWINDOW - > hyprListener_fullscreenWindow . removeCallback ( ) ;
2023-11-09 23:43:52 +01:00
PWINDOW - > hyprListener_ackConfigure . removeCallback ( ) ;
2022-03-28 17:51:03 +02:00
} else {
2022-07-26 21:41:29 +02:00
Debug : : log ( LOG , " Unregistered late callbacks XWL " ) ;
2022-03-28 22:31:39 +02:00
PWINDOW - > hyprListener_fullscreenWindow . removeCallback ( ) ;
PWINDOW - > hyprListener_activateX11 . removeCallback ( ) ;
PWINDOW - > hyprListener_setTitleWindow . removeCallback ( ) ;
2022-07-08 11:24:07 +02:00
PWINDOW - > hyprListener_setGeometryX11U . removeCallback ( ) ;
2022-10-28 20:18:10 +02:00
PWINDOW - > hyprListener_requestMaximize . removeCallback ( ) ;
PWINDOW - > hyprListener_requestMinimize . removeCallback ( ) ;
2022-03-28 17:51:03 +02:00
}
2023-08-09 14:28:04 +02:00
if ( PWINDOW - > m_bIsFullscreen )
2022-09-19 20:09:21 +02:00
g_pCompositor - > setWindowFullscreen ( PWINDOW , false , FULLSCREEN_FULL ) ;
2023-08-09 14:28:04 +02:00
2022-04-24 16:41:01 +02:00
// Allow the renderer to catch the last frame.
g_pHyprOpenGL - > makeWindowSnapshot ( PWINDOW ) ;
2022-10-01 20:19:15 +02:00
// swallowing
if ( PWINDOW - > m_pSwallowed & & g_pCompositor - > windowExists ( PWINDOW - > m_pSwallowed ) ) {
2022-10-14 21:46:32 +02:00
PWINDOW - > m_pSwallowed - > setHidden ( false ) ;
2022-10-01 20:19:15 +02:00
g_pLayoutManager - > getCurrentLayout ( ) - > onWindowCreated ( PWINDOW - > m_pSwallowed ) ;
PWINDOW - > m_pSwallowed = nullptr ;
}
2022-08-24 11:14:11 +02:00
bool wasLastWindow = false ;
2022-04-02 18:57:09 +02:00
if ( PWINDOW = = g_pCompositor - > m_pLastWindow ) {
2022-12-16 18:17:31 +01:00
wasLastWindow = true ;
2022-04-02 18:57:09 +02:00
g_pCompositor - > m_pLastWindow = nullptr ;
2022-12-16 18:17:31 +01:00
g_pCompositor - > m_pLastFocus = nullptr ;
2023-04-07 13:54:11 +02:00
g_pInputManager - > releaseAllMouseButtons ( ) ;
2022-04-02 18:57:09 +02:00
}
2022-03-21 15:17:04 +01:00
2022-03-22 20:04:39 +01:00
PWINDOW - > m_bMappedX11 = false ;
2022-03-21 19:18:33 +01:00
// remove the fullscreen window status from workspace if we closed it
const auto PWORKSPACE = g_pCompositor - > getWorkspaceByID ( PWINDOW - > m_iWorkspaceID ) ;
2022-04-11 19:51:37 +02:00
if ( PWORKSPACE - > m_bHasFullscreenWindow & & PWINDOW - > m_bIsFullscreen )
PWORKSPACE - > m_bHasFullscreenWindow = false ;
2022-03-21 19:18:33 +01:00
2022-03-21 15:17:04 +01:00
g_pLayoutManager - > getCurrentLayout ( ) - > onWindowRemoved ( PWINDOW ) ;
2022-03-22 22:22:59 +01:00
// do this after onWindowRemoved because otherwise it'll think the window is invalid
PWINDOW - > m_bIsMapped = false ;
2022-08-24 11:14:11 +02:00
// refocus on a new window if needed
if ( wasLastWindow ) {
2022-10-24 13:25:36 +02:00
const auto PWINDOWCANDIDATE = g_pLayoutManager - > getCurrentLayout ( ) - > getNextWindowCandidate ( PWINDOW ) ;
2022-08-20 18:12:59 +02:00
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " On closed window, new focused candidate is {} " , PWINDOWCANDIDATE ) ;
2022-08-20 18:12:59 +02:00
2023-11-01 20:50:32 +01:00
if ( PWINDOWCANDIDATE ! = g_pCompositor - > m_pLastWindow & & PWINDOWCANDIDATE )
g_pCompositor - > focusWindow ( PWINDOWCANDIDATE ) ;
2023-11-02 22:36:16 +01:00
if ( g_pCompositor - > vectorToWindowIdeal ( g_pInputManager - > getMouseCoordsInternal ( ) ) = = PWINDOWCANDIDATE )
g_pInputManager - > simulateMouseMovement ( ) ;
2023-10-06 02:11:47 +02:00
// CWindow::onUnmap will remove this window's active status, but we can't really do it above.
if ( PWINDOW = = g_pCompositor - > m_pLastWindow | | ! g_pCompositor - > m_pLastWindow ) {
g_pEventManager - > postEvent ( SHyprIPCEvent { " activewindow " , " , " } ) ;
g_pEventManager - > postEvent ( SHyprIPCEvent { " activewindowv2 " , " , " } ) ;
EMIT_HOOK_EVENT ( " activeWindow " , ( CWindow * ) nullptr ) ;
2022-08-24 11:14:11 +02:00
}
} else {
Debug : : log ( LOG , " Unmapped was not focused, ignoring a refocus. " ) ;
2022-08-23 23:15:04 +02:00
}
2022-08-03 12:03:18 +02:00
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Destroying the SubSurface tree of unmapped window {} " , PWINDOW ) ;
2022-03-27 21:46:27 +02:00
SubsurfaceTree : : destroySurfaceTree ( PWINDOW - > m_pSurfaceTree ) ;
2022-09-25 20:07:48 +02:00
2022-03-27 21:46:27 +02:00
PWINDOW - > m_pSurfaceTree = nullptr ;
2022-04-05 19:28:10 +02:00
PWINDOW - > m_bFadingOut = true ;
2022-07-25 21:08:54 +02:00
g_pCompositor - > addToFadingOutSafe ( PWINDOW ) ;
2022-04-14 17:00:35 +02:00
g_pHyprRenderer - > damageMonitor ( g_pCompositor - > getMonitorFromID ( PWINDOW - > m_iMonitorID ) ) ;
2022-05-28 18:28:55 +02:00
2022-12-16 18:17:31 +01:00
if ( ! PWINDOW - > m_bX11DoesntWantBorders ) // don't animate out if they weren't animated in.
PWINDOW - > m_vRealPosition = PWINDOW - > m_vRealPosition . vec ( ) + Vector2D ( 0.01f , 0.01f ) ; // it has to be animated, otherwise onWindowPostCreateClose will ignore it
2022-09-25 20:07:48 +02:00
2022-07-28 13:28:43 +02:00
// anims
2022-05-28 18:28:55 +02:00
g_pAnimationManager - > onWindowPostCreateClose ( PWINDOW , true ) ;
2022-07-28 13:28:43 +02:00
PWINDOW - > m_fAlpha = 0.f ;
2022-05-29 11:24:42 +02:00
// Destroy Foreign Toplevel
2022-08-06 20:57:38 +02:00
PWINDOW - > destroyToplevelHandle ( ) ;
2022-07-06 15:42:37 +02:00
// recheck idle inhibitors
g_pInputManager - > recheckIdleInhibitorStatus ( ) ;
2022-10-22 23:10:34 +02:00
// force report all sizes (QT sometimes has an issue with this)
g_pCompositor - > forceReportSizesToWindowsOnWorkspace ( PWINDOW - > m_iWorkspaceID ) ;
2022-11-04 16:56:31 +01:00
// update lastwindow after focus
PWINDOW - > onUnmap ( ) ;
2022-03-21 15:17:04 +01:00
}
2023-11-09 23:43:52 +01:00
void Events : : listener_ackConfigure ( void * owner , void * data ) {
CWindow * PWINDOW = ( CWindow * ) owner ;
const auto E = ( wlr_xdg_surface_configure * ) data ;
2023-11-10 01:13:22 +01:00
// find last matching serial
const auto SERIAL = std : : find_if ( PWINDOW - > m_vPendingSizeAcks . rbegin ( ) , PWINDOW - > m_vPendingSizeAcks . rend ( ) , [ & ] ( const auto & e ) { return e . first = = E - > serial ; } ) ;
if ( SERIAL = = PWINDOW - > m_vPendingSizeAcks . rend ( ) )
2023-11-09 23:43:52 +01:00
return ;
2023-11-10 01:13:22 +01:00
PWINDOW - > m_pPendingSizeAck = * SERIAL ;
std : : erase_if ( PWINDOW - > m_vPendingSizeAcks , [ & ] ( const auto & el ) { return el . first = = SERIAL - > first ; } ) ;
2023-11-09 23:43:52 +01:00
}
2022-03-28 22:31:39 +02:00
void Events : : listener_commitWindow ( void * owner , void * data ) {
2022-04-05 18:29:58 +02:00
CWindow * PWINDOW = ( CWindow * ) owner ;
2022-10-14 21:46:32 +02:00
if ( ! PWINDOW - > m_bMappedX11 | | PWINDOW - > isHidden ( ) | | ( PWINDOW - > m_bIsX11 & & ! PWINDOW - > m_bMappedX11 ) )
2022-04-05 18:29:58 +02:00
return ;
2022-03-21 15:17:04 +01:00
2023-11-10 01:13:22 +01:00
if ( PWINDOW - > m_bIsX11 )
2023-11-09 23:43:52 +01:00
PWINDOW - > m_vReportedSize = PWINDOW - > m_vPendingReportedSize ; // apply pending size. We pinged, the window ponged.
2023-11-10 01:13:22 +01:00
else if ( PWINDOW - > m_pPendingSizeAck . has_value ( ) ) {
PWINDOW - > m_vReportedSize = PWINDOW - > m_pPendingSizeAck - > second ;
PWINDOW - > m_pPendingSizeAck . reset ( ) ;
}
2023-10-20 21:15:41 +02:00
2023-03-16 02:04:54 +01:00
PWINDOW - > updateSurfaceOutputs ( ) ;
2023-06-11 21:52:13 +02:00
g_pHyprRenderer - > damageSurface ( PWINDOW - > m_pWLSurface . wlr ( ) , PWINDOW - > m_vRealPosition . goalv ( ) . x , PWINDOW - > m_vRealPosition . goalv ( ) . y ,
PWINDOW - > m_bIsX11 ? 1.0 / PWINDOW - > m_fX11SurfaceScaledBy : 1.0 ) ;
2022-07-04 15:58:12 +02:00
2023-05-26 14:49:03 +02:00
if ( PWINDOW - > m_bIsX11 | | ! PWINDOW - > m_bIsFloating | | PWINDOW - > m_bIsFullscreen )
return ;
const auto ISRIGID = PWINDOW - > m_uSurface . xdg - > toplevel - > current . max_height = = PWINDOW - > m_uSurface . xdg - > toplevel - > current . min_height & &
PWINDOW - > m_uSurface . xdg - > toplevel - > current . max_width = = PWINDOW - > m_uSurface . xdg - > toplevel - > current . min_width ;
if ( ! ISRIGID )
return ;
const Vector2D REQUESTEDSIZE = { PWINDOW - > m_uSurface . xdg - > toplevel - > current . max_width , PWINDOW - > m_uSurface . xdg - > toplevel - > current . max_height } ;
if ( REQUESTEDSIZE = = PWINDOW - > m_vReportedSize | | REQUESTEDSIZE . x < 5 | | REQUESTEDSIZE . y < 5 )
return ;
const Vector2D DELTA = PWINDOW - > m_vReportedSize - REQUESTEDSIZE ;
PWINDOW - > m_vRealPosition = PWINDOW - > m_vRealPosition . goalv ( ) + DELTA / 2.0 ;
PWINDOW - > m_vRealSize = REQUESTEDSIZE ;
g_pXWaylandManager - > setWindowSize ( PWINDOW , REQUESTEDSIZE , true ) ;
g_pHyprRenderer - > damageWindow ( PWINDOW ) ;
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events : : listener_destroyWindow ( void * owner , void * data ) {
CWindow * PWINDOW = ( CWindow * ) owner ;
2022-03-21 15:17:04 +01:00
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " {:c} destroyed, queueing. " , PWINDOW ) ;
2022-06-28 12:43:08 +02:00
if ( PWINDOW - > m_bIsX11 )
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " XWayland class raw: {} " , PWINDOW - > m_uSurface . xwayland - > _class ? PWINDOW - > m_uSurface . xwayland - > _class : " null " ) ;
2022-03-24 21:34:24 +01:00
2022-04-02 18:57:09 +02:00
if ( PWINDOW = = g_pCompositor - > m_pLastWindow ) {
g_pCompositor - > m_pLastWindow = nullptr ;
2022-12-16 18:17:31 +01:00
g_pCompositor - > m_pLastFocus = nullptr ;
2022-04-02 18:57:09 +02:00
}
2022-03-21 15:17:04 +01:00
2022-04-10 16:19:49 +02:00
PWINDOW - > hyprListener_mapWindow . removeCallback ( ) ;
PWINDOW - > hyprListener_unmapWindow . removeCallback ( ) ;
PWINDOW - > hyprListener_destroyWindow . removeCallback ( ) ;
2023-03-01 14:47:40 +01:00
PWINDOW - > hyprListener_configureX11 . removeCallback ( ) ;
PWINDOW - > hyprListener_setOverrideRedirect . removeCallback ( ) ;
2023-06-05 20:51:47 +02:00
PWINDOW - > hyprListener_associateX11 . removeCallback ( ) ;
PWINDOW - > hyprListener_dissociateX11 . removeCallback ( ) ;
2022-04-10 16:19:49 +02:00
g_pLayoutManager - > getCurrentLayout ( ) - > onWindowRemoved ( PWINDOW ) ;
if ( PWINDOW - > m_pSurfaceTree ) {
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Destroying Subsurface tree of {} in destroyWindow " , PWINDOW ) ;
2022-04-10 16:19:49 +02:00
SubsurfaceTree : : destroySurfaceTree ( PWINDOW - > m_pSurfaceTree ) ;
PWINDOW - > m_pSurfaceTree = nullptr ;
}
2022-04-10 11:17:06 +02:00
PWINDOW - > m_bReadyToDelete = true ;
2022-12-16 18:17:31 +01:00
2022-12-07 15:32:24 +01:00
if ( ! PWINDOW - > m_bFadingOut ) {
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Unmapped {} removed instantly " , PWINDOW ) ;
2023-11-01 19:53:36 +01:00
g_pCompositor - > removeWindowFromVectorSafe ( PWINDOW ) ; // most likely X11 unmanaged or sumn
2022-12-07 15:32:24 +01:00
}
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events : : listener_setTitleWindow ( void * owner , void * data ) {
CWindow * PWINDOW = ( CWindow * ) owner ;
2022-03-21 15:17:04 +01:00
2022-03-22 17:31:19 +01:00
if ( ! g_pCompositor - > windowValidMapped ( PWINDOW ) )
2022-12-16 18:17:31 +01:00
return ;
2022-03-22 17:31:19 +01:00
2022-03-24 21:34:24 +01:00
PWINDOW - > m_szTitle = g_pXWaylandManager - > getTitle ( PWINDOW ) ;
2023-09-20 09:26:20 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " windowtitle " , std : : format ( " {:x} " , ( uintptr_t ) PWINDOW ) } ) ;
2023-06-03 11:18:49 +02:00
EMIT_HOOK_EVENT ( " windowTitle " , PWINDOW ) ;
2022-04-05 22:28:06 +02:00
2023-02-06 14:16:54 +01:00
if ( PWINDOW = = g_pCompositor - > m_pLastWindow ) { // if it's the active, let's post an event to update others
2022-07-20 18:39:08 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activewindow " , g_pXWaylandManager - > getAppIDClass ( PWINDOW ) + " , " + PWINDOW - > m_szTitle } ) ;
2023-09-20 09:26:20 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activewindowv2 " , std : : format ( " {:x} " , ( uintptr_t ) PWINDOW ) } ) ;
2023-02-19 21:54:53 +01:00
EMIT_HOOK_EVENT ( " activeWindow " , PWINDOW ) ;
2023-02-06 14:16:54 +01:00
}
2022-05-25 17:29:44 +02:00
2022-11-15 11:21:26 +01:00
PWINDOW - > updateDynamicRules ( ) ;
g_pCompositor - > updateWindowAnimatedDecorationValues ( PWINDOW ) ;
2022-08-06 20:57:38 +02:00
PWINDOW - > updateToplevel ( ) ;
2022-05-29 11:24:42 +02:00
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Window {:x} set title to {} " , PWINDOW , PWINDOW - > m_szTitle ) ;
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events : : listener_fullscreenWindow ( void * owner , void * data ) {
CWindow * PWINDOW = ( CWindow * ) owner ;
2022-03-21 15:17:04 +01:00
2022-08-21 22:30:48 +02:00
if ( ! PWINDOW - > m_bIsMapped ) {
PWINDOW - > m_bWantsInitialFullscreen = true ;
return ;
}
2022-11-26 21:44:40 +01:00
if ( PWINDOW - > isHidden ( ) | | PWINDOW - > m_bNoFullscreenRequest )
2022-08-16 21:30:53 +02:00
return ;
2023-01-06 13:29:43 +01:00
bool requestedFullState = false ;
2022-05-20 15:02:51 +02:00
if ( ! PWINDOW - > m_bIsX11 ) {
const auto REQUESTED = & PWINDOW - > m_uSurface . xdg - > toplevel - > requested ;
2023-01-11 13:40:15 +01:00
if ( REQUESTED - > fullscreen & & PWINDOW - > m_bIsFullscreen ) {
const auto PWORKSPACE = g_pCompositor - > getWorkspaceByID ( PWINDOW - > m_iWorkspaceID ) ;
if ( PWORKSPACE - > m_efFullscreenMode ! = FULLSCREEN_FULL ) {
2023-01-17 13:20:10 +01:00
// Store that we were maximized
PWINDOW - > m_bWasMaximized = true ;
2023-01-11 13:40:15 +01:00
g_pCompositor - > setWindowFullscreen ( PWINDOW , false , FULLSCREEN_MAXIMIZED ) ;
g_pCompositor - > setWindowFullscreen ( PWINDOW , true , FULLSCREEN_FULL ) ;
2023-01-20 19:03:17 +01:00
} else
2023-01-17 13:20:10 +01:00
PWINDOW - > m_bWasMaximized = false ;
} else if ( REQUESTED - > fullscreen ! = PWINDOW - > m_bIsFullscreen & & ! PWINDOW - > m_bFakeFullscreenState ) {
2022-08-14 23:03:47 +02:00
g_pCompositor - > setWindowFullscreen ( PWINDOW , REQUESTED - > fullscreen , FULLSCREEN_FULL ) ;
2023-01-17 13:20:10 +01:00
if ( PWINDOW - > m_bWasMaximized & & ! REQUESTED - > fullscreen ) {
// Was maximized before the fullscreen request, return now back to maximized instead of normal
g_pCompositor - > setWindowFullscreen ( PWINDOW , true , FULLSCREEN_MAXIMIZED ) ;
}
}
2023-03-30 00:44:25 +02:00
// Disable the maximize flag when we receive a de-fullscreen request
2023-01-17 13:20:10 +01:00
PWINDOW - > m_bWasMaximized & = REQUESTED - > fullscreen ;
2022-07-16 00:11:21 +02:00
2023-01-06 13:29:43 +01:00
requestedFullState = REQUESTED - > fullscreen ;
2022-07-16 00:11:21 +02:00
wlr_xdg_surface_schedule_configure ( PWINDOW - > m_uSurface . xdg ) ;
2022-05-20 15:02:51 +02:00
} else {
2023-06-03 12:20:23 +02:00
if ( ! PWINDOW - > m_uSurface . xwayland - > surface - > mapped )
2022-10-28 20:18:10 +02:00
return ;
2023-01-06 13:29:43 +01:00
if ( ! PWINDOW - > m_bFakeFullscreenState )
g_pCompositor - > setWindowFullscreen ( PWINDOW , PWINDOW - > m_uSurface . xwayland - > fullscreen , FULLSCREEN_FULL ) ;
requestedFullState = PWINDOW - > m_uSurface . xwayland - > fullscreen ;
}
if ( ! requestedFullState & & PWINDOW - > m_bFakeFullscreenState ) {
g_pXWaylandManager - > setWindowFullscreen ( PWINDOW , false ) ; // fixes for apps expecting a de-fullscreen (e.g. ff)
g_pXWaylandManager - > setWindowFullscreen ( PWINDOW , true ) ;
2022-05-20 15:02:51 +02:00
}
2022-04-07 17:07:42 +02:00
2022-08-06 20:57:38 +02:00
PWINDOW - > updateToplevel ( ) ;
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " {} fullscreen to {} " , PWINDOW , PWINDOW - > m_bIsFullscreen ) ;
2022-03-21 15:17:04 +01:00
}
2022-10-22 17:43:47 +02:00
void Events : : listener_activateXDG ( wl_listener * listener , void * data ) {
2022-12-16 18:17:31 +01:00
const auto E = ( wlr_xdg_activation_v1_request_activate_event * ) data ;
2022-10-22 17:43:47 +02:00
2022-12-16 18:17:31 +01:00
static auto * const PFOCUSONACTIVATE = & g_pConfigManager - > getConfigValuePtr ( " misc:focus_on_activate " ) - > intValue ;
2022-10-22 17:43:47 +02:00
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " Activate request for surface at {:x} " , ( uintptr_t ) E - > surface ) ;
2022-10-22 17:43:47 +02:00
2023-02-03 13:43:43 +01:00
if ( ! wlr_xdg_surface_try_from_wlr_surface ( E - > surface ) )
2022-10-22 17:43:47 +02:00
return ;
const auto PWINDOW = g_pCompositor - > getWindowFromSurface ( E - > surface ) ;
2022-10-22 17:45:33 +02:00
if ( ! PWINDOW | | PWINDOW = = g_pCompositor - > m_pLastWindow )
2022-10-22 17:43:47 +02:00
return ;
2023-09-20 09:26:20 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " urgent " , std : : format ( " {:x} " , ( uintptr_t ) PWINDOW ) } ) ;
2023-02-19 21:54:53 +01:00
EMIT_HOOK_EVENT ( " urgent " , PWINDOW ) ;
2023-01-29 17:20:53 +01:00
2023-01-14 20:31:11 +01:00
PWINDOW - > m_bIsUrgent = true ;
if ( ! * PFOCUSONACTIVATE )
return ;
2023-01-11 17:59:35 +01:00
if ( PWINDOW - > m_bIsFloating )
2023-09-21 23:18:26 +02:00
g_pCompositor - > changeWindowZOrder ( PWINDOW , true ) ;
2023-01-11 17:59:35 +01:00
2022-10-22 17:43:47 +02:00
g_pCompositor - > focusWindow ( PWINDOW ) ;
2023-09-11 11:09:34 +02:00
g_pCompositor - > warpCursorTo ( PWINDOW - > middle ( ) ) ;
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events : : listener_activateX11 ( void * owner , void * data ) {
2022-12-16 18:17:31 +01:00
const auto PWINDOW = ( CWindow * ) owner ;
2022-03-21 15:17:04 +01:00
2022-12-16 18:17:31 +01:00
static auto * const PFOCUSONACTIVATE = & g_pConfigManager - > getConfigValuePtr ( " misc:focus_on_activate " ) - > intValue ;
2022-10-22 17:43:47 +02:00
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " X11 Activate request for window {} " , PWINDOW ) ;
2022-10-22 17:43:47 +02:00
2023-02-03 22:21:14 +01:00
if ( PWINDOW - > m_iX11Type = = 2 ) {
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Unmanaged X11 {} requests activate " , PWINDOW ) ;
2023-02-03 22:21:14 +01:00
if ( g_pCompositor - > m_pLastWindow & & g_pCompositor - > m_pLastWindow - > getPID ( ) ! = PWINDOW - > getPID ( ) )
return ;
g_pCompositor - > focusWindow ( PWINDOW ) ;
return ;
}
if ( PWINDOW = = g_pCompositor - > m_pLastWindow )
2023-01-29 17:20:53 +01:00
return ;
2023-09-20 09:26:20 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " urgent " , std : : format ( " {:x} " , ( uintptr_t ) PWINDOW ) } ) ;
2023-02-19 21:54:53 +01:00
EMIT_HOOK_EVENT ( " urgent " , PWINDOW ) ;
2023-01-29 17:20:53 +01:00
if ( ! * PFOCUSONACTIVATE )
2022-10-22 17:43:47 +02:00
return ;
2023-01-11 17:59:35 +01:00
if ( PWINDOW - > m_bIsFloating )
2023-09-21 23:18:26 +02:00
g_pCompositor - > changeWindowZOrder ( PWINDOW , true ) ;
2023-01-11 17:59:35 +01:00
2022-10-22 17:43:47 +02:00
g_pCompositor - > focusWindow ( PWINDOW ) ;
2023-09-11 11:09:34 +02:00
g_pCompositor - > warpCursorTo ( PWINDOW - > middle ( ) ) ;
2022-03-21 15:17:04 +01:00
}
2022-03-28 22:31:39 +02:00
void Events : : listener_configureX11 ( void * owner , void * data ) {
2023-02-28 19:50:47 +01:00
CWindow * PWINDOW = ( CWindow * ) owner ;
2022-03-21 15:17:04 +01:00
2023-02-28 19:50:47 +01:00
const auto E = ( wlr_xwayland_surface_configure_event * ) data ;
2023-06-03 12:20:23 +02:00
if ( ! PWINDOW - > m_uSurface . xwayland - > surface | | ! PWINDOW - > m_uSurface . xwayland - > surface - > mapped | | ! PWINDOW - > m_bMappedX11 ) {
2023-02-28 19:50:47 +01:00
wlr_xwayland_surface_configure ( PWINDOW - > m_uSurface . xwayland , E - > x , E - > y , E - > width , E - > height ) ;
2023-11-04 14:09:33 +01:00
PWINDOW - > m_vReportedSize = { E - > width , E - > height } ;
2022-04-05 18:29:58 +02:00
return ;
2023-02-28 19:50:47 +01:00
}
2022-04-05 18:29:58 +02:00
2022-05-23 22:07:29 +02:00
g_pHyprRenderer - > damageWindow ( PWINDOW ) ;
2022-03-21 15:17:04 +01:00
2023-02-28 19:52:03 +01:00
if ( ! PWINDOW - > m_bIsFloating | | PWINDOW - > m_bIsFullscreen | | g_pInputManager - > currentlyDraggedWindow = = PWINDOW ) {
2022-11-04 16:56:31 +01:00
g_pXWaylandManager - > setWindowSize ( PWINDOW , PWINDOW - > m_vRealSize . goalv ( ) , true ) ;
2022-04-05 18:29:58 +02:00
g_pInputManager - > refocus ( ) ;
2022-05-23 22:07:29 +02:00
g_pHyprRenderer - > damageWindow ( PWINDOW ) ;
return ;
}
2022-07-28 15:40:06 +02:00
if ( E - > width > 1 & & E - > height > 1 )
2022-10-14 21:46:32 +02:00
PWINDOW - > setHidden ( false ) ;
2022-07-28 15:40:06 +02:00
else
2022-10-14 21:46:32 +02:00
PWINDOW - > setHidden ( true ) ;
2022-07-28 15:40:06 +02:00
2023-08-15 20:09:32 +02:00
const auto LOGICALPOS = g_pXWaylandManager - > xwaylandToWaylandCoords ( { E - > x , E - > y } ) ;
PWINDOW - > m_vRealPosition . setValueAndWarp ( LOGICALPOS ) ;
2022-04-23 14:35:34 +02:00
PWINDOW - > m_vRealSize . setValueAndWarp ( Vector2D ( E - > width , E - > height ) ) ;
2023-06-22 21:43:31 +02:00
static auto * const PXWLFORCESCALEZERO = & g_pConfigManager - > getConfigValuePtr ( " xwayland:force_zero_scaling " ) - > intValue ;
if ( * PXWLFORCESCALEZERO ) {
2023-11-11 00:49:23 +01:00
if ( const auto PMONITOR = g_pCompositor - > getMonitorFromID ( PWINDOW - > m_iMonitorID ) ; PMONITOR ) {
const Vector2D DELTA = PWINDOW - > m_vRealSize . goalv ( ) - PWINDOW - > m_vRealSize . goalv ( ) / PMONITOR - > scale ;
2023-06-22 21:43:31 +02:00
PWINDOW - > m_vRealSize . setValueAndWarp ( PWINDOW - > m_vRealSize . goalv ( ) / PMONITOR - > scale ) ;
2023-11-11 00:49:23 +01:00
PWINDOW - > m_vRealPosition . setValueAndWarp ( PWINDOW - > m_vRealPosition . goalv ( ) + DELTA / 2.0 ) ;
}
2023-06-22 21:43:31 +02:00
}
2022-05-23 22:07:29 +02:00
PWINDOW - > m_vPosition = PWINDOW - > m_vRealPosition . vec ( ) ;
2022-12-16 18:17:31 +01:00
PWINDOW - > m_vSize = PWINDOW - > m_vRealSize . vec ( ) ;
2022-04-05 18:29:58 +02:00
2022-05-23 22:07:29 +02:00
wlr_xwayland_surface_configure ( PWINDOW - > m_uSurface . xwayland , E - > x , E - > y , E - > width , E - > height ) ;
2023-12-12 02:15:17 +01:00
PWINDOW - > m_vReportedSize = { E - > width , E - > height } ;
PWINDOW - > updateWindowDecos ( ) ;
if ( ! g_pCompositor - > isWorkspaceVisible ( PWINDOW - > m_iWorkspaceID ) )
return ; // further things are only for visible windows
2022-07-19 16:21:35 +02:00
PWINDOW - > m_iWorkspaceID = g_pCompositor - > getMonitorFromVector ( PWINDOW - > m_vRealPosition . vec ( ) + PWINDOW - > m_vRealSize . vec ( ) / 2.f ) - > activeWorkspace ;
2023-09-21 23:18:26 +02:00
g_pCompositor - > changeWindowZOrder ( PWINDOW , true ) ;
2022-05-23 22:07:29 +02:00
PWINDOW - > m_bCreatedOverFullscreen = true ;
2022-04-05 18:29:58 +02:00
2022-10-20 23:38:49 +02:00
if ( ! PWINDOW - > m_sAdditionalConfigData . windowDanceCompat )
g_pInputManager - > refocus ( ) ;
2022-05-23 22:07:29 +02:00
g_pHyprRenderer - > damageWindow ( PWINDOW ) ;
2022-03-21 16:13:43 +01:00
}
2022-07-08 11:24:07 +02:00
void Events : : listener_unmanagedSetGeometry ( void * owner , void * data ) {
CWindow * PWINDOW = ( CWindow * ) owner ;
2022-10-14 21:46:32 +02:00
if ( ! PWINDOW - > m_bMappedX11 )
2022-07-08 11:24:07 +02:00
return ;
const auto POS = PWINDOW - > m_vRealPosition . goalv ( ) ;
2022-07-11 15:31:31 +02:00
const auto SIZ = PWINDOW - > m_vRealSize . goalv ( ) ;
2022-07-08 11:24:07 +02:00
2022-07-28 15:40:06 +02:00
if ( PWINDOW - > m_uSurface . xwayland - > width > 1 & & PWINDOW - > m_uSurface . xwayland - > height > 1 )
2022-10-14 21:46:32 +02:00
PWINDOW - > setHidden ( false ) ;
2022-07-28 15:40:06 +02:00
else
2022-10-14 21:46:32 +02:00
PWINDOW - > setHidden ( true ) ;
2022-07-28 15:40:06 +02:00
2022-11-04 16:56:31 +01:00
if ( PWINDOW - > m_bIsFullscreen | | ! PWINDOW - > m_bIsFloating ) {
g_pXWaylandManager - > setWindowSize ( PWINDOW , PWINDOW - > m_vRealSize . goalv ( ) , true ) ;
g_pHyprRenderer - > damageWindow ( PWINDOW ) ;
return ;
}
2023-06-22 21:43:31 +02:00
static auto * const PXWLFORCESCALEZERO = & g_pConfigManager - > getConfigValuePtr ( " xwayland:force_zero_scaling " ) - > intValue ;
2023-08-21 00:39:39 +02:00
const auto LOGICALPOS = g_pXWaylandManager - > xwaylandToWaylandCoords ( { PWINDOW - > m_uSurface . xwayland - > x , PWINDOW - > m_uSurface . xwayland - > y } ) ;
if ( abs ( std : : floor ( POS . x ) - LOGICALPOS . x ) > 2 | | abs ( std : : floor ( POS . y ) - LOGICALPOS . y ) > 2 | | abs ( std : : floor ( SIZ . x ) - PWINDOW - > m_uSurface . xwayland - > width ) > 2 | |
abs ( std : : floor ( SIZ . y ) - PWINDOW - > m_uSurface . xwayland - > height ) > 2 ) {
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Unmanaged window {} requests geometry update to {:j} {} {} " , PWINDOW , LOGICALPOS , ( int ) PWINDOW - > m_uSurface . xwayland - > width ,
( int ) PWINDOW - > m_uSurface . xwayland - > height ) ;
2022-09-25 20:07:48 +02:00
2022-07-08 11:24:07 +02:00
g_pHyprRenderer - > damageWindow ( PWINDOW ) ;
2023-08-21 00:39:39 +02:00
PWINDOW - > m_vRealPosition . setValueAndWarp ( Vector2D ( LOGICALPOS . x , LOGICALPOS . y ) ) ;
2022-07-12 14:14:12 +02:00
2022-07-20 18:39:08 +02:00
if ( abs ( std : : floor ( SIZ . x ) - PWINDOW - > m_uSurface . xwayland - > width ) > 2 | | abs ( std : : floor ( SIZ . y ) - PWINDOW - > m_uSurface . xwayland - > height ) > 2 )
2022-07-12 14:14:12 +02:00
PWINDOW - > m_vRealSize . setValueAndWarp ( Vector2D ( PWINDOW - > m_uSurface . xwayland - > width , PWINDOW - > m_uSurface . xwayland - > height ) ) ;
2022-07-19 16:21:35 +02:00
2023-06-22 21:43:31 +02:00
if ( * PXWLFORCESCALEZERO ) {
2023-11-11 00:49:23 +01:00
if ( const auto PMONITOR = g_pCompositor - > getMonitorFromID ( PWINDOW - > m_iMonitorID ) ; PMONITOR ) {
const Vector2D DELTA = PWINDOW - > m_vRealSize . goalv ( ) - PWINDOW - > m_vRealSize . goalv ( ) / PMONITOR - > scale ;
2023-06-22 21:43:31 +02:00
PWINDOW - > m_vRealSize . setValueAndWarp ( PWINDOW - > m_vRealSize . goalv ( ) / PMONITOR - > scale ) ;
2023-11-11 00:49:23 +01:00
PWINDOW - > m_vRealPosition . setValueAndWarp ( PWINDOW - > m_vRealPosition . goalv ( ) + DELTA / 2.0 ) ;
}
2023-06-22 21:43:31 +02:00
}
PWINDOW - > m_vPosition = PWINDOW - > m_vRealPosition . goalv ( ) ;
PWINDOW - > m_vSize = PWINDOW - > m_vRealSize . goalv ( ) ;
2022-07-19 16:21:35 +02:00
PWINDOW - > m_iWorkspaceID = g_pCompositor - > getMonitorFromVector ( PWINDOW - > m_vRealPosition . vec ( ) + PWINDOW - > m_vRealSize . vec ( ) / 2.f ) - > activeWorkspace ;
2023-09-21 23:18:26 +02:00
g_pCompositor - > changeWindowZOrder ( PWINDOW , true ) ;
2022-07-11 19:07:59 +02:00
PWINDOW - > updateWindowDecos ( ) ;
2022-07-08 11:24:07 +02:00
g_pHyprRenderer - > damageWindow ( PWINDOW ) ;
}
}
2023-02-28 19:50:47 +01:00
void Events : : listener_setOverrideRedirect ( void * owner , void * data ) {
2023-03-04 01:53:39 +01:00
// const auto PWINDOW = (CWindow*)owner;
2023-02-28 19:50:47 +01:00
2023-03-01 14:47:40 +01:00
//if (!PWINDOW->m_bIsMapped && PWINDOW->m_uSurface.xwayland->mapped) {
// Events::listener_mapWindow(PWINDOW, nullptr);
//}
2023-02-28 19:50:47 +01:00
}
2023-06-03 12:20:23 +02:00
void Events : : listener_associateX11 ( void * owner , void * data ) {
const auto PWINDOW = ( CWindow * ) owner ;
PWINDOW - > hyprListener_mapWindow . initCallback ( & PWINDOW - > m_uSurface . xwayland - > surface - > events . map , & Events : : listener_mapWindow , PWINDOW , " XWayland Window " ) ;
}
void Events : : listener_dissociateX11 ( void * owner , void * data ) {
const auto PWINDOW = ( CWindow * ) owner ;
PWINDOW - > hyprListener_mapWindow . removeCallback ( ) ;
}
2022-03-21 16:13:43 +01:00
void Events : : listener_surfaceXWayland ( wl_listener * listener , void * data ) {
const auto XWSURFACE = ( wlr_xwayland_surface * ) data ;
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " New XWayland Surface created (class {}). " , XWSURFACE - > _class ? XWSURFACE - > _class : " null " ) ;
2022-06-28 12:46:32 +02:00
if ( XWSURFACE - > parent )
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " Window parent data: {} at {:x} " , XWSURFACE - > parent - > _class ? XWSURFACE - > parent - > _class : " null " , ( uintptr_t ) XWSURFACE - > parent ) ;
2022-03-24 21:34:24 +01:00
2023-03-01 14:15:51 +01:00
const auto PNEWWINDOW = ( CWindow * ) g_pCompositor - > m_vWindows . emplace_back ( std : : make_unique < CWindow > ( ) ) . get ( ) ;
2022-03-21 16:13:43 +01:00
PNEWWINDOW - > m_uSurface . xwayland = XWSURFACE ;
2022-12-16 18:17:31 +01:00
PNEWWINDOW - > m_iX11Type = XWSURFACE - > override_redirect ? 2 : 1 ;
PNEWWINDOW - > m_bIsX11 = true ;
2022-03-21 16:13:43 +01:00
2022-06-30 15:44:26 +02:00
PNEWWINDOW - > m_pX11Parent = g_pCompositor - > getX11Parent ( PNEWWINDOW ) ;
2023-06-03 12:20:23 +02:00
PNEWWINDOW - > hyprListener_associateX11 . initCallback ( & XWSURFACE - > events . associate , & Events : : listener_associateX11 , PNEWWINDOW , " XWayland Window " ) ;
PNEWWINDOW - > hyprListener_dissociateX11 . initCallback ( & XWSURFACE - > events . dissociate , & Events : : listener_dissociateX11 , PNEWWINDOW , " XWayland Window " ) ;
2022-03-28 22:31:39 +02:00
PNEWWINDOW - > hyprListener_destroyWindow . initCallback ( & XWSURFACE - > events . destroy , & Events : : listener_destroyWindow , PNEWWINDOW , " XWayland Window " ) ;
2023-02-28 19:50:47 +01:00
PNEWWINDOW - > hyprListener_setOverrideRedirect . initCallback ( & XWSURFACE - > events . set_override_redirect , & Events : : listener_setOverrideRedirect , PNEWWINDOW , " XWayland Window " ) ;
PNEWWINDOW - > hyprListener_configureX11 . initCallback ( & XWSURFACE - > events . request_configure , & Events : : listener_configureX11 , PNEWWINDOW , " XWayland Window " ) ;
2022-03-21 16:13:43 +01:00
}
2023-11-24 11:54:21 +01:00
void Events : : listener_newXDGToplevel ( wl_listener * listener , void * data ) {
2022-03-21 16:13:43 +01:00
// A window got opened
2023-11-30 02:18:55 +01:00
const auto XDGTOPLEVEL = ( wlr_xdg_toplevel * ) data ;
const auto XDGSURFACE = XDGTOPLEVEL - > base ;
2022-03-21 16:13:43 +01:00
2023-11-30 02:18:55 +01:00
Debug : : log ( LOG , " New XDG Toplevel created. (class: {}) " , XDGSURFACE - > toplevel - > app_id ? XDGSURFACE - > toplevel - > app_id : " null " ) ;
2022-07-31 13:14:56 +02:00
2022-12-16 18:17:31 +01:00
const auto PNEWWINDOW = g_pCompositor - > m_vWindows . emplace_back ( std : : make_unique < CWindow > ( ) ) . get ( ) ;
2022-03-21 16:13:43 +01:00
PNEWWINDOW - > m_uSurface . xdg = XDGSURFACE ;
2023-06-03 12:20:23 +02:00
PNEWWINDOW - > hyprListener_mapWindow . initCallback ( & XDGSURFACE - > surface - > events . map , & Events : : listener_mapWindow , PNEWWINDOW , " XDG Window " ) ;
2022-03-28 22:31:39 +02:00
PNEWWINDOW - > hyprListener_destroyWindow . initCallback ( & XDGSURFACE - > events . destroy , & Events : : listener_destroyWindow , PNEWWINDOW , " XDG Window " ) ;
2022-03-27 22:34:02 +02:00
}
2022-05-10 11:01:03 +02:00
void Events : : listener_NewXDGDeco ( wl_listener * listener , void * data ) {
const auto WLRDECO = ( wlr_xdg_toplevel_decoration_v1 * ) data ;
wlr_xdg_toplevel_decoration_v1_set_mode ( WLRDECO , WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE ) ;
}
2022-07-16 00:11:21 +02:00
void Events : : listener_requestMaximize ( void * owner , void * data ) {
const auto PWINDOW = ( CWindow * ) owner ;
2023-07-23 19:47:41 +02:00
if ( PWINDOW - > m_bNoMaximizeRequest )
2022-11-26 21:44:40 +01:00
return ;
2022-09-29 11:24:54 +02:00
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Maximize request for {} " , PWINDOW ) ;
2022-10-28 20:18:10 +02:00
if ( ! PWINDOW - > m_bIsX11 ) {
const auto EV = ( wlr_foreign_toplevel_handle_v1_maximized_event * ) data ;
2022-12-16 18:17:31 +01:00
g_pCompositor - > setWindowFullscreen ( PWINDOW , EV ? EV - > maximized : ! PWINDOW - > m_bIsFullscreen ,
FULLSCREEN_MAXIMIZED ) ; // this will be rejected if there already is a fullscreen window
2022-10-28 20:18:10 +02:00
wlr_xdg_surface_schedule_configure ( PWINDOW - > m_uSurface . xdg ) ;
} else {
if ( ! PWINDOW - > m_bMappedX11 | | PWINDOW - > m_iX11Type ! = 1 )
return ;
g_pCompositor - > setWindowFullscreen ( PWINDOW , ! PWINDOW - > m_bIsFullscreen , FULLSCREEN_MAXIMIZED ) ;
}
2022-07-16 00:11:21 +02:00
}
void Events : : listener_requestMinimize ( void * owner , void * data ) {
2022-10-28 20:18:10 +02:00
const auto PWINDOW = ( CWindow * ) owner ;
2023-09-20 17:25:03 +02:00
Debug : : log ( LOG , " Minimize request for {} " , PWINDOW ) ;
2022-10-28 20:18:10 +02:00
2022-11-04 16:56:31 +01:00
if ( PWINDOW - > m_bIsX11 ) {
if ( ! PWINDOW - > m_bMappedX11 | | PWINDOW - > m_iX11Type ! = 1 )
return ;
2022-10-28 20:18:10 +02:00
2022-11-04 16:56:31 +01:00
const auto E = ( wlr_xwayland_minimize_event * ) data ;
2022-10-28 20:18:10 +02:00
2023-09-20 09:26:20 +02:00
g_pEventManager - > postEvent ( { " minimize " , std : : format ( " {:x},{} " , ( uintptr_t ) PWINDOW , ( int ) E - > minimize ) } ) ;
2023-02-19 21:54:53 +01:00
EMIT_HOOK_EVENT ( " minimize " , ( std : : vector < void * > { PWINDOW , ( void * ) E - > minimize } ) ) ;
2023-01-29 17:26:14 +01:00
2022-11-04 16:56:31 +01:00
wlr_xwayland_surface_set_minimized ( PWINDOW - > m_uSurface . xwayland , E - > minimize & & g_pCompositor - > m_pLastWindow ! = PWINDOW ) ; // fucking DXVK
2023-01-29 17:26:14 +01:00
} else {
const auto E = ( wlr_foreign_toplevel_handle_v1_minimized_event * ) data ;
2023-09-20 09:26:20 +02:00
g_pEventManager - > postEvent ( { " minimize " , std : : format ( " {:x},{} " , ( uintptr_t ) PWINDOW , E ? ( int ) E - > minimized : 1 ) } ) ;
2023-02-20 12:01:03 +01:00
EMIT_HOOK_EVENT ( " minimize " , ( std : : vector < void * > { PWINDOW , ( void * ) ( E ? ( uint64_t ) E - > minimized : 1 ) } ) ) ;
2022-11-04 16:56:31 +01:00
}
2022-07-16 00:11:21 +02:00
}
void Events : : listener_requestMove ( void * owner , void * data ) {
const auto PWINDOW = ( CWindow * ) owner ;
// ignore
wlr_xdg_surface_schedule_configure ( PWINDOW - > m_uSurface . xdg ) ;
}
void Events : : listener_requestResize ( void * owner , void * data ) {
const auto PWINDOW = ( CWindow * ) owner ;
// ignore
wlr_xdg_surface_schedule_configure ( PWINDOW - > m_uSurface . xdg ) ;
2022-09-25 20:07:48 +02:00
}