@@ -40,26 +40,46 @@ ShortcutsInhibitManager::createShortcutsInhibitor(QtWaylandClient::QWaylandWindo
4040 auto * wlSurface = surface->surface ();
4141
4242 if (this ->inhibitors .contains (wlSurface)) {
43- qCWarning (logShortcutsInhibit)
44- << " An inhibitor already exists for surface, skipping creation." << wlSurface;
45- return nullptr ;
43+ auto * inhibitor = this ->inhibitors .value (wlSurface);
44+ this ->refCounts [inhibitor]++;
45+ qCDebug (logShortcutsInhibit) << " Reusing existing inhibitor" << inhibitor << " for surface"
46+ << wlSurface << " - refcount:" << this ->refCounts [inhibitor];
47+ return inhibitor;
4648 }
4749
4850 auto * inhibitor =
4951 new ShortcutsInhibitor (this ->inhibit_shortcuts (wlSurface, inputDevice->object ()), wlSurface);
5052 this ->inhibitors .insert (wlSurface, inhibitor);
53+ this ->refCounts .insert (inhibitor, 1 );
5154 qCDebug (logShortcutsInhibit) << " Created inhibitor" << inhibitor << " for surface" << wlSurface;
5255 return inhibitor;
5356}
5457
55- void ShortcutsInhibitManager::destroyShortcutsInhibitor (ShortcutsInhibitor* inhibitor) {
56- if (inhibitor) { this ->inhibitors .remove (inhibitor->surface ()); }
58+ void ShortcutsInhibitManager::refShortcutsInhibitor (ShortcutsInhibitor* inhibitor) {
59+ if (inhibitor && this ->refCounts .contains (inhibitor)) {
60+ this ->refCounts [inhibitor]++;
61+ qCDebug (logShortcutsInhibit) << " Incremented refcount for inhibitor" << inhibitor
62+ << " - refcount:" << this ->refCounts [inhibitor];
63+ }
64+ }
65+
66+ void ShortcutsInhibitManager::unrefShortcutsInhibitor (ShortcutsInhibitor* inhibitor) {
67+ if (!inhibitor || !this ->refCounts .contains (inhibitor)) return ;
68+
69+ this ->refCounts [inhibitor]--;
70+ qCDebug (logShortcutsInhibit) << " Decremented refcount for inhibitor" << inhibitor
71+ << " - refcount:" << this ->refCounts [inhibitor];
72+
73+ if (this ->refCounts [inhibitor] <= 0 ) {
74+ qCDebug (logShortcutsInhibit) << " Refcount reached 0, destroying inhibitor" << inhibitor;
75+ this ->inhibitors .remove (inhibitor->surface ());
76+ this ->refCounts .remove (inhibitor);
77+ delete inhibitor;
78+ }
5779}
5880
5981ShortcutsInhibitor::~ShortcutsInhibitor () {
6082 qCDebug (logShortcutsInhibit) << " Destroying inhibitor" << this << " for surface" << this ->mSurface ;
61- auto * manager = ShortcutsInhibitManager::instance ();
62- if (manager) { manager->destroyShortcutsInhibitor (this ); }
6383 if (this ->isInitialized ()) this ->destroy ();
6484}
6585
0 commit comments