6#include "waylandinhibition_p.h"
8#include "kguiaddons_debug.h"
11#include <QGuiApplication>
12#include <QSharedPointer>
13#include <QWaylandClientExtensionTemplate>
15#include <qpa/qplatformwindow_p.h>
17#include "qwayland-keyboard-shortcuts-inhibit-unstable-v1.h"
19class ShortcutsInhibitor :
public QtWayland::zwp_keyboard_shortcuts_inhibitor_v1
22 ShortcutsInhibitor(::zwp_keyboard_shortcuts_inhibitor_v1 *
id)
23 : QtWayland::zwp_keyboard_shortcuts_inhibitor_v1(id)
27 ~ShortcutsInhibitor()
override
32 void zwp_keyboard_shortcuts_inhibitor_v1_active()
override
37 void zwp_keyboard_shortcuts_inhibitor_v1_inactive()
override
48 bool m_active =
false;
51class ShortcutsInhibitManager :
public QWaylandClientExtensionTemplate<ShortcutsInhibitManager>,
public QtWayland::zwp_keyboard_shortcuts_inhibit_manager_v1
54 ShortcutsInhibitManager()
55 : QWaylandClientExtensionTemplate<ShortcutsInhibitManager>(1)
59 ~ShortcutsInhibitManager()
override
61 if (isInitialized()) {
66 void startInhibition(
QWindow *window)
68 if (m_inhibitions.
contains(window)) {
72 auto waylandWindow =
window->nativeInterface<QNativeInterface::Private::QWaylandWindow>();
73 if (!waylandApp || !waylandWindow) {
77 auto seat = waylandApp->lastInputSeat();
78 auto surface = waylandWindow->surface();
80 if (!seat || !surface) {
83 m_inhibitions[
window].reset(
new ShortcutsInhibitor(inhibit_shortcuts(surface, seat)));
86 bool isInhibited(
QWindow *window)
const
88 return m_inhibitions.
contains(window);
91 void stopInhibition(
QWindow *window)
93 m_inhibitions.
remove(window);
99static std::shared_ptr<ShortcutsInhibitManager> theManager()
101 static std::weak_ptr<ShortcutsInhibitManager> managerInstance;
102 std::shared_ptr<ShortcutsInhibitManager> ret = managerInstance.lock();
104 ret = std::make_shared<ShortcutsInhibitManager>();
105 managerInstance = ret;
110WaylandInhibition::WaylandInhibition(
QWindow *window)
111 : ShortcutInhibition()
113 , m_manager(theManager())
117WaylandInhibition::~WaylandInhibition() =
default;
119bool WaylandInhibition::shortcutsAreInhibited()
const
121 return m_manager->isInhibited(m_window);
124void WaylandInhibition::enableInhibition()
126 if (!m_manager->isActive()) {
127 qCInfo(KGUIADDONS_LOG) <<
"The compositor does not support the keyboard-shortcuts-inhibit-unstable-v1 protocol. Inhibiting shortcuts will not work.";
130 m_manager->startInhibition(m_window);
133void WaylandInhibition::disableInhibition()
135 if (!m_manager->isActive()) {
138 m_manager->stopInhibition(m_window);
KCRASH_EXPORT void initialize()
bool contains(const Key &key) const const
bool remove(const Key &key)