2024-04-21 20:04:58 +01:00
# include "XDGDecoration.hpp"
# include <algorithm>
2025-05-04 23:39:00 +02:00
CXDGDecoration : : CXDGDecoration ( SP < CZxdgToplevelDecorationV1 > resource_ , wl_resource * toplevel ) : m_resource ( resource_ ) , m_toplevelResource ( toplevel ) {
if UNLIKELY ( ! m_resource - > resource ( ) )
2024-04-21 20:04:58 +01:00
return ;
2025-05-04 23:39:00 +02:00
m_resource - > setDestroy ( [ this ] ( CZxdgToplevelDecorationV1 * pMgr ) { PROTO : : xdgDecoration - > destroyDecoration ( this ) ; } ) ;
m_resource - > setOnDestroy ( [ this ] ( CZxdgToplevelDecorationV1 * pMgr ) { PROTO : : xdgDecoration - > destroyDecoration ( this ) ; } ) ;
2024-04-21 20:04:58 +01:00
2025-05-04 23:39:00 +02:00
m_resource - > setSetMode ( [ this ] ( CZxdgToplevelDecorationV1 * , zxdgToplevelDecorationV1Mode mode ) {
2024-04-21 20:04:58 +01:00
std : : string modeString ;
switch ( mode ) {
2024-04-21 21:20:48 +01:00
case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE : modeString = " MODE_CLIENT_SIDE " ; break ;
case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE : modeString = " MODE_SERVER_SIDE " ; break ;
2024-04-21 20:04:58 +01:00
default : modeString = " INVALID " ; break ;
}
2025-12-18 17:23:24 +00:00
LOGM ( Log : : DEBUG , " setMode: {}. {} MODE_SERVER_SIDE as reply. " , modeString , ( mode = = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE ? " Sending " : " Ignoring and sending " ) ) ;
2025-09-02 04:49:24 -05:00
auto sendMode = xdgModeOnRequestCSD ( mode ) ;
m_resource - > sendConfigure ( sendMode ) ;
mostRecentlySent = sendMode ;
mostRecentlyRequested = mode ;
2024-04-21 20:04:58 +01:00
} ) ;
2025-05-04 23:39:00 +02:00
m_resource - > setUnsetMode ( [ this ] ( CZxdgToplevelDecorationV1 * ) {
2025-12-18 17:23:24 +00:00
LOGM ( Log : : DEBUG , " unsetMode. Sending MODE_SERVER_SIDE. " ) ;
2025-09-02 04:49:24 -05:00
auto sendMode = xdgModeOnReleaseCSD ( ) ;
m_resource - > sendConfigure ( sendMode ) ;
mostRecentlySent = sendMode ;
mostRecentlyRequested = 0 ;
2024-04-21 20:04:58 +01:00
} ) ;
2024-06-02 15:14:20 +02:00
2025-09-02 04:49:24 -05:00
auto sendMode = xdgDefaultModeCSD ( ) ;
m_resource - > sendConfigure ( sendMode ) ;
mostRecentlySent = sendMode ;
}
zxdgToplevelDecorationV1Mode CXDGDecoration : : xdgDefaultModeCSD ( ) {
return ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE ;
}
zxdgToplevelDecorationV1Mode CXDGDecoration : : xdgModeOnRequestCSD ( uint32_t modeRequestedByClient ) {
return xdgDefaultModeCSD ( ) ;
}
zxdgToplevelDecorationV1Mode CXDGDecoration : : xdgModeOnReleaseCSD ( ) {
return xdgDefaultModeCSD ( ) ;
2024-04-21 20:04:58 +01:00
}
bool CXDGDecoration : : good ( ) {
2025-05-04 23:39:00 +02:00
return m_resource - > resource ( ) ;
2024-04-21 20:04:58 +01:00
}
wl_resource * CXDGDecoration : : toplevelResource ( ) {
2025-05-04 23:39:00 +02:00
return m_toplevelResource ;
2024-04-21 20:04:58 +01:00
}
CXDGDecorationProtocol : : CXDGDecorationProtocol ( const wl_interface * iface , const int & ver , const std : : string & name ) : IWaylandProtocol ( iface , ver , name ) {
;
}
void CXDGDecorationProtocol : : bindManager ( wl_client * client , void * data , uint32_t ver , uint32_t id ) {
2025-05-04 23:39:00 +02:00
const auto RESOURCE = m_managers . emplace_back ( makeUnique < CZxdgDecorationManagerV1 > ( client , ver , id ) ) . get ( ) ;
2024-04-21 20:04:58 +01:00
RESOURCE - > setOnDestroy ( [ this ] ( CZxdgDecorationManagerV1 * p ) { this - > onManagerResourceDestroy ( p - > resource ( ) ) ; } ) ;
RESOURCE - > setDestroy ( [ this ] ( CZxdgDecorationManagerV1 * pMgr ) { this - > onManagerResourceDestroy ( pMgr - > resource ( ) ) ; } ) ;
RESOURCE - > setGetToplevelDecoration ( [ this ] ( CZxdgDecorationManagerV1 * pMgr , uint32_t id , wl_resource * xdgToplevel ) { this - > onGetDecoration ( pMgr , id , xdgToplevel ) ; } ) ;
}
void CXDGDecorationProtocol : : onManagerResourceDestroy ( wl_resource * res ) {
2025-05-04 23:39:00 +02:00
std : : erase_if ( m_managers , [ & ] ( const auto & other ) { return other - > resource ( ) = = res ; } ) ;
2024-04-21 20:04:58 +01:00
}
void CXDGDecorationProtocol : : destroyDecoration ( CXDGDecoration * decoration ) {
2025-05-04 23:39:00 +02:00
m_decorations . erase ( decoration - > toplevelResource ( ) ) ;
2024-04-21 20:04:58 +01:00
}
void CXDGDecorationProtocol : : onGetDecoration ( CZxdgDecorationManagerV1 * pMgr , uint32_t id , wl_resource * xdgToplevel ) {
2025-05-04 23:39:00 +02:00
if UNLIKELY ( m_decorations . contains ( xdgToplevel ) ) {
2024-05-01 19:40:35 +01:00
pMgr - > error ( ZXDG_TOPLEVEL_DECORATION_V1_ERROR_ALREADY_CONSTRUCTED , " Decoration object already exists " ) ;
2024-04-21 20:04:58 +01:00
return ;
}
2024-05-01 19:40:35 +01:00
const auto CLIENT = pMgr - > client ( ) ;
2024-04-21 20:04:58 +01:00
const auto RESOURCE =
2025-05-04 23:39:00 +02:00
m_decorations . emplace ( xdgToplevel , makeUnique < CXDGDecoration > ( makeShared < CZxdgToplevelDecorationV1 > ( CLIENT , pMgr - > version ( ) , id ) , xdgToplevel ) ) . first - > second . get ( ) ;
2024-04-21 20:04:58 +01:00
2025-01-17 18:21:34 +01:00
if UNLIKELY ( ! RESOURCE - > good ( ) ) {
2024-05-01 19:40:35 +01:00
pMgr - > noMemory ( ) ;
2025-05-04 23:39:00 +02:00
m_decorations . erase ( xdgToplevel ) ;
2024-04-21 20:04:58 +01:00
return ;
}
2025-09-02 04:49:24 -05:00
}