11#include " inhibitor.hpp"
22
33#include < private/qwaylandwindow_p.h>
4+ #include < qguiapplication.h>
45#include < qlogging.h>
56#include < qloggingcategory.h>
67#include < qobject.h>
8+ #include < qtmetamacros.h>
79
810#include " ../../window/proxywindow.hpp"
911#include " ../../window/windowinterface.hpp"
@@ -19,8 +21,19 @@ ShortcutInhibitor::ShortcutInhibitor() {
1921
2022 this ->bActive .setBinding ([this ]() {
2123 auto * inhibitor = this ->bInhibitor .value ();
22- return inhibitor ? inhibitor->bindableActive ().value () : false ;
24+ if (!inhibitor) return false ;
25+ if (!inhibitor->bindableActive ().value ()) return false ;
26+ return this ->bWindow .value () == this ->bFocusedWindow ;
2327 });
28+
29+ QObject::connect (
30+ dynamic_cast <QGuiApplication*>(QGuiApplication::instance ()),
31+ &QGuiApplication::focusWindowChanged,
32+ this ,
33+ &ShortcutInhibitor::onFocusedWindowChanged
34+ );
35+
36+ this ->onFocusedWindowChanged (QGuiApplication::focusWindow ());
2437}
2538
2639ShortcutInhibitor::~ShortcutInhibitor () {
@@ -32,7 +45,7 @@ ShortcutInhibitor::~ShortcutInhibitor() {
3245 manager->unrefShortcutsInhibitor (this ->bInhibitor );
3346}
3447
35- void ShortcutInhibitor::boundWindowChanged () {
48+ void ShortcutInhibitor::onBoundWindowChanged () {
3649 auto * window = this ->bBoundWindow .value ();
3750 auto * proxyWindow = qobject_cast<ProxyWindowBase*>(window);
3851
@@ -44,17 +57,17 @@ void ShortcutInhibitor::boundWindowChanged() {
4457
4558 if (proxyWindow == this ->proxyWindow ) return ;
4659
60+ if (this ->proxyWindow ) {
61+ QObject::disconnect (this ->proxyWindow , nullptr , this , nullptr );
62+ this ->proxyWindow = nullptr ;
63+ }
64+
4765 if (this ->mWaylandWindow ) {
4866 QObject::disconnect (this ->mWaylandWindow , nullptr , this , nullptr );
4967 this ->mWaylandWindow = nullptr ;
5068 this ->onWaylandSurfaceDestroyed ();
5169 }
5270
53- if (this ->proxyWindow ) {
54- QObject::disconnect (this ->proxyWindow , nullptr , this , nullptr );
55- this ->proxyWindow = nullptr ;
56- }
57-
5871 if (proxyWindow) {
5972 this ->proxyWindow = proxyWindow;
6073
@@ -74,7 +87,6 @@ void ShortcutInhibitor::boundWindowChanged() {
7487void ShortcutInhibitor::onWindowDestroyed () {
7588 this ->proxyWindow = nullptr ;
7689 this ->onWaylandSurfaceDestroyed ();
77- this ->bWindowObject = nullptr ;
7890}
7991
8092void ShortcutInhibitor::onWindowVisibilityChanged () {
@@ -90,6 +102,7 @@ void ShortcutInhibitor::onWindowVisibilityChanged() {
90102 }
91103 if (waylandWindow == this ->mWaylandWindow ) return ;
92104 this ->mWaylandWindow = waylandWindow;
105+ this ->bWindow = window;
93106
94107 QObject::connect (
95108 waylandWindow,
@@ -144,7 +157,7 @@ void ShortcutInhibitor::onWaylandSurfaceDestroyed() {
144157 this ->bInhibitor = nullptr ;
145158}
146159
147- void ShortcutInhibitor::inhibitorChanged () {
160+ void ShortcutInhibitor::onInhibitorChanged () {
148161 auto * inhibitor = this ->bInhibitor .value ();
149162 if (inhibitor) {
150163 QObject::connect (
@@ -162,7 +175,12 @@ void ShortcutInhibitor::onInhibitorActiveChanged() {
162175 // Compositor has deactivated the inhibitor, making it invalid.
163176 // Set enabled to false so the user can enable it again to create a new inhibitor.
164177 this ->bEnabled = false ;
178+ emit this ->cancelled ();
165179 }
166180}
167181
182+ void ShortcutInhibitor::onFocusedWindowChanged (QWindow* focusedWindow) {
183+ this ->bFocusedWindow = focusedWindow;
184+ }
185+
168186} // namespace qs::wayland::shortcuts_inhibit
0 commit comments