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>
|
2018-09-15 00:00:24 +00:00
|
|
|
Copyright (C) 2018 Roman Gilg <subdiff@gmail.com>
|
2020-01-14 16:17:18 +00:00
|
|
|
Copyright (C) 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2013-06-26 08:15:20 +00:00
|
|
|
|
|
|
|
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"
|
2019-12-01 17:51:15 +00:00
|
|
|
#include "effects.h"
|
|
|
|
#include "gestures.h"
|
|
|
|
#include "globalshortcuts.h"
|
2016-10-07 12:47:25 +00:00
|
|
|
#include "input_event.h"
|
2016-12-27 19:16:50 +00:00
|
|
|
#include "input_event_spy.h"
|
2016-02-15 12:42:48 +00:00
|
|
|
#include "keyboard_input.h"
|
2019-12-01 17:51:15 +00:00
|
|
|
#include "logind.h"
|
|
|
|
#include "main.h"
|
2016-02-12 12:30:00 +00:00
|
|
|
#include "pointer_input.h"
|
2019-12-01 17:51:15 +00:00
|
|
|
#include "tablet_input.h"
|
2018-12-01 13:52:47 +00:00
|
|
|
#include "touch_hide_cursor_spy.h"
|
2019-12-01 17:51:15 +00:00
|
|
|
#include "touch_input.h"
|
2019-09-24 08:48:08 +00:00
|
|
|
#include "x11client.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
|
|
|
#include "libinput/connection.h"
|
2016-05-24 08:57:57 +00:00
|
|
|
#include "libinput/device.h"
|
2016-04-07 07:24:17 +00:00
|
|
|
#include "platform.h"
|
2017-03-25 17:41:28 +00:00
|
|
|
#include "popup_input_filter.h"
|
2019-08-30 21:36:58 +00:00
|
|
|
#include "xdgshellclient.h"
|
2015-02-26 14:32:44 +00:00
|
|
|
#include "wayland_server.h"
|
2018-08-22 12:56:48 +00:00
|
|
|
#include "xwl/xwayland_interface.h"
|
2019-08-26 07:44:04 +00:00
|
|
|
#include "internal_client.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>
|
2016-10-07 12:47:25 +00:00
|
|
|
#include <KWayland/Server/relativepointer_interface.h>
|
2015-06-03 16:09:54 +00:00
|
|
|
#include <decorations/decoratedclient.h>
|
|
|
|
#include <KDecoration2/Decoration>
|
2017-05-06 23:40:48 +00:00
|
|
|
#include <KGlobalAccel>
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool InputEventFilter::touchDown(qint32 id, const QPointF &point, quint32 time)
|
2016-02-03 14:17:49 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(point)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool InputEventFilter::touchMotion(qint32 id, const QPointF &point, quint32 time)
|
2016-02-03 14:17:49 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(point)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool InputEventFilter::touchUp(qint32 id, quint32 time)
|
2016-02-03 14:17:49 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-12-27 19:25:36 +00:00
|
|
|
bool InputEventFilter::switchEvent(SwitchEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-01 17:51:15 +00:00
|
|
|
bool InputEventFilter::tabletToolEvent(QTabletEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::tabletToolButtonEvent(const QSet<uint> &pressedButtons)
|
|
|
|
{
|
|
|
|
Q_UNUSED(pressedButtons)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::tabletPadButtonEvent(const QSet<uint> &pressedButtons)
|
|
|
|
{
|
|
|
|
Q_UNUSED(pressedButtons)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::tabletPadStripEvent(int number, int position, bool isFinger)
|
|
|
|
{
|
|
|
|
Q_UNUSED(number)
|
|
|
|
Q_UNUSED(position)
|
|
|
|
Q_UNUSED(isFinger)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputEventFilter::tabletPadRingEvent(int number, int position, bool isFinger)
|
|
|
|
{
|
|
|
|
Q_UNUSED(number)
|
|
|
|
Q_UNUSED(position)
|
|
|
|
Q_UNUSED(isFinger)
|
|
|
|
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
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 (pointerSurfaceAllowed()) {
|
2018-09-15 00:00:24 +00:00
|
|
|
// TODO: should the pointer position always stay in sync, i.e. not do the check?
|
2016-02-09 16:18:58 +00:00
|
|
|
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()) {
|
2018-09-15 00:00:24 +00:00
|
|
|
// TODO: can we leak presses/releases here when we move the mouse in between from an allowed surface to
|
|
|
|
// disallowed one or vice versa?
|
2016-02-09 16:18:58 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchDown(qint32 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
|
|
|
input()->touch()->insertId(id, seat->touchDown(pos));
|
2016-02-10 15:43:06 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchMotion(qint32 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;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchUp(qint32 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-10-27 07:10:08 +00:00
|
|
|
bool pinchGestureBegin(int fingerCount, quint32 time) override {
|
|
|
|
Q_UNUSED(fingerCount)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
// no touchpad multi-finger gestures on lock screen
|
|
|
|
return waylandServer()->isScreenLocked();
|
|
|
|
}
|
|
|
|
bool pinchGestureUpdate(qreal scale, qreal angleDelta, const QSizeF &delta, quint32 time) override {
|
|
|
|
Q_UNUSED(scale)
|
|
|
|
Q_UNUSED(angleDelta)
|
|
|
|
Q_UNUSED(delta)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
// no touchpad multi-finger gestures on lock screen
|
|
|
|
return waylandServer()->isScreenLocked();
|
|
|
|
}
|
|
|
|
bool pinchGestureEnd(quint32 time) override {
|
|
|
|
Q_UNUSED(time)
|
|
|
|
// no touchpad multi-finger gestures on lock screen
|
|
|
|
return waylandServer()->isScreenLocked();
|
|
|
|
}
|
|
|
|
bool pinchGestureCancelled(quint32 time) override {
|
|
|
|
Q_UNUSED(time)
|
|
|
|
// no touchpad multi-finger gestures on lock screen
|
|
|
|
return waylandServer()->isScreenLocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool swipeGestureBegin(int fingerCount, quint32 time) override {
|
|
|
|
Q_UNUSED(fingerCount)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
// no touchpad multi-finger gestures on lock screen
|
|
|
|
return waylandServer()->isScreenLocked();
|
|
|
|
}
|
|
|
|
bool swipeGestureUpdate(const QSizeF &delta, quint32 time) override {
|
|
|
|
Q_UNUSED(delta)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
// no touchpad multi-finger gestures on lock screen
|
|
|
|
return waylandServer()->isScreenLocked();
|
|
|
|
}
|
|
|
|
bool swipeGestureEnd(quint32 time) override {
|
|
|
|
Q_UNUSED(time)
|
|
|
|
// no touchpad multi-finger gestures on lock screen
|
|
|
|
return waylandServer()->isScreenLocked();
|
|
|
|
}
|
|
|
|
bool swipeGestureCancelled(quint32 time) override {
|
|
|
|
Q_UNUSED(time)
|
|
|
|
// no touchpad multi-finger gestures on lock screen
|
|
|
|
return waylandServer()->isScreenLocked();
|
|
|
|
}
|
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);
|
|
|
|
}
|
2019-11-14 12:50:45 +00:00
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
|
|
|
if (!effects) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast<EffectsHandlerImpl*>(effects)->checkInputWindowEvent(event);
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchDown(qint32 id, const QPointF &pos, quint32 time) override {
|
2016-08-15 13:44:10 +00:00
|
|
|
if (!effects) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast< EffectsHandlerImpl* >(effects)->touchDown(id, pos, time);
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchMotion(qint32 id, const QPointF &pos, quint32 time) override {
|
2016-08-15 13:44:10 +00:00
|
|
|
if (!effects) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return static_cast< EffectsHandlerImpl* >(effects)->touchMotion(id, pos, time);
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchUp(qint32 id, quint32 time) override {
|
2016-08-15 13:44:10 +00:00
|
|
|
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)
|
2019-04-18 12:28:11 +00:00
|
|
|
AbstractClient *c = workspace()->moveResizeClient();
|
2016-02-03 14:17:49 +00:00
|
|
|
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
|
2019-04-18 12:28:11 +00:00
|
|
|
return workspace()->moveResizeClient() != nullptr;
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
bool keyEvent(QKeyEvent *event) override {
|
2019-04-18 12:28:11 +00:00
|
|
|
AbstractClient *c = workspace()->moveResizeClient();
|
2016-02-03 14:17:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchDown(qint32 id, const QPointF &pos, quint32 time) override {
|
2018-09-15 00:00:24 +00:00
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(pos)
|
|
|
|
Q_UNUSED(time)
|
2019-04-18 12:28:11 +00:00
|
|
|
AbstractClient *c = workspace()->moveResizeClient();
|
2018-09-15 00:00:24 +00:00
|
|
|
if (!c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchMotion(qint32 id, const QPointF &pos, quint32 time) override {
|
2018-09-15 00:00:24 +00:00
|
|
|
Q_UNUSED(time)
|
2019-04-18 12:28:11 +00:00
|
|
|
AbstractClient *c = workspace()->moveResizeClient();
|
2018-09-15 00:00:24 +00:00
|
|
|
if (!c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!m_set) {
|
|
|
|
m_id = id;
|
|
|
|
m_set = true;
|
|
|
|
}
|
|
|
|
if (m_id == id) {
|
|
|
|
c->updateMoveResize(pos.toPoint());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchUp(qint32 id, quint32 time) override {
|
2018-09-15 00:00:24 +00:00
|
|
|
Q_UNUSED(time)
|
2019-04-18 12:28:11 +00:00
|
|
|
AbstractClient *c = workspace()->moveResizeClient();
|
2018-09-15 00:00:24 +00:00
|
|
|
if (!c) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_id == id || !m_set) {
|
|
|
|
c->endMoveResize();
|
|
|
|
m_set = false;
|
|
|
|
// pass through to update decoration filter later on
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_set = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
private:
|
2019-08-11 19:57:45 +00:00
|
|
|
qint32 m_id = 0;
|
2018-09-15 00:00:24 +00:00
|
|
|
bool m_set = false;
|
2016-02-03 14:17:49 +00:00
|
|
|
};
|
|
|
|
|
2016-11-15 13:23:51 +00:00
|
|
|
class WindowSelectorFilter : public InputEventFilter {
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
Q_UNUSED(nativeButton)
|
|
|
|
if (!m_active) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
if (event->buttons() == Qt::NoButton) {
|
|
|
|
if (event->button() == Qt::RightButton) {
|
|
|
|
cancel();
|
|
|
|
} else {
|
2017-03-27 17:58:03 +00:00
|
|
|
accept(event->globalPos());
|
2016-11-15 13:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
|
|
|
Q_UNUSED(event)
|
|
|
|
// filter out while selecting a window
|
|
|
|
return m_active;
|
|
|
|
}
|
|
|
|
bool keyEvent(QKeyEvent *event) override {
|
|
|
|
Q_UNUSED(event)
|
|
|
|
if (!m_active) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
waylandServer()->seat()->setFocusedKeyboardSurface(nullptr);
|
|
|
|
passToWaylandServer(event);
|
|
|
|
|
|
|
|
if (event->type() == QEvent::KeyPress) {
|
|
|
|
// x11 variant does this on key press, so do the same
|
|
|
|
if (event->key() == Qt::Key_Escape) {
|
|
|
|
cancel();
|
|
|
|
} else if (event->key() == Qt::Key_Enter ||
|
|
|
|
event->key() == Qt::Key_Return ||
|
|
|
|
event->key() == Qt::Key_Space) {
|
2017-03-27 17:58:03 +00:00
|
|
|
accept(input()->globalPointer());
|
2016-11-15 13:23:51 +00:00
|
|
|
}
|
|
|
|
if (input()->supportsPointerWarping()) {
|
|
|
|
int mx = 0;
|
|
|
|
int my = 0;
|
|
|
|
if (event->key() == Qt::Key_Left) {
|
|
|
|
mx = -10;
|
|
|
|
}
|
|
|
|
if (event->key() == Qt::Key_Right) {
|
|
|
|
mx = 10;
|
|
|
|
}
|
|
|
|
if (event->key() == Qt::Key_Up) {
|
|
|
|
my = -10;
|
|
|
|
}
|
|
|
|
if (event->key() == Qt::Key_Down) {
|
|
|
|
my = 10;
|
|
|
|
}
|
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
|
|
|
mx /= 10;
|
|
|
|
my /= 10;
|
|
|
|
}
|
|
|
|
input()->warpPointer(input()->globalPointer() + QPointF(mx, my));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// filter out while selecting a window
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchDown(qint32 id, const QPointF &pos, quint32 time) override {
|
2017-03-27 17:58:03 +00:00
|
|
|
Q_UNUSED(time)
|
|
|
|
if (!isActive()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_touchPoints.insert(id, pos);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchMotion(qint32 id, const QPointF &pos, quint32 time) override {
|
2017-03-27 17:58:03 +00:00
|
|
|
Q_UNUSED(time)
|
|
|
|
if (!isActive()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto it = m_touchPoints.find(id);
|
|
|
|
if (it != m_touchPoints.end()) {
|
|
|
|
*it = pos;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchUp(qint32 id, quint32 time) override {
|
2017-03-27 17:58:03 +00:00
|
|
|
Q_UNUSED(time)
|
|
|
|
if (!isActive()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto it = m_touchPoints.find(id);
|
|
|
|
if (it != m_touchPoints.end()) {
|
|
|
|
const auto pos = it.value();
|
|
|
|
m_touchPoints.erase(it);
|
|
|
|
if (m_touchPoints.isEmpty()) {
|
|
|
|
accept(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-15 13:23:51 +00:00
|
|
|
bool isActive() const {
|
|
|
|
return m_active;
|
|
|
|
}
|
|
|
|
void start(std::function<void(KWin::Toplevel*)> callback) {
|
|
|
|
Q_ASSERT(!m_active);
|
|
|
|
m_active = true;
|
|
|
|
m_callback = callback;
|
|
|
|
input()->keyboard()->update();
|
2017-03-27 17:58:03 +00:00
|
|
|
input()->cancelTouch();
|
2016-11-15 13:23:51 +00:00
|
|
|
}
|
2016-11-23 14:53:17 +00:00
|
|
|
void start(std::function<void(const QPoint &)> callback) {
|
|
|
|
Q_ASSERT(!m_active);
|
|
|
|
m_active = true;
|
|
|
|
m_pointSelectionFallback = callback;
|
|
|
|
input()->keyboard()->update();
|
2017-03-27 17:58:03 +00:00
|
|
|
input()->cancelTouch();
|
2016-11-23 14:53:17 +00:00
|
|
|
}
|
2016-11-15 13:23:51 +00:00
|
|
|
private:
|
|
|
|
void deactivate() {
|
|
|
|
m_active = false;
|
|
|
|
m_callback = std::function<void(KWin::Toplevel*)>();
|
2016-11-23 14:53:17 +00:00
|
|
|
m_pointSelectionFallback = std::function<void(const QPoint &)>();
|
2016-11-15 13:23:51 +00:00
|
|
|
input()->pointer()->removeWindowSelectionCursor();
|
|
|
|
input()->keyboard()->update();
|
2017-03-27 17:58:03 +00:00
|
|
|
m_touchPoints.clear();
|
2016-11-15 13:23:51 +00:00
|
|
|
}
|
|
|
|
void cancel() {
|
2016-11-23 14:53:17 +00:00
|
|
|
if (m_callback) {
|
|
|
|
m_callback(nullptr);
|
|
|
|
}
|
|
|
|
if (m_pointSelectionFallback) {
|
|
|
|
m_pointSelectionFallback(QPoint(-1, -1));
|
|
|
|
}
|
2016-11-15 13:23:51 +00:00
|
|
|
deactivate();
|
|
|
|
}
|
2017-03-27 17:58:03 +00:00
|
|
|
void accept(const QPoint &pos) {
|
2016-11-23 14:53:17 +00:00
|
|
|
if (m_callback) {
|
|
|
|
// TODO: this ignores shaped windows
|
2017-03-27 17:58:03 +00:00
|
|
|
m_callback(input()->findToplevel(pos));
|
2016-11-23 14:53:17 +00:00
|
|
|
}
|
|
|
|
if (m_pointSelectionFallback) {
|
2017-03-27 17:58:03 +00:00
|
|
|
m_pointSelectionFallback(pos);
|
2016-11-23 14:53:17 +00:00
|
|
|
}
|
2016-11-15 13:23:51 +00:00
|
|
|
deactivate();
|
|
|
|
}
|
2017-03-27 17:58:03 +00:00
|
|
|
void accept(const QPointF &pos) {
|
|
|
|
accept(pos.toPoint());
|
|
|
|
}
|
2016-11-15 13:23:51 +00:00
|
|
|
bool m_active = false;
|
|
|
|
std::function<void(KWin::Toplevel*)> m_callback;
|
2016-11-23 14:53:17 +00:00
|
|
|
std::function<void(const QPoint &)> m_pointSelectionFallback;
|
2017-03-27 17:58:03 +00:00
|
|
|
QMap<quint32, QPointF> m_touchPoints;
|
2016-11-15 13:23:51 +00:00
|
|
|
};
|
|
|
|
|
2016-02-03 14:17:49 +00:00
|
|
|
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 {
|
2020-02-22 10:53:59 +00:00
|
|
|
if (event->type() == QEvent::KeyPress) {
|
2017-07-28 19:31:09 +00:00
|
|
|
return input()->shortcuts()->processKey(static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts(), event->key());
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-18 10:00:30 +00:00
|
|
|
bool swipeGestureBegin(int fingerCount, quint32 time) override {
|
|
|
|
Q_UNUSED(time)
|
|
|
|
input()->shortcuts()->processSwipeStart(fingerCount);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool swipeGestureUpdate(const QSizeF &delta, quint32 time) override {
|
|
|
|
Q_UNUSED(time)
|
|
|
|
input()->shortcuts()->processSwipeUpdate(delta);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool swipeGestureCancelled(quint32 time) override {
|
|
|
|
Q_UNUSED(time)
|
|
|
|
input()->shortcuts()->processSwipeCancel();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool swipeGestureEnd(quint32 time) override {
|
|
|
|
Q_UNUSED(time)
|
|
|
|
input()->shortcuts()->processSwipeEnd();
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
};
|
|
|
|
|
2018-02-11 09:49:31 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
enum class MouseAction {
|
|
|
|
ModifierOnly,
|
|
|
|
ModifierAndWindow
|
|
|
|
};
|
|
|
|
std::pair<bool, bool> performClientMouseAction(QMouseEvent *event, AbstractClient *client, MouseAction action = MouseAction::ModifierOnly)
|
|
|
|
{
|
|
|
|
Options::MouseCommand command = Options::MouseNothing;
|
|
|
|
bool wasAction = false;
|
|
|
|
if (static_cast<MouseEvent*>(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) {
|
2018-10-07 19:02:09 +00:00
|
|
|
if (!input()->pointer()->isConstrained() && !workspace()->globalShortcutsDisabled()) {
|
2018-10-06 16:03:19 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-02-11 09:49:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (action == MouseAction::ModifierAndWindow) {
|
|
|
|
command = client->getMouseCommand(event->button(), &wasAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wasAction) {
|
|
|
|
return std::make_pair(wasAction, !client->performMouseCommand(command, event->globalPos()));
|
|
|
|
}
|
|
|
|
return std::make_pair(wasAction, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<bool, bool> performClientWheelAction(QWheelEvent *event, AbstractClient *c, MouseAction action = MouseAction::ModifierOnly)
|
|
|
|
{
|
|
|
|
bool wasAction = false;
|
|
|
|
Options::MouseCommand command = Options::MouseNothing;
|
|
|
|
if (static_cast<WheelEvent*>(event)->modifiersRelevantForGlobalShortcuts() == options->commandAllModifier()) {
|
2018-10-07 19:02:09 +00:00
|
|
|
if (!input()->pointer()->isConstrained() && !workspace()->globalShortcutsDisabled()) {
|
|
|
|
wasAction = true;
|
|
|
|
command = options->operationWindowMouseWheel(-1 * event->angleDelta().y());
|
|
|
|
}
|
2018-02-11 09:49:31 +00:00
|
|
|
} else {
|
|
|
|
if (action == MouseAction::ModifierAndWindow) {
|
|
|
|
command = c->getWheelCommand(Qt::Vertical, &wasAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (wasAction) {
|
|
|
|
return std::make_pair(wasAction, !c->performMouseCommand(command, event->globalPos()));
|
|
|
|
}
|
|
|
|
return std::make_pair(wasAction, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-03 14:17:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-02-11 09:49:31 +00:00
|
|
|
// find client
|
|
|
|
switch (event->type())
|
|
|
|
{
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::MouseButtonRelease: {
|
2019-08-26 07:44:04 +00:00
|
|
|
auto s = qobject_cast<InternalClient *>(workspace()->findInternal(internal));
|
2018-02-11 09:49:31 +00:00
|
|
|
if (s && s->isDecorated()) {
|
|
|
|
// only perform mouse commands on decorated internal windows
|
|
|
|
const auto actionResult = performClientMouseAction(event, s);
|
|
|
|
if (actionResult.first) {
|
|
|
|
return actionResult.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
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;
|
|
|
|
}
|
2018-02-11 09:49:31 +00:00
|
|
|
if (event->angleDelta().y() != 0) {
|
2019-08-26 07:44:04 +00:00
|
|
|
auto s = qobject_cast<InternalClient *>(workspace()->findInternal(internal));
|
2018-02-11 09:49:31 +00:00
|
|
|
if (s && s->isDecorated()) {
|
|
|
|
// client window action only on vertical scrolling
|
|
|
|
const auto actionResult = performClientWheelAction(event, s);
|
|
|
|
if (actionResult.first) {
|
|
|
|
return actionResult.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
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 {
|
2019-08-26 07:44:04 +00:00
|
|
|
const QList<InternalClient *> &internalClients = workspace()->internalClients();
|
2016-02-17 12:34:24 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-01-02 20:51:18 +00:00
|
|
|
if (w->property("outputOnly").toBool()) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-01 14:21:12 +00:00
|
|
|
if (w->flags().testFlag(Qt::ToolTip)) {
|
|
|
|
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;
|
|
|
|
}
|
2017-07-22 10:49:57 +00:00
|
|
|
auto xkb = input()->keyboard()->xkb();
|
|
|
|
Qt::Key key = xkb->toQtKey(xkb->toKeysym(event->nativeScanCode()));
|
|
|
|
if (key == Qt::Key_Super_L || key == Qt::Key_Super_R) {
|
|
|
|
// workaround for QTBUG-62102
|
|
|
|
key = Qt::Key_Meta;
|
|
|
|
}
|
|
|
|
QKeyEvent internalEvent(event->type(), key,
|
|
|
|
event->modifiers(), event->nativeScanCode(), event->nativeVirtualKey(),
|
|
|
|
event->nativeModifiers(), event->text());
|
|
|
|
internalEvent.setAccepted(false);
|
|
|
|
if (QCoreApplication::sendEvent(found, &internalEvent)) {
|
2016-08-11 09:17:09 +00:00
|
|
|
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
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchDown(qint32 id, const QPointF &pos, quint32 time) override {
|
2016-05-23 15:07:08 +00:00
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
if (seat->isTouchSequence()) {
|
|
|
|
// something else is getting the events
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto touch = input()->touch();
|
|
|
|
if (touch->internalPressId() != -1) {
|
2018-09-15 00:00:24 +00:00
|
|
|
// already on internal window, ignore further touch points, but filter out
|
2016-05-23 15:07:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// a new touch point
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
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());
|
2018-09-15 00:00:24 +00:00
|
|
|
|
|
|
|
QEnterEvent enterEvent(m_lastLocalTouchPos, m_lastLocalTouchPos, pos);
|
|
|
|
QCoreApplication::sendEvent(internal.data(), &enterEvent);
|
|
|
|
|
2016-05-23 15:07:08 +00:00
|
|
|
QMouseEvent e(QEvent::MouseButtonPress, m_lastLocalTouchPos, pos, Qt::LeftButton, Qt::LeftButton, input()->keyboardModifiers());
|
|
|
|
e.setAccepted(false);
|
|
|
|
QCoreApplication::sendEvent(internal.data(), &e);
|
|
|
|
return true;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchMotion(qint32 id, const QPointF &pos, quint32 time) override {
|
2016-05-23 15:07:08 +00:00
|
|
|
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());
|
2018-09-15 00:00:24 +00:00
|
|
|
|
2016-05-23 15:07:08 +00:00
|
|
|
QMouseEvent e(QEvent::MouseMove, m_lastLocalTouchPos, m_lastGlobalTouchPos, Qt::LeftButton, Qt::LeftButton, input()->keyboardModifiers());
|
|
|
|
QCoreApplication::instance()->sendEvent(internal.data(), &e);
|
|
|
|
return true;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchUp(qint32 id, quint32 time) override {
|
2016-05-23 15:07:08 +00:00
|
|
|
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);
|
|
|
|
|
2018-09-15 00:00:24 +00:00
|
|
|
QEvent leaveEvent(QEvent::Leave);
|
|
|
|
QCoreApplication::sendEvent(internal.data(), &leaveEvent);
|
|
|
|
|
2016-05-23 15:07:08 +00:00
|
|
|
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: {
|
|
|
|
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: {
|
2017-11-11 11:28:10 +00:00
|
|
|
const auto actionResult = performClientMouseAction(event, decoration->client());
|
|
|
|
if (actionResult.first) {
|
|
|
|
return actionResult.second;
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2017-11-11 11:28:10 +00:00
|
|
|
if (event->angleDelta().y() != 0) {
|
|
|
|
// client window action only on vertical scrolling
|
|
|
|
const auto actionResult = performClientWheelAction(event, decoration->client());
|
|
|
|
if (actionResult.first) {
|
|
|
|
return actionResult.second;
|
|
|
|
}
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchDown(qint32 id, const QPointF &pos, quint32 time) override {
|
2016-05-12 14:33:03 +00:00
|
|
|
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);
|
|
|
|
auto decoration = input()->touch()->decoration();
|
|
|
|
if (!decoration) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
|
2016-05-12 14:33:03 +00:00
|
|
|
input()->touch()->setDecorationPressId(id);
|
|
|
|
m_lastGlobalTouchPos = pos;
|
|
|
|
m_lastLocalTouchPos = pos - decoration->client()->pos();
|
2018-09-15 00:00:24 +00:00
|
|
|
|
|
|
|
QHoverEvent hoverEvent(QEvent::HoverMove, m_lastLocalTouchPos, m_lastLocalTouchPos);
|
|
|
|
QCoreApplication::sendEvent(decoration->decoration(), &hoverEvent);
|
|
|
|
|
2016-05-12 14:33:03 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchMotion(qint32 id, const QPointF &pos, quint32 time) override {
|
2016-05-12 14:33:03 +00:00
|
|
|
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();
|
2018-09-15 00:00:24 +00:00
|
|
|
|
|
|
|
QHoverEvent e(QEvent::HoverMove, m_lastLocalTouchPos, m_lastLocalTouchPos);
|
|
|
|
QCoreApplication::instance()->sendEvent(decoration->decoration(), &e);
|
|
|
|
decoration->client()->processDecorationMove(m_lastLocalTouchPos.toPoint(), pos.toPoint());
|
2016-05-12 14:33:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchUp(qint32 id, quint32 time) override {
|
2016-05-12 14:33:03 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
|
2016-05-12 14:33:03 +00:00
|
|
|
// send mouse up
|
2018-09-15 00:00:24 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
QHoverEvent leaveEvent(QEvent::HoverLeave, QPointF(), QPointF());
|
|
|
|
QCoreApplication::sendEvent(decoration->decoration(), &leaveEvent);
|
2016-05-12 14:33:03 +00:00
|
|
|
|
|
|
|
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);
|
2018-07-15 18:44:21 +00:00
|
|
|
input()->pointer()->setEnableConstraints(false);
|
2016-09-15 06:31:05 +00:00
|
|
|
// 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-12-26 13:19:56 +00:00
|
|
|
} else if (static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts() == Qt::NoModifier) {
|
2016-09-14 11:19:43 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchDown(qint32 id, const QPointF &pos, quint32 time) override {
|
2017-03-19 10:40:03 +00:00
|
|
|
Q_UNUSED(time)
|
2018-08-29 18:02:16 +00:00
|
|
|
// TODO: better check whether a touch sequence is in progress
|
2017-03-19 10:40:03 +00:00
|
|
|
if (m_touchInProgress || waylandServer()->seat()->isTouchSequence()) {
|
|
|
|
// cancel existing touch
|
|
|
|
ScreenEdges::self()->gestureRecognizer()->cancelSwipeGesture();
|
|
|
|
m_touchInProgress = false;
|
|
|
|
m_id = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ScreenEdges::self()->gestureRecognizer()->startSwipeGesture(pos) > 0) {
|
|
|
|
m_touchInProgress = true;
|
|
|
|
m_id = id;
|
|
|
|
m_lastPos = pos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchMotion(qint32 id, const QPointF &pos, quint32 time) override {
|
2017-03-19 10:40:03 +00:00
|
|
|
Q_UNUSED(time)
|
|
|
|
if (m_touchInProgress && m_id == id) {
|
|
|
|
ScreenEdges::self()->gestureRecognizer()->updateSwipeGesture(QSizeF(pos.x() - m_lastPos.x(), pos.y() - m_lastPos.y()));
|
|
|
|
m_lastPos = pos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchUp(qint32 id, quint32 time) override {
|
2017-03-19 10:40:03 +00:00
|
|
|
Q_UNUSED(time)
|
|
|
|
if (m_touchInProgress && m_id == id) {
|
|
|
|
ScreenEdges::self()->gestureRecognizer()->endSwipeGesture();
|
|
|
|
m_touchInProgress = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
bool m_touchInProgress = false;
|
2019-08-11 19:57:45 +00:00
|
|
|
qint32 m_id = 0;
|
2017-03-19 10:40:03 +00:00
|
|
|
QPointF m_lastPos;
|
2016-02-11 14:51:25 +00:00
|
|
|
};
|
|
|
|
|
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
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-02-18 08:57:47 +00:00
|
|
|
class WindowActionInputFilter : public InputEventFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
Q_UNUSED(nativeButton)
|
|
|
|
if (event->type() != QEvent::MouseButtonPress) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
AbstractClient *c = dynamic_cast<AbstractClient*>(input()->pointer()->focus().data());
|
2016-02-18 08:57:47 +00:00
|
|
|
if (!c) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-11-11 11:28:10 +00:00
|
|
|
const auto actionResult = performClientMouseAction(event, c, MouseAction::ModifierAndWindow);
|
|
|
|
if (actionResult.first) {
|
|
|
|
return actionResult.second;
|
2016-02-18 08:57:47 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
|
|
|
if (event->angleDelta().y() == 0) {
|
|
|
|
// only actions on vertical scroll
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
AbstractClient *c = dynamic_cast<AbstractClient*>(input()->pointer()->focus().data());
|
2016-02-18 08:57:47 +00:00
|
|
|
if (!c) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-11-11 11:28:10 +00:00
|
|
|
const auto actionResult = performClientWheelAction(event, c, MouseAction::ModifierAndWindow);
|
|
|
|
if (actionResult.first) {
|
|
|
|
return actionResult.second;
|
2016-02-18 08:57:47 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchDown(qint32 id, const QPointF &pos, quint32 time) override {
|
2016-02-18 08:57:47 +00:00
|
|
|
Q_UNUSED(id)
|
|
|
|
Q_UNUSED(time)
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
if (seat->isTouchSequence()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
AbstractClient *c = dynamic_cast<AbstractClient*>(input()->touch()->focus().data());
|
2016-02-18 08:57:47 +00:00
|
|
|
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
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-02-03 14:17:49 +00:00
|
|
|
class ForwardInputFilter : public InputEventFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(event->timestamp());
|
|
|
|
switch (event->type()) {
|
2016-10-07 12:47:25 +00:00
|
|
|
case QEvent::MouseMove: {
|
2016-02-03 14:17:49 +00:00
|
|
|
seat->setPointerPos(event->globalPos());
|
2016-10-07 12:47:25 +00:00
|
|
|
MouseEvent *e = static_cast<MouseEvent*>(event);
|
|
|
|
if (e->delta() != QSizeF()) {
|
|
|
|
seat->relativePointerMotion(e->delta(), e->deltaUnaccelerated(), e->timestampMicroseconds());
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
break;
|
2016-10-07 12:47:25 +00:00
|
|
|
}
|
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);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool wheelEvent(QWheelEvent *event) override {
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(event->timestamp());
|
Send axis_source, axis_discrete, and axis_stop
Summary:
So far KWin didn't send axis_source, axis_discrete, and axis_stop. Even
though most of those events are optional, clients need them to work as
expected. For example, one needs axis_source and axis_stop to implement
kinetic scrolling; Xwayland needs axis_discrete to prevent multiple
scroll events when the compositor sends axis deltas greater than 10, etc.
BUG: 404152
FIXED-IN: 5.17.0
Test Plan:
* Content of a webpage in Firefox is moved by one line per each mouse
wheel "click";
* Scrolled gedit using 2 fingers on GNOME Shell, sway, and KDE Plasma;
in all three cases wayland debug looked the same (except diagonal scroll
motions).
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19000
2019-02-12 09:14:51 +00:00
|
|
|
auto _event = static_cast<WheelEvent *>(event);
|
|
|
|
KWayland::Server::PointerAxisSource source;
|
|
|
|
switch (_event->axisSource()) {
|
|
|
|
case KWin::InputRedirection::PointerAxisSourceWheel:
|
|
|
|
source = KWayland::Server::PointerAxisSource::Wheel;
|
|
|
|
break;
|
|
|
|
case KWin::InputRedirection::PointerAxisSourceFinger:
|
|
|
|
source = KWayland::Server::PointerAxisSource::Finger;
|
|
|
|
break;
|
|
|
|
case KWin::InputRedirection::PointerAxisSourceContinuous:
|
|
|
|
source = KWayland::Server::PointerAxisSource::Continuous;
|
|
|
|
break;
|
|
|
|
case KWin::InputRedirection::PointerAxisSourceWheelTilt:
|
|
|
|
source = KWayland::Server::PointerAxisSource::WheelTilt;
|
|
|
|
break;
|
|
|
|
case KWin::InputRedirection::PointerAxisSourceUnknown:
|
|
|
|
default:
|
|
|
|
source = KWayland::Server::PointerAxisSource::Unknown;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
seat->pointerAxisV5(_event->orientation(), _event->delta(), _event->discreteDelta(), source);
|
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;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchDown(qint32 id, const QPointF &pos, quint32 time) override {
|
2016-02-03 14:17:49 +00:00
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
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;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchMotion(qint32 id, const QPointF &pos, quint32 time) override {
|
2016-02-03 14:17:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchUp(qint32 id, quint32 time) override {
|
2016-02-03 14:17:49 +00:00
|
|
|
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-10-27 07:10:08 +00:00
|
|
|
bool pinchGestureBegin(int fingerCount, quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->startPointerPinchGesture(fingerCount);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool pinchGestureUpdate(qreal scale, qreal angleDelta, const QSizeF &delta, quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->updatePointerPinchGesture(delta, scale, angleDelta);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool pinchGestureEnd(quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->endPointerPinchGesture();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool pinchGestureCancelled(quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->cancelPointerPinchGesture();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool swipeGestureBegin(int fingerCount, quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->startPointerSwipeGesture(fingerCount);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool swipeGestureUpdate(const QSizeF &delta, quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->updatePointerSwipeGesture(delta);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool swipeGestureEnd(quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->endPointerSwipeGesture();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool swipeGestureCancelled(quint32 time) override {
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
seat->cancelPointerSwipeGesture();
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
};
|
|
|
|
|
2019-12-05 14:34:23 +00:00
|
|
|
/**
|
|
|
|
* Useful when there's no proper tablet support on the clients
|
|
|
|
*/
|
|
|
|
class FakeTabletInputFilter : public InputEventFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FakeTabletInputFilter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tabletToolEvent(QTabletEvent *event) override
|
|
|
|
{
|
|
|
|
if (!workspace()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::TabletMove:
|
|
|
|
case QEvent::TabletEnterProximity:
|
|
|
|
input()->pointer()->processMotion(event->globalPosF(), event->timestamp());
|
|
|
|
break;
|
|
|
|
case QEvent::TabletPress:
|
|
|
|
input()->pointer()->processButton(KWin::qtMouseButtonToButton(Qt::LeftButton),
|
|
|
|
InputRedirection::PointerButtonPressed, event->timestamp());
|
|
|
|
break;
|
|
|
|
case QEvent::TabletRelease:
|
|
|
|
input()->pointer()->processButton(KWin::qtMouseButtonToButton(Qt::LeftButton),
|
|
|
|
InputRedirection::PointerButtonReleased, event->timestamp());
|
|
|
|
break;
|
|
|
|
case QEvent::TabletLeaveProximity:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qCWarning(KWIN_CORE) << "Unexpected tablet event type" << event;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
waylandServer()->simulateUserActivity();
|
|
|
|
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;
|
|
|
|
}
|
2018-09-18 14:46:27 +00:00
|
|
|
if (seat->isDragTouch()) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-01 07:42:07 +00:00
|
|
|
seat->setTimestamp(event->timestamp());
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::MouseMove: {
|
2018-09-14 10:54:40 +00:00
|
|
|
const auto pos = input()->globalPointer();
|
|
|
|
seat->setPointerPos(pos);
|
2018-08-22 12:56:48 +00:00
|
|
|
|
|
|
|
const auto eventPos = event->globalPos();
|
|
|
|
// TODO: use InputDeviceHandler::at() here and check isClient()?
|
|
|
|
Toplevel *t = input()->findManagedToplevel(eventPos);
|
|
|
|
if (auto *xwl = xwayland()) {
|
|
|
|
const auto ret = xwl->dragMoveFilter(t, eventPos);
|
|
|
|
if (ret == Xwl::DragEventReply::Ignore) {
|
|
|
|
return false;
|
|
|
|
} else if (ret == Xwl::DragEventReply::Take) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t) {
|
2016-03-01 07:42:07 +00:00
|
|
|
// TODO: consider decorations
|
|
|
|
if (t->surface() != seat->dragSurface()) {
|
|
|
|
if (AbstractClient *c = qobject_cast<AbstractClient*>(t)) {
|
2018-09-02 21:01:48 +00:00
|
|
|
workspace()->activateClient(c);
|
2016-03-01 07:42:07 +00:00
|
|
|
}
|
2018-09-14 10:54:40 +00:00
|
|
|
seat->setDragTarget(t->surface(), t->inputTransformation());
|
2016-03-01 07:42:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// no window at that place, if we have a surface we need to reset
|
|
|
|
seat->setDragTarget(nullptr);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2018-09-18 14:46:27 +00:00
|
|
|
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchDown(qint32 id, const QPointF &pos, quint32 time) override {
|
2018-09-18 14:46:27 +00:00
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
if (seat->isDragPointer()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!seat->isDragTouch()) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-04 19:30:24 +00:00
|
|
|
if (m_touchId != id) {
|
2018-09-18 14:46:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
input()->touch()->insertId(id, seat->touchDown(pos));
|
|
|
|
return true;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchMotion(qint32 id, const QPointF &pos, quint32 time) override {
|
2018-09-18 14:46:27 +00:00
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
if (seat->isDragPointer()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!seat->isDragTouch()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_touchId < 0) {
|
|
|
|
// We take for now the first id appearing as a move after a drag
|
|
|
|
// started. We can optimize by specifying the id the drag is
|
|
|
|
// associated with by implementing a key-value getter in KWayland.
|
|
|
|
m_touchId = id;
|
|
|
|
}
|
2019-01-04 19:30:24 +00:00
|
|
|
if (m_touchId != id) {
|
2018-09-18 14:46:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
const qint32 kwaylandId = input()->touch()->mappedId(id);
|
|
|
|
if (kwaylandId == -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
seat->touchMove(kwaylandId, pos);
|
|
|
|
|
|
|
|
if (Toplevel *t = input()->findToplevel(pos.toPoint())) {
|
|
|
|
// TODO: consider decorations
|
|
|
|
if (t->surface() != seat->dragSurface()) {
|
|
|
|
if (AbstractClient *c = qobject_cast<AbstractClient*>(t)) {
|
|
|
|
workspace()->activateClient(c);
|
|
|
|
}
|
|
|
|
seat->setDragTarget(t->surface(), pos, t->inputTransformation());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// no window at that place, if we have a surface we need to reset
|
|
|
|
seat->setDragTarget(nullptr);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-08-11 19:57:45 +00:00
|
|
|
bool touchUp(qint32 id, quint32 time) override {
|
2018-09-18 14:46:27 +00:00
|
|
|
auto seat = waylandServer()->seat();
|
|
|
|
if (!seat->isDragTouch()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
seat->setTimestamp(time);
|
|
|
|
const qint32 kwaylandId = input()->touch()->mappedId(id);
|
|
|
|
if (kwaylandId != -1) {
|
|
|
|
seat->touchUp(kwaylandId);
|
|
|
|
input()->touch()->removeId(id);
|
|
|
|
}
|
2019-01-04 19:30:24 +00:00
|
|
|
if (m_touchId == id) {
|
2018-09-18 14:46:27 +00:00
|
|
|
m_touchId = -1;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
qint32 m_touchId = -1;
|
2016-03-01 07:42:07 +00:00
|
|
|
};
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
KWIN_SINGLETON_FACTORY(InputRedirection)
|
|
|
|
|
2017-05-06 23:40:48 +00:00
|
|
|
static const QString s_touchpadComponent = QStringLiteral("kcm_touchpad");
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
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))
|
2019-12-01 17:51:15 +00:00
|
|
|
, m_tablet(new TabletInputRedirection(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 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 {
|
2017-09-30 07:36:30 +00:00
|
|
|
LibInput::Connection::createThread();
|
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
|
|
|
}
|
|
|
|
}
|
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()
|
|
|
|
{
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
s_self = nullptr;
|
2016-02-03 14:17:49 +00:00
|
|
|
qDeleteAll(m_filters);
|
2016-12-27 19:16:50 +00:00
|
|
|
qDeleteAll(m_spies);
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::installInputEventFilter(InputEventFilter *filter)
|
|
|
|
{
|
2017-01-02 18:55:03 +00:00
|
|
|
Q_ASSERT(!m_filters.contains(filter));
|
2016-02-03 14:17:49 +00:00
|
|
|
m_filters << filter;
|
|
|
|
}
|
|
|
|
|
2017-01-02 19:13:30 +00:00
|
|
|
void InputRedirection::prependInputEventFilter(InputEventFilter *filter)
|
2016-02-15 14:40:25 +00:00
|
|
|
{
|
2017-01-02 18:55:03 +00:00
|
|
|
Q_ASSERT(!m_filters.contains(filter));
|
2016-02-15 14:40:25 +00:00
|
|
|
m_filters.prepend(filter);
|
|
|
|
}
|
|
|
|
|
2016-02-03 14:17:49 +00:00
|
|
|
void InputRedirection::uninstallInputEventFilter(InputEventFilter *filter)
|
|
|
|
{
|
2017-01-02 18:55:03 +00:00
|
|
|
m_filters.removeOne(filter);
|
2014-08-15 07:30:08 +00:00
|
|
|
}
|
|
|
|
|
2016-12-27 19:16:50 +00:00
|
|
|
void InputRedirection::installInputEventSpy(InputEventSpy *spy)
|
|
|
|
{
|
|
|
|
m_spies << spy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::uninstallInputEventSpy(InputEventSpy *spy)
|
|
|
|
{
|
|
|
|
m_spies.removeOne(spy);
|
|
|
|
}
|
|
|
|
|
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);
|
2017-12-29 17:29:19 +00:00
|
|
|
waylandServer()->simulateUserActivity();
|
2015-07-06 02:44:07 +00:00
|
|
|
}
|
|
|
|
);
|
2019-01-09 06:45:48 +00:00
|
|
|
connect(device, &FakeInputDevice::pointerMotionAbsoluteRequested, this,
|
|
|
|
[this] (const QPointF &pos) {
|
|
|
|
// TODO: Fix time
|
|
|
|
m_pointer->processMotion(pos, 0);
|
|
|
|
waylandServer()->simulateUserActivity();
|
|
|
|
}
|
|
|
|
);
|
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);
|
2017-12-29 17:29:19 +00:00
|
|
|
waylandServer()->simulateUserActivity();
|
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);
|
2017-12-29 17:29:19 +00:00
|
|
|
waylandServer()->simulateUserActivity();
|
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
|
Send axis_source, axis_discrete, and axis_stop
Summary:
So far KWin didn't send axis_source, axis_discrete, and axis_stop. Even
though most of those events are optional, clients need them to work as
expected. For example, one needs axis_source and axis_stop to implement
kinetic scrolling; Xwayland needs axis_discrete to prevent multiple
scroll events when the compositor sends axis deltas greater than 10, etc.
BUG: 404152
FIXED-IN: 5.17.0
Test Plan:
* Content of a webpage in Firefox is moved by one line per each mouse
wheel "click";
* Scrolled gedit using 2 fingers on GNOME Shell, sway, and KDE Plasma;
in all three cases wayland debug looked the same (except diagonal scroll
motions).
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19000
2019-02-12 09:14:51 +00:00
|
|
|
m_pointer->processAxis(axis, delta, 0, InputRedirection::PointerAxisSourceUnknown, 0);
|
2017-12-29 17:29:19 +00:00
|
|
|
waylandServer()->simulateUserActivity();
|
2015-07-06 02:44:07 +00:00
|
|
|
}
|
|
|
|
);
|
2016-06-03 11:14:25 +00:00
|
|
|
connect(device, &FakeInputDevice::touchDownRequested, this,
|
2019-08-11 19:57:45 +00:00
|
|
|
[this] (qint32 id, const QPointF &pos) {
|
2016-06-03 11:14:25 +00:00
|
|
|
// TODO: Fix time
|
|
|
|
m_touch->processDown(id, pos, 0);
|
2017-12-29 17:29:19 +00:00
|
|
|
waylandServer()->simulateUserActivity();
|
2016-06-03 11:14:25 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::touchMotionRequested, this,
|
2019-08-11 19:57:45 +00:00
|
|
|
[this] (qint32 id, const QPointF &pos) {
|
2016-06-03 11:14:25 +00:00
|
|
|
// TODO: Fix time
|
|
|
|
m_touch->processMotion(id, pos, 0);
|
2017-12-29 17:29:19 +00:00
|
|
|
waylandServer()->simulateUserActivity();
|
2016-06-03 11:14:25 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::touchUpRequested, this,
|
2019-08-11 19:57:45 +00:00
|
|
|
[this] (qint32 id) {
|
2016-06-03 11:14:25 +00:00
|
|
|
// TODO: Fix time
|
|
|
|
m_touch->processUp(id, 0);
|
2017-12-29 17:29:19 +00:00
|
|
|
waylandServer()->simulateUserActivity();
|
2016-06-03 11:14:25 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::touchCancelRequested, this,
|
|
|
|
[this] () {
|
|
|
|
m_touch->cancel();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::touchFrameRequested, this,
|
|
|
|
[this] () {
|
|
|
|
m_touch->frame();
|
|
|
|
}
|
|
|
|
);
|
2019-09-07 11:36:18 +00:00
|
|
|
connect(device, &FakeInputDevice::keyboardKeyPressRequested, this,
|
|
|
|
[this] (quint32 button) {
|
|
|
|
// TODO: Fix time
|
|
|
|
m_keyboard->processKey(button, InputRedirection::KeyboardKeyPressed, 0);
|
|
|
|
waylandServer()->simulateUserActivity();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
connect(device, &FakeInputDevice::keyboardKeyReleaseRequested, this,
|
|
|
|
[this] (quint32 button) {
|
|
|
|
// TODO: Fix time
|
|
|
|
m_keyboard->processKey(button, InputRedirection::KeyboardKeyReleased, 0);
|
|
|
|
waylandServer()->simulateUserActivity();
|
|
|
|
}
|
|
|
|
);
|
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();
|
2019-12-01 17:51:15 +00:00
|
|
|
m_tablet->init();
|
2015-06-13 15:54:08 +00:00
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
setupInputFilters();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::setupInputFilters()
|
|
|
|
{
|
2018-12-02 12:09:37 +00:00
|
|
|
const bool hasGlobalShortcutSupport = !waylandServer() || waylandServer()->hasGlobalShortcutSupport();
|
|
|
|
if (LogindIntegration::self()->hasSessionControl() && hasGlobalShortcutSupport) {
|
2016-02-03 14:17:49 +00:00
|
|
|
installInputEventFilter(new VirtualTerminalFilter);
|
|
|
|
}
|
|
|
|
if (waylandServer()) {
|
2018-12-01 13:52:47 +00:00
|
|
|
installInputEventSpy(new TouchHideCursorSpy);
|
2018-12-02 12:09:37 +00:00
|
|
|
if (hasGlobalShortcutSupport) {
|
|
|
|
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);
|
2017-03-25 17:41:28 +00:00
|
|
|
installInputEventFilter(new PopupInputFilter);
|
2016-11-15 13:23:51 +00:00
|
|
|
m_windowSelector = new WindowSelectorFilter;
|
|
|
|
installInputEventFilter(m_windowSelector);
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
2018-12-02 12:09:37 +00:00
|
|
|
if (hasGlobalShortcutSupport) {
|
|
|
|
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
|
2018-12-02 12:09:37 +00:00
|
|
|
if (hasGlobalShortcutSupport) {
|
|
|
|
installInputEventFilter(new GlobalShortcutFilter);
|
|
|
|
}
|
2016-02-03 14:17:49 +00:00
|
|
|
installInputEventFilter(new DecorationEventFilter);
|
2018-09-15 00:00:24 +00:00
|
|
|
installInputEventFilter(new InternalWindowEventFilter);
|
2016-02-03 14:17:49 +00:00
|
|
|
if (waylandServer()) {
|
2016-02-18 08:57:47 +00:00
|
|
|
installInputEventFilter(new WindowActionInputFilter);
|
2016-02-03 14:17:49 +00:00
|
|
|
installInputEventFilter(new ForwardInputFilter);
|
2019-12-05 14:34:23 +00:00
|
|
|
installInputEventFilter(new FakeTabletInputFilter);
|
2016-02-03 14:17:49 +00:00
|
|
|
}
|
2015-06-13 15:54:08 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 08:29:06 +00:00
|
|
|
void InputRedirection::reconfigure()
|
|
|
|
{
|
|
|
|
if (Application::usesLibinput()) {
|
2017-04-19 15:00:02 +00:00
|
|
|
auto inputConfig = kwinApp()->inputConfig();
|
|
|
|
inputConfig->reparseConfiguration();
|
2019-07-10 23:12:05 +00:00
|
|
|
const auto config = 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-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-10-07 12:47:25 +00:00
|
|
|
|
|
|
|
if (waylandServer()) {
|
|
|
|
// create relative pointer manager
|
|
|
|
waylandServer()->display()->createRelativePointerManager(KWayland::Server::RelativePointerInterfaceVersion::UnstableV1, waylandServer()->display())->create();
|
|
|
|
}
|
|
|
|
|
2017-04-19 15:00:02 +00:00
|
|
|
conn->setInputConfig(kwinApp()->inputConfig());
|
2016-10-05 09:50:20 +00:00
|
|
|
conn->updateLEDs(m_keyboard->xkb()->leds());
|
2019-06-21 14:02:50 +00:00
|
|
|
waylandServer()->updateKeyState(m_keyboard->xkb()->leds());
|
|
|
|
connect(m_keyboard, &KeyboardInputRedirection::ledsChanged, waylandServer(), &WaylandServer::updateKeyState);
|
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
|
|
|
|
);
|
Fix race condition with libinput events on startup
Summary:
In some cases, it's possible that libinput wrote device added events to
the file descriptor before the connection to handle those events was
in-place. This resulted in a compositor without any input devices.
Test Plan:
Ran a wayland session. In about 60% of all cases, no input was
possible. kwin_libinput showed the enumeration of all devices correctly,
but KWin::LibInput::Context did not have any m_devices.
After this change, this did not appear anymore.
Reviewers: #plasma, graesslin, davidedmundson
Reviewed By: #plasma, graesslin, davidedmundson
Subscribers: anthonyfieroni, ngraham, kwin, #kwin, plasma-devel
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D8888
2017-11-18 22:23:27 +00:00
|
|
|
conn->setup();
|
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-10-07 12:47:25 +00:00
|
|
|
[this] (const QSizeF &delta, const QSizeF &deltaNonAccel, uint32_t time, quint64 timeMicroseconds, LibInput::Device *device) {
|
|
|
|
m_pointer->processMotion(m_pointer->pos() + QPointF(delta.width(), delta.height()), delta, deltaNonAccel, time, timeMicroseconds, 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);
|
2017-12-27 19:25:36 +00:00
|
|
|
auto handleSwitchEvent = [this] (SwitchEvent::State state, quint32 time, quint64 timeMicroseconds, LibInput::Device *device) {
|
|
|
|
SwitchEvent event(state, time, timeMicroseconds, device);
|
|
|
|
processSpies(std::bind(&InputEventSpy::switchEvent, std::placeholders::_1, &event));
|
|
|
|
processFilters(std::bind(&InputEventFilter::switchEvent, std::placeholders::_1, &event));
|
|
|
|
};
|
|
|
|
connect(conn, &LibInput::Connection::switchToggledOn, this,
|
|
|
|
std::bind(handleSwitchEvent, SwitchEvent::State::On, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
|
|
|
connect(conn, &LibInput::Connection::switchToggledOff, this,
|
|
|
|
std::bind(handleSwitchEvent, SwitchEvent::State::Off, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
2019-12-01 17:51:15 +00:00
|
|
|
|
|
|
|
connect(conn, &LibInput::Connection::tabletToolEvent,
|
|
|
|
m_tablet, &TabletInputRedirection::tabletToolEvent);
|
|
|
|
connect(conn, &LibInput::Connection::tabletToolButtonEvent,
|
|
|
|
m_tablet, &TabletInputRedirection::tabletToolButtonEvent);
|
|
|
|
connect(conn, &LibInput::Connection::tabletPadButtonEvent,
|
|
|
|
m_tablet, &TabletInputRedirection::tabletPadButtonEvent);
|
|
|
|
connect(conn, &LibInput::Connection::tabletPadRingEvent,
|
|
|
|
m_tablet, &TabletInputRedirection::tabletPadRingEvent);
|
|
|
|
connect(conn, &LibInput::Connection::tabletPadStripEvent,
|
|
|
|
m_tablet, &TabletInputRedirection::tabletPadStripEvent);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
);
|
Expose if the tablet mode switch is available
Summary:
expose in the libinput wrapper a property that tells whether
a tablet mode switch input device is present on the machine,
expose it trough dbus
Test Plan:
still not complete, I need a way to either access the connection
from TabletModeManager or setting to TabletModeManager from input.cpp
Reviewers: #kwin, #plasma, graesslin
Reviewed By: #kwin, #plasma, graesslin
Subscribers: graesslin, ngraham, davidedmundson, plasma-devel, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9944
2018-01-24 10:36:56 +00:00
|
|
|
connect(conn, &LibInput::Connection::hasTabletModeSwitchChanged, this,
|
|
|
|
[this] (bool set) {
|
|
|
|
if (m_libInput->isSuspended()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
emit hasTabletModeSwitchChanged(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
|
|
|
}
|
2017-05-06 23:40:48 +00:00
|
|
|
setupTouchpadShortcuts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputRedirection::setupTouchpadShortcuts()
|
|
|
|
{
|
|
|
|
if (!m_libInput) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QAction *touchpadToggleAction = new QAction(this);
|
|
|
|
QAction *touchpadOnAction = new QAction(this);
|
|
|
|
QAction *touchpadOffAction = new QAction(this);
|
|
|
|
|
|
|
|
touchpadToggleAction->setObjectName(QStringLiteral("Toggle Touchpad"));
|
|
|
|
touchpadToggleAction->setProperty("componentName", s_touchpadComponent);
|
|
|
|
touchpadOnAction->setObjectName(QStringLiteral("Enable Touchpad"));
|
|
|
|
touchpadOnAction->setProperty("componentName", s_touchpadComponent);
|
|
|
|
touchpadOffAction->setObjectName(QStringLiteral("Disable Touchpad"));
|
|
|
|
touchpadOffAction->setProperty("componentName", s_touchpadComponent);
|
|
|
|
KGlobalAccel::self()->setDefaultShortcut(touchpadToggleAction, QList<QKeySequence>{Qt::Key_TouchpadToggle});
|
|
|
|
KGlobalAccel::self()->setShortcut(touchpadToggleAction, QList<QKeySequence>{Qt::Key_TouchpadToggle});
|
|
|
|
KGlobalAccel::self()->setDefaultShortcut(touchpadOnAction, QList<QKeySequence>{Qt::Key_TouchpadOn});
|
|
|
|
KGlobalAccel::self()->setShortcut(touchpadOnAction, QList<QKeySequence>{Qt::Key_TouchpadOn});
|
|
|
|
KGlobalAccel::self()->setDefaultShortcut(touchpadOffAction, QList<QKeySequence>{Qt::Key_TouchpadOff});
|
|
|
|
KGlobalAccel::self()->setShortcut(touchpadOffAction, QList<QKeySequence>{Qt::Key_TouchpadOff});
|
|
|
|
#ifndef KWIN_BUILD_TESTING
|
|
|
|
registerShortcut(Qt::Key_TouchpadToggle, touchpadToggleAction);
|
|
|
|
registerShortcut(Qt::Key_TouchpadOn, touchpadOnAction);
|
|
|
|
registerShortcut(Qt::Key_TouchpadOff, touchpadOffAction);
|
|
|
|
#endif
|
|
|
|
connect(touchpadToggleAction, &QAction::triggered, m_libInput, &LibInput::Connection::toggleTouchpads);
|
|
|
|
connect(touchpadOnAction, &QAction::triggered, m_libInput, &LibInput::Connection::enableTouchpads);
|
|
|
|
connect(touchpadOffAction, &QAction::triggered, m_libInput, &LibInput::Connection::disableTouchpads);
|
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 (m_libInput) {
|
|
|
|
return m_libInput->hasAlphaNumericKeyboard();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Expose if the tablet mode switch is available
Summary:
expose in the libinput wrapper a property that tells whether
a tablet mode switch input device is present on the machine,
expose it trough dbus
Test Plan:
still not complete, I need a way to either access the connection
from TabletModeManager or setting to TabletModeManager from input.cpp
Reviewers: #kwin, #plasma, graesslin
Reviewed By: #kwin, #plasma, graesslin
Subscribers: graesslin, ngraham, davidedmundson, plasma-devel, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9944
2018-01-24 10:36:56 +00:00
|
|
|
bool InputRedirection::hasTabletModeSwitch()
|
|
|
|
{
|
|
|
|
if (m_libInput) {
|
|
|
|
return m_libInput->hasTabletModeSwitch();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-30 06:55:41 +00:00
|
|
|
void InputRedirection::setupLibInputWithScreens()
|
|
|
|
{
|
|
|
|
if (!screens() || !m_libInput) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_libInput->setScreenSize(screens()->size());
|
2017-11-10 17:07:15 +00:00
|
|
|
m_libInput->updateScreens();
|
2015-03-30 06:55:41 +00:00
|
|
|
connect(screens(), &Screens::sizeChanged, this,
|
|
|
|
[this] {
|
|
|
|
m_libInput->setScreenSize(screens()->size());
|
|
|
|
}
|
|
|
|
);
|
2017-11-10 17:07:15 +00:00
|
|
|
connect(screens(), &Screens::changed, m_libInput, &LibInput::Connection::updateScreens);
|
2015-03-30 06:55:41 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
Send axis_source, axis_discrete, and axis_stop
Summary:
So far KWin didn't send axis_source, axis_discrete, and axis_stop. Even
though most of those events are optional, clients need them to work as
expected. For example, one needs axis_source and axis_stop to implement
kinetic scrolling; Xwayland needs axis_discrete to prevent multiple
scroll events when the compositor sends axis deltas greater than 10, etc.
BUG: 404152
FIXED-IN: 5.17.0
Test Plan:
* Content of a webpage in Firefox is moved by one line per each mouse
wheel "click";
* Scrolled gedit using 2 fingers on GNOME Shell, sway, and KDE Plasma;
in all three cases wayland debug looked the same (except diagonal scroll
motions).
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19000
2019-02-12 09:14:51 +00:00
|
|
|
void InputRedirection::processPointerAxis(InputRedirection::PointerAxis axis, qreal delta, qint32 discreteDelta, PointerAxisSource source, uint32_t time)
|
2013-06-26 08:15:20 +00:00
|
|
|
{
|
Send axis_source, axis_discrete, and axis_stop
Summary:
So far KWin didn't send axis_source, axis_discrete, and axis_stop. Even
though most of those events are optional, clients need them to work as
expected. For example, one needs axis_source and axis_stop to implement
kinetic scrolling; Xwayland needs axis_discrete to prevent multiple
scroll events when the compositor sends axis deltas greater than 10, etc.
BUG: 404152
FIXED-IN: 5.17.0
Test Plan:
* Content of a webpage in Firefox is moved by one line per each mouse
wheel "click";
* Scrolled gedit using 2 fingers on GNOME Shell, sway, and KDE Plasma;
in all three cases wayland debug looked the same (except diagonal scroll
motions).
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19000
2019-02-12 09:14:51 +00:00
|
|
|
m_pointer->processAxis(axis, delta, discreteDelta, source, 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;
|
|
|
|
}
|
2020-01-16 20:15:24 +00:00
|
|
|
// TODO: What about sub-surfaces sticking outside the main surface?
|
|
|
|
const QPoint localPoint = pos - t->bufferGeometry().topLeft();
|
|
|
|
return input.contains(localPoint);
|
2015-06-18 21:19:13 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
Drop some custom list typedefs
Summary:
Qt has its own thing where a type might also have corresponding list
alias, e.g. QObject and QObjectList, QWidget and QWidgetList. I don't
know why Qt does that, maybe for some historical reasons, but what
matters is that we copy this pattern here in KWin. While this pattern
might be useful with some long list types, for example
QList<QWeakPointer<TabBoxClient>> TabBoxClientList
in general, it causes more harm than good. For example, we've got two
new client types, do we need corresponding list typedefs for them? If
no, why do we have ClientList and so on?
Another problem with these typedefs is that you need to include utils.h
header in order to use them. A better way to handle such things is to
just forward declare a client class (if that's possible) and use it
directly with QList or QVector. This way translation units don't get
"bloated" with utils.h stuff for no apparent reason.
So, in order to make code more consistent and easier to follow, this
change drops some of our custom typedefs. Namely ConstClientList,
ClientList, DeletedList, UnmanagedList, ToplevelList, and GroupList.
Test Plan: Compiles.
Reviewers: #kwin
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24950
2019-10-16 09:11:04 +00:00
|
|
|
const QList<Unmanaged *> &unmanaged = Workspace::self()->unmanagedList();
|
2015-11-16 10:46:20 +00:00
|
|
|
foreach (Unmanaged *u, unmanaged) {
|
2019-09-27 10:01:10 +00:00
|
|
|
if (u->inputGeometry().contains(pos) && acceptsInput(u, pos)) {
|
2015-11-16 10:46:20 +00:00
|
|
|
return u;
|
|
|
|
}
|
2013-07-01 06:37:59 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-22 12:56:48 +00:00
|
|
|
return findManagedToplevel(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
Toplevel *InputRedirection::findManagedToplevel(const QPoint &pos)
|
|
|
|
{
|
|
|
|
if (!Workspace::self()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const bool isScreenLocked = waylandServer() && waylandServer()->isScreenLocked();
|
Drop some custom list typedefs
Summary:
Qt has its own thing where a type might also have corresponding list
alias, e.g. QObject and QObjectList, QWidget and QWidgetList. I don't
know why Qt does that, maybe for some historical reasons, but what
matters is that we copy this pattern here in KWin. While this pattern
might be useful with some long list types, for example
QList<QWeakPointer<TabBoxClient>> TabBoxClientList
in general, it causes more harm than good. For example, we've got two
new client types, do we need corresponding list typedefs for them? If
no, why do we have ClientList and so on?
Another problem with these typedefs is that you need to include utils.h
header in order to use them. A better way to handle such things is to
just forward declare a client class (if that's possible) and use it
directly with QList or QVector. This way translation units don't get
"bloated" with utils.h stuff for no apparent reason.
So, in order to make code more consistent and easier to follow, this
change drops some of our custom typedefs. Namely ConstClientList,
ClientList, DeletedList, UnmanagedList, ToplevelList, and GroupList.
Test Plan: Compiles.
Reviewers: #kwin
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D24950
2019-10-16 09:11:04 +00:00
|
|
|
const QList<Toplevel *> &stacking = Workspace::self()->stackingOrder();
|
2013-07-01 06:37:59 +00:00
|
|
|
if (stacking.isEmpty()) {
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
return nullptr;
|
2013-07-01 06:37:59 +00:00
|
|
|
}
|
|
|
|
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)) {
|
2019-09-14 08:58:12 +00:00
|
|
|
if (!c->isOnCurrentActivity() || !c->isOnCurrentDesktop() || c->isMinimized() || 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());
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
return nullptr;
|
2013-07-01 06:37:59 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-26 13:19:56 +00:00
|
|
|
Qt::KeyboardModifiers InputRedirection::modifiersRelevantForGlobalShortcuts() const
|
|
|
|
{
|
|
|
|
return m_keyboard->modifiersRelevantForGlobalShortcuts();
|
|
|
|
}
|
|
|
|
|
2013-07-10 09:41:16 +00:00
|
|
|
void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action)
|
|
|
|
{
|
2017-07-28 19:31:09 +00:00
|
|
|
Q_UNUSED(shortcut)
|
2017-01-17 06:12:44 +00:00
|
|
|
kwinApp()->platform()->setupActionForGlobalAccel(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);
|
|
|
|
}
|
|
|
|
|
2017-03-18 10:00:30 +00:00
|
|
|
void InputRedirection::registerTouchpadSwipeShortcut(SwipeDirection direction, QAction *action)
|
|
|
|
{
|
|
|
|
m_shortcuts->registerTouchpadSwipe(action, direction);
|
|
|
|
}
|
|
|
|
|
2015-06-26 11:47:08 +00:00
|
|
|
void InputRedirection::registerGlobalAccel(KGlobalAccelInterface *interface)
|
|
|
|
{
|
|
|
|
m_shortcuts->setKGlobalAccelInterface(interface);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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-11-15 13:23:51 +00:00
|
|
|
void InputRedirection::startInteractiveWindowSelection(std::function<void(KWin::Toplevel*)> callback, const QByteArray &cursorName)
|
|
|
|
{
|
|
|
|
if (!m_windowSelector || m_windowSelector->isActive()) {
|
|
|
|
callback(nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_windowSelector->start(callback);
|
|
|
|
m_pointer->setWindowSelectionCursor(cursorName);
|
|
|
|
}
|
|
|
|
|
2016-11-23 14:53:17 +00:00
|
|
|
void InputRedirection::startInteractivePositionSelection(std::function<void(const QPoint &)> callback)
|
|
|
|
{
|
|
|
|
if (!m_windowSelector || m_windowSelector->isActive()) {
|
|
|
|
callback(QPoint(-1, -1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_windowSelector->start(callback);
|
|
|
|
m_pointer->setWindowSelectionCursor(QByteArray());
|
|
|
|
}
|
|
|
|
|
2016-11-15 13:23:51 +00:00
|
|
|
bool InputRedirection::isSelectingWindow() const
|
|
|
|
{
|
|
|
|
return m_windowSelector ? m_windowSelector->isActive() : false;
|
|
|
|
}
|
|
|
|
|
2016-05-12 14:33:03 +00:00
|
|
|
InputDeviceHandler::InputDeviceHandler(InputRedirection *input)
|
|
|
|
: QObject(input)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InputDeviceHandler::~InputDeviceHandler() = default;
|
|
|
|
|
2018-09-15 00:00:24 +00:00
|
|
|
void InputDeviceHandler::init()
|
2016-05-12 14:33:03 +00:00
|
|
|
{
|
2018-09-15 00:00:24 +00:00
|
|
|
connect(workspace(), &Workspace::stackingOrderChanged, this, &InputDeviceHandler::update);
|
|
|
|
connect(workspace(), &Workspace::clientMinimizedChanged, this, &InputDeviceHandler::update);
|
|
|
|
connect(VirtualDesktopManager::self(), &VirtualDesktopManager::currentChanged, this, &InputDeviceHandler::update);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputDeviceHandler::setAt(Toplevel *toplevel)
|
|
|
|
{
|
2019-06-06 21:17:01 +00:00
|
|
|
if (m_at.at == toplevel) {
|
2018-09-15 00:00:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-06-06 21:17:01 +00:00
|
|
|
auto old = m_at.at;
|
|
|
|
disconnect(m_at.surfaceCreatedConnection);
|
|
|
|
m_at.surfaceCreatedConnection = QMetaObject::Connection();
|
|
|
|
|
|
|
|
m_at.at = toplevel;
|
2018-09-15 00:00:24 +00:00
|
|
|
emit atChanged(old, toplevel);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDeviceHandler::setFocus(Toplevel *toplevel)
|
|
|
|
{
|
|
|
|
m_focus.focus = toplevel;
|
|
|
|
//TODO: call focusUpdate?
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDeviceHandler::setDecoration(QPointer<Decoration::DecoratedClientImpl> decoration)
|
|
|
|
{
|
|
|
|
auto oldDeco = m_focus.decoration;
|
|
|
|
m_focus.decoration = decoration;
|
|
|
|
cleanupDecoration(oldDeco.data(), m_focus.decoration.data());
|
|
|
|
emit decorationChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDeviceHandler::setInternalWindow(QWindow *window)
|
|
|
|
{
|
|
|
|
m_focus.internalWindow = window;
|
|
|
|
//TODO: call internalWindowUpdate?
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputDeviceHandler::updateFocus()
|
|
|
|
{
|
|
|
|
auto oldFocus = m_focus.focus;
|
2019-06-06 21:17:01 +00:00
|
|
|
|
|
|
|
if (m_at.at && !m_at.at->surface()) {
|
|
|
|
// The surface has not yet been created (special XWayland case).
|
|
|
|
// Therefore listen for its creation.
|
|
|
|
if (!m_at.surfaceCreatedConnection) {
|
|
|
|
m_at.surfaceCreatedConnection = connect(m_at.at, &Toplevel::surfaceChanged,
|
|
|
|
this, &InputDeviceHandler::update);
|
|
|
|
}
|
|
|
|
m_focus.focus = nullptr;
|
|
|
|
} else {
|
|
|
|
m_focus.focus = m_at.at;
|
|
|
|
}
|
|
|
|
|
2018-09-15 00:00:24 +00:00
|
|
|
focusUpdate(oldFocus, m_focus.focus);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InputDeviceHandler::updateDecoration()
|
|
|
|
{
|
|
|
|
const auto oldDeco = m_focus.decoration;
|
|
|
|
m_focus.decoration = nullptr;
|
|
|
|
|
2019-06-06 21:17:01 +00:00
|
|
|
auto *ac = qobject_cast<AbstractClient*>(m_at.at);
|
2018-09-15 00:00:24 +00:00
|
|
|
if (ac && ac->decoratedClient()) {
|
|
|
|
const QRect clientRect = QRect(ac->clientPos(), ac->clientSize()).translated(ac->pos());
|
|
|
|
if (!clientRect.contains(position().toPoint())) {
|
|
|
|
// input device above decoration
|
|
|
|
m_focus.decoration = ac->decoratedClient();
|
2016-05-12 14:33:03 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
|
|
|
|
if (m_focus.decoration == oldDeco) {
|
|
|
|
// no change to decoration
|
|
|
|
return false;
|
2016-05-12 14:33:03 +00:00
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
cleanupDecoration(oldDeco.data(), m_focus.decoration.data());
|
|
|
|
emit decorationChanged();
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-12 14:33:03 +00:00
|
|
|
|
2018-09-15 00:00:24 +00:00
|
|
|
void InputDeviceHandler::updateInternalWindow(QWindow *window)
|
|
|
|
{
|
|
|
|
if (m_focus.internalWindow == window) {
|
|
|
|
// no change
|
|
|
|
return;
|
2016-05-12 14:33:03 +00:00
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
const auto oldInternal = m_focus.internalWindow;
|
|
|
|
m_focus.internalWindow = window;
|
|
|
|
cleanupInternalWindow(oldInternal, window);
|
|
|
|
}
|
2016-05-12 14:33:03 +00:00
|
|
|
|
2018-09-15 00:00:24 +00:00
|
|
|
void InputDeviceHandler::update()
|
|
|
|
{
|
|
|
|
if (!m_inited) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-13 09:46:21 +00:00
|
|
|
Toplevel *toplevel = nullptr;
|
|
|
|
QWindow *internalWindow = nullptr;
|
2018-09-15 00:00:24 +00:00
|
|
|
|
2018-12-13 09:46:21 +00:00
|
|
|
if (!positionValid()) {
|
|
|
|
const auto pos = position().toPoint();
|
|
|
|
internalWindow = findInternalWindow(pos);
|
|
|
|
if (internalWindow) {
|
2019-08-26 07:44:04 +00:00
|
|
|
toplevel = workspace()->findInternal(internalWindow);
|
2018-12-13 09:46:21 +00:00
|
|
|
} else {
|
|
|
|
toplevel = input()->findToplevel(pos);
|
|
|
|
}
|
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
// Always set the toplevel at the position of the input device.
|
|
|
|
setAt(toplevel);
|
|
|
|
|
|
|
|
if (focusUpdatesBlocked()) {
|
|
|
|
return;
|
2016-05-12 14:33:03 +00:00
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
|
|
|
|
if (internalWindow) {
|
|
|
|
if (m_focus.internalWindow != internalWindow) {
|
|
|
|
// changed internal window
|
|
|
|
updateDecoration();
|
|
|
|
updateInternalWindow(internalWindow);
|
|
|
|
updateFocus();
|
|
|
|
} else if (updateDecoration()) {
|
|
|
|
// went onto or off from decoration, update focus
|
|
|
|
updateFocus();
|
2016-05-12 14:33:03 +00:00
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
updateInternalWindow(nullptr);
|
|
|
|
|
2019-06-06 21:17:01 +00:00
|
|
|
if (m_focus.focus != m_at.at) {
|
2018-09-15 00:00:24 +00:00
|
|
|
// focus change
|
|
|
|
updateDecoration();
|
|
|
|
updateFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// check if switched to/from decoration while staying on the same Toplevel
|
|
|
|
if (updateDecoration()) {
|
|
|
|
// went onto or off from decoration, update focus
|
|
|
|
updateFocus();
|
2016-05-12 14:33:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-15 00:00:24 +00:00
|
|
|
QWindow* InputDeviceHandler::findInternalWindow(const QPoint &pos) const
|
2016-05-23 15:07:08 +00:00
|
|
|
{
|
2018-09-15 00:00:24 +00:00
|
|
|
if (waylandServer()->isScreenLocked()) {
|
|
|
|
return nullptr;
|
2016-05-23 15:07:08 +00:00
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
|
2019-08-26 07:44:04 +00:00
|
|
|
const QList<InternalClient *> &internalClients = workspace()->internalClients();
|
2018-09-15 00:00:24 +00:00
|
|
|
if (internalClients.isEmpty()) {
|
|
|
|
return nullptr;
|
2016-05-23 15:07:08 +00:00
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
|
|
|
|
auto it = internalClients.end();
|
|
|
|
do {
|
|
|
|
--it;
|
|
|
|
QWindow *w = (*it)->internalWindow();
|
|
|
|
if (!w || !w->isVisible()) {
|
|
|
|
continue;
|
2016-05-23 15:07:08 +00:00
|
|
|
}
|
2019-09-27 10:01:10 +00:00
|
|
|
if (!(*it)->frameGeometry().contains(pos)) {
|
2018-09-15 00:00:24 +00:00
|
|
|
continue;
|
2016-05-23 15:07:08 +00:00
|
|
|
}
|
2018-09-15 00:00:24 +00:00
|
|
|
// check input mask
|
|
|
|
const QRegion mask = w->mask().translated(w->geometry().topLeft());
|
|
|
|
if (!mask.isEmpty() && !mask.contains(pos)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (w->property("outputOnly").toBool()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return w;
|
|
|
|
} while (it != internalClients.begin());
|
|
|
|
|
|
|
|
return nullptr;
|
2016-05-23 15:07:08 +00:00
|
|
|
}
|
|
|
|
|
2013-06-26 08:15:20 +00:00
|
|
|
} // namespace
|