KWin
Loading...
Searching...
No Matches
modifier_only_shortcuts.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016, 2017 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
10
11#include <config-kwin.h>
12
13#include "input_event.h"
14#include "options.h"
15#if KWIN_BUILD_SCREENLOCKER
16#include "screenlockerwatcher.h"
17#endif
18#include "wayland_server.h"
19#include "workspace.h"
20
21#include <QDBusConnection>
22#include <QDBusMessage>
23#include <QDBusPendingCall>
24
25namespace KWin
26{
27
29 : QObject()
31{
32#if KWIN_BUILD_SCREENLOCKER
33 connect(kwinApp()->screenLockerWatcher(), &ScreenLockerWatcher::locked, this, &ModifierOnlyShortcuts::reset);
34#endif
35}
36
38
40{
41 if (event->isAutoRepeat()) {
42 return;
43 }
44 if (event->type() == QEvent::KeyPress) {
45 const bool wasEmpty = m_pressedKeys.isEmpty();
46 m_pressedKeys.insert(event->nativeScanCode());
47 if (wasEmpty && m_pressedKeys.size() == 1 &&
48#if KWIN_BUILD_SCREENLOCKER
49 !kwinApp()->screenLockerWatcher()->isLocked() &&
50#endif
51 m_pressedButtons == Qt::NoButton && m_cachedMods == Qt::NoModifier) {
52 m_modifier = Qt::KeyboardModifier(int(event->modifiersRelevantForGlobalShortcuts()));
53 } else {
54 m_modifier = Qt::NoModifier;
55 }
56 } else if (!m_pressedKeys.isEmpty()) {
57 m_pressedKeys.remove(event->nativeScanCode());
58 if (m_pressedKeys.isEmpty() && event->modifiersRelevantForGlobalShortcuts() == Qt::NoModifier && workspace() && !workspace()->globalShortcutsDisabled()) {
59 if (m_modifier != Qt::NoModifier) {
60 const auto list = options->modifierOnlyDBusShortcut(m_modifier);
61 if (list.size() >= 4) {
62 if (!waylandServer() || !waylandServer()->isKeyboardShortcutsInhibited()) {
63 auto call = QDBusMessage::createMethodCall(list.at(0), list.at(1), list.at(2), list.at(3));
64 QVariantList args;
65 for (int i = 4; i < list.size(); ++i) {
66 args << list.at(i);
67 }
68 call.setArguments(args);
69 QDBusConnection::sessionBus().asyncCall(call);
70 }
71 }
72 }
73 }
74 m_modifier = Qt::NoModifier;
75 } else {
76 m_modifier = Qt::NoModifier;
77 }
78 m_cachedMods = event->modifiersRelevantForGlobalShortcuts();
79}
80
82{
83 if (event->type() == QEvent::MouseMove) {
84 return;
85 }
86 m_pressedButtons = event->buttons();
87 reset();
88}
89
94
95}
96
97#include "moc_modifier_only_shortcuts.cpp"
Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const
void keyEvent(KeyEvent *event) override
void pointerEvent(MouseEvent *event) override
void wheelEvent(WheelEvent *event) override
QStringList modifierOnlyDBusShortcut(Qt::KeyboardModifier mod) const
Definition options.cpp:1020
void locked(bool locked)
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830
Options * options
Definition main.cpp:73