[wayland] Add a plugin for kglobalaccel

The KGlobalAccelD which gets created by KWin needs a plugin for the
platform specific parts. This change introduces such a plugin. It's
linked against kwin so that it can integrate with the core.

On enable the plugin registers itself in the InputRedirection and
GlobalShortcutsManager checks the plugin whether a shortcut got
triggered.

As the loading of the plugin must happen after InputRedirection is
fully created a dedicated init method is added to InputRedirection.

REVIEW: 124187
This commit is contained in:
Martin Gräßlin 2015-06-26 13:47:08 +02:00
parent 8461344ce1
commit 3041a7c32d
11 changed files with 177 additions and 14 deletions

View file

@ -4,7 +4,7 @@ set(PROJECT_VERSION_MAJOR 5)
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
set(QT_MIN_VERSION "5.4.0")
set(KF5_MIN_VERSION "5.8.0")
set(KF5_MIN_VERSION "5.12.0")
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH} )
@ -603,6 +603,7 @@ if(HAVE_WAYLAND)
install(TARGETS kwin_wayland ${INSTALL_TARGETS_DEFAULT_ARGS} )
add_subdirectory(backends)
add_subdirectory(plugins)
endif()
########### install files ###############

View file

@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kkeyserver.h>
#include <KConfigGroup>
#include <KGlobalAccel/private/kglobalacceld.h>
#include <KGlobalAccel/private/kglobalaccel_interface.h>
// Qt
#include <QAction>
@ -94,16 +95,6 @@ GlobalShortcutsManager::GlobalShortcutsManager(QObject *parent)
: QObject(parent)
, m_config(KSharedConfig::openConfig(QStringLiteral("kglobalshortcutsrc"), KConfig::SimpleConfig))
{
if (kwinApp()->shouldUseWaylandForCompositing()) {
m_kglobalAccel = new KGlobalAccelD(this);
if (!m_kglobalAccel->init()) {
qCDebug(KWIN_CORE) << "Init of kglobalaccel failed";
delete m_kglobalAccel;
m_kglobalAccel = nullptr;
} else {
qCDebug(KWIN_CORE) << "KGlobalAcceld inited";
}
}
}
template <typename T>
@ -121,6 +112,20 @@ GlobalShortcutsManager::~GlobalShortcutsManager()
clearShortcuts(m_axisShortcuts);
}
void GlobalShortcutsManager::init()
{
if (kwinApp()->shouldUseWaylandForCompositing()) {
m_kglobalAccel = new KGlobalAccelD(this);
if (!m_kglobalAccel->init()) {
qCDebug(KWIN_CORE) << "Init of kglobalaccel failed";
delete m_kglobalAccel;
m_kglobalAccel = nullptr;
} else {
qCDebug(KWIN_CORE) << "KGlobalAcceld inited";
}
}
}
template <typename T>
void handleDestroyedAction(QObject *object, T &shortcuts)
{
@ -240,7 +245,24 @@ bool processShortcut(Qt::KeyboardModifiers mods, T key, U &shortcuts)
bool GlobalShortcutsManager::processKey(Qt::KeyboardModifiers mods, uint32_t key)
{
return processShortcut(mods, key, m_shortcuts);
if (m_kglobalAccelInterface) {
bool retVal = false;
int keyQt = 0;
if (KKeyServer::symXToKeyQt(key, &keyQt)) {
QMetaObject::invokeMethod(m_kglobalAccelInterface,
"checkKeyPressed",
Qt::DirectConnection,
Q_RETURN_ARG(bool, retVal),
Q_ARG(int, int(mods) | keyQt));
if (retVal) {
return true;
}
}
}
if (processShortcut(mods, key, m_shortcuts)) {
return true;
}
return false;
}
bool GlobalShortcutsManager::processPointerPressed(Qt::KeyboardModifiers mods, Qt::MouseButtons pointerButtons)

View file

@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
class QAction;
class KGlobalAccelD;
class KGlobalAccelInterface;
namespace KWin
{
@ -49,6 +50,8 @@ class GlobalShortcutsManager : public QObject
public:
explicit GlobalShortcutsManager(QObject *parent = nullptr);
virtual ~GlobalShortcutsManager();
void init();
/**
* @brief Registers an internal global shortcut
*
@ -98,6 +101,11 @@ public:
* @return @c true if a shortcut triggered, @c false otherwise
*/
bool processAxis(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis);
void setKGlobalAccelInterface(KGlobalAccelInterface *interface) {
m_kglobalAccelInterface = interface;
}
private:
void objectDeleted(QObject *object);
QKeySequence getShortcutForAction(const QString &componentName, const QString &actionName, const QKeySequence &defaultShortcut);
@ -106,6 +114,7 @@ private:
QHash<Qt::KeyboardModifiers, QHash<PointerAxisDirection, GlobalShortcut*> > m_axisShortcuts;
KSharedConfigPtr m_config;
KGlobalAccelD *m_kglobalAccel = nullptr;
KGlobalAccelInterface *m_kglobalAccelInterface = nullptr;
};
class GlobalShortcut

View file

@ -264,6 +264,11 @@ InputRedirection::~InputRedirection()
s_self = NULL;
}
void InputRedirection::init()
{
m_shortcuts->init();
}
void InputRedirection::setupWorkspace()
{
#if HAVE_WAYLAND
@ -1119,6 +1124,11 @@ void InputRedirection::registerAxisShortcut(Qt::KeyboardModifiers modifiers, Poi
m_shortcuts->registerAxisShortcut(action, modifiers, axis);
}
void InputRedirection::registerGlobalAccel(KGlobalAccelInterface *interface)
{
m_shortcuts->setKGlobalAccelInterface(interface);
}
void InputRedirection::registerShortcutForGlobalAccelTimestamp(QAction *action)
{
connect(action, &QAction::triggered, kwinApp(), [action] {

View file

@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QWeakPointer>
#include <config-kwin.h>
class KGlobalAccelInterface;
class QKeySequence;
struct xkb_context;
@ -62,7 +63,7 @@ namespace LibInput
* a full input grab.
*
*/
class InputRedirection : public QObject
class KWIN_EXPORT InputRedirection : public QObject
{
Q_OBJECT
public:
@ -79,6 +80,7 @@ public:
KeyboardKeyPressed
};
virtual ~InputRedirection();
void init();
/**
* @return const QPointF& The current global pointer position
@ -108,6 +110,7 @@ public:
void registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, void (T::*slot)());
void registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action);
void registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action);
void registerGlobalAccel(KGlobalAccelInterface *interface);
/**
* @internal

View file

@ -384,7 +384,8 @@ void Application::createWorkspace()
void Application::createInput()
{
LogindIntegration::create(this);
InputRedirection::create(this);
auto input = InputRedirection::create(this);
input->init();
Cursor::create(this);
}

1
plugins/CMakeLists.txt Normal file
View file

@ -0,0 +1 @@
add_subdirectory(kglobalaccel)

View file

@ -0,0 +1,16 @@
set(kglobalaccel_plugin_SRCS
kglobalaccel_plugin.cpp
)
add_library(KF5GlobalAccelPrivateKWin MODULE ${kglobalaccel_plugin_SRCS})
target_link_libraries(KF5GlobalAccelPrivateKWin
KF5::GlobalAccelPrivate
kwin
)
install(
TARGETS
KF5GlobalAccelPrivateKWin
DESTINATION
${PLUGIN_INSTALL_DIR}/org.kde.kglobalaccel5.platforms/
)

View file

@ -0,0 +1,51 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "kglobalaccel_plugin.h"
#include "../../input.h"
#include <QDebug>
KGlobalAccelImpl::KGlobalAccelImpl(QObject *parent)
: KGlobalAccelInterface(parent)
{
}
KGlobalAccelImpl::~KGlobalAccelImpl() = default;
bool KGlobalAccelImpl::grabKey(int key, bool grab)
{
Q_UNUSED(key)
Q_UNUSED(grab)
return true;
}
void KGlobalAccelImpl::setEnabled(bool enabled)
{
static KWin::InputRedirection *s_input = KWin::InputRedirection::self();
if (!s_input) {
qFatal("This plugin is intended to be used with KWin and this is not KWin, exiting now");
}
s_input->registerGlobalAccel(enabled ? this : nullptr);
}
bool KGlobalAccelImpl::checkKeyPressed(int keyQt)
{
return keyPressed(keyQt);
}

View file

@ -0,0 +1,46 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KGLOBALACCEL_PLUGIN_H
#define KGLOBALACCEL_PLUGIN_H
#include <KGlobalAccel/private/kglobalaccel_interface.h>
#include <QObject>
class KGlobalAccelImpl : public KGlobalAccelInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kde.kglobalaccel5.KGlobalAccelInterface" FILE "kwin.json")
Q_INTERFACES(KGlobalAccelInterface)
public:
KGlobalAccelImpl(QObject *parent = 0);
virtual ~KGlobalAccelImpl();
bool grabKey(int key, bool grab) override;
void setEnabled(bool) override;
public Q_SLOTS:
bool checkKeyPressed(int keyQt);
private:
};
#endif

View file

@ -0,0 +1,3 @@
{
"platforms": ["wayland", "wayland-egl"]
}