Add support to keyboard shortcuts inhibitor

Summary:
- Disable all global shortcuts
- For now don't disable spies (So opening menu with meta key is not disabled for now)

Depends on D29231

Test Plan: Tested with https://github.com/swaywm/wlroots/blob/master/examples/keyboard-shortcuts-inhibit.c

Reviewers: davidedmundson, zzag

Reviewed By: davidedmundson

Subscribers: romangg, broulik, apol, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D29272
This commit is contained in:
Benjamin Port 2020-04-29 10:45:02 +02:00 committed by Benjamin Port
parent 98701b6f38
commit 4a90f6ab60
4 changed files with 34 additions and 8 deletions

View file

@ -788,7 +788,9 @@ public:
return ret;
}
} else if (event->type() == QEvent::KeyPress) {
return input()->shortcuts()->processKey(static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts(), event->key());
if (!waylandServer()->isKeyboardShortcutsInhibited()) {
return input()->shortcuts()->processKey(static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts(), event->key());
}
}
return false;
}

View file

@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "input_event.h"
#include "options.h"
#include "screenlockerwatcher.h"
#include "wayland_server.h"
#include "workspace.h"
#include <QDBusConnection>
@ -63,13 +64,15 @@ void ModifierOnlyShortcuts::keyEvent(KeyEvent *event)
if (m_modifier != Qt::NoModifier) {
const auto list = options->modifierOnlyDBusShortcut(m_modifier);
if (list.size() >= 4) {
auto call = QDBusMessage::createMethodCall(list.at(0), list.at(1), list.at(2), list.at(3));
QVariantList args;
for (int i = 4; i < list.size(); ++i) {
args << list.at(i);
if (!waylandServer() || !waylandServer()->isKeyboardShortcutsInhibited()) {
auto call = QDBusMessage::createMethodCall(list.at(0), list.at(1), list.at(2), list.at(3));
QVariantList args;
for (int i = 4; i < list.size(); ++i) {
args << list.at(i);
}
call.setArguments(args);
QDBusConnection::sessionBus().asyncCall(call);
}
call.setArguments(args);
QDBusConnection::sessionBus().asyncCall(call);
}
}
}

View file

@ -65,6 +65,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KWaylandServer/xdgoutput_interface.h>
#include <KWaylandServer/keystate_interface.h>
#include <KWaylandServer/filtered_display.h>
#include <KWaylandServer/keyboard_shortcuts_inhibit_interface.h>
// KF
#include <KServiceTypeTrader>
@ -322,7 +323,7 @@ bool WaylandServer::init(const QByteArray &socketName, InitializationFlags flags
);
m_tabletManager = m_display->createTabletManagerInterface(m_display);
m_keyboardShortcutsInhibitManager = m_display->createKeyboardShortcutsInhibitManager(m_display);
m_xdgShell = m_display->createXdgShell(XdgShellInterfaceVersion::Stable, m_display);
m_xdgShell->create();
connect(m_xdgShell, &XdgShellInterface::surfaceCreated, this, &WaylandServer::createSurface<XdgShellSurfaceInterface>);
@ -840,4 +841,14 @@ void WaylandServer::updateKeyState(KWin::Xkb::LEDs leds)
m_keyState->setState(KeyStateInterface::Key::ScrollLock, leds & KWin::Xkb::LED::ScrollLock ? KeyStateInterface::State::Locked : KeyStateInterface::State::Unlocked);
}
bool WaylandServer::isKeyboardShortcutsInhibited() const
{
auto surface = seat()->focusedKeyboardSurface();
if (surface) {
auto inhibitor = keyboardShortcutsInhibitManager()->findInhibitor(surface, seat());
return inhibitor && inhibitor->isActive();
}
return false;
}
}

View file

@ -70,6 +70,7 @@ class KeyStateInterface;
class LinuxDmabufUnstableV1Interface;
class LinuxDmabufUnstableV1Buffer;
class TabletManagerInterface;
class KeyboardShortcutsInhibitManagerInterface;
}
@ -83,6 +84,7 @@ class Toplevel;
class KWIN_EXPORT WaylandServer : public QObject
{
Q_OBJECT
public:
enum class InitializationFlag {
NoOptions = 0x0,
@ -131,6 +133,13 @@ public:
KWaylandServer::XdgOutputManagerInterface *xdgOutputManager() const {
return m_xdgOutputManager;
}
KWaylandServer::KeyboardShortcutsInhibitManagerInterface *keyboardShortcutsInhibitManager() const
{
return m_keyboardShortcutsInhibitManager;
}
bool isKeyboardShortcutsInhibited() const;
KWaylandServer::LinuxDmabufUnstableV1Interface *linuxDmabuf();
QList<AbstractClient *> clients() const {
@ -272,6 +281,7 @@ private:
KWaylandServer::XdgOutputManagerInterface *m_xdgOutputManager = nullptr;
KWaylandServer::XdgDecorationManagerInterface *m_xdgDecorationManager = nullptr;
KWaylandServer::LinuxDmabufUnstableV1Interface *m_linuxDmabuf = nullptr;
KWaylandServer::KeyboardShortcutsInhibitManagerInterface *m_keyboardShortcutsInhibitManager = nullptr;
QSet<KWaylandServer::LinuxDmabufUnstableV1Buffer*> m_linuxDmabufBuffers;
struct {
KWaylandServer::ClientConnection *client = nullptr;