6#include "waylandinhibition_p.h"
9#include <QGuiApplication>
10#include <QSharedPointer>
11#include <QWaylandClientExtensionTemplate>
12#include <QtWaylandClientVersion>
13#include <qpa/qplatformnativeinterface.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)) {
69 QPlatformNativeInterface *nativeInterface = qGuiApp->platformNativeInterface();
70 if (!nativeInterface) {
73 auto seat =
static_cast<wl_seat *
>(nativeInterface->nativeResourceForIntegration(
"wl_seat"));
74 auto surface =
static_cast<wl_surface *
>(nativeInterface->nativeResourceForWindow(
"surface", window));
75 if (!seat || !surface) {
78 m_inhibitions[
window].reset(
new ShortcutsInhibitor(inhibit_shortcuts(surface, seat)));
81 bool isInhibited(
QWindow *window)
const
83 return m_inhibitions.
contains(window);
86 void stopInhibition(
QWindow *window)
88 m_inhibitions.
remove(window);
94static std::shared_ptr<ShortcutsInhibitManager> theManager()
96 static std::weak_ptr<ShortcutsInhibitManager> managerInstance;
97 std::shared_ptr<ShortcutsInhibitManager> ret = managerInstance.lock();
99 ret = std::make_shared<ShortcutsInhibitManager>();
100 managerInstance = ret;
105WaylandInhibition::WaylandInhibition(
QWindow *window)
106 : ShortcutInhibition()
108 , m_manager(theManager())
112WaylandInhibition::~WaylandInhibition() =
default;
114bool WaylandInhibition::shortcutsAreInhibited()
const
116 return m_manager->isInhibited(m_window);
119void WaylandInhibition::enableInhibition()
121 m_manager->startInhibition(m_window);
124void WaylandInhibition::disableInhibition()
126 m_manager->stopInhibition(m_window);
void initialize(StandardShortcut id)
bool contains(const Key &key) const const
bool remove(const Key &key)