2013-06-26 08:15:20 +00: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"
|
2016-02-15 12:42:48 +00:00
|
|
|
#include "keyboard_input.h"
|
2016-02-12 12:30:00 +00:00
|
|
|
#include "pointer_input.h"
|
2016-02-15 08:36:59 +00:00
|
|
|
#include "touch_input.h"
|
2013-07-01 06:37:59 +00:00
|
|
|
#include "client.h"
|
2013-06-26 09:40:30 +00:00
|
|
|
#include "effects.h"
|
2013-07-10 09:41:16 +00:00
|
|
|
#include "globalshortcuts.h"
|
2014-08-15 07:30:08 +00:00
|
|
|
#include "logind.h"
|
|
|
|
#include "main.h"
|
2013-07-10 11:20:43 +00:00
|
|
|
#ifdef KWIN_BUILD_TABBOX
|
|
|
|
#include "tabbox/tabbox.h"
|
|
|
|
#endif
|
2013-07-01 06:37:59 +00:00
|
|
|
#include "unmanaged.h"
|
2016-02-11 14:51:25 +00:00
|
|
|
#include "screenedge.h"
|
2014-10-20 13:01:12 +00:00
|
|
|
#include "screens.h"
|
2013-07-01 06:37:59 +00:00
|
|
|
#include "workspace.h"
|
2014-08-14 12:43:57 +00:00
|
|
|
#if HAVE_INPUT
|
|
|
|
#include "libinput/connection.h"
|
2016-05-24 08:57:57 +00:00
|
|
|
#include "libinput/device.h"
|
2014-08-14 12:43:57 +00:00
|
|
|
#endif
|
2016-04-07 07:24:17 +00:00
|
|
|
#include "platform.h"
|
2015-06-06 01:26:24 +00:00
|
|
|
#include "shell_client.h"
|
2015-02-26 14:32:44 +00:00
|
|
|
#include "wayland_server.h"
|
2015-07-06 02:44:07 +00:00
|
|
|
#include <KWayland/Server/display.h>
|
|
|
|
#include <KWayland/Server/fakeinput_interface.h>
|
2015-02-26 14:32:44 +00:00
|
|
|
#include <KWayland/Server/seat_interface.h>
|
2015-06-03 16:09:54 +00:00
|
|
|
#include <decorations/decoratedclient.h>
|
|
|
|
#include <KDecoration2/Decoration>
|
2016-02-16 11:54:21 +00:00
|
|
|
//screenlocker
|
|
|
|
#include <KScreenLocker/KsldApp>
|
2014-12-02 12:50:26 +00:00
|
|
|
// Qt
|
|
|
|
#include <QKeyEvent>
|
2016-02-09 16:18:58 +00:00
|
|
|
|
2014-03-28 08:41:48 +00:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2013-06-26 08:15:20 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2016-02-03 14:17:49 +00:00
|
|
|
InputEventFilter::InputEventFilter() = default;
|
|
|
|
|
|
|
|
InputEventFilter::~InputEventFilter()
|
|
|
|
{
|
|
|
|
if (input()) {
|
|
|
|
input()->uninstallInputEventFilter(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::pointerEvent(QMouseEvent *event, quint32 nativeButton)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
Q_UNUSED(nativeButton)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::keyEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::touchDown(quint32 id, const QPointF &point, quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(point)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::touchMotion(quint32 id, const QPointF &point, quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(point)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::touchUp(quint32 id, quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-05 12:35:33 +00:00
|
|
|
bool InputEventFilter::pinchGestureBegin(int fingerCount, quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(fingerCount)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::pinchGestureUpdate(qreal scale, qreal angleDelta, const QSizeF &delta, quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(scale)
|
|
|
|
Q_UNUSED(angleDelta)
|
|
|
|
Q_UNUSED(delta)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::pinchGestureEnd(quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::pinchGestureCancelled(quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::swipeGestureBegin(int fingerCount, quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(fingerCount)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::swipeGestureUpdate(const QSizeF &delta, quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(delta)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::swipeGestureEnd(quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::swipeGestureCancelled(quint32 time)
|
|
|
|
{
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-15 06:47:01 +00:00
|
|
|
void InputEventFilter::passToWaylandServer(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
Q_ASSERT(waylandServer());
|
|
|
|
if (event->isAutoRepeat()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::KeyPress:
|
|
|
|
waylandServer()->seat()->keyPressed(event->nativeScanCode());
|
|
|
|
break;
|
|
|
|
case QEvent::KeyRelease:
|
|
|
|
waylandServer()->seat()->keyReleased(event->nativeScanCode());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-03 14:17:49 +00:00
|
|
|
#if HAVE_INPUT
|
|
|
|
class VirtualTerminalFilter : public InputEventFilter {
|
|
|
|
public:
|
|
|
|
bool keyEvent(QKeyEvent *event) override {
|
|
|
|
// really on press and not on release? X11 switches on press.
|
2016-02-19 06:53:20 +00:00
|
|
|
if (event->type() == QEvent::KeyPress && !event->isAutoRepeat()) {
|
2016-02-03 14:17:49 +00:00
|
|
|
const xkb_keysym_t keysym = event->nativeVirtualKey();
|
|
|
|
if (keysym >= XKB_KEY_XF86Switch_VT_1 && keysym <= XKB_KEY_XF86Switch_VT_12) {
|
2016-04-19 07:36:28 +00:00
|
|
|
LogindIntegration::self()->switchVirtualTerminal(keysym - XKB_KEY_XF86Switch_VT_1 + 1);
|
2016-02-03 14:17:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-03-10 19:30:49 +00:00
|
|
|
class TerminateServerFilter : public InputEventFilter {
|
|
|
|
public:
|
|
|
|
bool keyEvent(QKeyEvent *event) override {
|
|
|
|
if (event->type() == QEvent::KeyPress && !event->isAutoRepeat()) {
|
|
|
|
if (event->nativeVirtualKey() == XKB_KEY_Terminate_Server) {
|
|
|
|
qCWarning(KWIN_CORE) << "Request to terminate server";
|
|
|
|
QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-03 14:17:49 +00:00
|
|
|
class LockScreenFilter : public InputEventFilter {
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
if (!waylandServer()->isScreenLocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(event->timestamp());
|
|
|
|
if (event->type() == QEvent::MouseMove) {
|
2016-02-09 16:18:58 +00:00
|
|
|
if (event->buttons() == Qt::NoButton) {
|
|
|
|
// update pointer window only if no button is pressed
|
2016-02-12 12:30:00 +00:00
|
|
|
input()->pointer()->update();
|
2016-02-09 16:18:58 +00:00
|
|
|
}
|
|
|
|
if (pointerSurfaceAllowed()) {
|
|
|
|
seat->setPointerPos(event->screenPos().toPoint());
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
} else if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease) {
|
2016-02-09 16:18:58 +00:00
|
|
|
if (pointerSurfaceAllowed()) {
|
|
|
|
event->type() == QEvent::MouseButtonPress ? seat->pointerButtonPressed(nativeButton) : seat->pointerButtonReleased(nativeButton);
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
|
|
|
if (!waylandServer()->isScreenLocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
2016-02-09 16:18:58 +00:00
|
|
|
if (pointerSurfaceAllowed()) {
|
|
|
|
seat->setTimestamp(event->timestamp());
|
|
|
|
const Qt::Orientation orientation = event->angleDelta().x() == 0 ? Qt::Vertical : Qt::Horizontal;
|
|
|
|
seat->pointerAxis(orientation, orientation == Qt::Horizontal ? event->angleDelta().x() : event->angleDelta().y());
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool keyEvent(QKeyEvent * event) override {
|
|
|
|
if (!waylandServer()->isScreenLocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-19 06:53:20 +00:00
|
|
|
if (event->isAutoRepeat()) {
|
|
|
|
// wayland client takes care of it
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-16 11:54:21 +00:00
|
|
|
// send event to KSldApp for global accel
|
|
|
|
// if event is set to accepted it means a whitelisted shortcut was triggered
|
|
|
|
// in that case we filter it out and don't process it further
|
|
|
|
event->setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(ScreenLocker::KSldApp::self(), event);
|
|
|
|
if (event->isAccepted()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// continue normal processing
|
2016-02-15 12:42:48 +00:00
|
|
|
input()->keyboard()->update();
|
2016-02-16 16:14:28 +00:00
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(event->timestamp());
|
2016-02-10 13:40:56 +00:00
|
|
|
if (!keyboardSurfaceAllowed()) {
|
|
|
|
// don't pass event to seat
|
|
|
|
return true;
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::KeyPress:
|
|
|
|
seat->keyPressed(event->nativeScanCode());
|
|
|
|
break;
|
|
|
|
case QEvent::KeyRelease:
|
|
|
|
seat->keyReleased(event->nativeScanCode());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-15 09:36:42 +00:00
|
|
|
bool touchDown(quint32 id, const QPointF &pos, quint32 time) override {
|
2016-02-10 15:43:06 +00:00
|
|
|
if (!waylandServer()->isScreenLocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
if (!seat->isTouchSequence()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
input()->touch()->update(pos);
|
2016-02-10 15:43:06 +00:00
|
|
|
}
|
|
|
|
if (touchSurfaceAllowed()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
input()->touch()->insertId(id, seat->touchDown(pos));
|
2016-02-10 15:43:06 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-15 09:36:42 +00:00
|
|
|
bool touchMotion(quint32 id, const QPointF &pos, quint32 time) override {
|
2016-02-10 15:43:06 +00:00
|
|
|
if (!waylandServer()->isScreenLocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
if (touchSurfaceAllowed()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
const qint32 kwaylandId = input()->touch()->mappedId(id);
|
2016-02-10 15:43:06 +00:00
|
|
|
if (kwaylandId != -1) {
|
|
|
|
seat->touchMove(kwaylandId, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-15 09:36:42 +00:00
|
|
|
bool touchUp(quint32 id, quint32 time) override {
|
2016-02-10 15:43:06 +00:00
|
|
|
if (!waylandServer()->isScreenLocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
if (touchSurfaceAllowed()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
const qint32 kwaylandId = input()->touch()->mappedId(id);
|
2016-02-10 15:43:06 +00:00
|
|
|
if (kwaylandId != -1) {
|
|
|
|
seat->touchUp(kwaylandId);
|
2016-02-15 08:36:59 +00:00
|
|
|
input()->touch()->removeId(id);
|
2016-02-10 15:43:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-09 16:18:58 +00:00
|
|
|
private:
|
2016-02-10 13:40:56 +00:00
|
|
|
bool surfaceAllowed(KWayland::Server::SurfaceInterface *(KWayland::Server::SeatInterface::*method)() const) const {
|
|
|
|
if (KWayland::Server::SurfaceInterface *s = (waylandServer()->seat()->*method)()) {
|
2016-02-09 16:18:58 +00:00
|
|
|
if (Toplevel *t = waylandServer()->findClient(s)) {
|
|
|
|
return t->isLockScreen() || t->isInputMethod();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-10 13:40:56 +00:00
|
|
|
bool pointerSurfaceAllowed() const {
|
|
|
|
return surfaceAllowed(&KWayland::Server::SeatInterface::focusedPointerSurface);
|
|
|
|
}
|
|
|
|
bool keyboardSurfaceAllowed() const {
|
|
|
|
return surfaceAllowed(&KWayland::Server::SeatInterface::focusedKeyboardSurface);
|
|
|
|
}
|
2016-02-10 15:43:06 +00:00
|
|
|
bool touchSurfaceAllowed() const {
|
|
|
|
return surfaceAllowed(&KWayland::Server::SeatInterface::focusedTouchSurface);
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class EffectsFilter : public InputEventFilter {
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
Q_UNUSED(nativeButton)
|
|
|
|
if (!effects) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast<EffectsHandlerImpl*>(effects)->checkInputWindowEvent(event);
|
|
|
|
}
|
|
|
|
bool keyEvent(QKeyEvent *event) override {
|
|
|
|
if (!effects || !static_cast< EffectsHandlerImpl* >(effects)->hasKeyboardGrab()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-11 09:17:09 +00:00
|
|
|
waylandServer()->seat()->setFocusedKeyboardSurface(nullptr);
|
2016-09-15 06:47:01 +00:00
|
|
|
passToWaylandServer(event);
|
2016-02-03 14:17:49 +00:00
|
|
|
static_cast< EffectsHandlerImpl* >(effects)->grabbedKeyboardEvent(event);
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-15 13:44:10 +00:00
|
|
|
bool touchDown(quint32 id, const QPointF &pos, quint32 time) override {
|
|
|
|
if (!effects) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast< EffectsHandlerImpl* >(effects)->touchDown(id, pos, time);
|
|
|
|
}
|
|
|
|
bool touchMotion(quint32 id, const QPointF &pos, quint32 time) override {
|
|
|
|
if (!effects) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast< EffectsHandlerImpl* >(effects)->touchMotion(id, pos, time);
|
|
|
|
}
|
|
|
|
bool touchUp(quint32 id, quint32 time) override {
|
|
|
|
if (!effects) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast< EffectsHandlerImpl* >(effects)->touchUp(id, time);
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MoveResizeFilter : public InputEventFilter {
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
Q_UNUSED(nativeButton)
|
|
|
|
AbstractClient *c = workspace()->getMovingClient();
|
|
|
|
if (!c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::MouseMove:
|
|
|
|
c->updateMoveResize(event->screenPos().toPoint());
|
|
|
|
break;
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
if (event->buttons() == Qt::NoButton) {
|
|
|
|
c->endMoveResize();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
|
|
|
Q_UNUSED(event)
|
|
|
|
// filter out while moving a window
|
|
|
|
return workspace()->getMovingClient() != nullptr;
|
|
|
|
}
|
|
|
|
bool keyEvent(QKeyEvent *event) override {
|
|
|
|
AbstractClient *c = workspace()->getMovingClient();
|
|
|
|
if (!c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (event->type() == QEvent::KeyPress) {
|
|
|
|
c->keyPressEvent(event->key() | event->modifiers());
|
|
|
|
if (c->isMove() || c->isResize()) {
|
|
|
|
// only update if mode didn't end
|
|
|
|
c->updateMoveResize(input()->globalPointer());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GlobalShortcutFilter : public InputEventFilter {
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
Q_UNUSED(nativeButton);
|
|
|
|
if (event->type() == QEvent::MouseButtonPress) {
|
|
|
|
if (input()->shortcuts()->processPointerPressed(event->modifiers(), event->buttons())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
|
|
|
if (event->modifiers() == Qt::NoModifier) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PointerAxisDirection direction = PointerAxisUp;
|
|
|
|
if (event->angleDelta().x() < 0) {
|
|
|
|
direction = PointerAxisRight;
|
|
|
|
} else if (event->angleDelta().x() > 0) {
|
|
|
|
direction = PointerAxisLeft;
|
|
|
|
} else if (event->angleDelta().y() < 0) {
|
|
|
|
direction = PointerAxisDown;
|
|
|
|
} else if (event->angleDelta().y() > 0) {
|
|
|
|
direction = PointerAxisUp;
|
|
|
|
}
|
|
|
|
return input()->shortcuts()->processAxis(event->modifiers(), direction);
|
|
|
|
}
|
|
|
|
bool keyEvent(QKeyEvent *event) override {
|
2016-08-12 05:45:31 +00:00
|
|
|
if (event->type() == QEvent::KeyPress) {
|
2016-09-15 07:02:38 +00:00
|
|
|
return input()->shortcuts()->processKey(input()->keyboard()->xkb()->modifiersRelevantForGlobalShortcuts(), event->nativeVirtualKey(), event->key());
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class InternalWindowEventFilter : public InputEventFilter {
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
Q_UNUSED(nativeButton)
|
2016-02-12 12:30:00 +00:00
|
|
|
auto internal = input()->pointer()->internalWindow();
|
2016-02-03 14:17:49 +00:00
|
|
|
if (!internal) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-09 12:48:10 +00:00
|
|
|
if (event->buttons() == Qt::NoButton) {
|
|
|
|
// update pointer window only if no button is pressed
|
|
|
|
input()->pointer()->update();
|
|
|
|
}
|
|
|
|
if (!internal) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
QMouseEvent e(event->type(),
|
|
|
|
event->pos() - internal->position(),
|
|
|
|
event->globalPos(),
|
|
|
|
event->button(), event->buttons(), event->modifiers());
|
|
|
|
e.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(internal.data(), &e);
|
|
|
|
return e.isAccepted();
|
|
|
|
}
|
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
2016-02-12 12:30:00 +00:00
|
|
|
auto internal = input()->pointer()->internalWindow();
|
2016-02-03 14:17:49 +00:00
|
|
|
if (!internal) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const QPointF localPos = event->globalPosF() - QPointF(internal->x(), internal->y());
|
|
|
|
const Qt::Orientation orientation = (event->angleDelta().x() != 0) ? Qt::Horizontal : Qt::Vertical;
|
|
|
|
const int delta = event->angleDelta().x() != 0 ? event->angleDelta().x() : event->angleDelta().y();
|
|
|
|
QWheelEvent e(localPos, event->globalPosF(), QPoint(),
|
2016-11-03 12:10:02 +00:00
|
|
|
event->angleDelta() * -1,
|
|
|
|
delta * -1,
|
2016-02-03 14:17:49 +00:00
|
|
|
orientation,
|
|
|
|
event->buttons(),
|
|
|
|
event->modifiers());
|
|
|
|
e.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(internal.data(), &e);
|
|
|
|
return e.isAccepted();
|
|
|
|
}
|
|
|
|
bool keyEvent(QKeyEvent *event) override {
|
2016-02-17 12:34:24 +00:00
|
|
|
const auto &internalClients = waylandServer()->internalClients();
|
|
|
|
if (internalClients.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QWindow *found = nullptr;
|
|
|
|
auto it = internalClients.end();
|
|
|
|
do {
|
|
|
|
it--;
|
|
|
|
if (QWindow *w = (*it)->internalWindow()) {
|
|
|
|
if (!w->isVisible()) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-09 21:21:10 +00:00
|
|
|
if (!screens()->geometry().contains(w->geometry())) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-29 13:34:02 +00:00
|
|
|
if (w->property("_q_showWithoutActivating").toBool()) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-02-17 12:34:24 +00:00
|
|
|
found = w;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (it != internalClients.begin());
|
|
|
|
if (!found) {
|
2016-02-03 14:17:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
event->setAccepted(false);
|
2016-08-11 09:17:09 +00:00
|
|
|
if (QCoreApplication::sendEvent(found, event)) {
|
|
|
|
waylandServer()->seat()->setFocusedKeyboardSurface(nullptr);
|
2016-09-15 06:47:01 +00:00
|
|
|
passToWaylandServer(event);
|
2016-08-11 09:17:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
2016-05-23 15:07:08 +00:00
|
|
|
|
|
|
|
bool touchDown(quint32 id, const QPointF &pos, quint32 time) override {
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
if (seat->isTouchSequence()) {
|
|
|
|
// something else is getting the events
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto touch = input()->touch();
|
|
|
|
if (touch->internalPressId() != -1) {
|
|
|
|
// already on a decoration, ignore further touch points, but filter out
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// a new touch point
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
touch->update(pos);
|
|
|
|
auto internal = touch->internalWindow();
|
|
|
|
if (!internal) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
touch->setInternalPressId(id);
|
|
|
|
// Qt's touch event API is rather complex, let's do fake mouse events instead
|
|
|
|
m_lastGlobalTouchPos = pos;
|
|
|
|
m_lastLocalTouchPos = pos - QPointF(internal->x(), internal->y());
|
|
|
|
QMouseEvent e(QEvent::MouseButtonPress, m_lastLocalTouchPos, pos, Qt::LeftButton, Qt::LeftButton, input()->keyboardModifiers());
|
|
|
|
e.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(internal.data(), &e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool touchMotion(quint32 id, const QPointF &pos, quint32 time) override {
|
|
|
|
auto touch = input()->touch();
|
|
|
|
auto internal = touch->internalWindow();
|
|
|
|
if (!internal) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (touch->internalPressId() == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
waylandServer()->seat()->setTimestamp(time);
|
|
|
|
if (touch->internalPressId() != qint32(id)) {
|
|
|
|
// ignore, but filter out
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
m_lastGlobalTouchPos = pos;
|
|
|
|
m_lastLocalTouchPos = pos - QPointF(internal->x(), internal->y());
|
|
|
|
QMouseEvent e(QEvent::MouseMove, m_lastLocalTouchPos, m_lastGlobalTouchPos, Qt::LeftButton, Qt::LeftButton, input()->keyboardModifiers());
|
|
|
|
QCoreApplication::instance()->sendEvent(internal.data(), &e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool touchUp(quint32 id, quint32 time) override {
|
|
|
|
auto touch = input()->touch();
|
|
|
|
auto internal = touch->internalWindow();
|
|
|
|
if (!internal) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (touch->internalPressId() == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
waylandServer()->seat()->setTimestamp(time);
|
|
|
|
if (touch->internalPressId() != qint32(id)) {
|
|
|
|
// ignore, but filter out
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// send mouse up
|
|
|
|
QMouseEvent e(QEvent::MouseButtonRelease, m_lastLocalTouchPos, m_lastGlobalTouchPos, Qt::LeftButton, Qt::MouseButtons(), input()->keyboardModifiers());
|
|
|
|
e.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(internal.data(), &e);
|
|
|
|
|
|
|
|
m_lastGlobalTouchPos = QPointF();
|
|
|
|
m_lastLocalTouchPos = QPointF();
|
|
|
|
input()->touch()->setInternalPressId(-1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
QPointF m_lastGlobalTouchPos;
|
|
|
|
QPointF m_lastLocalTouchPos;
|
2016-02-03 14:17:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DecorationEventFilter : public InputEventFilter {
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
Q_UNUSED(nativeButton)
|
2016-02-12 12:30:00 +00:00
|
|
|
auto decoration = input()->pointer()->decoration();
|
2016-02-03 14:17:49 +00:00
|
|
|
if (!decoration) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const QPointF p = event->globalPos() - decoration->client()->pos();
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::MouseMove: {
|
|
|
|
if (event->buttons() == Qt::NoButton) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QHoverEvent e(QEvent::HoverMove, p, p);
|
|
|
|
QCoreApplication::instance()->sendEvent(decoration->decoration(), &e);
|
2016-03-11 11:48:01 +00:00
|
|
|
decoration->client()->processDecorationMove(p.toPoint(), event->globalPos());
|
2016-02-03 14:17:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::MouseButtonRelease: {
|
|
|
|
QMouseEvent e(event->type(), p, event->globalPos(), event->button(), event->buttons(), event->modifiers());
|
|
|
|
e.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(decoration->decoration(), &e);
|
|
|
|
if (!e.isAccepted() && event->type() == QEvent::MouseButtonPress) {
|
|
|
|
decoration->client()->processDecorationButtonPress(&e);
|
|
|
|
}
|
|
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
decoration->client()->processDecorationButtonRelease(&e);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
2016-02-12 12:30:00 +00:00
|
|
|
auto decoration = input()->pointer()->decoration();
|
2016-02-03 14:17:49 +00:00
|
|
|
if (!decoration) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const QPointF localPos = event->globalPosF() - decoration->client()->pos();
|
|
|
|
const Qt::Orientation orientation = (event->angleDelta().x() != 0) ? Qt::Horizontal : Qt::Vertical;
|
|
|
|
const int delta = event->angleDelta().x() != 0 ? event->angleDelta().x() : event->angleDelta().y();
|
|
|
|
QWheelEvent e(localPos, event->globalPosF(), QPoint(),
|
|
|
|
event->angleDelta(),
|
|
|
|
delta,
|
|
|
|
orientation,
|
|
|
|
event->buttons(),
|
|
|
|
event->modifiers());
|
|
|
|
e.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(decoration.data(), &e);
|
|
|
|
if (e.isAccepted()) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-12 08:28:40 +00:00
|
|
|
if ((orientation == Qt::Vertical) && decoration->client()->titlebarPositionUnderMouse()) {
|
2016-02-03 14:17:49 +00:00
|
|
|
decoration->client()->performMouseCommand(options->operationTitlebarMouseWheel(delta * -1),
|
|
|
|
event->globalPosF().toPoint());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-12 14:33:03 +00:00
|
|
|
bool touchDown(quint32 id, const QPointF &pos, quint32 time) override {
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
if (seat->isTouchSequence()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (input()->touch()->decorationPressId() != -1) {
|
|
|
|
// already on a decoration, ignore further touch points, but filter out
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
input()->touch()->update(pos);
|
|
|
|
auto decoration = input()->touch()->decoration();
|
|
|
|
if (!decoration) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
input()->touch()->setDecorationPressId(id);
|
|
|
|
m_lastGlobalTouchPos = pos;
|
|
|
|
m_lastLocalTouchPos = pos - decoration->client()->pos();
|
|
|
|
QMouseEvent e(QEvent::MouseButtonPress, m_lastLocalTouchPos, pos, Qt::LeftButton, Qt::LeftButton, input()->keyboardModifiers());
|
|
|
|
e.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(decoration->decoration(), &e);
|
|
|
|
if (!e.isAccepted()) {
|
|
|
|
decoration->client()->processDecorationButtonPress(&e);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool touchMotion(quint32 id, const QPointF &pos, quint32 time) override {
|
|
|
|
Q_UNUSED(time)
|
|
|
|
auto decoration = input()->touch()->decoration();
|
|
|
|
if (!decoration) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (input()->touch()->decorationPressId() == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-29 09:03:43 +00:00
|
|
|
if (input()->touch()->decorationPressId() != qint32(id)) {
|
2016-05-12 14:33:03 +00:00
|
|
|
// ignore, but filter out
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
m_lastGlobalTouchPos = pos;
|
|
|
|
m_lastLocalTouchPos = pos - decoration->client()->pos();
|
|
|
|
QHoverEvent e(QEvent::HoverMove, m_lastLocalTouchPos, m_lastLocalTouchPos);
|
|
|
|
QCoreApplication::instance()->sendEvent(decoration->decoration(), &e);
|
|
|
|
decoration->client()->processDecorationMove(m_lastLocalTouchPos.toPoint(), pos.toPoint());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool touchUp(quint32 id, quint32 time) override {
|
|
|
|
Q_UNUSED(time);
|
|
|
|
auto decoration = input()->touch()->decoration();
|
|
|
|
if (!decoration) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (input()->touch()->decorationPressId() == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-29 09:03:43 +00:00
|
|
|
if (input()->touch()->decorationPressId() != qint32(id)) {
|
2016-05-12 14:33:03 +00:00
|
|
|
// ignore, but filter out
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// send mouse up
|
|
|
|
QMouseEvent e(QEvent::MouseButtonRelease, m_lastLocalTouchPos, m_lastGlobalTouchPos, Qt::LeftButton, Qt::MouseButtons(), input()->keyboardModifiers());
|
|
|
|
e.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(decoration->decoration(), &e);
|
|
|
|
decoration->client()->processDecorationButtonRelease(&e);
|
|
|
|
|
|
|
|
m_lastGlobalTouchPos = QPointF();
|
|
|
|
m_lastLocalTouchPos = QPointF();
|
|
|
|
input()->touch()->setDecorationPressId(-1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
QPointF m_lastGlobalTouchPos;
|
|
|
|
QPointF m_lastLocalTouchPos;
|
2016-02-03 14:17:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef KWIN_BUILD_TABBOX
|
|
|
|
class TabBoxInputFilter : public InputEventFilter
|
|
|
|
{
|
|
|
|
public:
|
2016-03-04 13:15:27 +00:00
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 button) override {
|
|
|
|
Q_UNUSED(button)
|
|
|
|
if (!TabBox::TabBox::self() || !TabBox::TabBox::self()->isGrabbed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return TabBox::TabBox::self()->handleMouseEvent(event);
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
bool keyEvent(QKeyEvent *event) override {
|
|
|
|
if (!TabBox::TabBox::self() || !TabBox::TabBox::self()->isGrabbed()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-15 06:31:05 +00:00
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setFocusedKeyboardSurface(nullptr);
|
|
|
|
// pass the key event to the seat, so that it has a proper model of the currently hold keys
|
|
|
|
// this is important for combinations like alt+shift to ensure that shift is not considered pressed
|
2016-09-15 06:47:01 +00:00
|
|
|
passToWaylandServer(event);
|
2016-09-15 06:31:05 +00:00
|
|
|
|
2016-09-14 11:19:43 +00:00
|
|
|
if (event->type() == QEvent::KeyPress) {
|
2016-03-04 14:38:51 +00:00
|
|
|
TabBox::TabBox::self()->keyPress(event->modifiers() | event->key());
|
2016-09-14 11:19:43 +00:00
|
|
|
} else if (input()->keyboard()->xkb()->modifiersRelevantForGlobalShortcuts() == Qt::NoModifier) {
|
|
|
|
TabBox::TabBox::self()->modifiersReleased();
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-04 13:15:27 +00:00
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
|
|
|
if (!TabBox::TabBox::self() || !TabBox::TabBox::self()->isGrabbed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return TabBox::TabBox::self()->handleWheelEvent(event);
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-02-11 14:51:25 +00:00
|
|
|
class ScreenEdgeInputFilter : public InputEventFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
Q_UNUSED(nativeButton)
|
|
|
|
ScreenEdges::self()->isEntered(event);
|
|
|
|
// always forward
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-18 08:57:47 +00:00
|
|
|
/**
|
|
|
|
* This filter implements window actions. If the event should not be passed to the
|
|
|
|
* current pointer window it will filter out the event
|
|
|
|
**/
|
|
|
|
class WindowActionInputFilter : public InputEventFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
Q_UNUSED(nativeButton)
|
|
|
|
if (event->type() != QEvent::MouseButtonPress) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
AbstractClient *c = dynamic_cast<AbstractClient*>(input()->pointer()->window().data());
|
|
|
|
if (!c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool wasAction = false;
|
|
|
|
Options::MouseCommand command = Options::MouseNothing;
|
|
|
|
if (event->modifiers() == options->commandAllModifier()) {
|
|
|
|
wasAction = true;
|
|
|
|
switch (event->button()) {
|
|
|
|
case Qt::LeftButton:
|
|
|
|
command = options->commandAll1();
|
|
|
|
break;
|
|
|
|
case Qt::MiddleButton:
|
|
|
|
command = options->commandAll2();
|
|
|
|
break;
|
|
|
|
case Qt::RightButton:
|
|
|
|
command = options->commandAll3();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2016-02-22 09:07:02 +00:00
|
|
|
command = c->getMouseCommand(event->button(), &wasAction);
|
2016-02-18 08:57:47 +00:00
|
|
|
}
|
|
|
|
if (wasAction) {
|
|
|
|
return !c->performMouseCommand(command, event->globalPos());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
|
|
|
if (event->angleDelta().y() == 0) {
|
|
|
|
// only actions on vertical scroll
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
AbstractClient *c = dynamic_cast<AbstractClient*>(input()->pointer()->window().data());
|
|
|
|
if (!c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool wasAction = false;
|
|
|
|
Options::MouseCommand command = Options::MouseNothing;
|
|
|
|
if (event->modifiers() == options->commandAllModifier()) {
|
|
|
|
wasAction = true;
|
2016-02-18 09:11:20 +00:00
|
|
|
command = options->operationWindowMouseWheel(-1 * event->angleDelta().y());
|
2016-02-18 08:57:47 +00:00
|
|
|
} else {
|
|
|
|
command = c->getWheelCommand(Qt::Vertical, &wasAction);
|
|
|
|
}
|
|
|
|
if (wasAction) {
|
|
|
|
return !c->performMouseCommand(command, event->globalPos());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool touchDown(quint32 id, const QPointF &pos, quint32 time) override {
|
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
if (seat->isTouchSequence()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
input()->touch()->update(pos);
|
|
|
|
AbstractClient *c = dynamic_cast<AbstractClient*>(input()->touch()->window().data());
|
|
|
|
if (!c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool wasAction = false;
|
|
|
|
const Options::MouseCommand command = c->getMouseCommand(Qt::LeftButton, &wasAction);
|
|
|
|
if (wasAction) {
|
|
|
|
return !c->performMouseCommand(command, pos.toPoint());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-03 14:17:49 +00:00
|
|
|
/**
|
|
|
|
* The remaining default input filter which forwards events to other windows
|
|
|
|
**/
|
|
|
|
class ForwardInputFilter : public InputEventFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(event->timestamp());
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::MouseMove:
|
|
|
|
if (event->buttons() == Qt::NoButton) {
|
|
|
|
// update pointer window only if no button is pressed
|
2016-02-12 12:30:00 +00:00
|
|
|
input()->pointer()->update();
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
seat->setPointerPos(event->globalPos());
|
|
|
|
break;
|
2016-02-18 08:57:47 +00:00
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
seat->pointerButtonPressed(nativeButton);
|
2016-02-03 14:17:49 +00:00
|
|
|
break;
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
seat->pointerButtonReleased(nativeButton);
|
|
|
|
if (event->buttons() == Qt::NoButton) {
|
2016-02-12 12:30:00 +00:00
|
|
|
input()->pointer()->update();
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(event->timestamp());
|
|
|
|
const Qt::Orientation orientation = event->angleDelta().x() == 0 ? Qt::Vertical : Qt::Horizontal;
|
2016-02-18 08:57:47 +00:00
|
|
|
seat->pointerAxis(orientation, orientation == Qt::Horizontal ? event->angleDelta().x() : event->angleDelta().y());
|
2016-02-03 14:17:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool keyEvent(QKeyEvent *event) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-19 06:53:20 +00:00
|
|
|
if (event->isAutoRepeat()) {
|
|
|
|
// handled by Wayland client
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
auto seat = waylandServer()->seat();
|
2016-02-15 12:42:48 +00:00
|
|
|
input()->keyboard()->update();
|
2016-02-03 14:17:49 +00:00
|
|
|
seat->setTimestamp(event->timestamp());
|
2016-09-15 06:47:01 +00:00
|
|
|
passToWaylandServer(event);
|
2016-02-03 14:17:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool touchDown(quint32 id, const QPointF &pos, quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
if (!seat->isTouchSequence()) {
|
2016-02-15 08:36:59 +00:00
|
|
|
input()->touch()->update(pos);
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
2016-02-15 08:36:59 +00:00
|
|
|
input()->touch()->insertId(id, seat->touchDown(pos));
|
2016-02-03 14:17:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool touchMotion(quint32 id, const QPointF &pos, quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
2016-02-15 08:36:59 +00:00
|
|
|
const qint32 kwaylandId = input()->touch()->mappedId(id);
|
2016-02-03 14:17:49 +00:00
|
|
|
if (kwaylandId != -1) {
|
|
|
|
seat->touchMove(kwaylandId, pos);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool touchUp(quint32 id, quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
2016-02-15 08:36:59 +00:00
|
|
|
const qint32 kwaylandId = input()->touch()->mappedId(id);
|
2016-02-03 14:17:49 +00:00
|
|
|
if (kwaylandId != -1) {
|
|
|
|
seat->touchUp(kwaylandId);
|
2016-02-15 08:36:59 +00:00
|
|
|
input()->touch()->removeId(id);
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-01 07:42:07 +00:00
|
|
|
class DragAndDropInputFilter : public InputEventFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
if (!seat->isDragPointer()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
seat->setTimestamp(event->timestamp());
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::MouseMove: {
|
|
|
|
if (Toplevel *t = input()->findToplevel(event->globalPos())) {
|
|
|
|
// TODO: consider decorations
|
|
|
|
if (t->surface() != seat->dragSurface()) {
|
|
|
|
if (AbstractClient *c = qobject_cast<AbstractClient*>(t)) {
|
|
|
|
workspace()->raiseClient(c);
|
|
|
|
}
|
|
|
|
seat->setPointerPos(event->globalPos());
|
|
|
|
seat->setDragTarget(t->surface(), event->globalPos(), t->inputTransformation());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// no window at that place, if we have a surface we need to reset
|
|
|
|
seat->setDragTarget(nullptr);
|
|
|
|
}
|
|
|
|
seat->setPointerPos(event->globalPos());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
seat->pointerButtonPressed(nativeButton);
|
|
|
|
break;
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
seat->pointerButtonReleased(nativeButton);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// TODO: should we pass through effects?
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
KWIN_SINGLETON_FACTORY(InputRedirection)
|
|
|
|
|
|
|
|
InputRedirection::InputRedirection(QObject *parent)
|
|
|
|
: QObject(parent)
|
2016-02-15 12:42:48 +00:00
|
|
|
, m_keyboard(new KeyboardInputRedirection(this))
|
2016-02-12 12:30:00 +00:00
|
|
|
, m_pointer(new PointerInputRedirection(this))
|
2016-02-15 08:36:59 +00:00
|
|
|
, m_touch(new TouchInputRedirection(this))
|
2013-07-10 09:41:16 +00:00
|
|
|
, m_shortcuts(new GlobalShortcutsManager(this))
|
2013-06-26 08:15:20 +00:00
|
|
|
{
|
2015-09-02 08:10:49 +00:00
|
|
|
qRegisterMetaType<KWin::InputRedirection::KeyboardKeyState>();
|
|
|
|
qRegisterMetaType<KWin::InputRedirection::PointerButtonState>();
|
|
|
|
qRegisterMetaType<KWin::InputRedirection::PointerAxis>();
|
2014-08-15 07:30:08 +00:00
|
|
|
#if HAVE_INPUT
|
2014-08-15 12:03:52 +00:00
|
|
|
if (Application::usesLibinput()) {
|
2016-04-19 07:43:23 +00:00
|
|
|
if (LogindIntegration::self()->hasSessionControl()) {
|
2015-04-15 15:47:56 +00:00
|
|
|
setupLibInput();
|
2014-08-15 07:30:08 +00:00
|
|
|
} else {
|
2016-04-19 07:43:23 +00:00
|
|
|
if (LogindIntegration::self()->isConnected()) {
|
|
|
|
LogindIntegration::self()->takeControl();
|
|
|
|
} else {
|
|
|
|
connect(LogindIntegration::self(), &LogindIntegration::connectedChanged, LogindIntegration::self(), &LogindIntegration::takeControl);
|
|
|
|
}
|
|
|
|
connect(LogindIntegration::self(), &LogindIntegration::hasSessionControlChanged, this,
|
|
|
|
[this] (bool sessionControl) {
|
|
|
|
if (sessionControl) {
|
|
|
|
setupLibInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2014-08-15 07:30:08 +00:00
|
|
|
}
|
2016-05-06 07:53:36 +00:00
|
|
|
m_inputConfig = KSharedConfig::openConfig(QStringLiteral("kcminputrc"));
|
2014-08-15 07:30:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-06-13 15:54:08 +00:00
|
|
|
connect(kwinApp(), &Application::workspaceCreated, this, &InputRedirection::setupWorkspace);
|
2015-09-15 08:29:06 +00:00
|
|
|
reconfigure();
|
2014-08-15 07:30:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InputRedirection::~InputRedirection()
|
|
|
|
{
|
|
|
|
s_self = NULL;
|
2016-02-03 14:17:49 +00:00
|
|
|
qDeleteAll(m_filters);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::installInputEventFilter(InputEventFilter *filter)
|
|
|
|
{
|
|
|
|
m_filters << filter;
|
|
|
|
}
|
|
|
|
|
2016-02-15 14:40:25 +00:00
|
|
|
void InputRedirection::prepandInputEventFilter(InputEventFilter *filter)
|
|
|
|
{
|
|
|
|
m_filters.prepend(filter);
|
|
|
|
}
|
|
|
|
|
2016-02-03 14:17:49 +00:00
|
|
|
void InputRedirection::uninstallInputEventFilter(InputEventFilter *filter)
|
|
|
|
{
|
|
|
|
m_filters.removeAll(filter);
|
2014-08-15 07:30:08 +00:00
|
|
|
}
|
|
|
|
|
2015-06-26 11:47:08 +00:00
|
|
|
void InputRedirection::init()
|
|
|
|
{
|
|
|
|
m_shortcuts->init();
|
|
|
|
}
|
|
|
|
|
2015-06-13 15:54:08 +00:00
|
|
|
void InputRedirection::setupWorkspace()
|
|
|
|
{
|
|
|
|
if (waylandServer()) {
|
2015-07-06 02:44:07 +00: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) {
|
2016-06-29 08:50:51 +00:00
|
|
|
Q_UNUSED(application)
|
|
|
|
Q_UNUSED(reason)
|
2015-07-06 02:44:07 +00:00
|
|
|
// TODO: make secure
|
|
|
|
device->setAuthentication(true);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::pointerMotionRequested, this,
|
|
|
|
[this] (const QSizeF &delta) {
|
|
|
|
// TODO: Fix time
|
2016-02-12 12:30:00 +00:00
|
|
|
m_pointer->processMotion(globalPointer() + QPointF(delta.width(), delta.height()), 0);
|
2015-07-06 02:44:07 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::pointerButtonPressRequested, this,
|
|
|
|
[this] (quint32 button) {
|
|
|
|
// TODO: Fix time
|
2016-02-12 12:30:00 +00:00
|
|
|
m_pointer->processButton(button, InputRedirection::PointerButtonPressed, 0);
|
2015-07-06 02:44:07 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::pointerButtonReleaseRequested, this,
|
|
|
|
[this] (quint32 button) {
|
|
|
|
// TODO: Fix time
|
2016-02-12 12:30:00 +00:00
|
|
|
m_pointer->processButton(button, InputRedirection::PointerButtonReleased, 0);
|
2015-07-06 02:44:07 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
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
|
2016-02-12 12:30:00 +00:00
|
|
|
m_pointer->processAxis(axis, delta, 0);
|
2015-07-06 02:44:07 +00:00
|
|
|
}
|
|
|
|
);
|
2016-06-03 11:14:25 +00:00
|
|
|
connect(device, &FakeInputDevice::touchDownRequested, this,
|
|
|
|
[this] (quint32 id, const QPointF &pos) {
|
|
|
|
// TODO: Fix time
|
|
|
|
m_touch->processDown(id, pos, 0);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::touchMotionRequested, this,
|
|
|
|
[this] (quint32 id, const QPointF &pos) {
|
|
|
|
// TODO: Fix time
|
|
|
|
m_touch->processMotion(id, pos, 0);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::touchUpRequested, this,
|
|
|
|
[this] (quint32 id) {
|
|
|
|
// TODO: Fix time
|
|
|
|
m_touch->processUp(id, 0);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::touchCancelRequested, this,
|
|
|
|
[this] () {
|
|
|
|
m_touch->cancel();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::touchFrameRequested, this,
|
|
|
|
[this] () {
|
|
|
|
m_touch->frame();
|
|
|
|
}
|
|
|
|
);
|
2015-07-06 02:44:07 +00:00
|
|
|
}
|
|
|
|
);
|
2015-09-15 08:29:06 +00:00
|
|
|
connect(workspace(), &Workspace::configChanged, this, &InputRedirection::reconfigure);
|
2016-02-09 16:18:58 +00:00
|
|
|
|
2016-02-15 12:42:48 +00:00
|
|
|
m_keyboard->init();
|
2016-02-12 12:30:00 +00:00
|
|
|
m_pointer->init();
|
2016-02-15 08:36:59 +00:00
|
|
|
m_touch->init();
|
2015-06-13 15:54:08 +00:00
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
setupInputFilters();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::setupInputFilters()
|
|
|
|
{
|
|
|
|
#if HAVE_INPUT
|
2016-04-19 07:43:23 +00:00
|
|
|
if (LogindIntegration::self()->hasSessionControl()) {
|
2016-02-03 14:17:49 +00:00
|
|
|
installInputEventFilter(new VirtualTerminalFilter);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (waylandServer()) {
|
2016-03-10 19:30:49 +00:00
|
|
|
installInputEventFilter(new TerminateServerFilter);
|
2016-03-01 07:42:07 +00:00
|
|
|
installInputEventFilter(new DragAndDropInputFilter);
|
2016-02-03 14:17:49 +00:00
|
|
|
installInputEventFilter(new LockScreenFilter);
|
|
|
|
}
|
2016-02-11 14:51:25 +00:00
|
|
|
installInputEventFilter(new ScreenEdgeInputFilter);
|
2016-02-03 14:17:49 +00:00
|
|
|
installInputEventFilter(new EffectsFilter);
|
|
|
|
installInputEventFilter(new MoveResizeFilter);
|
|
|
|
#ifdef KWIN_BUILD_TABBOX
|
|
|
|
installInputEventFilter(new TabBoxInputFilter);
|
|
|
|
#endif
|
2016-03-04 14:38:51 +00:00
|
|
|
installInputEventFilter(new GlobalShortcutFilter);
|
2016-02-03 14:17:49 +00:00
|
|
|
installInputEventFilter(new InternalWindowEventFilter);
|
|
|
|
installInputEventFilter(new DecorationEventFilter);
|
|
|
|
if (waylandServer()) {
|
2016-02-18 08:57:47 +00:00
|
|
|
installInputEventFilter(new WindowActionInputFilter);
|
2016-02-03 14:17:49 +00:00
|
|
|
installInputEventFilter(new ForwardInputFilter);
|
|
|
|
}
|
2015-06-13 15:54:08 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 08:29:06 +00:00
|
|
|
void InputRedirection::reconfigure()
|
|
|
|
{
|
|
|
|
#if HAVE_INPUT
|
|
|
|
if (Application::usesLibinput()) {
|
2016-05-06 07:53:36 +00:00
|
|
|
m_inputConfig->reparseConfiguration();
|
|
|
|
const auto config = m_inputConfig->group(QStringLiteral("keyboard"));
|
2015-09-15 08:29:06 +00:00
|
|
|
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 15:19:26 +00:00
|
|
|
static KWayland::Server::SeatInterface *findSeat()
|
|
|
|
{
|
|
|
|
auto server = waylandServer();
|
|
|
|
if (!server) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return server->seat();
|
|
|
|
}
|
|
|
|
|
2014-08-15 07:30:08 +00:00
|
|
|
void InputRedirection::setupLibInput()
|
|
|
|
{
|
2014-08-14 12:43:57 +00:00
|
|
|
#if HAVE_INPUT
|
2014-08-15 12:03:52 +00:00
|
|
|
if (!Application::usesLibinput()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-30 06:55:41 +00:00
|
|
|
if (m_libInput) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-14 12:43:57 +00:00
|
|
|
LibInput::Connection *conn = LibInput::Connection::create(this);
|
2015-03-30 06:55:41 +00:00
|
|
|
m_libInput = conn;
|
2014-08-14 12:43:57 +00:00
|
|
|
if (conn) {
|
2016-05-06 07:53:36 +00:00
|
|
|
conn->setInputConfig(m_inputConfig);
|
2016-10-05 09:50:20 +00:00
|
|
|
conn->updateLEDs(m_keyboard->xkb()->leds());
|
2014-08-14 12:43:57 +00:00
|
|
|
conn->setup();
|
2016-10-05 09:50:20 +00:00
|
|
|
connect(m_keyboard, &KeyboardInputRedirection::ledsChanged, conn, &LibInput::Connection::updateLEDs);
|
2015-09-02 09:32:26 +00:00
|
|
|
connect(conn, &LibInput::Connection::eventsRead, this,
|
|
|
|
[this] {
|
|
|
|
m_libInput->processEvents();
|
|
|
|
}, Qt::QueuedConnection
|
|
|
|
);
|
2016-02-12 12:30:00 +00:00
|
|
|
connect(conn, &LibInput::Connection::pointerButtonChanged, m_pointer, &PointerInputRedirection::processButton);
|
|
|
|
connect(conn, &LibInput::Connection::pointerAxisChanged, m_pointer, &PointerInputRedirection::processAxis);
|
2016-08-05 12:35:33 +00:00
|
|
|
connect(conn, &LibInput::Connection::pinchGestureBegin, m_pointer, &PointerInputRedirection::processPinchGestureBegin);
|
|
|
|
connect(conn, &LibInput::Connection::pinchGestureUpdate, m_pointer, &PointerInputRedirection::processPinchGestureUpdate);
|
|
|
|
connect(conn, &LibInput::Connection::pinchGestureEnd, m_pointer, &PointerInputRedirection::processPinchGestureEnd);
|
|
|
|
connect(conn, &LibInput::Connection::pinchGestureCancelled, m_pointer, &PointerInputRedirection::processPinchGestureCancelled);
|
|
|
|
connect(conn, &LibInput::Connection::swipeGestureBegin, m_pointer, &PointerInputRedirection::processSwipeGestureBegin);
|
|
|
|
connect(conn, &LibInput::Connection::swipeGestureUpdate, m_pointer, &PointerInputRedirection::processSwipeGestureUpdate);
|
|
|
|
connect(conn, &LibInput::Connection::swipeGestureEnd, m_pointer, &PointerInputRedirection::processSwipeGestureEnd);
|
|
|
|
connect(conn, &LibInput::Connection::swipeGestureCancelled, m_pointer, &PointerInputRedirection::processSwipeGestureCancelled);
|
2016-02-15 12:42:48 +00:00
|
|
|
connect(conn, &LibInput::Connection::keyChanged, m_keyboard, &KeyboardInputRedirection::processKey);
|
2014-10-17 07:21:38 +00:00
|
|
|
connect(conn, &LibInput::Connection::pointerMotion, this,
|
2016-05-24 08:57:57 +00:00
|
|
|
[this] (QPointF delta, uint32_t time, LibInput::Device *device) {
|
|
|
|
m_pointer->processMotion(m_pointer->pos() + delta, time, device);
|
2014-10-17 07:21:38 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(conn, &LibInput::Connection::pointerMotionAbsolute, this,
|
2016-05-24 08:57:57 +00:00
|
|
|
[this] (QPointF orig, QPointF screen, uint32_t time, LibInput::Device *device) {
|
2014-10-17 07:21:38 +00:00
|
|
|
Q_UNUSED(orig)
|
2016-05-24 08:57:57 +00:00
|
|
|
m_pointer->processMotion(screen, time, device);
|
2014-10-17 07:21:38 +00:00
|
|
|
}
|
|
|
|
);
|
2016-02-15 08:36:59 +00:00
|
|
|
connect(conn, &LibInput::Connection::touchDown, m_touch, &TouchInputRedirection::processDown);
|
|
|
|
connect(conn, &LibInput::Connection::touchUp, m_touch, &TouchInputRedirection::processUp);
|
|
|
|
connect(conn, &LibInput::Connection::touchMotion, m_touch, &TouchInputRedirection::processMotion);
|
|
|
|
connect(conn, &LibInput::Connection::touchCanceled, m_touch, &TouchInputRedirection::cancel);
|
|
|
|
connect(conn, &LibInput::Connection::touchFrame, m_touch, &TouchInputRedirection::frame);
|
2014-10-17 09:57:14 +00:00
|
|
|
if (screens()) {
|
2015-03-30 06:55:41 +00:00
|
|
|
setupLibInputWithScreens();
|
|
|
|
} else {
|
|
|
|
connect(kwinApp(), &Application::screensCreated, this, &InputRedirection::setupLibInputWithScreens);
|
2014-10-17 09:57:14 +00:00
|
|
|
}
|
2015-03-26 15:19:26 +00:00
|
|
|
if (auto s = findSeat()) {
|
2016-08-03 06:31:58 +00:00
|
|
|
// Workaround for QTBUG-54371: if there is no real keyboard Qt doesn't request virtual keyboard
|
|
|
|
s->setHasKeyboard(true);
|
2015-03-26 15:19:26 +00:00
|
|
|
s->setHasPointer(conn->hasPointer());
|
|
|
|
s->setHasTouch(conn->hasTouch());
|
2016-05-25 08:55:07 +00:00
|
|
|
connect(conn, &LibInput::Connection::hasAlphaNumericKeyboardChanged, this,
|
2016-08-03 06:31:58 +00:00
|
|
|
[this] (bool set) {
|
2015-03-31 07:16:16 +00:00
|
|
|
if (m_libInput->isSuspended()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-03 06:31:58 +00:00
|
|
|
// TODO: this should update the seat, only workaround for QTBUG-54371
|
|
|
|
emit hasAlphaNumericKeyboardChanged(set);
|
2015-03-31 07:16:16 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
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 15:19:26 +00:00
|
|
|
}
|
2016-04-19 07:43:23 +00:00
|
|
|
connect(LogindIntegration::self(), &LogindIntegration::sessionActiveChanged, m_libInput,
|
2015-04-15 15:47:56 +00:00
|
|
|
[this] (bool active) {
|
|
|
|
if (!active) {
|
|
|
|
m_libInput->deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-02-26 14:32:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
2015-03-26 15:19:26 +00:00
|
|
|
}
|
2015-02-26 14:32:44 +00:00
|
|
|
|
2016-08-03 06:31:58 +00:00
|
|
|
bool InputRedirection::hasAlphaNumericKeyboard()
|
|
|
|
{
|
|
|
|
#if HAVE_INPUT
|
|
|
|
if (m_libInput) {
|
|
|
|
return m_libInput->hasAlphaNumericKeyboard();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-30 06:55:41 +00: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());
|
|
|
|
}
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
void InputRedirection::processPointerMotion(const QPointF &pos, uint32_t time)
|
|
|
|
{
|
2016-02-12 12:30:00 +00:00
|
|
|
m_pointer->processMotion(pos, time);
|
2013-06-26 08:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processPointerButton(uint32_t button, InputRedirection::PointerButtonState state, uint32_t time)
|
|
|
|
{
|
2016-02-12 12:30:00 +00:00
|
|
|
m_pointer->processButton(button, state, time);
|
2013-06-26 08:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processPointerAxis(InputRedirection::PointerAxis axis, qreal delta, uint32_t time)
|
|
|
|
{
|
2016-02-12 12:30:00 +00:00
|
|
|
m_pointer->processAxis(axis, delta, time);
|
2013-06-26 08:15:20 +00:00
|
|
|
}
|
|
|
|
|
2013-07-02 09:44:18 +00:00
|
|
|
void InputRedirection::processKeyboardKey(uint32_t key, InputRedirection::KeyboardKeyState state, uint32_t time)
|
|
|
|
{
|
2016-02-15 12:42:48 +00:00
|
|
|
m_keyboard->processKey(key, state, time);
|
2013-07-02 09:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processKeyboardModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group)
|
|
|
|
{
|
2016-02-15 12:42:48 +00:00
|
|
|
m_keyboard->processModifiers(modsDepressed, modsLatched, modsLocked, group);
|
2013-07-02 09:44:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processKeymapChange(int fd, uint32_t size)
|
|
|
|
{
|
2016-02-15 12:42:48 +00:00
|
|
|
m_keyboard->processKeymapChange(fd, size);
|
2013-07-02 09:44:18 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 13:50:14 +00:00
|
|
|
void InputRedirection::processTouchDown(qint32 id, const QPointF &pos, quint32 time)
|
|
|
|
{
|
2016-02-15 08:36:59 +00:00
|
|
|
m_touch->processDown(id, pos, time);
|
2015-03-25 13:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processTouchUp(qint32 id, quint32 time)
|
|
|
|
{
|
2016-02-15 08:36:59 +00:00
|
|
|
m_touch->processUp(id, time);
|
2015-03-25 13:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::processTouchMotion(qint32 id, const QPointF &pos, quint32 time)
|
|
|
|
{
|
2016-02-15 08:36:59 +00:00
|
|
|
m_touch->processMotion(id, pos, time);
|
2015-03-25 13:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::cancelTouch()
|
|
|
|
{
|
2016-02-15 08:36:59 +00:00
|
|
|
m_touch->cancel();
|
2015-03-25 13:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::touchFrame()
|
|
|
|
{
|
2016-02-15 08:36:59 +00:00
|
|
|
m_touch->frame();
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
|
2013-06-26 09:40:30 +00:00
|
|
|
Qt::MouseButtons InputRedirection::qtButtonStates() const
|
|
|
|
{
|
2016-02-12 12:30:00 +00:00
|
|
|
return m_pointer->buttons();
|
2013-06-26 09:40:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-18 21:19:13 +00: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 06:37:59 +00:00
|
|
|
Toplevel *InputRedirection::findToplevel(const QPoint &pos)
|
|
|
|
{
|
2015-03-20 13:43:47 +00:00
|
|
|
if (!Workspace::self()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-11-16 10:46:20 +00:00
|
|
|
const bool isScreenLocked = waylandServer() && waylandServer()->isScreenLocked();
|
2013-07-01 06:37:59 +00:00
|
|
|
// TODO: check whether the unmanaged wants input events at all
|
2015-11-16 10:46:20 +00:00
|
|
|
if (!isScreenLocked) {
|
2016-02-25 08:15:41 +00:00
|
|
|
// if an effect overrides the cursor we don't have a window to focus
|
|
|
|
if (effects && static_cast<EffectsHandlerImpl*>(effects)->isMouseInterception()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-11-16 10:46:20 +00:00
|
|
|
const UnmanagedList &unmanaged = Workspace::self()->unmanagedList();
|
|
|
|
foreach (Unmanaged *u, unmanaged) {
|
|
|
|
if (u->geometry().contains(pos) && acceptsInput(u, pos)) {
|
|
|
|
return u;
|
|
|
|
}
|
2013-07-01 06:37:59 +00: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 11:53:46 +00:00
|
|
|
if (AbstractClient *c = dynamic_cast<AbstractClient*>(t)) {
|
2016-07-04 13:06:20 +00:00
|
|
|
if (!c->isOnCurrentActivity() || !c->isOnCurrentDesktop() || c->isMinimized() || !c->isCurrentTab() || c->isHiddenInternal()) {
|
2013-07-01 06:37:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-05-18 13:30:10 +00:00
|
|
|
if (!t->readyForPainting()) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-11-16 10:46:20 +00:00
|
|
|
if (isScreenLocked) {
|
|
|
|
if (!t->isLockScreen() && !t->isInputMethod()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2016-09-15 09:44:32 +00:00
|
|
|
if (t->inputGeometry().contains(pos) && acceptsInput(t, pos)) {
|
2013-07-01 06:37:59 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
} while (it != stacking.begin());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-02 09:44:18 +00:00
|
|
|
Qt::KeyboardModifiers InputRedirection::keyboardModifiers() const
|
|
|
|
{
|
2016-02-15 12:42:48 +00:00
|
|
|
return m_keyboard->modifiers();
|
2013-07-02 09:44:18 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 09:41:16 +00:00
|
|
|
void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action)
|
|
|
|
{
|
|
|
|
m_shortcuts->registerShortcut(action, shortcut);
|
2015-02-19 09:38:49 +00:00
|
|
|
registerShortcutForGlobalAccelTimestamp(action);
|
2013-07-10 09:41:16 +00:00
|
|
|
}
|
2013-07-02 09:44:18 +00:00
|
|
|
|
2013-07-14 20:52:58 +00:00
|
|
|
void InputRedirection::registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action)
|
|
|
|
{
|
|
|
|
m_shortcuts->registerPointerShortcut(action, modifiers, pointerButtons);
|
|
|
|
}
|
|
|
|
|
2013-07-15 09:26:56 +00:00
|
|
|
void InputRedirection::registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action)
|
|
|
|
{
|
|
|
|
m_shortcuts->registerAxisShortcut(action, modifiers, axis);
|
|
|
|
}
|
|
|
|
|
2015-06-26 11:47:08 +00:00
|
|
|
void InputRedirection::registerGlobalAccel(KGlobalAccelInterface *interface)
|
|
|
|
{
|
|
|
|
m_shortcuts->setKGlobalAccelInterface(interface);
|
|
|
|
}
|
|
|
|
|
2015-02-19 09:38:49 +00: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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-02-12 12:30:00 +00:00
|
|
|
void InputRedirection::warpPointer(const QPointF &pos)
|
2014-10-17 13:44:12 +00:00
|
|
|
{
|
2016-02-12 12:30:00 +00:00
|
|
|
m_pointer->warp(pos);
|
2014-10-17 13:44:12 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 12:30:00 +00:00
|
|
|
bool InputRedirection::supportsPointerWarping() const
|
2014-10-17 13:44:12 +00:00
|
|
|
{
|
2016-02-12 12:30:00 +00:00
|
|
|
return m_pointer->supportsWarping();
|
2014-10-17 13:44:12 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 04:43:12 +00:00
|
|
|
|
2016-02-12 12:30:00 +00:00
|
|
|
QPointF InputRedirection::globalPointer() const
|
2015-06-05 17:34:03 +00:00
|
|
|
{
|
2016-02-12 12:30:00 +00:00
|
|
|
return m_pointer->pos();
|
2015-06-05 17:34:03 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 14:33:03 +00:00
|
|
|
InputDeviceHandler::InputDeviceHandler(InputRedirection *input)
|
|
|
|
: QObject(input)
|
|
|
|
, m_input(input)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDeviceHandler::~InputDeviceHandler() = default;
|
|
|
|
|
|
|
|
void InputDeviceHandler::updateDecoration(Toplevel *t, const QPointF &pos)
|
|
|
|
{
|
|
|
|
const auto oldDeco = m_decoration;
|
|
|
|
bool needsReset = waylandServer()->isScreenLocked();
|
|
|
|
if (AbstractClient *c = dynamic_cast<AbstractClient*>(t)) {
|
|
|
|
// check whether it's on a Decoration
|
|
|
|
if (c->decoratedClient()) {
|
|
|
|
const QRect clientRect = QRect(c->clientPos(), c->clientSize()).translated(c->pos());
|
|
|
|
if (!clientRect.contains(pos.toPoint())) {
|
|
|
|
m_decoration = c->decoratedClient();
|
|
|
|
} else {
|
|
|
|
needsReset = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
needsReset = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
needsReset = true;
|
|
|
|
}
|
|
|
|
if (needsReset) {
|
|
|
|
m_decoration.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool leftSend = false;
|
|
|
|
auto oldWindow = qobject_cast<AbstractClient*>(m_window.data());
|
|
|
|
if (oldWindow && (m_decoration && m_decoration->client() != oldWindow)) {
|
|
|
|
leftSend = true;
|
|
|
|
oldWindow->leaveEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldDeco && oldDeco != m_decoration) {
|
|
|
|
if (oldDeco->client() != t && !leftSend) {
|
|
|
|
leftSend = true;
|
|
|
|
oldDeco->client()->leaveEvent();
|
|
|
|
}
|
|
|
|
// send leave
|
|
|
|
QHoverEvent event(QEvent::HoverLeave, QPointF(), QPointF());
|
|
|
|
QCoreApplication::instance()->sendEvent(oldDeco->decoration(), &event);
|
|
|
|
}
|
|
|
|
if (m_decoration) {
|
|
|
|
if (m_decoration->client() != oldWindow) {
|
|
|
|
m_decoration->client()->enterEvent(pos.toPoint());
|
|
|
|
workspace()->updateFocusMousePosition(pos.toPoint());
|
|
|
|
}
|
|
|
|
const QPointF p = pos - t->pos();
|
|
|
|
QHoverEvent event(QEvent::HoverMove, p, p);
|
|
|
|
QCoreApplication::instance()->sendEvent(m_decoration->decoration(), &event);
|
|
|
|
m_decoration->client()->processDecorationMove(p.toPoint(), pos.toPoint());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-23 15:07:08 +00:00
|
|
|
void InputDeviceHandler::updateInternalWindow(const QPointF &pos)
|
|
|
|
{
|
|
|
|
const auto oldInternalWindow = m_internalWindow;
|
|
|
|
bool found = false;
|
|
|
|
// TODO: screen locked check without going through wayland server
|
|
|
|
bool needsReset = waylandServer()->isScreenLocked();
|
|
|
|
const auto &internalClients = waylandServer()->internalClients();
|
|
|
|
const bool change = m_internalWindow.isNull() || !(m_internalWindow->flags().testFlag(Qt::Popup) && m_internalWindow->isVisible());
|
|
|
|
if (!internalClients.isEmpty() && change) {
|
|
|
|
auto it = internalClients.end();
|
|
|
|
do {
|
|
|
|
it--;
|
|
|
|
if (QWindow *w = (*it)->internalWindow()) {
|
|
|
|
if (!w->isVisible()) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-05-09 12:48:10 +00:00
|
|
|
if ((*it)->geometry().contains(pos.toPoint())) {
|
2016-05-23 15:07:08 +00:00
|
|
|
// check input mask
|
|
|
|
const QRegion mask = w->mask().translated(w->geometry().topLeft());
|
|
|
|
if (!mask.isEmpty() && !mask.contains(pos.toPoint())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
m_internalWindow = QPointer<QWindow>(w);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (it != internalClients.begin());
|
|
|
|
if (!found) {
|
|
|
|
needsReset = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (needsReset) {
|
|
|
|
m_internalWindow.clear();
|
|
|
|
}
|
|
|
|
if (oldInternalWindow != m_internalWindow) {
|
|
|
|
// changed
|
|
|
|
if (oldInternalWindow) {
|
|
|
|
QEvent event(QEvent::Leave);
|
|
|
|
QCoreApplication::sendEvent(oldInternalWindow.data(), &event);
|
|
|
|
}
|
|
|
|
if (m_internalWindow) {
|
|
|
|
QEnterEvent event(pos - m_internalWindow->position(),
|
|
|
|
pos - m_internalWindow->position(),
|
|
|
|
pos);
|
|
|
|
QCoreApplication::sendEvent(m_internalWindow.data(), &event);
|
|
|
|
}
|
|
|
|
emit internalWindowChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
} // namespace
|