Skip to content

Commit 61d7c40

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

File tree

4 files changed

+36
-35
lines changed

4 files changed

+36
-35
lines changed

src/wayland/shortcuts_inhibit/inhibitor.cpp

Lines changed: 25 additions & 15 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"
@@ -11,19 +12,29 @@
1112
namespace qs::wayland::shortcuts_inhibit {
1213
using QtWaylandClient::QWaylandWindow;
1314

14-
ShortcutsInhibitor::ShortcutsInhibitor() {
15+
ShortcutsInhibitor::ShortcutsInhibitor()
16+
: bEnabled(false)
17+
, bWindowObject(nullptr)
18+
, bBoundWindow(nullptr)
19+
, bInhibitor(nullptr)
20+
, bActive(false) {
1521
this->bBoundWindow.setBinding([this] {
1622
return this->bEnabled ? this->bWindowObject.value() : nullptr;
1723
});
24+
25+
this->bActive.setBinding([this]() {
26+
auto* inhibitor = this->bInhibitor.value();
27+
return inhibitor ? inhibitor->bindableActive().value() : false;
28+
});
1829
}
1930

2031
ShortcutsInhibitor::~ShortcutsInhibitor() {
21-
if (!this->inhibitor) return;
32+
if (!this->bInhibitor) return;
2233

2334
auto* manager = impl::ShortcutsInhibitManager::instance();
2435
if (!manager) return;
2536

26-
manager->unrefShortcutsInhibitor(this->inhibitor);
37+
manager->unrefShortcutsInhibitor(this->bInhibitor);
2738
}
2839

2940
QObject* ShortcutsInhibitor::window() const { return this->bWindowObject; }
@@ -87,7 +98,10 @@ void ShortcutsInhibitor::onWindowVisibilityChanged() {
8798
if (!window->handle()) window->create();
8899

89100
auto* waylandWindow = dynamic_cast<QWaylandWindow*>(window->handle());
90-
if (!waylandWindow) return;
101+
if (!waylandWindow) {
102+
qCCritical(impl::logShortcutsInhibit()) << "Window handle is not a QWaylandWindow";
103+
return;
104+
}
91105
if (waylandWindow == this->mWaylandWindow) return;
92106
this->mWaylandWindow = waylandWindow;
93107

@@ -127,27 +141,23 @@ void ShortcutsInhibitor::onWaylandSurfaceCreated() {
127141
return;
128142
}
129143

130-
if (this->inhibitor) {
144+
if (this->bInhibitor) {
131145
qFatal("ShortcutsInhibitor: inhibitor already exists when creating surface");
132146
}
133147

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-
}
148+
this->bInhibitor = manager->createShortcutsInhibitor(this->mWaylandWindow);
141149
}
142150

143151
void ShortcutsInhibitor::onWaylandSurfaceDestroyed() {
144-
if (!this->inhibitor) return;
152+
if (!this->bInhibitor) return;
145153

146154
auto* manager = impl::ShortcutsInhibitManager::instance();
147155
if (!manager) return;
148156

149-
manager->unrefShortcutsInhibitor(this->inhibitor);
150-
this->inhibitor = nullptr;
157+
manager->unrefShortcutsInhibitor(this->bInhibitor);
158+
this->bInhibitor = nullptr;
151159
}
152160

161+
void ShortcutsInhibitor::inhibitorChanged() {}
162+
153163
} // 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: 8 additions & 3 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();
@@ -37,21 +39,24 @@ class ShortcutsInhibitor
3739
public:
3840
explicit ShortcutsInhibitor(::zwp_keyboard_shortcuts_inhibitor_v1* inhibitor, wl_surface* surface)
3941
: QtWayland::zwp_keyboard_shortcuts_inhibitor_v1(inhibitor)
40-
, mSurface(surface) {}
42+
, mSurface(surface)
43+
, bActive(false) {}
4144

4245
~ShortcutsInhibitor() override;
4346
Q_DISABLE_COPY_MOVE(ShortcutsInhibitor);
4447

45-
[[nodiscard]] QBindable<bool> bindableActive() { return &this->bActive; }
48+
[[nodiscard]] QBindable<bool> bindableActive() const { return &this->bActive; }
4649
[[nodiscard]] bool isActive() const { return this->bActive; }
4750
[[nodiscard]] wl_surface* surface() const { return this->mSurface; }
4851

4952
signals:
5053
void activeChanged();
5154

5255
protected:
56+
// NOLINTBEGIN(readability-identifier-naming)
5357
void zwp_keyboard_shortcuts_inhibitor_v1_active() override;
5458
void zwp_keyboard_shortcuts_inhibitor_v1_inactive() override;
59+
// NOLINTEND(readability-identifier-naming)
5560

5661
private:
5762
wl_surface* mSurface;

0 commit comments

Comments
 (0)