6#include "waylandinhibition_p.h"
9#include <QGuiApplication>
10#include <QSharedPointer>
11#include <QWaylandClientExtensionTemplate>
13#include <qpa/qplatformwindow_p.h>
15#include "qwayland-keyboard-shortcuts-inhibit-unstable-v1.h"
17class ShortcutsInhibitor :
public QtWayland::zwp_keyboard_shortcuts_inhibitor_v1
20 ShortcutsInhibitor(::zwp_keyboard_shortcuts_inhibitor_v1 *
id)
21 : QtWayland::zwp_keyboard_shortcuts_inhibitor_v1(id)
25 ~ShortcutsInhibitor()
override
30 void zwp_keyboard_shortcuts_inhibitor_v1_active()
override
35 void zwp_keyboard_shortcuts_inhibitor_v1_inactive()
override
46 bool m_active =
false;
49class ShortcutsInhibitManager :
public QWaylandClientExtensionTemplate<ShortcutsInhibitManager>,
public QtWayland::zwp_keyboard_shortcuts_inhibit_manager_v1
52 ShortcutsInhibitManager()
53 : QWaylandClientExtensionTemplate<ShortcutsInhibitManager>(1)
57 ~ShortcutsInhibitManager()
override
59 if (isInitialized()) {
64 void startInhibition(
QWindow *window)
66 if (m_inhibitions.
contains(window)) {
70 auto waylandWindow =
window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
71 if (!waylandApp || !waylandWindow) {
75 auto seat = waylandApp->lastInputSeat();
76 auto surface = waylandWindow->surface();
78 if (!seat || !surface) {
81 m_inhibitions[
window].reset(
new ShortcutsInhibitor(inhibit_shortcuts(surface, seat)));
84 bool isInhibited(
QWindow *window)
const
86 return m_inhibitions.
contains(window);
89 void stopInhibition(
QWindow *window)
91 m_inhibitions.
remove(window);
97static std::shared_ptr<ShortcutsInhibitManager> theManager()
99 static std::weak_ptr<ShortcutsInhibitManager> managerInstance;
100 std::shared_ptr<ShortcutsInhibitManager> ret = managerInstance.lock();
102 ret = std::make_shared<ShortcutsInhibitManager>();
103 managerInstance = ret;
108WaylandInhibition::WaylandInhibition(
QWindow *window)
109 : ShortcutInhibition()
111 , m_manager(theManager())
115WaylandInhibition::~WaylandInhibition() =
default;
117bool WaylandInhibition::shortcutsAreInhibited()
const
119 return m_manager->isInhibited(m_window);
122void WaylandInhibition::enableInhibition()
124 m_manager->startInhibition(m_window);
127void WaylandInhibition::disableInhibition()
129 m_manager->stopInhibition(m_window);
void initialize(StandardShortcut id)
bool contains(const Key &key) const const
bool remove(const Key &key)