Skip to content

Commit 824b7a1

Browse files
committed
wayland/shortcuts-inhibit: make inhibitor a bindable
1 parent 0a7c19c commit 824b7a1

File tree

4 files changed

+26
-33
lines changed

4 files changed

+26
-33
lines changed

src/wayland/shortcuts_inhibit/inhibitor.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <private/qwaylandwindow_p.h>
44
#include <qlogging.h>
5+
#include <qloggingcategory.h>
56
#include <qobject.h>
67

78
#include "../../window/proxywindow.hpp"
@@ -15,15 +16,20 @@ ShortcutsInhibitor::ShortcutsInhibitor() {
1516
this->bBoundWindow.setBinding([this] {
1617
return this->bEnabled ? this->bWindowObject.value() : nullptr;
1718
});
19+
20+
this->bActive.setBinding([this]() {
21+
auto* inhibitor = this->bInhibitor.value();
22+
return inhibitor ? inhibitor->bindableActive().value() : false;
23+
});
1824
}
1925

2026
ShortcutsInhibitor::~ShortcutsInhibitor() {
21-
if (!this->inhibitor) return;
27+
if (!this->bInhibitor) return;
2228

2329
auto* manager = impl::ShortcutsInhibitManager::instance();
2430
if (!manager) return;
2531

26-
manager->unrefShortcutsInhibitor(this->inhibitor);
32+
manager->unrefShortcutsInhibitor(this->bInhibitor);
2733
}
2834

2935
QObject* ShortcutsInhibitor::window() const { return this->bWindowObject; }
@@ -87,7 +93,10 @@ void ShortcutsInhibitor::onWindowVisibilityChanged() {
8793
if (!window->handle()) window->create();
8894

8995
auto* waylandWindow = dynamic_cast<QWaylandWindow*>(window->handle());
90-
if (!waylandWindow) return;
96+
if (!waylandWindow) {
97+
qCCritical(impl::logShortcutsInhibit()) << "Window handle is not a QWaylandWindow";
98+
return;
99+
}
91100
if (waylandWindow == this->mWaylandWindow) return;
92101
this->mWaylandWindow = waylandWindow;
93102

@@ -127,27 +136,23 @@ void ShortcutsInhibitor::onWaylandSurfaceCreated() {
127136
return;
128137
}
129138

130-
if (this->inhibitor) {
139+
if (this->bInhibitor) {
131140
qFatal("ShortcutsInhibitor: inhibitor already exists when creating surface");
132141
}
133142

134-
this->inhibitor = manager->createShortcutsInhibitor(this->mWaylandWindow);
135-
136-
if (this->inhibitor) {
137-
this->bActive.setBinding([this]() {
138-
return this->inhibitor ? this->inhibitor->bindableActive().value() : false;
139-
});
140-
}
143+
this->bInhibitor = manager->createShortcutsInhibitor(this->mWaylandWindow);
141144
}
142145

143146
void ShortcutsInhibitor::onWaylandSurfaceDestroyed() {
144-
if (!this->inhibitor) return;
147+
if (!this->bInhibitor) return;
145148

146149
auto* manager = impl::ShortcutsInhibitManager::instance();
147150
if (!manager) return;
148151

149-
manager->unrefShortcutsInhibitor(this->inhibitor);
150-
this->inhibitor = nullptr;
152+
manager->unrefShortcutsInhibitor(this->bInhibitor);
153+
this->bInhibitor = nullptr;
151154
}
152155

156+
void ShortcutsInhibitor::inhibitorChanged() {}
157+
153158
} // namespace qs::wayland::shortcuts_inhibit

