Skip to content

Commit 23bb7e4

Browse files
committed
wayland/shortcuts-inhibit: cleanups, move setup to constructor
1 parent 0a7c19c commit 23bb7e4

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed

src/wayland/shortcuts_inhibit/inhibitor.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ ShortcutsInhibitor::ShortcutsInhibitor() {
1515
this->bBoundWindow.setBinding([this] {
1616
return this->bEnabled ? this->bWindowObject.value() : nullptr;
1717
});
18+
19+
this->bActive.setBinding([this]() {
20+
return this->inhibitor ? this->inhibitor->bindableActive().value() : false;
21+
});
1822
}
1923

2024
ShortcutsInhibitor::~ShortcutsInhibitor() {
@@ -87,7 +91,10 @@ void ShortcutsInhibitor::onWindowVisibilityChanged() {
8791
if (!window->handle()) window->create();
8892

8993
auto* waylandWindow = dynamic_cast<QWaylandWindow*>(window->handle());
90-
if (!waylandWindow) return;
94+
if (!waylandWindow) {
95+
qCCritical(impl::logShortcutsInhibit()) << "Window handle is not a QWaylandWindow";
96+
return;
97+
}
9198
if (waylandWindow == this->mWaylandWindow) return;
9299
this->mWaylandWindow = waylandWindow;
93100

@@ -132,12 +139,6 @@ void ShortcutsInhibitor::onWaylandSurfaceCreated() {
132139
}
133140

134141
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-
}
141142
}
142143

143144
void ShortcutsInhibitor::onWaylandSurfaceDestroyed() {

src/wayland/shortcuts_inhibit/inhibitor.hpp

Lines changed: 1 addition & 1 deletion
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();

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)