2013-06-26 12:15:20 +04:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2013 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 "input.h"
|
2013-07-01 10:37:59 +04:00
|
|
|
#include "client.h"
|
2013-06-26 13:40:30 +04:00
|
|
|
#include "effects.h"
|
2013-07-10 13:41:16 +04:00
|
|
|
#include "globalshortcuts.h"
|
2014-08-15 11:30:08 +04:00
|
|
|
#include "logind.h"
|
|
|
|
#include "main.h"
|
2013-07-10 15:20:43 +04:00
|
|
|
#ifdef KWIN_BUILD_TABBOX
|
|
|
|
#include "tabbox/tabbox.h"
|
|
|
|
#endif
|
2013-07-01 10:37:59 +04:00
|
|
|
#include "unmanaged.h"
|
2014-10-20 17:01:12 +04:00
|
|
|
#include "screens.h"
|
2013-07-01 10:37:59 +04:00
|
|
|
#include "workspace.h"
|
2014-08-14 16:43:57 +04:00
|
|
|
#if HAVE_INPUT
|
|
|
|
#include "libinput/connection.h"
|
2015-11-27 10:44:59 +03:00
|
|
|
#include "virtual_terminal.h"
|
2014-08-14 16:43:57 +04:00
|
|
|
#endif
|
2015-03-20 16:41:03 +03:00
|
|
|
#include "abstract_backend.h"
|
2015-06-06 04:26:24 +03:00
|
|
|
#include "shell_client.h"
|
2015-02-26 17:32:44 +03:00
|
|
|
#include "wayland_server.h"
|
2015-07-06 05:44:07 +03:00
|
|
|
#include <KWayland/Server/display.h>
|
|
|
|
#include <KWayland/Server/fakeinput_interface.h>
|
2015-02-26 17:32:44 +03:00
|
|
|
#include <KWayland/Server/seat_interface.h>
|
2015-06-03 19:09:54 +03:00
|
|
|
#include <decorations/decoratedclient.h>
|
|
|
|
#include <KDecoration2/Decoration>
|
2014-12-02 15:50:26 +03:00
|
|
|
// Qt
|
Add support for modifier only shortcuts on Wayland
On popular demand!
This change tracks how modifiers are used and detects a modifier only
key press/release. That is:
* no other key is pressed when the modifier gets pressed
* no other key gets pressed before the modifier gets released
If such a press/release is detected, we call a configurable dbus call.
The possible shortcuts can be configured in kwinrc, group
"ModifierOnlyShortcuts". The following keys are supported:
* Shift
* Control
* Alt
* Meta
As value it takes a QStringList (comma seperated string) with
service,path,interface,method,additionalargs
E.g. to invoke Desktop Grid effect on Meta key:
[ModifierOnlyShortcuts]
Meta=org.kde.kglobalaccel,/component/kwin/,org.kde.kglobalaccel.Component,invokeShortcut,ShowDesktopGrid
I do not intend to add a config interface for it. Let's keep it a hidden
way.
REVIEW: 124954
2015-08-27 18:56:28 +03:00
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusPendingCall>
|
2014-12-02 15:50:26 +03:00
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QMouseEvent>
|
2015-05-28 11:17:41 +03:00
|
|
|
#include <QTemporaryFile>
|
2013-07-02 13:44:18 +04:00
|
|
|
// KDE
|
|
|
|
#include <kkeyserver.h>
|
2014-03-28 12:41:48 +04:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2015-03-31 10:33:05 +03:00
|
|
|
#include <xkbcommon/xkbcommon-keysyms.h>
|
2013-06-26 12:15:20 +04:00
|
|
|
// system
|
|
|
|
#include <linux/input.h>
|
2013-07-02 13:44:18 +04:00
|
|
|
#include <sys/mman.h>
|
2015-05-28 11:17:41 +03:00
|
|
|
#include <unistd.h>
|
2013-06-26 12:15:20 +04:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2015-05-28 11:17:41 +03:00
|
|
|
Xkb::Xkb(InputRedirection *input)
|
|
|
|
: m_input(input)
|
|
|
|
, m_context(xkb_context_new(static_cast<xkb_context_flags>(0)))
|
2013-07-02 13:44:18 +04:00
|
|
|
, m_keymap(NULL)
|
|
|
|
, m_state(NULL)
|
|
|
|
, m_shiftModifier(0)
|
|
|
|
, m_controlModifier(0)
|
|
|
|
, m_altModifier(0)
|
|
|
|
, m_metaModifier(0)
|
|
|
|
, m_modifiers(Qt::NoModifier)
|
|
|
|
{
|
|
|
|
if (!m_context) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Could not create xkb context";
|
2015-03-27 16:12:41 +03:00
|
|
|
} else {
|
|
|
|
// load default keymap
|
|
|
|
xkb_keymap *keymap = xkb_keymap_new_from_names(m_context, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
|
|
|
if (keymap) {
|
|
|
|
updateKeymap(keymap);
|
|
|
|
} else {
|
|
|
|
qCDebug(KWIN_CORE) << "Could not create default xkb keymap";
|
|
|
|
}
|
2013-07-02 13:44:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Xkb::~Xkb()
|
|
|
|
{
|
|
|
|
xkb_state_unref(m_state);
|
|
|
|
xkb_keymap_unref(m_keymap);
|
|
|
|
xkb_context_unref(m_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Xkb::installKeymap(int fd, uint32_t size)
|
|
|
|
{
|
|
|
|
if (!m_context) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char *map = reinterpret_cast<char*>(mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0));
|
|
|
|
if (map == MAP_FAILED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xkb_keymap *keymap = xkb_keymap_new_from_string(m_context, map, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_MAP_COMPILE_PLACEHOLDER);
|
|
|
|
munmap(map, size);
|
|
|
|
if (!keymap) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Could not map keymap from file";
|
2013-07-02 13:44:18 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-03-27 16:12:41 +03:00
|
|
|
updateKeymap(keymap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Xkb::updateKeymap(xkb_keymap *keymap)
|
|
|
|
{
|
|
|
|
Q_ASSERT(keymap);
|
2013-07-02 13:44:18 +04:00
|
|
|
xkb_state *state = xkb_state_new(keymap);
|
|
|
|
if (!state) {
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "Could not create XKB state";
|
2013-07-02 13:44:18 +04:00
|
|
|
xkb_keymap_unref(keymap);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// now release the old ones
|
|
|
|
xkb_state_unref(m_state);
|
|
|
|
xkb_keymap_unref(m_keymap);
|
|
|
|
|
|
|
|
m_keymap = keymap;
|
|
|
|
m_state = state;
|
|
|
|
|
|
|
|
m_shiftModifier = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_SHIFT);
|
|
|
|
m_controlModifier = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_CTRL);
|
|
|
|
m_altModifier = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_ALT);
|
|
|
|
m_metaModifier = xkb_keymap_mod_get_index(m_keymap, XKB_MOD_NAME_LOGO);
|
2015-05-28 11:17:41 +03:00
|
|
|
|
|
|
|
createKeymapFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Xkb::createKeymapFile()
|
|
|
|
{
|
|
|
|
if (!waylandServer()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// TODO: uninstall keymap on server?
|
|
|
|
if (!m_keymap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedCPointer<char> keymapString(xkb_keymap_get_as_string(m_keymap, XKB_KEYMAP_FORMAT_TEXT_V1));
|
|
|
|
if (keymapString.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const uint size = qstrlen(keymapString.data()) + 1;
|
|
|
|
|
|
|
|
QTemporaryFile *tmp = new QTemporaryFile(m_input);
|
|
|
|
if (!tmp->open()) {
|
|
|
|
delete tmp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unlink(tmp->fileName().toUtf8().constData());
|
|
|
|
if (!tmp->resize(size)) {
|
|
|
|
delete tmp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uchar *address = tmp->map(0, size);
|
|
|
|
if (!address) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (qstrncpy(reinterpret_cast<char*>(address), keymapString.data(), size) == nullptr) {
|
|
|
|
delete tmp;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
waylandServer()->seat()->setKeymap(tmp->handle(), size);
|
2013-07-02 13:44:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Xkb::updateModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group)
|
|
|
|
{
|
|
|
|
if (!m_keymap || !m_state) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xkb_state_update_mask(m_state, modsDepressed, modsLatched, modsLocked, 0, 0, group);
|
2015-03-27 16:15:25 +03:00
|
|
|
updateModifiers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Xkb::updateKey(uint32_t key, InputRedirection::KeyboardKeyState state)
|
|
|
|
{
|
|
|
|
if (!m_keymap || !m_state) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xkb_state_update_key(m_state, key + 8, static_cast<xkb_key_direction>(state));
|
|
|
|
updateModifiers();
|
Add support for modifier only shortcuts on Wayland
On popular demand!
This change tracks how modifiers are used and detects a modifier only
key press/release. That is:
* no other key is pressed when the modifier gets pressed
* no other key gets pressed before the modifier gets released
If such a press/release is detected, we call a configurable dbus call.
The possible shortcuts can be configured in kwinrc, group
"ModifierOnlyShortcuts". The following keys are supported:
* Shift
* Control
* Alt
* Meta
As value it takes a QStringList (comma seperated string) with
service,path,interface,method,additionalargs
E.g. to invoke Desktop Grid effect on Meta key:
[ModifierOnlyShortcuts]
Meta=org.kde.kglobalaccel,/component/kwin/,org.kde.kglobalaccel.Component,invokeShortcut,ShowDesktopGrid
I do not intend to add a config interface for it. Let's keep it a hidden
way.
REVIEW: 124954
2015-08-27 18:56:28 +03:00
|
|
|
if (state == InputRedirection::KeyboardKeyPressed) {
|
|
|
|
m_modOnlyShortcut.pressCount++;
|
|
|
|
if (m_modOnlyShortcut.pressCount == 1) {
|
|
|
|
m_modOnlyShortcut.modifier = Qt::KeyboardModifier(int(m_modifiers));
|
|
|
|
} else {
|
|
|
|
m_modOnlyShortcut.modifier = Qt::NoModifier;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_modOnlyShortcut.pressCount--;
|
|
|
|
// TODO: ignore on lock screen
|
|
|
|
if (m_modOnlyShortcut.pressCount == 0) {
|
|
|
|
if (m_modOnlyShortcut.modifier != Qt::NoModifier) {
|
|
|
|
const auto list = options->modifierOnlyDBusShortcut(m_modOnlyShortcut.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);
|
|
|
|
}
|
|
|
|
call.setArguments(args);
|
|
|
|
QDBusConnection::sessionBus().asyncCall(call);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_modOnlyShortcut.modifier = Qt::NoModifier;
|
|
|
|
}
|
2015-03-27 16:15:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Xkb::updateModifiers()
|
|
|
|
{
|
2013-07-02 13:44:18 +04:00
|
|
|
Qt::KeyboardModifiers mods = Qt::NoModifier;
|
|
|
|
if (xkb_state_mod_index_is_active(m_state, m_shiftModifier, XKB_STATE_MODS_EFFECTIVE) == 1) {
|
|
|
|
mods |= Qt::ShiftModifier;
|
|
|
|
}
|
|
|
|
if (xkb_state_mod_index_is_active(m_state, m_altModifier, XKB_STATE_MODS_EFFECTIVE) == 1) {
|
|
|
|
mods |= Qt::AltModifier;
|
|
|
|
}
|
|
|
|
if (xkb_state_mod_index_is_active(m_state, m_controlModifier, XKB_STATE_MODS_EFFECTIVE) == 1) {
|
|
|
|
mods |= Qt::ControlModifier;
|
|
|
|
}
|
|
|
|
if (xkb_state_mod_index_is_active(m_state, m_metaModifier, XKB_STATE_MODS_EFFECTIVE) == 1) {
|
|
|
|
mods |= Qt::MetaModifier;
|
|
|
|
}
|
|
|
|
m_modifiers = mods;
|
|
|
|
}
|
|
|
|
|
|
|
|
xkb_keysym_t Xkb::toKeysym(uint32_t key)
|
|
|
|
{
|
|
|
|
if (!m_state) {
|
|
|
|
return XKB_KEY_NoSymbol;
|
|
|
|
}
|
|
|
|
return xkb_state_key_get_one_sym(m_state, key + 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Xkb::toString(xkb_keysym_t keysym)
|
|
|
|
{
|
|
|
|
if (!m_state || keysym == XKB_KEY_NoSymbol) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
QByteArray byteArray(7, 0);
|
|
|
|
int ok = xkb_keysym_to_utf8(keysym, byteArray.data(), byteArray.size());
|
|
|
|
if (ok == -1 || ok == 0) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
return QString::fromUtf8(byteArray.constData());
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Key Xkb::toQtKey(xkb_keysym_t keysym)
|
|
|
|
{
|
|
|
|
int key = Qt::Key_unknown;
|
|
|
|
KKeyServer::symXToKeyQt(keysym, &key);
|
|
|
|
return static_cast<Qt::Key>(key);
|
|
|
|
}
|
2015-07-13 15:25:09 +03:00
|
|
|
|
|
|
|
quint32 Xkb::getMods(quint32 components)
|
|
|
|
{
|
|
|
|
if (!m_state) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return xkb_state_serialize_mods(m_state, xkb_state_component(components));
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 Xkb::getGroup()
|
|
|
|
{
|
|
|
|
if (!m_state) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE);
|
|
|
|
}
|
|
|
|
|
2013-06-26 12:15:20 +04:00
|
|
|
KWIN_SINGLETON_FACTORY(InputRedirection)
|
|
|
|
|
|
|
|
InputRedirection::InputRedirection(QObject *parent)
|
|
|
|
: QObject(parent)
|
2015-05-28 11:17:41 +03:00
|
|
|
, m_xkb(new Xkb(this))
|
2013-07-01 10:37:59 +04:00
|
|
|
, m_pointerWindow()
|
2013-07-10 13:41:16 +04:00
|
|
|
, m_shortcuts(new GlobalShortcutsManager(this))
|
2013-06-26 12:15:20 +04:00
|
|
|
{
|
2015-09-02 11:10:49 +03:00
|
|
|
qRegisterMetaType<KWin::InputRedirection::KeyboardKeyState>();
|
|
|
|
qRegisterMetaType<KWin::InputRedirection::PointerButtonState>();
|
|
|
|
qRegisterMetaType<KWin::InputRedirection::PointerAxis>();
|
2014-08-15 11:30:08 +04:00
|
|
|
#if HAVE_INPUT
|
2014-08-15 16:03:52 +04:00
|
|
|
if (Application::usesLibinput()) {
|
2015-04-15 18:47:56 +03:00
|
|
|
if (VirtualTerminal::self()) {
|
|
|
|
setupLibInput();
|
2014-08-15 11:30:08 +04:00
|
|
|
} else {
|
2015-04-15 18:47:56 +03:00
|
|
|
connect(kwinApp(), &Application::virtualTerminalCreated, this, &InputRedirection::setupLibInput);
|
2014-08-15 11:30:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-06-13 18:54:08 +03:00
|
|
|
connect(kwinApp(), &Application::workspaceCreated, this, &InputRedirection::setupWorkspace);
|
2015-09-15 11:29:06 +03:00
|
|
|
reconfigure();
|
2014-08-15 11:30:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
InputRedirection::~InputRedirection()
|
|
|
|
{
|
|
|
|
s_self = NULL;
|
|
|
|
}
|
|
|
|
|
2015-06-26 14:47:08 +03:00
|
|
|
void InputRedirection::init()
|
|
|
|
{
|
|
|
|
m_shortcuts->init();
|
|
|
|
}
|
|
|
|
|
2015-06-13 18:54:08 +03:00
|
|
|
void InputRedirection::setupWorkspace()
|
|
|
|
{
|
|
|
|
if (waylandServer()) {
|
|
|
|
connect(workspace(), &Workspace::clientActivated, this, &InputRedirection::updateKeyboardWindow);
|
2015-07-06 05:44:07 +03:00
|
|
|
using namespace KWayland::Server;
|
|
|
|
FakeInputInterface *fakeInput = waylandServer()->display()->createFakeInput(this);
|
|
|
|
fakeInput->create();
|
|
|
|
connect(fakeInput, &FakeInputInterface::deviceCreated, this,
|
|
|
|
[this] (FakeInputDevice *device) {
|
|
|
|
connect(device, &FakeInputDevice::authenticationRequested, this,
|
|
|
|
[this, device] (const QString &application, const QString &reason) {
|
|
|
|
// TODO: make secure
|
|
|
|
device->setAuthentication(true);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::pointerMotionRequested, this,
|
|
|
|
[this] (const QSizeF &delta) {
|
|
|
|
// TODO: Fix time
|
|
|
|
processPointerMotion(globalPointer() + QPointF(delta.width(), delta.height()), 0);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::pointerButtonPressRequested, this,
|
|
|
|
[this] (quint32 button) {
|
|
|
|
// TODO: Fix time
|
|
|
|
processPointerButton(button, InputRedirection::PointerButtonPressed, 0);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::pointerButtonReleaseRequested, this,
|
|
|
|
[this] (quint32 button) {
|
|
|
|
// TODO: Fix time
|
|
|
|
processPointerButton(button, InputRedirection::PointerButtonReleased, 0);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::pointerAxisRequested, this,
|
|
|
|
[this] (Qt::Orientation orientation, qreal delta) {
|
|
|
|
// TODO: Fix time
|
|
|
|
InputRedirection::PointerAxis axis;
|
|
|
|
switch (orientation) {
|
|
|
|
case Qt::Horizontal:
|
|
|
|
axis = InputRedirection::PointerAxisHorizontal;
|
|
|
|
break;
|
|
|
|
case Qt::Vertical:
|
|
|
|
axis = InputRedirection::PointerAxisVertical;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// TODO: Fix time
|
|
|
|
processPointerAxis(axis, delta, 0);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2015-07-13 15:25:09 +03:00
|
|
|
connect(this, &InputRedirection::keyboardModifiersChanged, waylandServer(),
|
|
|
|
[this] {
|
|
|
|
if (!waylandServer()->seat()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
waylandServer()->seat()->updateKeyboardModifiers(m_xkb->getMods(XKB_STATE_MODS_DEPRESSED),
|
|
|
|
m_xkb->getMods(XKB_STATE_MODS_LATCHED),
|
|
|
|
m_xkb->getMods(XKB_STATE_MODS_LOCKED),
|
|
|
|
m_xkb->getGroup());
|
|
|
|
}
|
|
|
|
);
|
2015-09-15 11:29:06 +03:00
|
|
|
connect(workspace(), &Workspace::configChanged, this, &InputRedirection::reconfigure);
|
2015-06-13 18:54:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-15 11:29:06 +03:00
|
|
|
void InputRedirection::reconfigure()
|
|
|
|
{
|
|
|
|
#if HAVE_INPUT
|
|
|
|
if (Application::usesLibinput()) {
|
|
|
|
const auto config = KSharedConfig::openConfig(QStringLiteral("kcminputrc"))->group(QStringLiteral("keyboard"));
|
|
|
|
const int delay = config.readEntry("RepeatDelay", 660);
|
|
|
|
const int rate = config.readEntry("RepeatRate", 25);
|
|
|
|
const bool enabled = config.readEntry("KeyboardRepeating", 0) == 0;
|
|
|
|
|
|
|
|
waylandServer()->seat()->setKeyRepeatInfo(enabled ? rate : 0, delay);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:19:26 +03:00
|
|
|
static KWayland::Server::SeatInterface *findSeat()
|
|
|
|
{
|
|
|
|
auto server = waylandServer();
|
|
|
|
if (!server) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return server->seat();
|
|
|
|
}
|
|
|
|
|
2014-08-15 11:30:08 +04:00
|
|
|
void InputRedirection::setupLibInput()
|
|
|
|
{
|
2014-08-14 16:43:57 +04:00
|
|
|
#if HAVE_INPUT
|
2014-08-15 16:03:52 +04:00
|
|
|
if (!Application::usesLibinput()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-30 09:55:41 +03:00
|
|
|
if (m_libInput) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-14 16:43:57 +04:00
|
|
|
LibInput::Connection *conn = LibInput::Connection::create(this);
|
2015-03-30 09:55:41 +03:00
|
|
|
m_libInput = conn;
|
2014-08-14 16:43:57 +04:00
|
|
|
if (conn) {
|
|
|
|
conn->setup();
|
2015-06-05 07:43:12 +03:00
|
|
|
m_pointerWarping = true;
|
2015-09-02 12:32:26 +03:00
|
|
|
connect(conn, &LibInput::Connection::eventsRead, this,
|
|
|
|
[this] {
|
|
|
|
m_libInput->processEvents();
|
|
|
|
}, Qt::QueuedConnection
|
|
|
|
);
|
2014-08-14 16:43:57 +04:00
|
|
|
connect(conn, &LibInput::Connection::pointerButtonChanged, this, &InputRedirection::processPointerButton);
|
|
|
|
connect(conn, &LibInput::Connection::pointerAxisChanged, this, &InputRedirection::processPointerAxis);
|
|
|
|
connect(conn, &LibInput::Connection::keyChanged, this, &InputRedirection::processKeyboardKey);
|
2014-10-17 11:21:38 +04:00
|
|
|
connect(conn, &LibInput::Connection::pointerMotion, this,
|
|
|
|
[this] (QPointF delta, uint32_t time) {
|
|
|
|
processPointerMotion(m_globalPointer + delta, time);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(conn, &LibInput::Connection::pointerMotionAbsolute, this,
|
|
|
|
[this] (QPointF orig, QPointF screen, uint32_t time) {
|
|
|
|
Q_UNUSED(orig)
|
|
|
|
processPointerMotion(screen, time);
|
|
|
|
}
|
|
|
|
);
|
2015-03-25 18:30:47 +03:00
|
|
|
connect(conn, &LibInput::Connection::touchDown, this, &InputRedirection::processTouchDown);
|
|
|
|
connect(conn, &LibInput::Connection::touchUp, this, &InputRedirection::processTouchUp);
|
|
|
|
connect(conn, &LibInput::Connection::touchMotion, this, &InputRedirection::processTouchMotion);
|
|
|
|
connect(conn, &LibInput::Connection::touchCanceled, this, &InputRedirection::cancelTouch);
|
|
|
|
connect(conn, &LibInput::Connection::touchFrame, this, &InputRedirection::touchFrame);
|
2014-10-17 13:57:14 +04:00
|
|
|
if (screens()) {
|
2015-03-30 09:55:41 +03:00
|
|
|
setupLibInputWithScreens();
|
|
|
|
} else {
|
|
|
|
connect(kwinApp(), &Application::screensCreated, this, &InputRedirection::setupLibInputWithScreens);
|
2014-10-17 13:57:14 +04:00
|
|
|
}
|
2015-03-26 18:19:26 +03:00
|
|
|
if (auto s = findSeat()) {
|
|
|
|
s->setHasKeyboard(conn->hasKeyboard());
|
|
|
|
s->setHasPointer(conn->hasPointer());
|
|
|
|
s->setHasTouch(conn->hasTouch());
|
2015-03-31 10:16:16 +03:00
|
|
|
connect(conn, &LibInput::Connection::hasKeyboardChanged, this,
|
|
|
|
[this, s] (bool set) {
|
|
|
|
if (m_libInput->isSuspended()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s->setHasKeyboard(set);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(conn, &LibInput::Connection::hasPointerChanged, this,
|
|
|
|
[this, s] (bool set) {
|
|
|
|
if (m_libInput->isSuspended()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s->setHasPointer(set);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(conn, &LibInput::Connection::hasTouchChanged, this,
|
|
|
|
[this, s] (bool set) {
|
|
|
|
if (m_libInput->isSuspended()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
s->setHasTouch(set);
|
|
|
|
}
|
|
|
|
);
|
2015-03-26 18:19:26 +03:00
|
|
|
}
|
2015-04-15 18:47:56 +03:00
|
|
|
connect(VirtualTerminal::self(), &VirtualTerminal::activeChanged, m_libInput,
|
|
|
|
[this] (bool active) {
|
|
|
|
if (!active) {
|
|
|
|
m_libInput->deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-02-26 17:32:44 +03:00
|
|
|
}
|
|
|
|
#endif
|
2015-03-26 18:19:26 +03:00
|
|
|
}
|
2015-02-26 17:32:44 +03:00
|
|
|
|
2015-03-30 09:55:41 +03:00
|
|
|
void InputRedirection::setupLibInputWithScreens()
|
|
|
|
{
|
|
|
|
#if HAVE_INPUT
|
|
|
|
if (!screens() || !m_libInput) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_libInput->setScreenSize(screens()->size());
|
|
|
|
connect(screens(), &Screens::sizeChanged, this,
|
|
|
|
[this] {
|
|
|
|
m_libInput->setScreenSize(screens()->size());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
// set pos to center of all screens
|
|
|
|
connect(screens(), &Screens::changed, this, &InputRedirection::updatePointerAfterScreenChange);
|
|
|
|
m_globalPointer = screens()->geometry().center();
|
|
|
|
emit globalPointerChanged(m_globalPointer);
|
|
|
|
// sanitize
|
|
|
|
updatePointerAfterScreenChange();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-07-01 10:37:59 +04:00
|
|
|
void InputRedirection::updatePointerWindow()
|
|
|
|
{
|
2015-11-16 13:46:20 +03:00
|
|
|
if (waylandServer() && waylandServer()->isScreenLocked()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-07-01 10:37:59 +04:00
|
|
|
// TODO: handle pointer grab aka popups
|
|
|
|
Toplevel *t = findToplevel(m_globalPointer.toPoint());
|
2015-06-06 04:26:24 +03:00
|
|
|
updatePointerInternalWindow();
|
|
|
|
if (!m_pointerInternalWindow) {
|
|
|
|
updatePointerDecoration(t);
|
|
|
|
} else {
|
|
|
|
m_pointerDecoration.clear();
|
|
|
|
}
|
|
|
|
if (m_pointerDecoration || m_pointerInternalWindow) {
|
2015-06-03 19:09:54 +03:00
|
|
|
t = nullptr;
|
|
|
|
}
|
2015-02-26 17:32:44 +03:00
|
|
|
auto oldWindow = m_pointerWindow;
|
|
|
|
if (!oldWindow.isNull() && t == m_pointerWindow.data()) {
|
2013-07-01 10:37:59 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-02-26 17:32:44 +03:00
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
// disconnect old surface
|
|
|
|
if (oldWindow) {
|
|
|
|
disconnect(oldWindow.data(), &Toplevel::geometryChanged, this, &InputRedirection::updateFocusedPointerPosition);
|
2015-03-20 16:41:03 +03:00
|
|
|
if (AbstractBackend *b = waylandServer()->backend()) {
|
2015-03-04 10:04:46 +03:00
|
|
|
if (auto p = seat->focusedPointer()) {
|
|
|
|
if (auto c = p->cursor()) {
|
|
|
|
disconnect(c, &KWayland::Server::Cursor::changed, b, &AbstractBackend::installCursorFromServer);
|
|
|
|
}
|
|
|
|
}
|
2015-03-20 16:41:03 +03:00
|
|
|
}
|
2015-02-26 17:32:44 +03:00
|
|
|
}
|
|
|
|
if (t && t->surface()) {
|
2015-12-07 16:25:08 +03:00
|
|
|
seat->setFocusedPointerSurface(t->surface(), t->inputTransformation());
|
2015-02-26 17:32:44 +03:00
|
|
|
connect(t, &Toplevel::geometryChanged, this, &InputRedirection::updateFocusedPointerPosition);
|
2015-03-20 16:41:03 +03:00
|
|
|
if (AbstractBackend *b = waylandServer()->backend()) {
|
|
|
|
b->installCursorFromServer();
|
2015-03-04 10:04:46 +03:00
|
|
|
if (auto p = seat->focusedPointer()) {
|
|
|
|
if (auto c = p->cursor()) {
|
|
|
|
connect(c, &KWayland::Server::Cursor::changed, b, &AbstractBackend::installCursorFromServer);
|
|
|
|
}
|
|
|
|
}
|
2015-03-20 16:41:03 +03:00
|
|
|
}
|
2015-02-26 17:32:44 +03:00
|
|
|
} else {
|
|
|
|
seat->setFocusedPointerSurface(nullptr);
|
|
|
|
t = nullptr;
|
|
|
|
}
|
2013-07-01 10:37:59 +04:00
|
|
|
}
|
|
|
|
if (!t) {
|
|
|
|
m_pointerWindow.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_pointerWindow = QWeakPointer<Toplevel>(t);
|
2015-02-26 17:32:44 +03:00
|
|
|
}
|
|
|
|
|
2015-06-03 19:09:54 +03:00
|
|
|
void InputRedirection::updatePointerDecoration(Toplevel *t)
|
|
|
|
{
|
|
|
|
const auto oldDeco = m_pointerDecoration;
|
2015-12-03 19:39:06 +03:00
|
|
|
if (AbstractClient *c = dynamic_cast<AbstractClient*>(t)) {
|
2015-06-03 19:09:54 +03:00
|
|
|
// check whether it's on a Decoration
|
|
|
|
if (c->decoratedClient()) {
|
|
|
|
const QRect clientRect = QRect(c->clientPos(), c->clientSize()).translated(c->pos());
|
|
|
|
if (!clientRect.contains(m_globalPointer.toPoint())) {
|
|
|
|
m_pointerDecoration = c->decoratedClient();
|
|
|
|
} else {
|
|
|
|
m_pointerDecoration.clear();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_pointerDecoration.clear();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_pointerDecoration.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldDeco && oldDeco != m_pointerDecoration) {
|
|
|
|
// send leave
|
|
|
|
QHoverEvent event(QEvent::HoverLeave, QPointF(), QPointF());
|
|
|
|
QCoreApplication::instance()->sendEvent(oldDeco->decoration(), &event);
|
2015-06-04 23:16:30 +03:00
|
|
|
if (!m_pointerDecoration && waylandServer()) {
|
|
|
|
waylandServer()->backend()->installCursorImage(Qt::ArrowCursor);
|
|
|
|
}
|
2015-06-03 19:09:54 +03:00
|
|
|
}
|
|
|
|
if (m_pointerDecoration) {
|
|
|
|
const QPointF p = m_globalPointer - t->pos();
|
|
|
|
QHoverEvent event(QEvent::HoverMove, p, p);
|
|
|
|
QCoreApplication::instance()->sendEvent(m_pointerDecoration->decoration(), &event);
|
|
|
|
m_pointerDecoration->client()->processDecorationMove();
|
2015-06-04 23:16:30 +03:00
|
|
|
installCursorFromDecoration();
|
2015-06-03 19:09:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 04:26:24 +03:00
|
|
|
void InputRedirection::updatePointerInternalWindow()
|
|
|
|
{
|
|
|
|
const auto oldInternalWindow = m_pointerInternalWindow;
|
|
|
|
if (waylandServer()) {
|
|
|
|
bool found = false;
|
|
|
|
const auto &internalClients = waylandServer()->internalClients();
|
2015-08-20 10:09:17 +03:00
|
|
|
const bool change = m_pointerInternalWindow.isNull() || !(m_pointerInternalWindow->flags().testFlag(Qt::Popup) && m_pointerInternalWindow->isVisible());
|
|
|
|
if (!internalClients.isEmpty() && change) {
|
2015-06-06 04:26:24 +03:00
|
|
|
auto it = internalClients.end();
|
|
|
|
do {
|
|
|
|
it--;
|
|
|
|
if (QWindow *w = (*it)->internalWindow()) {
|
|
|
|
if (!w->isVisible()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (w->geometry().contains(m_globalPointer.toPoint())) {
|
|
|
|
m_pointerInternalWindow = QPointer<QWindow>(w);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (it != internalClients.begin());
|
|
|
|
if (!found) {
|
|
|
|
m_pointerInternalWindow.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oldInternalWindow != m_pointerInternalWindow) {
|
|
|
|
// changed
|
|
|
|
if (oldInternalWindow) {
|
|
|
|
disconnect(oldInternalWindow.data(), &QWindow::visibleChanged, this, &InputRedirection::pointerInternalWindowVisibilityChanged);
|
|
|
|
QEvent event(QEvent::Leave);
|
|
|
|
QCoreApplication::sendEvent(oldInternalWindow.data(), &event);
|
|
|
|
}
|
|
|
|
if (m_pointerInternalWindow) {
|
|
|
|
connect(oldInternalWindow.data(), &QWindow::visibleChanged, this, &InputRedirection::pointerInternalWindowVisibilityChanged);
|
|
|
|
QEnterEvent event(m_globalPointer - m_pointerInternalWindow->position(),
|
|
|
|
m_globalPointer - m_pointerInternalWindow->position(),
|
|
|
|
m_globalPointer);
|
|
|
|
QCoreApplication::sendEvent(m_pointerInternalWindow.data(), &event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_pointerInternalWindow) {
|
|
|
|
// send mouse move
|
|
|
|
QMouseEvent event(QEvent::MouseMove,
|
|
|
|
m_globalPointer.toPoint() - m_pointerInternalWindow->position(),
|
|
|
|
m_globalPointer.toPoint(),
|
|
|
|
Qt::NoButton, qtButtonStates(), keyboardModifiers());
|
|
|
|
QCoreApplication::sendEvent(m_pointerInternalWindow.data(), &event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::pointerInternalWindowVisibilityChanged(bool visible)
|
|
|
|
{
|
|
|
|
if (!visible) {
|
|
|
|
updatePointerWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 23:16:30 +03:00
|
|
|
void InputRedirection::installCursorFromDecoration()
|
|
|
|
{
|
|
|
|
if (waylandServer() && m_pointerDecoration) {
|
|
|
|
waylandServer()->backend()->installCursorImage(m_pointerDecoration->client()->cursor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 17:32:44 +03:00
|
|
|
void InputRedirection::updateFocusedPointerPosition()
|
|
|
|
{
|
2015-11-16 13:50:29 +03:00
|
|
|
if (!workspace()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-26 17:32:44 +03:00
|
|
|
if (m_pointerWindow.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (workspace()->getMovingClient()) {
|
|
|
|
// don't update while moving
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
if (m_pointerWindow.data()->surface() != seat->focusedPointerSurface()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-12-07 16:25:08 +03:00
|
|
|
seat->setFocusedPointerSurfaceTransformation(m_pointerWindow.data()->inputTransformation());
|
2015-02-26 17:32:44 +03:00
|
|
|
}
|
2013-07-01 10:37:59 +04:00
|
|
|
}
|
|
|
|
|
2015-03-25 16:50:14 +03:00
|
|
|
void InputRedirection::updateFocusedTouchPosition()
|
|
|
|
{
|
|
|
|
if (m_touchWindow.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
if (m_touchWindow.data()->surface() != seat->focusedTouchSurface()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
seat->setFocusedTouchSurfacePosition(m_touchWindow.data()->pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-26 12:15:20 +04:00
|
|
|
void InputRedirection::processPointerMotion(const QPointF &pos, uint32_t time)
|
|
|
|
{
|
2015-06-06 04:26:24 +03:00
|
|
|
if (!workspace()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-16 13:46:20 +03:00
|
|
|
|
2015-11-18 16:30:32 +03:00
|
|
|
// first update to new mouse position
|
|
|
|
// const QPointF oldPos = m_globalPointer;
|
|
|
|
updatePointerPosition(pos);
|
|
|
|
|
2015-11-16 13:46:20 +03:00
|
|
|
if (waylandServer()->isScreenLocked()) {
|
2015-11-18 16:30:32 +03:00
|
|
|
Toplevel *t = findToplevel(m_globalPointer.toPoint());
|
2015-11-16 18:27:23 +03:00
|
|
|
if (t && t->surface()) {
|
|
|
|
if (auto seat = findSeat()) {
|
2015-12-07 16:25:08 +03:00
|
|
|
seat->setFocusedPointerSurface(t->surface(), t->inputTransformation());
|
2015-11-16 18:27:23 +03:00
|
|
|
seat->setTimestamp(time);
|
2015-11-18 16:30:32 +03:00
|
|
|
seat->setPointerPos(m_globalPointer);
|
2015-11-16 18:27:23 +03:00
|
|
|
}
|
2016-02-02 12:21:42 +03:00
|
|
|
} else {
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
seat->setFocusedPointerSurface(nullptr);
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->setPointerPos(m_globalPointer);
|
|
|
|
}
|
2015-11-16 13:46:20 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-26 12:15:20 +04:00
|
|
|
// TODO: check which part of KWin would like to intercept the event
|
2013-06-26 13:40:30 +04:00
|
|
|
QMouseEvent event(QEvent::MouseMove, m_globalPointer.toPoint(), m_globalPointer.toPoint(),
|
2013-07-02 13:44:18 +04:00
|
|
|
Qt::NoButton, qtButtonStates(), keyboardModifiers());
|
2013-06-26 13:40:30 +04:00
|
|
|
// check whether an effect has a mouse grab
|
|
|
|
if (effects && static_cast<EffectsHandlerImpl*>(effects)->checkInputWindowEvent(&event)) {
|
|
|
|
// an effect grabbed the pointer, we do not forward the event to surfaces
|
|
|
|
return;
|
|
|
|
}
|
2015-06-05 06:06:20 +03:00
|
|
|
if (AbstractClient *c = workspace()->getMovingClient()) {
|
|
|
|
c->updateMoveResize(m_globalPointer);
|
|
|
|
} else {
|
|
|
|
QWeakPointer<Toplevel> old = m_pointerWindow;
|
|
|
|
if (!areButtonsPressed()) {
|
|
|
|
// update pointer window only if no button is pressed
|
|
|
|
updatePointerWindow();
|
|
|
|
} else if (m_pointerDecoration) {
|
|
|
|
const QPointF p = m_globalPointer - m_pointerDecoration->client()->pos();
|
|
|
|
QHoverEvent event(QEvent::HoverMove, p, p);
|
|
|
|
QCoreApplication::instance()->sendEvent(m_pointerDecoration->decoration(), &event);
|
|
|
|
m_pointerDecoration->client()->processDecorationMove();
|
|
|
|
}
|
2015-06-03 18:56:59 +03:00
|
|
|
}
|
2015-02-26 17:32:44 +03:00
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
seat->setTimestamp(time);
|
2015-07-20 13:35:46 +03:00
|
|
|
seat->setPointerPos(m_globalPointer);
|
2013-07-01 10:37:59 +04:00
|
|
|
}
|
2013-06-26 12:15:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processPointerButton(uint32_t button, InputRedirection::PointerButtonState state, uint32_t time)
|
|
|
|
{
|
2015-11-16 13:50:29 +03:00
|
|
|
if (!workspace()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-06-26 12:15:20 +04:00
|
|
|
m_pointerButtons[button] = state;
|
|
|
|
emit pointerButtonStateChanged(button, state);
|
|
|
|
|
2013-06-26 13:40:30 +04:00
|
|
|
QMouseEvent event(buttonStateToEvent(state), m_globalPointer.toPoint(), m_globalPointer.toPoint(),
|
2013-07-02 13:44:18 +04:00
|
|
|
buttonToQtMouseButton(button), qtButtonStates(), keyboardModifiers());
|
2015-11-16 13:46:20 +03:00
|
|
|
|
|
|
|
if (waylandServer()->isScreenLocked()) {
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
KWayland::Server::SurfaceInterface *s = seat->focusedPointerSurface();
|
|
|
|
if (s) {
|
|
|
|
Toplevel *t = waylandServer()->findClient(s);
|
|
|
|
if (t->isLockScreen() || t->isInputMethod()) {
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
state == PointerButtonPressed ? seat->pointerButtonPressed(button) : seat->pointerButtonReleased(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-26 13:40:30 +04:00
|
|
|
// check whether an effect has a mouse grab
|
|
|
|
if (effects && static_cast<EffectsHandlerImpl*>(effects)->checkInputWindowEvent(&event)) {
|
|
|
|
// an effect grabbed the pointer, we do not forward the event to surfaces
|
|
|
|
return;
|
|
|
|
}
|
2015-10-28 12:43:49 +03:00
|
|
|
if (AbstractClient *c = workspace()->getMovingClient()) {
|
|
|
|
if (state == KWin::InputRedirection::PointerButtonReleased) {
|
|
|
|
if (!areButtonsPressed()) {
|
|
|
|
c->endMoveResize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2013-07-15 00:52:58 +04:00
|
|
|
if (state == KWin::InputRedirection::PointerButtonPressed) {
|
|
|
|
if (m_shortcuts->processPointerPressed(m_xkb->modifiers(), qtButtonStates())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-06-06 04:26:24 +03:00
|
|
|
if (m_pointerInternalWindow) {
|
|
|
|
// send mouse move
|
|
|
|
QMouseEvent event(buttonStateToEvent(state),
|
|
|
|
m_globalPointer.toPoint() - m_pointerInternalWindow->position(),
|
|
|
|
m_globalPointer.toPoint(),
|
|
|
|
buttonToQtMouseButton(button), qtButtonStates(), keyboardModifiers());
|
|
|
|
event.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(m_pointerInternalWindow.data(), &event);
|
|
|
|
}
|
2015-06-03 19:09:54 +03:00
|
|
|
if (m_pointerDecoration) {
|
|
|
|
const QPoint localPos = m_globalPointer.toPoint() - m_pointerDecoration->client()->pos();
|
|
|
|
QMouseEvent event(buttonStateToEvent(state),
|
|
|
|
localPos,
|
|
|
|
m_globalPointer.toPoint(),
|
|
|
|
buttonToQtMouseButton(button), qtButtonStates(), keyboardModifiers());
|
|
|
|
event.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(m_pointerDecoration->decoration(), &event);
|
|
|
|
if (!event.isAccepted()) {
|
|
|
|
if (state == PointerButtonPressed) {
|
|
|
|
m_pointerDecoration->client()->processDecorationButtonPress(&event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (state == PointerButtonReleased) {
|
|
|
|
m_pointerDecoration->client()->processDecorationButtonRelease(&event);
|
|
|
|
}
|
2015-06-04 23:16:30 +03:00
|
|
|
installCursorFromDecoration();
|
2015-06-03 19:09:54 +03:00
|
|
|
}
|
2013-06-26 12:15:20 +04:00
|
|
|
// TODO: check which part of KWin would like to intercept the event
|
2015-02-26 17:32:44 +03:00
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
seat->setTimestamp(time);
|
2015-07-09 17:22:08 +03:00
|
|
|
bool passThrough = true;
|
|
|
|
if (state == PointerButtonPressed) {
|
|
|
|
if (AbstractClient *c = dynamic_cast<AbstractClient*>(m_pointerWindow.data())) {
|
|
|
|
bool wasAction = false;
|
|
|
|
const Options::MouseCommand command = c->getMouseCommand(buttonToQtMouseButton(button), &wasAction);
|
|
|
|
if (wasAction) {
|
|
|
|
passThrough = c->performMouseCommand(command, m_globalPointer.toPoint());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (passThrough) {
|
|
|
|
state == PointerButtonPressed ? seat->pointerButtonPressed(button) : seat->pointerButtonReleased(button);
|
|
|
|
}
|
2013-06-26 12:15:20 +04:00
|
|
|
}
|
2015-06-03 18:56:59 +03:00
|
|
|
if (state == PointerButtonReleased && !areButtonsPressed()) {
|
|
|
|
updatePointerWindow();
|
|
|
|
}
|
2013-06-26 12:15:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processPointerAxis(InputRedirection::PointerAxis axis, qreal delta, uint32_t time)
|
|
|
|
{
|
|
|
|
if (delta == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-16 13:46:20 +03:00
|
|
|
|
2013-06-26 12:15:20 +04:00
|
|
|
emit pointerAxisChanged(axis, delta);
|
2015-11-16 13:46:20 +03:00
|
|
|
|
|
|
|
if (waylandServer()->isScreenLocked()) {
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
KWayland::Server::SurfaceInterface *s = seat->focusedPointerSurface();
|
|
|
|
if (s) {
|
|
|
|
Toplevel *t = waylandServer()->findClient(s);
|
|
|
|
if (t->isLockScreen() || t->isInputMethod()) {
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->pointerAxis(axis == InputRedirection::PointerAxisHorizontal ? Qt::Horizontal : Qt::Vertical, delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-15 13:26:56 +04:00
|
|
|
if (m_xkb->modifiers() != Qt::NoModifier) {
|
|
|
|
PointerAxisDirection direction = PointerAxisUp;
|
|
|
|
if (axis == PointerAxisHorizontal) {
|
|
|
|
if (delta > 0) {
|
|
|
|
direction = PointerAxisUp;
|
|
|
|
} else {
|
|
|
|
direction = PointerAxisDown;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (delta > 0) {
|
|
|
|
direction = PointerAxisLeft;
|
|
|
|
} else {
|
|
|
|
direction = PointerAxisRight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_shortcuts->processAxis(m_xkb->modifiers(), direction)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-06-26 12:15:20 +04:00
|
|
|
|
2015-06-06 04:26:24 +03:00
|
|
|
auto sendWheelEvent = [this, delta, axis] (const QPoint targetPos, QObject *target) -> bool {
|
|
|
|
const QPointF localPos = m_globalPointer - targetPos;
|
2015-06-03 19:09:54 +03:00
|
|
|
// TODO: add modifiers and buttons
|
|
|
|
QWheelEvent event(localPos, m_globalPointer, QPoint(),
|
|
|
|
(axis == PointerAxisHorizontal) ? QPoint(delta, 0) : QPoint(0, delta),
|
|
|
|
delta,
|
|
|
|
(axis == PointerAxisHorizontal) ? Qt::Horizontal : Qt::Vertical,
|
|
|
|
Qt::NoButton,
|
|
|
|
Qt::NoModifier);
|
|
|
|
event.setAccepted(false);
|
2015-06-06 04:26:24 +03:00
|
|
|
QCoreApplication::sendEvent(target, &event);
|
|
|
|
return event.isAccepted();
|
|
|
|
};
|
|
|
|
if (m_pointerDecoration) {
|
|
|
|
if (!sendWheelEvent(m_pointerDecoration->client()->pos(), m_pointerDecoration.data())
|
|
|
|
&& axis == PointerAxisVertical) {
|
|
|
|
if (m_pointerDecoration->decoration()->titleBar().contains(m_globalPointer.toPoint() - m_pointerDecoration->client()->pos())) {
|
2015-06-03 19:09:54 +03:00
|
|
|
m_pointerDecoration->client()->performMouseCommand(options->operationTitlebarMouseWheel(delta * -1),
|
|
|
|
m_globalPointer.toPoint());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-06 04:26:24 +03:00
|
|
|
if (m_pointerInternalWindow) {
|
|
|
|
sendWheelEvent(m_pointerInternalWindow->position(), m_pointerInternalWindow.data());
|
|
|
|
}
|
2015-06-03 19:09:54 +03:00
|
|
|
|
2013-06-26 12:15:20 +04:00
|
|
|
// TODO: check which part of KWin would like to intercept the event
|
2013-06-26 13:40:30 +04:00
|
|
|
// TODO: Axis support for effect redirection
|
2015-02-26 17:32:44 +03:00
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->pointerAxis(axis == InputRedirection::PointerAxisHorizontal ? Qt::Horizontal : Qt::Vertical, delta);
|
2013-06-26 12:15:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-13 18:54:08 +03:00
|
|
|
void InputRedirection::updateKeyboardWindow()
|
|
|
|
{
|
|
|
|
if (!workspace()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
// TODO: this needs better integration
|
2015-11-11 13:00:59 +03:00
|
|
|
Toplevel *t = workspace()->activeClient();
|
2015-06-13 18:54:08 +03:00
|
|
|
if (t && t->surface()) {
|
|
|
|
if (t->surface() != seat->focusedKeyboardSurface()) {
|
|
|
|
seat->setFocusedKeyboardSurface(t->surface());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 13:44:18 +04:00
|
|
|
void InputRedirection::processKeyboardKey(uint32_t key, InputRedirection::KeyboardKeyState state, uint32_t time)
|
|
|
|
{
|
2015-08-31 09:55:26 +03:00
|
|
|
emit keyStateChanged(key, state);
|
2015-03-27 16:15:25 +03:00
|
|
|
const Qt::KeyboardModifiers oldMods = keyboardModifiers();
|
2013-07-02 13:44:18 +04:00
|
|
|
m_xkb->updateKey(key, state);
|
2015-03-27 16:15:25 +03:00
|
|
|
if (oldMods != keyboardModifiers()) {
|
|
|
|
emit keyboardModifiersChanged(keyboardModifiers(), oldMods);
|
|
|
|
}
|
2015-03-31 10:33:05 +03:00
|
|
|
// check for vt-switch
|
2015-11-27 10:44:59 +03:00
|
|
|
#if HAVE_INPUT
|
2015-03-31 10:33:05 +03:00
|
|
|
if (VirtualTerminal::self()) {
|
|
|
|
const xkb_keysym_t keysym = m_xkb->toKeysym(key);
|
|
|
|
if (state == KWin::InputRedirection::KeyboardKeyPressed &&
|
|
|
|
(keysym >= XKB_KEY_XF86Switch_VT_1 && keysym <= XKB_KEY_XF86Switch_VT_12)) {
|
|
|
|
VirtualTerminal::self()->activate(keysym - XKB_KEY_XF86Switch_VT_1 + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-11-27 10:44:59 +03:00
|
|
|
#endif
|
2015-11-16 13:46:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
if (waylandServer()->isScreenLocked()) {
|
|
|
|
const ToplevelList &stacking = Workspace::self()->stackingOrder();
|
|
|
|
if (stacking.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto it = stacking.end();
|
|
|
|
do {
|
|
|
|
--it;
|
|
|
|
Toplevel *t = (*it);
|
|
|
|
if (t->isDeleted()) {
|
|
|
|
// a deleted window doesn't get mouse events
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!t->isLockScreen()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!t->readyForPainting()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
seat->setFocusedKeyboardSurface(t->surface());
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
state == InputRedirection::KeyboardKeyPressed ? seat->keyPressed(key) : seat->keyReleased(key);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} while (it != stacking.begin());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-02 13:44:18 +04:00
|
|
|
// TODO: pass to internal parts of KWin
|
2013-07-10 15:20:43 +04:00
|
|
|
#ifdef KWIN_BUILD_TABBOX
|
2015-03-27 16:40:57 +03:00
|
|
|
if (TabBox::TabBox::self() && TabBox::TabBox::self()->isGrabbed()) {
|
2013-07-10 15:20:43 +04:00
|
|
|
if (state == KWin::InputRedirection::KeyboardKeyPressed) {
|
|
|
|
TabBox::TabBox::self()->keyPress(m_xkb->modifiers() | m_xkb->toQtKey(m_xkb->toKeysym(key)));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2015-08-20 10:03:38 +03:00
|
|
|
auto toKeyEvent = [&] {
|
2013-07-02 13:44:18 +04:00
|
|
|
const xkb_keysym_t keysym = m_xkb->toKeysym(key);
|
|
|
|
// TODO: start auto-repeat
|
|
|
|
// TODO: add modifiers to the event
|
|
|
|
const QEvent::Type type = (state == KeyboardKeyPressed) ? QEvent::KeyPress : QEvent::KeyRelease;
|
|
|
|
QKeyEvent event(type, m_xkb->toQtKey(keysym), m_xkb->modifiers(), m_xkb->toString(keysym));
|
2015-08-20 10:03:38 +03:00
|
|
|
return event;
|
|
|
|
};
|
|
|
|
if (effects && static_cast< EffectsHandlerImpl* >(effects)->hasKeyboardGrab()) {
|
|
|
|
QKeyEvent event = toKeyEvent();
|
2013-07-02 13:44:18 +04:00
|
|
|
static_cast< EffectsHandlerImpl* >(effects)->grabbedKeyboardEvent(&event);
|
|
|
|
return;
|
|
|
|
}
|
2015-03-27 16:40:57 +03:00
|
|
|
if (workspace()) {
|
2015-10-23 16:32:51 +03:00
|
|
|
if (AbstractClient *c = workspace()->getMovingClient()) {
|
2016-01-29 11:52:01 +03:00
|
|
|
// TODO: handle key repeat
|
|
|
|
if (state == KeyboardKeyPressed) {
|
|
|
|
c->keyPressEvent(m_xkb->toQtKey(m_xkb->toKeysym(key)) | m_xkb->modifiers());
|
|
|
|
if (c->isMove() || c->isResize()) {
|
|
|
|
// only update if mode didn't end
|
|
|
|
c->updateMoveResize(m_globalPointer);
|
|
|
|
}
|
2015-08-21 11:49:06 +03:00
|
|
|
}
|
2015-03-27 16:40:57 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-08-20 10:03:38 +03:00
|
|
|
// TODO: Maybe it's better to select the top most visible internal window?
|
|
|
|
if (m_pointerInternalWindow) {
|
|
|
|
QKeyEvent event = toKeyEvent();
|
|
|
|
event.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(m_pointerInternalWindow.data(), &event);
|
|
|
|
return;
|
|
|
|
}
|
2013-07-02 16:00:08 +04:00
|
|
|
}
|
2013-07-10 13:41:16 +04:00
|
|
|
// process global shortcuts
|
|
|
|
if (state == KeyboardKeyPressed) {
|
|
|
|
if (m_shortcuts->processKey(m_xkb->modifiers(), m_xkb->toKeysym(key))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-02-26 18:06:48 +03:00
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
seat->setTimestamp(time);
|
2015-06-13 18:54:08 +03:00
|
|
|
state == InputRedirection::KeyboardKeyPressed ? seat->keyPressed(key) : seat->keyReleased(key);
|
2013-07-02 13:44:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processKeyboardModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group)
|
|
|
|
{
|
|
|
|
// TODO: send to proper Client and also send when active Client changes
|
2013-07-02 14:16:03 +04:00
|
|
|
Qt::KeyboardModifiers oldMods = keyboardModifiers();
|
2013-07-02 13:44:18 +04:00
|
|
|
m_xkb->updateModifiers(modsDepressed, modsLatched, modsLocked, group);
|
2013-07-02 14:16:03 +04:00
|
|
|
if (oldMods != keyboardModifiers()) {
|
|
|
|
emit keyboardModifiersChanged(keyboardModifiers(), oldMods);
|
|
|
|
}
|
2013-07-02 13:44:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processKeymapChange(int fd, uint32_t size)
|
|
|
|
{
|
|
|
|
// TODO: should we pass the keymap to our Clients? Or only to the currently active one and update
|
|
|
|
m_xkb->installKeymap(fd, size);
|
|
|
|
}
|
|
|
|
|
2015-03-25 16:50:14 +03:00
|
|
|
void InputRedirection::processTouchDown(qint32 id, const QPointF &pos, quint32 time)
|
|
|
|
{
|
|
|
|
// TODO: internal handling?
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
if (!seat->isTouchSequence()) {
|
|
|
|
updateTouchWindow(pos);
|
2015-07-09 17:31:55 +03:00
|
|
|
if (AbstractClient *c = dynamic_cast<AbstractClient*>(m_touchWindow.data())) {
|
|
|
|
// perform same handling as if it were a left click
|
|
|
|
bool wasAction = false;
|
|
|
|
const Options::MouseCommand command = c->getMouseCommand(Qt::LeftButton, &wasAction);
|
|
|
|
if (wasAction) {
|
|
|
|
// if no replay we filter out this touch point
|
|
|
|
if (!c->performMouseCommand(command, pos.toPoint())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-25 16:50:14 +03:00
|
|
|
}
|
|
|
|
m_touchIdMapper.insert(id, seat->touchDown(pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::updateTouchWindow(const QPointF &pos)
|
|
|
|
{
|
|
|
|
// TODO: handle pointer grab aka popups
|
|
|
|
Toplevel *t = findToplevel(pos.toPoint());
|
|
|
|
auto oldWindow = m_touchWindow;
|
|
|
|
if (!oldWindow.isNull() && t == oldWindow.data()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
// disconnect old surface
|
|
|
|
if (oldWindow) {
|
|
|
|
disconnect(oldWindow.data(), &Toplevel::geometryChanged, this, &InputRedirection::updateFocusedTouchPosition);
|
|
|
|
}
|
|
|
|
if (t && t->surface()) {
|
|
|
|
seat->setFocusedTouchSurface(t->surface(), t->pos());
|
|
|
|
connect(t, &Toplevel::geometryChanged, this, &InputRedirection::updateFocusedTouchPosition);
|
|
|
|
} else {
|
|
|
|
seat->setFocusedTouchSurface(nullptr);
|
|
|
|
t = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!t) {
|
|
|
|
m_touchWindow.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_touchWindow = QWeakPointer<Toplevel>(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InputRedirection::processTouchUp(qint32 id, quint32 time)
|
|
|
|
{
|
|
|
|
// TODO: internal handling?
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
auto it = m_touchIdMapper.constFind(id);
|
|
|
|
if (it != m_touchIdMapper.constEnd()) {
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->touchUp(it.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processTouchMotion(qint32 id, const QPointF &pos, quint32 time)
|
|
|
|
{
|
|
|
|
// TODO: internal handling?
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
auto it = m_touchIdMapper.constFind(id);
|
|
|
|
if (it != m_touchIdMapper.constEnd()) {
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->touchMove(it.value(), pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::cancelTouch()
|
|
|
|
{
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
seat->cancelTouchSequence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::touchFrame()
|
|
|
|
{
|
|
|
|
if (auto seat = findSeat()) {
|
|
|
|
seat->touchFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-26 13:40:30 +04:00
|
|
|
QEvent::Type InputRedirection::buttonStateToEvent(InputRedirection::PointerButtonState state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case KWin::InputRedirection::PointerButtonReleased:
|
|
|
|
return QEvent::MouseButtonRelease;
|
|
|
|
case KWin::InputRedirection::PointerButtonPressed:
|
|
|
|
return QEvent::MouseButtonPress;
|
|
|
|
}
|
|
|
|
return QEvent::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::MouseButton InputRedirection::buttonToQtMouseButton(uint32_t button)
|
|
|
|
{
|
|
|
|
switch (button) {
|
|
|
|
case BTN_LEFT:
|
|
|
|
return Qt::LeftButton;
|
|
|
|
case BTN_MIDDLE:
|
|
|
|
return Qt::MiddleButton;
|
|
|
|
case BTN_RIGHT:
|
|
|
|
return Qt::RightButton;
|
|
|
|
case BTN_BACK:
|
|
|
|
return Qt::XButton1;
|
|
|
|
case BTN_FORWARD:
|
|
|
|
return Qt::XButton2;
|
|
|
|
}
|
|
|
|
return Qt::NoButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::MouseButtons InputRedirection::qtButtonStates() const
|
|
|
|
{
|
|
|
|
Qt::MouseButtons buttons;
|
|
|
|
for (auto it = m_pointerButtons.constBegin(); it != m_pointerButtons.constEnd(); ++it) {
|
|
|
|
if (it.value() == KWin::InputRedirection::PointerButtonReleased) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Qt::MouseButton button = buttonToQtMouseButton(it.key());
|
|
|
|
if (button != Qt::NoButton) {
|
|
|
|
buttons |= button;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return buttons;
|
|
|
|
}
|
|
|
|
|
2015-06-03 18:56:59 +03:00
|
|
|
bool InputRedirection::areButtonsPressed() const
|
|
|
|
{
|
|
|
|
for (auto it = m_pointerButtons.constBegin(); it != m_pointerButtons.constEnd(); ++it) {
|
|
|
|
if (it.value() == KWin::InputRedirection::PointerButtonPressed) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-19 00:19:13 +03:00
|
|
|
static bool acceptsInput(Toplevel *t, const QPoint &pos)
|
|
|
|
{
|
|
|
|
const QRegion input = t->inputShape();
|
|
|
|
if (input.isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return input.translated(t->pos()).contains(pos);
|
|
|
|
}
|
|
|
|
|
2013-07-01 10:37:59 +04:00
|
|
|
Toplevel *InputRedirection::findToplevel(const QPoint &pos)
|
|
|
|
{
|
2015-03-20 16:43:47 +03:00
|
|
|
if (!Workspace::self()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-11-16 13:46:20 +03:00
|
|
|
const bool isScreenLocked = waylandServer() && waylandServer()->isScreenLocked();
|
2013-07-01 10:37:59 +04:00
|
|
|
// TODO: check whether the unmanaged wants input events at all
|
2015-11-16 13:46:20 +03:00
|
|
|
if (!isScreenLocked) {
|
|
|
|
const UnmanagedList &unmanaged = Workspace::self()->unmanagedList();
|
|
|
|
foreach (Unmanaged *u, unmanaged) {
|
|
|
|
if (u->geometry().contains(pos) && acceptsInput(u, pos)) {
|
|
|
|
return u;
|
|
|
|
}
|
2013-07-01 10:37:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const ToplevelList &stacking = Workspace::self()->stackingOrder();
|
|
|
|
if (stacking.isEmpty()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
auto it = stacking.end();
|
|
|
|
do {
|
|
|
|
--it;
|
|
|
|
Toplevel *t = (*it);
|
|
|
|
if (t->isDeleted()) {
|
|
|
|
// a deleted window doesn't get mouse events
|
|
|
|
continue;
|
|
|
|
}
|
2015-09-14 14:53:46 +03:00
|
|
|
if (AbstractClient *c = dynamic_cast<AbstractClient*>(t)) {
|
2013-07-01 10:37:59 +04:00
|
|
|
if (!c->isOnCurrentActivity() || !c->isOnCurrentDesktop() || c->isMinimized() || !c->isCurrentTab()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-05-18 16:30:10 +03:00
|
|
|
if (!t->readyForPainting()) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-11-16 13:46:20 +03:00
|
|
|
if (isScreenLocked) {
|
|
|
|
if (!t->isLockScreen() && !t->isInputMethod()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-06-19 00:19:13 +03:00
|
|
|
if (t->geometry().contains(pos) && acceptsInput(t, pos)) {
|
2013-07-01 10:37:59 +04:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
} while (it != stacking.begin());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t InputRedirection::toXPointerButton(uint32_t button)
|
|
|
|
{
|
|
|
|
switch (button) {
|
|
|
|
case BTN_LEFT:
|
|
|
|
return XCB_BUTTON_INDEX_1;
|
|
|
|
case BTN_RIGHT:
|
|
|
|
return XCB_BUTTON_INDEX_3;
|
|
|
|
case BTN_MIDDLE:
|
|
|
|
return XCB_BUTTON_INDEX_2;
|
|
|
|
default:
|
|
|
|
// TODO: add more buttons
|
|
|
|
return XCB_BUTTON_INDEX_ANY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t InputRedirection::toXPointerButton(InputRedirection::PointerAxis axis, qreal delta)
|
|
|
|
{
|
|
|
|
switch (axis) {
|
|
|
|
case PointerAxisVertical:
|
|
|
|
if (delta < 0) {
|
|
|
|
return 4;
|
|
|
|
} else {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
case PointerAxisHorizontal:
|
|
|
|
if (delta < 0) {
|
|
|
|
return 6;
|
|
|
|
} else {
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return XCB_BUTTON_INDEX_ANY;
|
|
|
|
}
|
2013-06-26 13:40:30 +04:00
|
|
|
|
2013-07-02 13:44:18 +04:00
|
|
|
Qt::KeyboardModifiers InputRedirection::keyboardModifiers() const
|
|
|
|
{
|
|
|
|
return m_xkb->modifiers();
|
|
|
|
}
|
|
|
|
|
2013-07-10 13:41:16 +04:00
|
|
|
void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action)
|
|
|
|
{
|
|
|
|
m_shortcuts->registerShortcut(action, shortcut);
|
2015-02-19 12:38:49 +03:00
|
|
|
registerShortcutForGlobalAccelTimestamp(action);
|
2013-07-10 13:41:16 +04:00
|
|
|
}
|
2013-07-02 13:44:18 +04:00
|
|
|
|
2013-07-15 00:52:58 +04:00
|
|
|
void InputRedirection::registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action)
|
|
|
|
{
|
|
|
|
m_shortcuts->registerPointerShortcut(action, modifiers, pointerButtons);
|
|
|
|
}
|
|
|
|
|
2013-07-15 13:26:56 +04:00
|
|
|
void InputRedirection::registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action)
|
|
|
|
{
|
|
|
|
m_shortcuts->registerAxisShortcut(action, modifiers, axis);
|
|
|
|
}
|
|
|
|
|
2015-06-26 14:47:08 +03:00
|
|
|
void InputRedirection::registerGlobalAccel(KGlobalAccelInterface *interface)
|
|
|
|
{
|
|
|
|
m_shortcuts->setKGlobalAccelInterface(interface);
|
|
|
|
}
|
|
|
|
|
2015-02-19 12:38:49 +03:00
|
|
|
void InputRedirection::registerShortcutForGlobalAccelTimestamp(QAction *action)
|
|
|
|
{
|
|
|
|
connect(action, &QAction::triggered, kwinApp(), [action] {
|
|
|
|
QVariant timestamp = action->property("org.kde.kglobalaccel.activationTimestamp");
|
|
|
|
bool ok = false;
|
|
|
|
const quint32 t = timestamp.toULongLong(&ok);
|
|
|
|
if (ok) {
|
|
|
|
kwinApp()->setX11Time(t);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-10-17 17:44:12 +04:00
|
|
|
static bool screenContainsPos(const QPointF &pos)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < screens()->count(); ++i) {
|
|
|
|
if (screens()->geometry(i).contains(pos.toPoint())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::updatePointerPosition(const QPointF &pos)
|
|
|
|
{
|
|
|
|
// verify that at least one screen contains the pointer position
|
2015-07-20 13:35:46 +03:00
|
|
|
QPointF p = pos;
|
|
|
|
if (!screenContainsPos(p)) {
|
|
|
|
// allow either x or y to pass
|
|
|
|
p = QPointF(m_globalPointer.x(), pos.y());
|
|
|
|
if (!screenContainsPos(p)) {
|
|
|
|
p = QPointF(pos.x(), m_globalPointer.y());
|
|
|
|
if (!screenContainsPos(p)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-10-17 17:44:12 +04:00
|
|
|
}
|
2015-07-20 13:35:46 +03:00
|
|
|
m_globalPointer = p;
|
2014-10-17 17:44:12 +04:00
|
|
|
emit globalPointerChanged(m_globalPointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::updatePointerAfterScreenChange()
|
|
|
|
{
|
|
|
|
if (screenContainsPos(m_globalPointer)) {
|
|
|
|
// pointer still on a screen
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// pointer no longer on a screen, reposition to closes screen
|
|
|
|
m_globalPointer = screens()->geometry(screens()->number(m_globalPointer.toPoint())).center();
|
|
|
|
emit globalPointerChanged(m_globalPointer);
|
|
|
|
}
|
|
|
|
|
2015-06-05 07:43:12 +03:00
|
|
|
void InputRedirection::warpPointer(const QPointF &pos)
|
|
|
|
{
|
2015-06-05 20:34:03 +03:00
|
|
|
if (supportsPointerWarping()) {
|
|
|
|
if (waylandServer()) {
|
|
|
|
waylandServer()->backend()->warpPointer(pos);
|
|
|
|
}
|
2015-06-05 07:43:12 +03:00
|
|
|
updatePointerPosition(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 20:34:03 +03:00
|
|
|
bool InputRedirection::supportsPointerWarping() const
|
|
|
|
{
|
|
|
|
if (waylandServer() && waylandServer()->backend()->supportsPointerWarping()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return m_pointerWarping;
|
|
|
|
}
|
|
|
|
|
2013-06-26 12:15:20 +04:00
|
|
|
} // namespace
|