src/wayland/shortcuts_inhibit/inhibitor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ShortcutsInhibitor: public QObject {
5050
void setWindow(QObject* window);
5151

5252
[[nodiscard]] QBindable<bool> bindableEnabled() { return &this->bEnabled; }
53-
[[nodiscard]] QBindable<bool> bindableActive() { return &this->bActive; }
53+
[[nodiscard]] QBindable<bool> bindableActive() const { return &this->bActive; }
5454

5555
signals:
5656
void enabledChanged();
@@ -66,15 +66,15 @@ private slots:
6666

6767
private:
6868
void boundWindowChanged();
69+
void inhibitorChanged();
6970
ProxyWindowBase* proxyWindow = nullptr;
7071
QtWaylandClient::QWaylandWindow* mWaylandWindow = nullptr;
7172

72-
impl::ShortcutsInhibitor* inhibitor = nullptr;
73-
7473
// clang-format off
7574
Q_OBJECT_BINDABLE_PROPERTY(ShortcutsInhibitor, bool, bEnabled, &ShortcutsInhibitor::enabledChanged);
7675
Q_OBJECT_BINDABLE_PROPERTY(ShortcutsInhibitor, QObject*, bWindowObject, &ShortcutsInhibitor::windowChanged);
7776
Q_OBJECT_BINDABLE_PROPERTY(ShortcutsInhibitor, QObject*, bBoundWindow, &ShortcutsInhibitor::boundWindowChanged);
77+
Q_OBJECT_BINDABLE_PROPERTY(ShortcutsInhibitor, impl::ShortcutsInhibitor*, bInhibitor, &ShortcutsInhibitor::inhibitorChanged);
7878
Q_OBJECT_BINDABLE_PROPERTY(ShortcutsInhibitor, bool, bActive, &ShortcutsInhibitor::activeChanged);
7979
// clang-format on
8080
};

src/wayland/shortcuts_inhibit/proto.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
namespace qs::wayland::shortcuts_inhibit::impl {
1515

16-
namespace {
1716
QS_LOGGING_CATEGORY(logShortcutsInhibit, "quickshell.wayland.shortcuts_inhibit", QtWarningMsg);
18-
}
1917

2018
ShortcutsInhibitManager::ShortcutsInhibitManager(): QWaylandClientExtensionTemplate(1) {
2119
this->initialize();
@@ -54,18 +52,6 @@ ShortcutsInhibitManager::createShortcutsInhibitor(QtWaylandClient::QWaylandWindo
5452
return inhibitor;
5553
}
5654

57-
void ShortcutsInhibitManager::refShortcutsInhibitor(ShortcutsInhibitor* inhibitor) {
58-
if (!inhibitor) return;
59-
60-
auto* surface = inhibitor->surface();
61-
if (!this->inhibitors.contains(surface)) return;
62-
63-
auto& pair = this->inhibitors[surface];
64-
pair.second++;
65-
qCDebug(logShortcutsInhibit) << "Incremented refcount for inhibitor" << inhibitor
66-
<< "- refcount:" << pair.second;
67-
}
68-
6955
void ShortcutsInhibitManager::unrefShortcutsInhibitor(ShortcutsInhibitor* inhibitor) {
7056
if (!inhibitor) return;
7157

src/wayland/shortcuts_inhibit/proto.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
#include <qwayland-keyboard-shortcuts-inhibit-unstable-v1.h>
88
#include <qwaylandclientextension.h>
99

10+
#include "../../core/logcat.hpp"
1011
#include "wayland-keyboard-shortcuts-inhibit-unstable-v1-client-protocol.h"
1112

1213
namespace qs::wayland::shortcuts_inhibit::impl {
1314

15+
QS_DECLARE_LOGGING_CATEGORY(logShortcutsInhibit);
16+
1417
class ShortcutsInhibitor;
1518

1619
class ShortcutsInhibitManager
@@ -20,7 +23,6 @@ class ShortcutsInhibitManager
2023
explicit ShortcutsInhibitManager();
2124

2225
ShortcutsInhibitor* createShortcutsInhibitor(QtWaylandClient::QWaylandWindow* surface);
23-
void refShortcutsInhibitor(ShortcutsInhibitor* inhibitor);
2426
void unrefShortcutsInhibitor(ShortcutsInhibitor* inhibitor);
2527

2628
static ShortcutsInhibitManager* instance();
@@ -42,7 +44,7 @@ class ShortcutsInhibitor
4244
~ShortcutsInhibitor() override;
4345
Q_DISABLE_COPY_MOVE(ShortcutsInhibitor);
4446

45-
[[nodiscard]] QBindable<bool> bindableActive() { return &this->bActive; }
47+
[[nodiscard]] QBindable<bool> bindableActive() const { return &this->bActive; }
4648
[[nodiscard]] bool isActive() const { return this->bActive; }
4749
[[nodiscard]] wl_surface* surface() const { return this->mSurface; }
4850

0 commit comments

Comments
 (0)