@@ -68,10 +68,21 @@ void FdoSelectionManager::init()
6868 connect (m_selectionOwner, &KSelectionOwner::failedToClaimOwnership, this , &FdoSelectionManager::onFailedToClaimOwnership);
6969 connect (m_selectionOwner, &KSelectionOwner::lostOwnership, this , &FdoSelectionManager::onLostOwnership);
7070 m_selectionOwner->claim (true );
71+ }
7172
72- connect (m_trayManager, &TrayManager1::reclainRequested, this , [this ](){
73- m_selectionOwner->claim (true );
74- });
73+ void FdoSelectionManager::checkValid ()
74+ {
75+ if (!m_trayManager) {
76+ return ;
77+ }
78+
79+ const TrayList trayIcons = m_trayManager->trayIcons ();
80+ for (uint id : trayIcons) {
81+ const xcb_window_t window = static_cast <xcb_window_t >(id);
82+ if (!UTIL ->isValidX11Window (window)) {
83+ undock (window);
84+ }
85+ }
7586}
7687
7788bool FdoSelectionManager::addDamageWatch (xcb_window_t client)
@@ -82,7 +93,6 @@ bool FdoSelectionManager::addDamageWatch(xcb_window_t client)
8293 const auto attribsCookie = xcb_get_window_attributes_unchecked (c, client);
8394
8495 const auto damageId = xcb_generate_id (c);
85- m_damageWatches[client] = damageId;
8696 xcb_damage_create (c, damageId, client, XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY );
8797
8898 xcb_generic_error_t *error = nullptr ;
@@ -94,6 +104,7 @@ bool FdoSelectionManager::addDamageWatch(xcb_window_t client)
94104 }
95105 // if window is already gone, there is no need to handle it.
96106 if (getAttrError && getAttrError->error_code == XCB_WINDOW ) {
107+ xcb_damage_destroy (c, damageId);
97108 return false ;
98109 }
99110 // the event mask will not be removed again. We cannot track whether another component also needs STRUCTURE_NOTIFY (e.g. KWindowSystem).
@@ -102,9 +113,12 @@ bool FdoSelectionManager::addDamageWatch(xcb_window_t client)
102113 UniqueCPointer<xcb_generic_error_t > changeAttrError (xcb_request_check (c, changeAttrCookie));
103114 // if window is gone by this point, it will be caught by eventFilter, so no need to check later errors.
104115 if (changeAttrError && changeAttrError->error_code == XCB_WINDOW ) {
116+ xcb_damage_destroy (c, damageId);
105117 return false ;
106118 }
107119
120+ m_damageWatches[client] = damageId;
121+
108122 return true ;
109123}
110124
@@ -160,6 +174,8 @@ void FdoSelectionManager::dock(xcb_window_t winId)
160174 Q_CHECK_PTR (m_trayManager);
161175 qCDebug (SELECTIONMGR ) << " trying to dock window " << winId;
162176
177+ checkValid ();
178+
163179 if (m_trayManager->haveIcon (winId)) {
164180 return ;
165181 }
@@ -182,6 +198,12 @@ void FdoSelectionManager::undock(xcb_window_t winId)
182198
183199 // Unregister from TrayManager1 if available
184200 m_trayManager->unregisterIcon (winId);
201+
202+ const auto damageId = m_damageWatches.take (winId);
203+ if (damageId) {
204+ xcb_damage_destroy (Util::instance ()->getX11Connection (), damageId);
205+ xcb_flush (Util::instance ()->getX11Connection ());
206+ }
185207
186208 // m_proxies[winId]->deleteLater();
187209 // m_proxies.remove(winId);
@@ -192,7 +214,8 @@ void FdoSelectionManager::onClaimedOwnership()
192214 qCDebug (SELECTIONMGR ) << " Manager selection claimed" ;
193215
194216 initTrayManager ();
195- setSystemTrayVisual ();
217+ setSystemTrayProperties ();
218+ m_trayManager->notifyInited ();
196219}
197220
198221void FdoSelectionManager::onFailedToClaimOwnership ()
@@ -205,7 +228,7 @@ void FdoSelectionManager::onLostOwnership()
205228 qCWarning (SELECTIONMGR ) << " lost ownership of Systray Manager" ;
206229}
207230
208- void FdoSelectionManager::setSystemTrayVisual ()
231+ void FdoSelectionManager::setSystemTrayProperties ()
209232{
210233 xcb_connection_t *c = Util::instance ()->getX11Connection ();
211234 auto screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data ;
@@ -234,6 +257,11 @@ void FdoSelectionManager::setSystemTrayVisual()
234257 }
235258
236259 xcb_change_property (c, XCB_PROP_MODE_REPLACE , m_selectionOwner->ownerWindow (), UTIL ->getAtomByName (" _NET_SYSTEM_TRAY_VISUAL" ), XCB_ATOM_VISUALID , 32 , 1 , &trayVisual);
260+
261+ const uint32_t orientation = 0 ;
262+ xcb_change_property (c, XCB_PROP_MODE_REPLACE , m_selectionOwner->ownerWindow (), UTIL ->getAtomByName (" _NET_SYSTEM_TRAY_ORIENTATION" ), XCB_ATOM_CARDINAL , 32 , 1 , &orientation);
263+ xcb_change_property (c, XCB_PROP_MODE_REPLACE , m_selectionOwner->ownerWindow (), UTIL ->getAtomByName (" NET_SYSTEM_TRAY_ORIENTAION" ), XCB_ATOM_CARDINAL , 32 , 1 , &orientation);
264+ xcb_flush (c);
237265}
238266
239267void FdoSelectionManager::initTrayManager ()
@@ -253,8 +281,11 @@ void FdoSelectionManager::initTrayManager()
253281 QDBusConnection::sessionBus ().registerService (
254282 QStringLiteral (" org.deepin.dde.TrayManager1" )
255283 );
284+
285+ connect (m_trayManager, &TrayManager1::reclainRequested, this , [this ](){
286+ m_selectionOwner->claim (true );
287+ });
256288
257289 qCDebug (SELECTIONMGR ) << " TrayManager1 DBus interface registered" ;
258290 }
259291}
260-
0 commit comments