From 28d918fc8d327fe22c41f7b8f2704500bde46fa2 Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Thu, 17 Dec 2020 08:57:48 +0100 Subject: [PATCH] Use input handlers to move windows We don't need to customize ShellSurfaceItem to do this anymore. Closes: #196 --- src/compositor/qml/ShellSettings.qml | 3 + src/compositor/qml/windows/MoveItem.qml | 7 ++ src/compositor/qml/windows/WaylandChrome.qml | 28 +++-- src/imports/shell-private/CMakeLists.txt | 2 - src/imports/shell-private/plugin.cpp | 2 - .../shell-private/shellsurfaceitem.cpp | 106 ------------------ src/imports/shell-private/shellsurfaceitem.h | 56 --------- 7 files changed, 26 insertions(+), 178 deletions(-) delete mode 100644 src/imports/shell-private/shellsurfaceitem.cpp delete mode 100644 src/imports/shell-private/shellsurfaceitem.h diff --git a/src/compositor/qml/ShellSettings.qml b/src/compositor/qml/ShellSettings.qml index 7892c4bb4..f02b9cab4 100644 --- a/src/compositor/qml/ShellSettings.qml +++ b/src/compositor/qml/ShellSettings.qml @@ -37,6 +37,7 @@ FluidCore.Object { readonly property alias lockScreen: lockSettings readonly property alias shell: shellSettings readonly property alias session: sessionSettings + readonly property alias input: inputSettings readonly property int numWorkspaces: 4 /* @@ -79,6 +80,8 @@ FluidCore.Object { */ P.InputSettings { + id: inputSettings + compositor: liriCompositor } diff --git a/src/compositor/qml/windows/MoveItem.qml b/src/compositor/qml/windows/MoveItem.qml index d57b6037d..cf026d06f 100644 --- a/src/compositor/qml/windows/MoveItem.qml +++ b/src/compositor/qml/windows/MoveItem.qml @@ -22,10 +22,17 @@ ***************************************************************************/ import QtQuick 2.0 +import Liri.WaylandServer 1.0 as WS Item { id: moveItem + property bool moving: false + + onMovingChanged: { + shellHelper.grabCursor(moving ? WS.LiriShell.MoveGrabCursor : WS.LiriShell.ArrowGrabCursor); + } + ParallelAnimation { id: moveAnimation diff --git a/src/compositor/qml/windows/WaylandChrome.qml b/src/compositor/qml/windows/WaylandChrome.qml index ea3323783..03739f58f 100644 --- a/src/compositor/qml/windows/WaylandChrome.qml +++ b/src/compositor/qml/windows/WaylandChrome.qml @@ -21,8 +21,8 @@ * $END_LICENSE$ ***************************************************************************/ -import QtQuick 2.0 -import QtWayland.Compositor 1.0 +import QtQuick 2.15 +import QtWayland.Compositor 1.15 import Fluid.Effects 1.0 as FluidEffects import Liri.WaylandServer 1.0 as WS import Liri.private.shell 1.0 as P @@ -146,7 +146,7 @@ P.ChromeItem { visible: chrome.window.mapped && enabled } - P.ShellSurfaceItem { + ShellSurfaceItem { id: shellSurfaceItem x: chrome.window.borderSize @@ -159,20 +159,24 @@ P.ChromeItem { focusOnClick: chrome.window.focusable - onMoveStarted: { - // Move initiated with Meta+LeftMouseButton has started - shellHelper.grabCursor(WS.LiriShell.MoveGrabCursor); - } - onMoveStopped: { - // Move initiated with Meta+LeftMouseButton has stopped - shellHelper.grabCursor(WS.LiriShell.ArrowGrabCursor); - } - onSurfaceDestroyed: { bufferLocked = true; destroyAnimation.start(); } + // Drag windows with Meta + DragHandler { + id: dragHandler + + acceptedModifiers: liriCompositor.settings.input.windowActionKey + target: shellSurfaceItem.moveItem + property var movingBinding: Binding { + target: shellSurfaceItem.moveItem + property: "moving" + value: dragHandler.active + } + } + /* * Animations */ diff --git a/src/imports/shell-private/CMakeLists.txt b/src/imports/shell-private/CMakeLists.txt index 9d28a72f9..eae3672c9 100644 --- a/src/imports/shell-private/CMakeLists.txt +++ b/src/imports/shell-private/CMakeLists.txt @@ -43,8 +43,6 @@ liri_add_qml_plugin(shell-private screencast.h screenmodel.cpp screenmodel.h - shellsurfaceitem.cpp - shellsurfaceitem.h waylandwindow.cpp waylandwindow.h windowmousetracker.cpp diff --git a/src/imports/shell-private/plugin.cpp b/src/imports/shell-private/plugin.cpp index c57bb03f5..b0e6d3ccf 100644 --- a/src/imports/shell-private/plugin.cpp +++ b/src/imports/shell-private/plugin.cpp @@ -38,7 +38,6 @@ #include "quickoutput.h" #include "screencast.h" #include "screenmodel.h" -#include "shellsurfaceitem.h" #include "waylandwindow.h" #include "windowmousetracker.h" @@ -110,7 +109,6 @@ class ShellPrivatePlugin : public QQmlExtensionPlugin QStringLiteral("Cannot create instance of ScreenMode")); qmlRegisterUncreatableType(uri, versionMajor, versionMinor, "ScreenItem", QStringLiteral("Cannot create instance of ScreenItem")); - qmlRegisterType(uri, versionMajor, versionMinor, "ShellSurfaceItem"); qmlRegisterType(uri, versionMajor, versionMinor, "WaylandWindow"); qmlRegisterType(uri, versionMajor, versionMinor, "WindowMouseTracker"); diff --git a/src/imports/shell-private/shellsurfaceitem.cpp b/src/imports/shell-private/shellsurfaceitem.cpp deleted file mode 100644 index 642480693..000000000 --- a/src/imports/shell-private/shellsurfaceitem.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** - * This file is part of Liri. - * - * Copyright (C) 2019 Pier Luigi Fiorini - * - * $BEGIN_LICENSE:GPL3+$ - * - * 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 3 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 . - * - * $END_LICENSE$ - ***************************************************************************/ - -#include "shellsurfaceitem.h" - -ShellSurfaceItem::ShellSurfaceItem(QQuickItem *parent) - : QWaylandQuickShellSurfaceItem(parent) -{ -} - -void ShellSurfaceItem::keyPressEvent(QKeyEvent *event) -{ - if (inputEventsEnabled()) { - if (event->key() == Qt::Key_Alt) - moveState.modifier = true; - } - - QWaylandQuickShellSurfaceItem::keyPressEvent(event); -} - -void ShellSurfaceItem::keyReleaseEvent(QKeyEvent *event) -{ - if (inputEventsEnabled()) { - if (event->key() == Qt::Key_Alt) { - moveState.modifier = false; - moveState.initialized = false; - - if (moveState.started) { - moveState.started = false; - Q_EMIT moveStopped(); - } - } - } - - QWaylandQuickShellSurfaceItem::keyReleaseEvent(event); -} - -void ShellSurfaceItem::mousePressEvent(QMouseEvent *event) -{ - if (inputEventsEnabled()) { - if (event->buttons().testFlag(Qt::LeftButton)) - moveState.button = true; - } - - QWaylandQuickShellSurfaceItem::mousePressEvent(event); -} - -void ShellSurfaceItem::mouseReleaseEvent(QMouseEvent *event) -{ - if (!event->buttons().testFlag(Qt::LeftButton)) { - moveState.button = false; - moveState.initialized = false; - - if (moveState.started) { - moveState.started = false; - Q_EMIT moveStopped(); - } - } - - QWaylandQuickShellSurfaceItem::mouseReleaseEvent(event); -} - -void ShellSurfaceItem::mouseMoveEvent(QMouseEvent *event) -{ - if (inputEventsEnabled()) { - // Move as long as Alt+LMB were pressed - if (moveState.modifier && moveState.button) { - if (!moveState.initialized) { - moveState.initialOffset = moveItem()->mapFromItem(nullptr, event->windowPos()); - moveState.initialized = true; - moveState.started = true; - Q_EMIT moveStarted(); - } else if (moveItem()->parentItem()) { - QPointF parentPos = moveItem()->parentItem()->mapFromItem(nullptr, event->windowPos()); - moveItem()->setPosition(parentPos - moveState.initialOffset); - } - - event->ignore(); - return; - } else { - moveState.initialized = false; - } - } - - QWaylandQuickShellSurfaceItem::mouseMoveEvent(event); -} diff --git a/src/imports/shell-private/shellsurfaceitem.h b/src/imports/shell-private/shellsurfaceitem.h deleted file mode 100644 index 82c60956a..000000000 --- a/src/imports/shell-private/shellsurfaceitem.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - * This file is part of Liri. - * - * Copyright (C) 2019 Pier Luigi Fiorini - * - * $BEGIN_LICENSE:GPL3+$ - * - * 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 3 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 . - * - * $END_LICENSE$ - ***************************************************************************/ - -#ifndef SHELLSURFACEITEM_H -#define SHELLSURFACEITEM_H - -#include - -class ShellSurfaceItem : public QWaylandQuickShellSurfaceItem -{ - Q_OBJECT -public: - explicit ShellSurfaceItem(QQuickItem *parent = nullptr); - -Q_SIGNALS: - void moveStarted(); - void moveStopped(); - -protected: - void keyPressEvent(QKeyEvent *event) override; - void keyReleaseEvent(QKeyEvent *event) override; - void mousePressEvent(QMouseEvent *event) override; - void mouseReleaseEvent(QMouseEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; - -private: - struct { - bool modifier = false; - bool button = false; - bool initialized = false; - bool started = false; - QPointF initialOffset; - } moveState; -}; - -#endif // SHELLSURFACEITEM_H