2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2011-06-23 10:09:17 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
|
|
|
|
SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2011-06-23 10:09:17 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
Since the functionality provided in this class has been moved from
|
|
|
|
class Workspace, it is not clear who exactly has written the code.
|
|
|
|
The list below contains the copyright holders of the class Workspace.
|
2011-06-23 10:09:17 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2009 Lucas Murray <lmurray@undefinedfire.com>
|
2011-06-23 10:09:17 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2011-06-23 10:09:17 +00:00
|
|
|
|
|
|
|
#include "screenedge.h"
|
|
|
|
|
|
|
|
// KWin
|
2021-08-28 12:35:13 +00:00
|
|
|
#include "abstract_output.h"
|
2017-03-19 10:40:03 +00:00
|
|
|
#include "gestures.h"
|
2019-09-24 08:48:08 +00:00
|
|
|
#include <x11client.h>
|
2013-02-19 10:25:46 +00:00
|
|
|
#include "cursor.h"
|
2013-06-26 08:25:17 +00:00
|
|
|
#include "main.h"
|
2016-04-15 11:47:56 +00:00
|
|
|
#include "platform.h"
|
2011-06-23 10:09:17 +00:00
|
|
|
#include "utils.h"
|
2014-09-26 12:01:44 +00:00
|
|
|
#include <workspace.h>
|
2012-11-16 07:23:47 +00:00
|
|
|
#include "virtualdesktops.h"
|
2014-05-15 07:01:51 +00:00
|
|
|
// DBus generated
|
|
|
|
#include "screenlocker_interface.h"
|
2014-09-26 12:01:44 +00:00
|
|
|
// frameworks
|
|
|
|
#include <KConfigGroup>
|
2011-06-23 10:09:17 +00:00
|
|
|
// Qt
|
2017-03-31 05:41:21 +00:00
|
|
|
#include <QAction>
|
2016-02-11 14:51:25 +00:00
|
|
|
#include <QMouseEvent>
|
2014-08-27 19:48:23 +00:00
|
|
|
#include <QSharedPointer>
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QTextStream>
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QDBusInterface>
|
|
|
|
#include <QDBusPendingCall>
|
2014-09-26 12:01:44 +00:00
|
|
|
#include <QWidget>
|
2011-06-23 10:09:17 +00:00
|
|
|
|
|
|
|
namespace KWin {
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
// Mouse should not move more than this many pixels
|
|
|
|
static const int DISTANCE_RESET = 30;
|
|
|
|
|
2020-05-14 18:28:36 +00:00
|
|
|
// How large the touch target of the area recognizing touch gestures is
|
|
|
|
static const int TOUCH_TARGET = 3;
|
|
|
|
|
|
|
|
// How far the user needs to swipe before triggering an action.
|
|
|
|
static const int MINIMUM_DELTA = 44;
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
Edge::Edge(ScreenEdges *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_edges(parent)
|
|
|
|
, m_border(ElectricNone)
|
|
|
|
, m_action(ElectricActionNone)
|
|
|
|
, m_reserved(0)
|
2013-01-26 10:50:14 +00:00
|
|
|
, m_approaching(false)
|
2013-04-14 18:04:05 +00:00
|
|
|
, m_lastApproachingFactor(0)
|
2013-01-31 16:25:03 +00:00
|
|
|
, m_blocked(false)
|
2014-08-27 19:48:23 +00:00
|
|
|
, m_pushBackBlocked(false)
|
2014-02-20 11:39:23 +00:00
|
|
|
, m_client(nullptr)
|
2017-03-19 10:40:03 +00:00
|
|
|
, m_gesture(new SwipeGesture(this))
|
|
|
|
{
|
|
|
|
m_gesture->setMinimumFingerCount(1);
|
|
|
|
m_gesture->setMaximumFingerCount(1);
|
|
|
|
connect(m_gesture, &Gesture::triggered, this,
|
|
|
|
[this] {
|
|
|
|
stopApproaching();
|
|
|
|
if (m_client) {
|
|
|
|
m_client->showOnScreenEdge();
|
|
|
|
unreserve();
|
|
|
|
return;
|
|
|
|
}
|
2017-03-30 05:08:38 +00:00
|
|
|
handleTouchAction();
|
2017-03-31 05:41:21 +00:00
|
|
|
handleTouchCallback();
|
2017-03-19 10:40:03 +00:00
|
|
|
}, Qt::QueuedConnection
|
|
|
|
);
|
|
|
|
connect(m_gesture, &SwipeGesture::started, this, &Edge::startApproaching);
|
|
|
|
connect(m_gesture, &SwipeGesture::cancelled, this, &Edge::stopApproaching);
|
|
|
|
connect(m_gesture, &SwipeGesture::progress, this,
|
|
|
|
[this] (qreal progress) {
|
|
|
|
int factor = progress * 256.0f;
|
|
|
|
if (m_lastApproachingFactor != factor) {
|
|
|
|
m_lastApproachingFactor = factor;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT approaching(border(), m_lastApproachingFactor/256.0f, m_approachGeometry);
|
2017-03-19 10:40:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2017-03-30 05:08:38 +00:00
|
|
|
connect(this, &Edge::activatesForTouchGestureChanged, this,
|
|
|
|
[this] {
|
|
|
|
if (isReserved()) {
|
|
|
|
if (activatesForTouchGesture()) {
|
|
|
|
m_edges->gestureRecognizer()->registerGesture(m_gesture);
|
|
|
|
} else {
|
|
|
|
m_edges->gestureRecognizer()->unregisterGesture(m_gesture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
Edge::~Edge()
|
2011-06-23 10:09:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void Edge::reserve()
|
2011-06-25 18:08:51 +00:00
|
|
|
{
|
2013-01-21 08:04:06 +00:00
|
|
|
m_reserved++;
|
|
|
|
if (m_reserved == 1) {
|
|
|
|
// got activated
|
|
|
|
activate();
|
|
|
|
}
|
2011-06-25 18:08:51 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 11:47:06 +00:00
|
|
|
void Edge::reserve(QObject *object, const char *slot)
|
|
|
|
{
|
2020-09-23 18:39:59 +00:00
|
|
|
connect(object, &QObject::destroyed, this, qOverload<QObject *>(&Edge::unreserve));
|
2013-01-22 11:47:06 +00:00
|
|
|
m_callBacks.insert(object, QByteArray(slot));
|
|
|
|
reserve();
|
|
|
|
}
|
|
|
|
|
2017-03-31 05:41:21 +00:00
|
|
|
void Edge::reserveTouchCallBack(QAction *action)
|
|
|
|
{
|
|
|
|
if (m_touchActions.contains(action)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
connect(action, &QAction::destroyed, this,
|
|
|
|
[this, action] {
|
|
|
|
unreserveTouchCallBack(action);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
m_touchActions << action;
|
|
|
|
reserve();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::unreserveTouchCallBack(QAction *action)
|
|
|
|
{
|
|
|
|
auto it = std::find_if(m_touchActions.begin(), m_touchActions.end(), [action] (QAction *a) { return a == action; });
|
|
|
|
if (it != m_touchActions.end()) {
|
|
|
|
m_touchActions.erase(it);
|
|
|
|
unreserve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void Edge::unreserve()
|
2011-06-23 10:09:17 +00:00
|
|
|
{
|
2013-01-21 08:04:06 +00:00
|
|
|
m_reserved--;
|
|
|
|
if (m_reserved == 0) {
|
|
|
|
// got deactivated
|
2014-02-20 11:39:23 +00:00
|
|
|
stopApproaching();
|
2013-01-21 08:04:06 +00:00
|
|
|
deactivate();
|
|
|
|
}
|
|
|
|
}
|
2013-01-22 11:47:06 +00:00
|
|
|
void Edge::unreserve(QObject *object)
|
|
|
|
{
|
|
|
|
if (m_callBacks.contains(object)) {
|
|
|
|
m_callBacks.remove(object);
|
2020-09-23 18:39:59 +00:00
|
|
|
disconnect(object, &QObject::destroyed, this, qOverload<QObject *>(&Edge::unreserve));
|
2013-01-22 11:47:06 +00:00
|
|
|
unreserve();
|
|
|
|
}
|
|
|
|
}
|
2011-06-23 10:09:17 +00:00
|
|
|
|
2017-03-30 05:08:38 +00:00
|
|
|
bool Edge::activatesForPointer() const
|
|
|
|
{
|
|
|
|
if (m_client) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (m_edges->isDesktopSwitching()) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-06-18 11:36:27 +00:00
|
|
|
if (m_edges->isDesktopSwitchingMovingClients()) {
|
2019-04-18 12:28:11 +00:00
|
|
|
auto c = Workspace::self()->moveResizeClient();
|
2021-04-30 18:06:58 +00:00
|
|
|
if (c && !c->isInteractiveResize()) {
|
2017-06-18 11:36:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-03-30 05:08:38 +00:00
|
|
|
if (!m_callBacks.isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (m_action != ElectricActionNone) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Edge::activatesForTouchGesture() const
|
|
|
|
{
|
|
|
|
if (!isScreenEdge()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-11 18:59:54 +00:00
|
|
|
if (m_blocked) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-30 05:08:38 +00:00
|
|
|
if (m_client) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (m_touchAction != ElectricActionNone) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-31 05:41:21 +00:00
|
|
|
if (!m_touchActions.isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-30 05:08:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
bool Edge::triggersFor(const QPoint &cursorPos) const
|
|
|
|
{
|
2013-01-31 16:25:03 +00:00
|
|
|
if (isBlocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-30 05:08:38 +00:00
|
|
|
if (!activatesForPointer()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
if (!m_geometry.contains(cursorPos)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isLeft() && cursorPos.x() != m_geometry.x()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isRight() && cursorPos.x() != (m_geometry.x() + m_geometry.width() -1)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isTop() && cursorPos.y() != m_geometry.y()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isBottom() && cursorPos.y() != (m_geometry.y() + m_geometry.height() -1)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-20 11:39:23 +00:00
|
|
|
bool Edge::check(const QPoint &cursorPos, const QDateTime &triggerTime, bool forceNoPushBack)
|
2013-01-21 08:04:06 +00:00
|
|
|
{
|
|
|
|
if (!triggersFor(cursorPos)) {
|
2014-02-20 11:39:23 +00:00
|
|
|
return false;
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
2015-08-23 09:56:17 +00:00
|
|
|
if (m_lastTrigger.isValid() && // still in cooldown
|
2015-09-10 19:03:53 +00:00
|
|
|
m_lastTrigger.msecsTo(triggerTime) < edges()->reActivationThreshold() - edges()->timeThreshold()) {
|
2015-08-23 09:56:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
// no pushback so we have to activate at once
|
2015-05-26 20:39:29 +00:00
|
|
|
bool directActivate = forceNoPushBack || edges()->cursorPushBackDistance().isNull() || m_client;
|
2013-01-21 08:04:06 +00:00
|
|
|
if (directActivate || canActivate(cursorPos, triggerTime)) {
|
2014-02-20 11:39:23 +00:00
|
|
|
markAsTriggered(cursorPos, triggerTime);
|
2013-01-21 08:04:06 +00:00
|
|
|
handle(cursorPos);
|
2014-02-20 11:39:23 +00:00
|
|
|
return true;
|
2013-01-21 08:04:06 +00:00
|
|
|
} else {
|
|
|
|
pushCursorBack(cursorPos);
|
2014-02-20 11:39:23 +00:00
|
|
|
m_triggeredPoint = cursorPos;
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
2014-02-20 11:39:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::markAsTriggered(const QPoint &cursorPos, const QDateTime &triggerTime)
|
|
|
|
{
|
|
|
|
m_lastTrigger = triggerTime;
|
|
|
|
m_lastReset = QDateTime(); // invalidate
|
2013-01-21 08:04:06 +00:00
|
|
|
m_triggeredPoint = cursorPos;
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
bool Edge::canActivate(const QPoint &cursorPos, const QDateTime &triggerTime)
|
2012-11-25 09:13:34 +00:00
|
|
|
{
|
2018-08-29 18:02:16 +00:00
|
|
|
// we check whether either the timer has explicitly been invalidated (successful trigger) or is
|
2013-07-17 14:39:58 +00:00
|
|
|
// bigger than the reactivation threshold (activation "aborted", usually due to moving away the cursor
|
2018-08-29 18:02:16 +00:00
|
|
|
// from the corner after successful activation)
|
2013-07-17 14:39:58 +00:00
|
|
|
// either condition means that "this is the first event in a new attempt"
|
|
|
|
if (!m_lastReset.isValid() || m_lastReset.msecsTo(triggerTime) > edges()->reActivationThreshold()) {
|
2013-01-21 08:04:06 +00:00
|
|
|
m_lastReset = triggerTime;
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-10 19:03:53 +00:00
|
|
|
if (m_lastTrigger.isValid() && m_lastTrigger.msecsTo(triggerTime) < edges()->reActivationThreshold() - edges()->timeThreshold()) {
|
2013-01-21 08:04:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_lastReset.msecsTo(triggerTime) < edges()->timeThreshold()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// does the check on position make any sense at all?
|
|
|
|
if ((cursorPos - m_triggeredPoint).manhattanLength() > DISTANCE_RESET) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::handle(const QPoint &cursorPos)
|
|
|
|
{
|
2019-04-18 12:28:11 +00:00
|
|
|
AbstractClient *movingClient = Workspace::self()->moveResizeClient();
|
2021-04-30 18:06:58 +00:00
|
|
|
if ((edges()->isDesktopSwitchingMovingClients() && movingClient && !movingClient->isInteractiveResize()) ||
|
2013-01-21 08:04:06 +00:00
|
|
|
(edges()->isDesktopSwitching() && isScreenEdge())) {
|
|
|
|
// always switch desktops in case:
|
|
|
|
// moving a Client and option for switch on client move is enabled
|
|
|
|
// or switch on screen edge is enabled
|
|
|
|
switchDesktop(cursorPos);
|
2012-11-25 09:13:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-03 12:26:18 +00:00
|
|
|
if (movingClient) {
|
2013-02-13 09:37:10 +00:00
|
|
|
// if we are moving a window we don't want to trigger the actions. This just results in
|
|
|
|
// problems, e.g. Desktop Grid activated or screen locker activated which just cannot
|
|
|
|
// work as we hold a grab.
|
|
|
|
return;
|
|
|
|
}
|
2015-10-29 16:32:58 +00:00
|
|
|
|
|
|
|
if (m_client) {
|
|
|
|
pushCursorBack(cursorPos);
|
|
|
|
m_client->showOnScreenEdge();
|
|
|
|
unreserve();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-30 05:08:38 +00:00
|
|
|
if (handlePointerAction() || handleByCallback()) {
|
2013-01-21 08:04:06 +00:00
|
|
|
pushCursorBack(cursorPos);
|
|
|
|
return;
|
2012-11-25 09:13:34 +00:00
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
if (edges()->isDesktopSwitching() && isCorner()) {
|
|
|
|
// try again desktop switching for the corner
|
|
|
|
switchDesktop(cursorPos);
|
2012-11-25 09:13:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-30 05:08:38 +00:00
|
|
|
bool Edge::handleAction(ElectricBorderAction action)
|
2012-11-25 09:13:34 +00:00
|
|
|
{
|
2017-03-30 05:08:38 +00:00
|
|
|
switch (action) {
|
2013-01-21 08:04:06 +00:00
|
|
|
case ElectricActionShowDesktop: {
|
|
|
|
Workspace::self()->setShowingDesktop(!Workspace::self()->showingDesktop());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case ElectricActionLockScreen: { // Lock the screen
|
2014-05-15 07:01:51 +00:00
|
|
|
OrgFreedesktopScreenSaverInterface interface(QStringLiteral("org.freedesktop.ScreenSaver"),
|
|
|
|
QStringLiteral("/ScreenSaver"),
|
|
|
|
QDBusConnection::sessionBus());
|
|
|
|
if (interface.isValid()) {
|
|
|
|
interface.Lock();
|
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-04-07 19:07:41 +00:00
|
|
|
case ElectricActionKRunner: { // open krunner
|
|
|
|
QDBusConnection::sessionBus().asyncCall(
|
|
|
|
QDBusMessage::createMethodCall(QStringLiteral("org.kde.krunner"),
|
|
|
|
QStringLiteral("/App"),
|
|
|
|
QStringLiteral("org.kde.krunner.App"),
|
|
|
|
QStringLiteral("display")
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case ElectricActionActivityManager: { // open activity manager
|
|
|
|
QDBusConnection::sessionBus().asyncCall(
|
|
|
|
QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"),
|
|
|
|
QStringLiteral("/PlasmaShell"),
|
|
|
|
QStringLiteral("org.kde.PlasmaShell"),
|
|
|
|
QStringLiteral("toggleActivityManager")
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-10 13:07:54 +00:00
|
|
|
case ElectricActionApplicationLauncher: {
|
|
|
|
QDBusConnection::sessionBus().asyncCall(
|
|
|
|
QDBusMessage::createMethodCall(QStringLiteral("org.kde.plasmashell"),
|
|
|
|
QStringLiteral("/PlasmaShell"),
|
|
|
|
QStringLiteral("org.kde.PlasmaShell"),
|
|
|
|
QStringLiteral("activateLauncherMenu")
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 11:47:06 +00:00
|
|
|
bool Edge::handleByCallback()
|
2013-01-21 08:04:06 +00:00
|
|
|
{
|
2013-01-22 11:47:06 +00:00
|
|
|
if (m_callBacks.isEmpty()) {
|
2013-01-21 08:04:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-22 11:47:06 +00:00
|
|
|
for (QHash<QObject *, QByteArray>::iterator it = m_callBacks.begin();
|
|
|
|
it != m_callBacks.end();
|
|
|
|
++it) {
|
|
|
|
bool retVal = false;
|
|
|
|
QMetaObject::invokeMethod(it.key(), it.value().constData(), Q_RETURN_ARG(bool, retVal), Q_ARG(ElectricBorder, m_border));
|
|
|
|
if (retVal) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 05:41:21 +00:00
|
|
|
void Edge::handleTouchCallback()
|
|
|
|
{
|
|
|
|
if (m_touchActions.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_touchActions.first()->trigger();
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void Edge::switchDesktop(const QPoint &cursorPos)
|
|
|
|
{
|
|
|
|
QPoint pos(cursorPos);
|
|
|
|
VirtualDesktopManager *vds = VirtualDesktopManager::self();
|
2021-08-13 07:48:52 +00:00
|
|
|
VirtualDesktop *oldDesktop = vds->currentDesktop();
|
|
|
|
VirtualDesktop *desktop = oldDesktop;
|
2013-01-21 08:04:06 +00:00
|
|
|
const int OFFSET = 2;
|
|
|
|
if (isLeft()) {
|
2021-08-13 07:48:52 +00:00
|
|
|
const VirtualDesktop *interimDesktop = desktop;
|
2013-01-21 08:04:06 +00:00
|
|
|
desktop = vds->toLeft(desktop, vds->isNavigationWrappingAround());
|
2021-08-13 07:48:52 +00:00
|
|
|
if (desktop != interimDesktop) {
|
2021-08-31 07:19:43 +00:00
|
|
|
pos.setX(workspace()->geometry().width() - 1 - OFFSET);
|
2021-08-13 07:48:52 +00:00
|
|
|
}
|
2014-04-12 19:38:52 +00:00
|
|
|
} else if (isRight()) {
|
2021-08-13 07:48:52 +00:00
|
|
|
const VirtualDesktop *interimDesktop = desktop;
|
2013-01-21 08:04:06 +00:00
|
|
|
desktop = vds->toRight(desktop, vds->isNavigationWrappingAround());
|
2021-08-13 07:48:52 +00:00
|
|
|
if (desktop != interimDesktop) {
|
2014-04-12 19:38:52 +00:00
|
|
|
pos.setX(OFFSET);
|
2021-08-13 07:48:52 +00:00
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
if (isTop()) {
|
2021-08-13 07:48:52 +00:00
|
|
|
const VirtualDesktop *interimDesktop = desktop;
|
2013-01-21 08:04:06 +00:00
|
|
|
desktop = vds->above(desktop, vds->isNavigationWrappingAround());
|
2021-08-13 07:48:52 +00:00
|
|
|
if (desktop != interimDesktop) {
|
2021-08-31 07:19:43 +00:00
|
|
|
pos.setY(workspace()->geometry().height() - 1 - OFFSET);
|
2021-08-13 07:48:52 +00:00
|
|
|
}
|
2014-04-12 19:38:52 +00:00
|
|
|
} else if (isBottom()) {
|
2021-08-13 07:48:52 +00:00
|
|
|
const VirtualDesktop *interimDesktop = desktop;
|
2013-01-21 08:04:06 +00:00
|
|
|
desktop = vds->below(desktop, vds->isNavigationWrappingAround());
|
2021-08-13 07:48:52 +00:00
|
|
|
if (desktop != interimDesktop) {
|
2014-04-12 19:38:52 +00:00
|
|
|
pos.setY(OFFSET);
|
2021-08-13 07:48:52 +00:00
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
2014-09-26 12:01:44 +00:00
|
|
|
#ifndef KWIN_UNIT_TEST
|
2019-04-18 12:28:11 +00:00
|
|
|
if (AbstractClient *c = Workspace::self()->moveResizeClient()) {
|
2021-08-13 07:48:52 +00:00
|
|
|
const QVector<VirtualDesktop *> desktops{desktop};
|
|
|
|
if (c->rules()->checkDesktops(desktops) != desktops) {
|
2013-01-21 08:04:06 +00:00
|
|
|
// user attempts to move a client to another desktop where it is ruleforced to not be
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-09-26 12:01:44 +00:00
|
|
|
#endif
|
2013-01-21 08:04:06 +00:00
|
|
|
vds->setCurrent(desktop);
|
2021-08-13 07:48:52 +00:00
|
|
|
if (vds->currentDesktop() != oldDesktop) {
|
2014-08-27 19:48:23 +00:00
|
|
|
m_pushBackBlocked = true;
|
2020-04-02 16:18:01 +00:00
|
|
|
Cursors::self()->mouse()->setPos(pos);
|
2014-08-27 19:48:23 +00:00
|
|
|
QSharedPointer<QMetaObject::Connection> me(new QMetaObject::Connection);
|
|
|
|
*me = QObject::connect(QCoreApplication::eventDispatcher(),
|
|
|
|
&QAbstractEventDispatcher::aboutToBlock, this,
|
|
|
|
[this, me](){
|
|
|
|
QObject::disconnect(*me);
|
|
|
|
const_cast<QSharedPointer<QMetaObject::Connection>*>(&me)->reset(nullptr);
|
|
|
|
m_pushBackBlocked = false;
|
|
|
|
}
|
|
|
|
);
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::pushCursorBack(const QPoint &cursorPos)
|
|
|
|
{
|
2014-08-27 19:48:23 +00:00
|
|
|
if (m_pushBackBlocked)
|
|
|
|
return;
|
2013-01-21 08:04:06 +00:00
|
|
|
int x = cursorPos.x();
|
|
|
|
int y = cursorPos.y();
|
|
|
|
const QSize &distance = edges()->cursorPushBackDistance();
|
|
|
|
if (isLeft()) {
|
|
|
|
x += distance.width();
|
|
|
|
}
|
|
|
|
if (isRight()) {
|
|
|
|
x -= distance.width();
|
|
|
|
}
|
|
|
|
if (isTop()) {
|
|
|
|
y += distance.height();
|
|
|
|
}
|
|
|
|
if (isBottom()) {
|
|
|
|
y -= distance.height();
|
|
|
|
}
|
2020-04-02 16:18:01 +00:00
|
|
|
Cursors::self()->mouse()->setPos(x, y);
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
|
2013-01-26 10:50:14 +00:00
|
|
|
void Edge::setGeometry(const QRect &geometry)
|
|
|
|
{
|
|
|
|
if (m_geometry == geometry) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_geometry = geometry;
|
|
|
|
int x = m_geometry.x();
|
|
|
|
int y = m_geometry.y();
|
|
|
|
int width = m_geometry.width();
|
|
|
|
int height = m_geometry.height();
|
2021-10-05 12:32:36 +00:00
|
|
|
const int offset = m_edges->cornerOffset();
|
2013-01-26 10:50:14 +00:00
|
|
|
if (isCorner()) {
|
|
|
|
if (isRight()) {
|
2021-10-05 12:32:36 +00:00
|
|
|
x = x + width - offset;
|
2013-01-26 10:50:14 +00:00
|
|
|
}
|
|
|
|
if (isBottom()) {
|
2021-10-05 12:32:36 +00:00
|
|
|
y = y + height - offset;
|
2013-01-26 10:50:14 +00:00
|
|
|
}
|
2021-10-05 12:32:36 +00:00
|
|
|
width = offset;
|
|
|
|
height = offset;
|
2013-01-26 10:50:14 +00:00
|
|
|
} else {
|
|
|
|
if (isLeft()) {
|
2021-10-05 12:32:36 +00:00
|
|
|
y += offset;
|
|
|
|
width = offset;
|
|
|
|
height = height - offset * 2;
|
2013-01-26 10:50:14 +00:00
|
|
|
} else if (isRight()) {
|
2021-10-05 12:32:36 +00:00
|
|
|
x = x + width - offset;
|
|
|
|
y += offset;
|
|
|
|
width = offset;
|
|
|
|
height = height - offset * 2;
|
2013-01-26 10:50:14 +00:00
|
|
|
} else if (isTop()) {
|
2021-10-05 12:32:36 +00:00
|
|
|
x += offset;
|
|
|
|
width = width - offset * 2;
|
|
|
|
height = offset;
|
2013-01-26 10:50:14 +00:00
|
|
|
} else if (isBottom()) {
|
2021-10-05 12:32:36 +00:00
|
|
|
x += offset;
|
|
|
|
y = y + height - offset;
|
|
|
|
width = width - offset * 2;
|
|
|
|
height = offset;
|
2013-01-26 10:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_approachGeometry = QRect(x, y, width, height);
|
|
|
|
doGeometryUpdate();
|
2017-03-30 05:08:38 +00:00
|
|
|
|
|
|
|
if (isScreenEdge()) {
|
2021-08-28 12:35:13 +00:00
|
|
|
const AbstractOutput *output = kwinApp()->platform()->outputAt(m_geometry.center());
|
2017-03-30 05:08:38 +00:00
|
|
|
m_gesture->setStartGeometry(m_geometry);
|
2020-05-14 18:28:36 +00:00
|
|
|
m_gesture->setMinimumDelta(QSizeF(MINIMUM_DELTA, MINIMUM_DELTA) / output->scale());
|
2017-03-30 05:08:38 +00:00
|
|
|
}
|
2013-01-26 10:50:14 +00:00
|
|
|
}
|
|
|
|
|
2013-01-31 16:25:03 +00:00
|
|
|
void Edge::checkBlocking()
|
|
|
|
{
|
|
|
|
if (isCorner()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool newValue = false;
|
2015-03-06 12:37:56 +00:00
|
|
|
if (AbstractClient *client = Workspace::self()->activeClient()) {
|
2019-09-27 10:01:10 +00:00
|
|
|
newValue = client->isFullScreen() && client->frameGeometry().contains(m_geometry.center());
|
2013-01-31 16:25:03 +00:00
|
|
|
}
|
|
|
|
if (newValue == m_blocked) {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-11 18:59:54 +00:00
|
|
|
const bool wasTouch = activatesForTouchGesture();
|
2013-01-31 16:25:03 +00:00
|
|
|
m_blocked = newValue;
|
2017-04-11 18:59:54 +00:00
|
|
|
if (wasTouch != activatesForTouchGesture()) {
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT activatesForTouchGestureChanged();
|
2017-04-11 18:59:54 +00:00
|
|
|
}
|
2013-01-31 16:25:03 +00:00
|
|
|
doUpdateBlocking();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::doUpdateBlocking()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void Edge::doGeometryUpdate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::activate()
|
2017-03-19 10:40:03 +00:00
|
|
|
{
|
2017-03-30 05:08:38 +00:00
|
|
|
if (activatesForTouchGesture()) {
|
2017-03-19 10:40:03 +00:00
|
|
|
m_edges->gestureRecognizer()->registerGesture(m_gesture);
|
|
|
|
}
|
|
|
|
doActivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::doActivate()
|
2013-01-21 08:04:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::deactivate()
|
2017-03-19 10:40:03 +00:00
|
|
|
{
|
|
|
|
m_edges->gestureRecognizer()->unregisterGesture(m_gesture);
|
|
|
|
doDeactivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::doDeactivate()
|
2013-01-21 08:04:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-26 10:50:14 +00:00
|
|
|
void Edge::startApproaching()
|
|
|
|
{
|
|
|
|
if (m_approaching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_approaching = true;
|
|
|
|
doStartApproaching();
|
2013-04-14 18:04:05 +00:00
|
|
|
m_lastApproachingFactor = 0;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT approaching(border(), 0.0, m_approachGeometry);
|
2013-01-26 10:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::doStartApproaching()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::stopApproaching()
|
|
|
|
{
|
|
|
|
if (!m_approaching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_approaching = false;
|
|
|
|
doStopApproaching();
|
2013-04-14 18:04:05 +00:00
|
|
|
m_lastApproachingFactor = 0;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT approaching(border(), 0.0, m_approachGeometry);
|
2013-01-26 10:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::doStopApproaching()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::updateApproaching(const QPoint &point)
|
|
|
|
{
|
|
|
|
if (approachGeometry().contains(point)) {
|
2013-04-14 18:04:05 +00:00
|
|
|
int factor = 0;
|
|
|
|
const int edgeDistance = m_edges->cornerOffset();
|
2019-04-20 21:52:15 +00:00
|
|
|
auto cornerDistance = [=](const QPoint &corner) {
|
|
|
|
return qMax(qAbs(corner.x() - point.x()), qAbs(corner.y() - point.y()));
|
|
|
|
};
|
2013-01-26 10:50:14 +00:00
|
|
|
switch (border()) {
|
|
|
|
case ElectricTopLeft:
|
2019-04-20 21:52:15 +00:00
|
|
|
factor = (cornerDistance(approachGeometry().topLeft())<<8) / edgeDistance;
|
2013-01-26 10:50:14 +00:00
|
|
|
break;
|
|
|
|
case ElectricTopRight:
|
2019-04-20 21:52:15 +00:00
|
|
|
factor = (cornerDistance(approachGeometry().topRight())<<8) / edgeDistance;
|
2013-01-26 10:50:14 +00:00
|
|
|
break;
|
|
|
|
case ElectricBottomRight:
|
2019-04-20 21:52:15 +00:00
|
|
|
factor = (cornerDistance(approachGeometry().bottomRight())<<8) / edgeDistance;
|
2013-01-26 10:50:14 +00:00
|
|
|
break;
|
|
|
|
case ElectricBottomLeft:
|
2019-04-20 21:52:15 +00:00
|
|
|
factor = (cornerDistance(approachGeometry().bottomLeft())<<8) / edgeDistance;
|
2013-01-26 10:50:14 +00:00
|
|
|
break;
|
|
|
|
case ElectricTop:
|
2013-04-14 18:04:05 +00:00
|
|
|
factor = (qAbs(point.y() - approachGeometry().y())<<8) / edgeDistance;
|
2013-01-26 10:50:14 +00:00
|
|
|
break;
|
|
|
|
case ElectricRight:
|
2013-04-14 18:04:05 +00:00
|
|
|
factor = (qAbs(point.x() - approachGeometry().right())<<8) / edgeDistance;
|
2013-01-26 10:50:14 +00:00
|
|
|
break;
|
|
|
|
case ElectricBottom:
|
2013-04-14 18:04:05 +00:00
|
|
|
factor = (qAbs(point.y() - approachGeometry().bottom())<<8) / edgeDistance;
|
2013-01-26 10:50:14 +00:00
|
|
|
break;
|
|
|
|
case ElectricLeft:
|
2013-04-14 18:04:05 +00:00
|
|
|
factor = (qAbs(point.x() - approachGeometry().x())<<8) / edgeDistance;
|
2013-01-26 10:50:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-04-14 18:04:05 +00:00
|
|
|
factor = 256 - factor;
|
2013-01-26 10:50:14 +00:00
|
|
|
if (m_lastApproachingFactor != factor) {
|
|
|
|
m_lastApproachingFactor = factor;
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT approaching(border(), m_lastApproachingFactor/256.0f, m_approachGeometry);
|
2013-01-26 10:50:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stopApproaching();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-15 11:19:22 +00:00
|
|
|
quint32 Edge::window() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 Edge::approachWindow() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-19 10:40:03 +00:00
|
|
|
void Edge::setBorder(ElectricBorder border)
|
|
|
|
{
|
|
|
|
m_border = border;
|
|
|
|
switch (m_border) {
|
|
|
|
case ElectricTop:
|
|
|
|
m_gesture->setDirection(SwipeGesture::Direction::Down);
|
|
|
|
break;
|
|
|
|
case ElectricRight:
|
|
|
|
m_gesture->setDirection(SwipeGesture::Direction::Left);
|
|
|
|
break;
|
|
|
|
case ElectricBottom:
|
|
|
|
m_gesture->setDirection(SwipeGesture::Direction::Up);
|
|
|
|
break;
|
|
|
|
case ElectricLeft:
|
|
|
|
m_gesture->setDirection(SwipeGesture::Direction::Right);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-30 05:08:38 +00:00
|
|
|
void Edge::setTouchAction(ElectricBorderAction action) {
|
|
|
|
const bool wasTouch = activatesForTouchGesture();
|
|
|
|
m_touchAction = action;
|
|
|
|
if (wasTouch != activatesForTouchGesture()) {
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT activatesForTouchGestureChanged();
|
2017-03-30 05:08:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::setClient(AbstractClient *client)
|
|
|
|
{
|
|
|
|
const bool wasTouch = activatesForTouchGesture();
|
|
|
|
m_client = client;
|
|
|
|
if (wasTouch != activatesForTouchGesture()) {
|
2021-06-08 07:02:14 +00:00
|
|
|
Q_EMIT activatesForTouchGestureChanged();
|
2017-03-30 05:08:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
/**********************************************************
|
|
|
|
* ScreenEdges
|
|
|
|
*********************************************************/
|
2013-04-05 07:41:25 +00:00
|
|
|
KWIN_SINGLETON_FACTORY(ScreenEdges)
|
2013-01-25 09:15:00 +00:00
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
ScreenEdges::ScreenEdges(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_desktopSwitching(false)
|
|
|
|
, m_desktopSwitchingMovingClients(false)
|
|
|
|
, m_timeThreshold(0)
|
|
|
|
, m_reactivateThreshold(0)
|
2019-12-30 05:54:08 +00:00
|
|
|
, m_virtualDesktopLayout({})
|
2013-01-21 08:04:06 +00:00
|
|
|
, m_actionTopLeft(ElectricActionNone)
|
|
|
|
, m_actionTop(ElectricActionNone)
|
|
|
|
, m_actionTopRight(ElectricActionNone)
|
|
|
|
, m_actionRight(ElectricActionNone)
|
|
|
|
, m_actionBottomRight(ElectricActionNone)
|
|
|
|
, m_actionBottom(ElectricActionNone)
|
|
|
|
, m_actionBottomLeft(ElectricActionNone)
|
|
|
|
, m_actionLeft(ElectricActionNone)
|
2017-03-19 10:40:03 +00:00
|
|
|
, m_gestureRecognizer(new GestureRecognizer(this))
|
2013-01-21 08:04:06 +00:00
|
|
|
{
|
2021-08-31 07:19:43 +00:00
|
|
|
// TODO: Maybe calculate the corner offset based on font metrics instead?
|
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
if (!outputs.isEmpty()) {
|
|
|
|
const QSize size = outputs[0]->geometry().size();
|
|
|
|
const QSizeF physicalSize = outputs[0]->physicalSize();
|
|
|
|
|
|
|
|
const int physicalDpiX = size.width() / physicalSize.width() * qreal(25.4);
|
|
|
|
const int physicalDpiY = size.height() / physicalSize.height() * qreal(25.4);
|
|
|
|
|
|
|
|
m_cornerOffset = (physicalDpiX + physicalDpiY + 5) / 6;
|
|
|
|
}
|
2014-02-20 11:39:23 +00:00
|
|
|
|
2016-09-15 19:03:40 +00:00
|
|
|
connect(workspace(), &Workspace::clientRemoved, this, &ScreenEdges::deleteEdgeForClient);
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScreenEdges::~ScreenEdges()
|
|
|
|
{
|
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;
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdges::init()
|
|
|
|
{
|
|
|
|
reconfigure();
|
2012-11-25 09:13:34 +00:00
|
|
|
updateLayout();
|
2013-01-21 08:04:06 +00:00
|
|
|
recreateEdges();
|
|
|
|
}
|
|
|
|
static ElectricBorderAction electricBorderAction(const QString& name)
|
|
|
|
{
|
|
|
|
QString lowerName = name.toLower();
|
2015-10-19 13:39:52 +00:00
|
|
|
if (lowerName == QStringLiteral("showdesktop")) {
|
2013-01-21 08:04:06 +00:00
|
|
|
return ElectricActionShowDesktop;
|
2013-07-23 05:02:52 +00:00
|
|
|
} else if (lowerName == QStringLiteral("lockscreen")) {
|
2013-01-21 08:04:06 +00:00
|
|
|
return ElectricActionLockScreen;
|
2016-04-07 19:07:41 +00:00
|
|
|
} else if (lowerName == QLatin1String("krunner")) {
|
|
|
|
return ElectricActionKRunner;
|
|
|
|
} else if (lowerName == QLatin1String("activitymanager")) {
|
|
|
|
return ElectricActionActivityManager;
|
2016-08-10 13:07:54 +00:00
|
|
|
} else if (lowerName == QLatin1String("applicationlauncher")) {
|
|
|
|
return ElectricActionApplicationLauncher;
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
return ElectricActionNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdges::reconfigure()
|
|
|
|
{
|
|
|
|
if (!m_config) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// TODO: migrate settings to a group ScreenEdges
|
|
|
|
KConfigGroup windowsConfig = m_config->group("Windows");
|
|
|
|
setTimeThreshold(windowsConfig.readEntry("ElectricBorderDelay", 150));
|
2013-08-16 17:38:26 +00:00
|
|
|
setReActivationThreshold(qMax(timeThreshold() + 50, windowsConfig.readEntry("ElectricBorderCooldown", 350)));
|
2013-01-21 08:04:06 +00:00
|
|
|
int desktopSwitching = windowsConfig.readEntry("ElectricBorders", static_cast<int>(ElectricDisabled));
|
|
|
|
if (desktopSwitching == ElectricDisabled) {
|
|
|
|
setDesktopSwitching(false);
|
|
|
|
setDesktopSwitchingMovingClients(false);
|
|
|
|
} else if (desktopSwitching == ElectricMoveOnly) {
|
|
|
|
setDesktopSwitching(false);
|
|
|
|
setDesktopSwitchingMovingClients(true);
|
|
|
|
} else if (desktopSwitching == ElectricAlways) {
|
|
|
|
setDesktopSwitching(true);
|
|
|
|
setDesktopSwitchingMovingClients(true);
|
|
|
|
}
|
|
|
|
const int pushBack = windowsConfig.readEntry("ElectricBorderPushbackPixels", 1);
|
|
|
|
m_cursorPushBackDistance = QSize(pushBack, pushBack);
|
|
|
|
|
|
|
|
KConfigGroup borderConfig = m_config->group("ElectricBorders");
|
|
|
|
setActionForBorder(ElectricTopLeft, &m_actionTopLeft,
|
|
|
|
electricBorderAction(borderConfig.readEntry("TopLeft", "None")));
|
|
|
|
setActionForBorder(ElectricTop, &m_actionTop,
|
|
|
|
electricBorderAction(borderConfig.readEntry("Top", "None")));
|
|
|
|
setActionForBorder(ElectricTopRight, &m_actionTopRight,
|
|
|
|
electricBorderAction(borderConfig.readEntry("TopRight", "None")));
|
|
|
|
setActionForBorder(ElectricRight, &m_actionRight,
|
|
|
|
electricBorderAction(borderConfig.readEntry("Right", "None")));
|
|
|
|
setActionForBorder(ElectricBottomRight, &m_actionBottomRight,
|
|
|
|
electricBorderAction(borderConfig.readEntry("BottomRight", "None")));
|
|
|
|
setActionForBorder(ElectricBottom, &m_actionBottom,
|
|
|
|
electricBorderAction(borderConfig.readEntry("Bottom", "None")));
|
|
|
|
setActionForBorder(ElectricBottomLeft, &m_actionBottomLeft,
|
|
|
|
electricBorderAction(borderConfig.readEntry("BottomLeft", "None")));
|
|
|
|
setActionForBorder(ElectricLeft, &m_actionLeft,
|
|
|
|
electricBorderAction(borderConfig.readEntry("Left", "None")));
|
2017-03-30 05:08:38 +00:00
|
|
|
|
|
|
|
borderConfig = m_config->group("TouchEdges");
|
|
|
|
setActionForTouchBorder(ElectricTop, electricBorderAction(borderConfig.readEntry("Top", "None")));
|
|
|
|
setActionForTouchBorder(ElectricRight, electricBorderAction(borderConfig.readEntry("Right", "None")));
|
|
|
|
setActionForTouchBorder(ElectricBottom, electricBorderAction(borderConfig.readEntry("Bottom", "None")));
|
|
|
|
setActionForTouchBorder(ElectricLeft, electricBorderAction(borderConfig.readEntry("Left", "None")));
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdges::setActionForBorder(ElectricBorder border, ElectricBorderAction *oldValue, ElectricBorderAction newValue)
|
|
|
|
{
|
|
|
|
if (*oldValue == newValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*oldValue == ElectricActionNone) {
|
|
|
|
// have to reserve
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2013-01-21 08:04:06 +00:00
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->reserve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newValue == ElectricActionNone) {
|
|
|
|
// have to unreserve
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2013-01-21 08:04:06 +00:00
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->unreserve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*oldValue = newValue;
|
|
|
|
// update action on all Edges for given border
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2013-01-21 08:04:06 +00:00
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->setAction(newValue);
|
|
|
|
}
|
|
|
|
}
|
2012-11-25 09:13:34 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 05:08:38 +00:00
|
|
|
void ScreenEdges::setActionForTouchBorder(ElectricBorder border, ElectricBorderAction newValue)
|
|
|
|
{
|
|
|
|
auto it = m_touchActions.find(border);
|
|
|
|
ElectricBorderAction oldValue = ElectricActionNone;
|
2017-04-07 17:35:14 +00:00
|
|
|
if (it != m_touchActions.end()) {
|
2017-03-30 05:08:38 +00:00
|
|
|
oldValue = it.value();
|
|
|
|
}
|
|
|
|
if (oldValue == newValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (oldValue == ElectricActionNone) {
|
|
|
|
// have to reserve
|
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->reserve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newValue == ElectricActionNone) {
|
|
|
|
// have to unreserve
|
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->unreserve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_touchActions.erase(it);
|
|
|
|
} else {
|
|
|
|
m_touchActions.insert(border, newValue);
|
|
|
|
}
|
|
|
|
// update action on all Edges for given border
|
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->setTouchAction(newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void ScreenEdges::updateLayout()
|
2012-11-25 09:13:34 +00:00
|
|
|
{
|
|
|
|
const QSize desktopMatrix = VirtualDesktopManager::self()->grid().size();
|
2019-12-23 13:08:58 +00:00
|
|
|
Qt::Orientations newLayout = {};
|
2012-11-25 09:13:34 +00:00
|
|
|
if (desktopMatrix.width() > 1) {
|
|
|
|
newLayout |= Qt::Horizontal;
|
|
|
|
}
|
|
|
|
if (desktopMatrix.height() > 1) {
|
|
|
|
newLayout |= Qt::Vertical;
|
|
|
|
}
|
|
|
|
if (newLayout == m_virtualDesktopLayout) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
if (isDesktopSwitching()) {
|
2012-11-25 09:13:34 +00:00
|
|
|
reserveDesktopSwitching(false, m_virtualDesktopLayout);
|
|
|
|
}
|
|
|
|
m_virtualDesktopLayout = newLayout;
|
2013-01-21 08:04:06 +00:00
|
|
|
if (isDesktopSwitching()) {
|
2012-11-25 09:13:34 +00:00
|
|
|
reserveDesktopSwitching(true, m_virtualDesktopLayout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
static bool isLeftScreen(const QRect &screen, const QRect &fullArea)
|
2011-06-23 10:09:17 +00:00
|
|
|
{
|
2021-08-31 07:19:43 +00:00
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
if (outputs.count() == 1) {
|
2013-01-21 08:04:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (screen.x() == fullArea.x()) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
// If any other screen has a right edge against our left edge, then this screen is not a left screen
|
2021-08-31 07:19:43 +00:00
|
|
|
for (const AbstractOutput *output : outputs) {
|
|
|
|
const QRect otherGeo = output->geometry();
|
2013-01-21 08:04:06 +00:00
|
|
|
if (otherGeo == screen) {
|
|
|
|
// that's our screen to test
|
|
|
|
continue;
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
if (screen.x() == otherGeo.x() + otherGeo.width()
|
|
|
|
&& screen.y() < otherGeo.y() + otherGeo.height()
|
|
|
|
&& screen.y() + screen.height() > otherGeo.y()) {
|
|
|
|
// There is a screen to the left
|
2013-01-21 08:04:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
// No screen exists to the left, so this is a left screen
|
2013-01-21 08:04:06 +00:00
|
|
|
return true;
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
static bool isRightScreen(const QRect &screen, const QRect &fullArea)
|
2011-06-23 10:09:17 +00:00
|
|
|
{
|
2021-08-31 07:19:43 +00:00
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
if (outputs.count() == 1) {
|
2013-01-21 08:04:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (screen.x() + screen.width() == fullArea.x() + fullArea.width()) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
// If any other screen has any left edge against any of our right edge, then this screen is not a right screen
|
2021-08-31 07:19:43 +00:00
|
|
|
for (const AbstractOutput *output : outputs) {
|
|
|
|
const QRect otherGeo = output->geometry();
|
2013-01-21 08:04:06 +00:00
|
|
|
if (otherGeo == screen) {
|
|
|
|
// that's our screen to test
|
|
|
|
continue;
|
2012-05-03 17:48:20 +00:00
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
if (screen.x() + screen.width() == otherGeo.x()
|
|
|
|
&& screen.y() < otherGeo.y() + otherGeo.height()
|
|
|
|
&& screen.y() + screen.height() > otherGeo.y()) {
|
|
|
|
// There is a screen to the right
|
2013-01-21 08:04:06 +00:00
|
|
|
return false;
|
2012-05-03 17:48:20 +00:00
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
// No screen exists to the right, so this is a right screen
|
2013-01-21 08:04:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isTopScreen(const QRect &screen, const QRect &fullArea)
|
|
|
|
{
|
2021-08-31 07:19:43 +00:00
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
if (outputs.count() == 1) {
|
2013-01-21 08:04:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (screen.y() == fullArea.y()) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
// If any other screen has any bottom edge against any of our top edge, then this screen is not a top screen
|
2021-08-31 07:19:43 +00:00
|
|
|
for (const AbstractOutput *output : outputs) {
|
|
|
|
const QRect otherGeo = output->geometry();
|
2013-01-21 08:04:06 +00:00
|
|
|
if (otherGeo == screen) {
|
|
|
|
// that's our screen to test
|
|
|
|
continue;
|
2012-05-03 17:48:20 +00:00
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
if (screen.y() == otherGeo.y() + otherGeo.height()
|
|
|
|
&& screen.x() < otherGeo.x() + otherGeo.width()
|
|
|
|
&& screen.x() + screen.width() > otherGeo.x()) {
|
|
|
|
// There is a screen to the top
|
2013-01-21 08:04:06 +00:00
|
|
|
return false;
|
2012-05-03 17:48:20 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
// No screen exists to the top, so this is a top screen
|
2013-01-21 08:04:06 +00:00
|
|
|
return true;
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
static bool isBottomScreen(const QRect &screen, const QRect &fullArea)
|
2011-06-23 10:09:17 +00:00
|
|
|
{
|
2021-08-31 07:19:43 +00:00
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
if (outputs.count() == 1) {
|
2013-01-21 08:04:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (screen.y() + screen.height() == fullArea.y() + fullArea.height()) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
// If any other screen has any top edge against any of our bottom edge, then this screen is not a bottom screen
|
2021-08-31 07:19:43 +00:00
|
|
|
for (const AbstractOutput *output : outputs) {
|
|
|
|
const QRect otherGeo = output->geometry();
|
2013-01-21 08:04:06 +00:00
|
|
|
if (otherGeo == screen) {
|
|
|
|
// that's our screen to test
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
if (screen.y() + screen.height() == otherGeo.y()
|
|
|
|
&& screen.x() < otherGeo.x() + otherGeo.width()
|
|
|
|
&& screen.x() + screen.width() > otherGeo.x()) {
|
|
|
|
// There is a screen to the bottom
|
2013-01-21 08:04:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2021-09-10 22:58:18 +00:00
|
|
|
// No screen exists to the bottom, so this is a bottom screen
|
2013-01-21 08:04:06 +00:00
|
|
|
return true;
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void ScreenEdges::recreateEdges()
|
2011-06-23 10:09:17 +00:00
|
|
|
{
|
2013-06-26 08:25:17 +00:00
|
|
|
QList<Edge*> oldEdges(m_edges);
|
2013-01-21 08:04:06 +00:00
|
|
|
m_edges.clear();
|
2021-08-31 07:19:43 +00:00
|
|
|
const QRect fullArea = workspace()->geometry();
|
2014-09-04 19:13:55 +00:00
|
|
|
QRegion processedRegion;
|
2021-08-31 07:19:43 +00:00
|
|
|
|
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
for (const AbstractOutput *output : outputs) {
|
|
|
|
const QRegion screen = QRegion(output->geometry()).subtracted(processedRegion);
|
2014-09-04 19:13:55 +00:00
|
|
|
processedRegion += screen;
|
2019-07-09 20:08:47 +00:00
|
|
|
for (const QRect &screenPart : screen) {
|
2014-09-04 19:13:55 +00:00
|
|
|
if (isLeftScreen(screenPart, fullArea)) {
|
|
|
|
// left most screen
|
|
|
|
createVerticalEdge(ElectricLeft, screenPart, fullArea);
|
|
|
|
}
|
|
|
|
if (isRightScreen(screenPart, fullArea)) {
|
|
|
|
// right most screen
|
|
|
|
createVerticalEdge(ElectricRight, screenPart, fullArea);
|
|
|
|
}
|
|
|
|
if (isTopScreen(screenPart, fullArea)) {
|
|
|
|
// top most screen
|
|
|
|
createHorizontalEdge(ElectricTop, screenPart, fullArea);
|
|
|
|
}
|
|
|
|
if (isBottomScreen(screenPart, fullArea)) {
|
|
|
|
// bottom most screen
|
|
|
|
createHorizontalEdge(ElectricBottom, screenPart, fullArea);
|
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-22 11:47:06 +00:00
|
|
|
// copy over the effect/script reservations from the old edges
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
Edge *edge = *it;
|
|
|
|
for (auto oldIt = oldEdges.constBegin();
|
2013-01-22 11:47:06 +00:00
|
|
|
oldIt != oldEdges.constEnd();
|
|
|
|
++oldIt) {
|
2013-06-26 08:25:17 +00:00
|
|
|
Edge *oldEdge = *oldIt;
|
2014-02-20 11:39:23 +00:00
|
|
|
if (oldEdge->client()) {
|
|
|
|
// show the client again and don't recreate the edge
|
|
|
|
oldEdge->client()->showOnScreenEdge();
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-22 11:47:06 +00:00
|
|
|
if (oldEdge->border() != edge->border()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const QHash<QObject *, QByteArray> &callbacks = oldEdge->callBacks();
|
|
|
|
for (QHash<QObject *, QByteArray>::const_iterator callback = callbacks.begin();
|
|
|
|
callback != callbacks.end();
|
|
|
|
++callback) {
|
|
|
|
edge->reserve(callback.key(), callback.value().constData());
|
|
|
|
}
|
2017-03-31 05:41:21 +00:00
|
|
|
const auto touchCallBacks = oldEdge->touchCallBacks();
|
|
|
|
for (auto a : touchCallBacks) {
|
|
|
|
edge->reserveTouchCallBack(a);
|
|
|
|
}
|
2013-01-22 11:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
qDeleteAll(oldEdges);
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void ScreenEdges::createVerticalEdge(ElectricBorder border, const QRect &screen, const QRect &fullArea)
|
2011-06-23 10:09:17 +00:00
|
|
|
{
|
2013-01-21 08:04:06 +00:00
|
|
|
if (border != ElectricRight && border != KWin::ElectricLeft) {
|
2011-06-23 10:09:17 +00:00
|
|
|
return;
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
int y = screen.y();
|
|
|
|
int height = screen.height();
|
2020-05-14 18:28:36 +00:00
|
|
|
const int x = (border == ElectricLeft) ? screen.x() : screen.x() + screen.width() - TOUCH_TARGET;
|
2013-01-21 08:04:06 +00:00
|
|
|
if (isTopScreen(screen, fullArea)) {
|
|
|
|
// also top most screen
|
2013-04-14 18:04:05 +00:00
|
|
|
height -= m_cornerOffset;
|
|
|
|
y += m_cornerOffset;
|
2013-01-21 08:04:06 +00:00
|
|
|
// create top left/right edge
|
|
|
|
const ElectricBorder edge = (border == ElectricLeft) ? ElectricTopLeft : ElectricTopRight;
|
2020-05-14 18:28:36 +00:00
|
|
|
m_edges << createEdge(edge, x, screen.y(), TOUCH_TARGET, TOUCH_TARGET);
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
if (isBottomScreen(screen, fullArea)) {
|
|
|
|
// also bottom most screen
|
2013-04-14 18:04:05 +00:00
|
|
|
height -= m_cornerOffset;
|
2013-01-21 08:04:06 +00:00
|
|
|
// create bottom left/right edge
|
|
|
|
const ElectricBorder edge = (border == ElectricLeft) ? ElectricBottomLeft : ElectricBottomRight;
|
2020-05-14 18:28:36 +00:00
|
|
|
m_edges << createEdge(edge, x, screen.y() + screen.height() - TOUCH_TARGET, TOUCH_TARGET, TOUCH_TARGET);
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
2020-08-17 19:37:40 +00:00
|
|
|
if (height <= m_cornerOffset) {
|
|
|
|
// An overlap with another output is near complete. We ignore this border.
|
|
|
|
return;
|
|
|
|
}
|
2020-05-14 18:28:36 +00:00
|
|
|
m_edges << createEdge(border, x, y, TOUCH_TARGET, height);
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
2011-06-23 10:09:17 +00:00
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void ScreenEdges::createHorizontalEdge(ElectricBorder border, const QRect &screen, const QRect &fullArea)
|
|
|
|
{
|
|
|
|
if (border != ElectricTop && border != ElectricBottom) {
|
2011-06-23 10:09:17 +00:00
|
|
|
return;
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
int x = screen.x();
|
|
|
|
int width = screen.width();
|
|
|
|
if (isLeftScreen(screen, fullArea)) {
|
|
|
|
// also left most - adjust only x and width
|
2013-04-14 18:04:05 +00:00
|
|
|
x += m_cornerOffset;
|
|
|
|
width -= m_cornerOffset;
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
if (isRightScreen(screen, fullArea)) {
|
|
|
|
// also right most edge
|
2013-04-14 18:04:05 +00:00
|
|
|
width -= m_cornerOffset;
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
2020-08-17 19:37:40 +00:00
|
|
|
if (width <= m_cornerOffset) {
|
|
|
|
// An overlap with another output is near complete. We ignore this border.
|
|
|
|
return;
|
|
|
|
}
|
2020-05-14 18:28:36 +00:00
|
|
|
const int y = (border == ElectricTop) ? screen.y() : screen.y() + screen.height() - TOUCH_TARGET;
|
|
|
|
m_edges << createEdge(border, x, y, width, TOUCH_TARGET);
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
2011-06-23 10:09:17 +00:00
|
|
|
|
2013-06-26 08:25:17 +00:00
|
|
|
Edge *ScreenEdges::createEdge(ElectricBorder border, int x, int y, int width, int height, bool createAction)
|
2013-01-21 08:04:06 +00:00
|
|
|
{
|
2016-04-15 11:47:56 +00:00
|
|
|
Edge *edge = kwinApp()->platform()->createScreenEdge(this);
|
2020-08-17 19:37:40 +00:00
|
|
|
// Edges can not have negative size.
|
|
|
|
Q_ASSERT(width >= 0);
|
|
|
|
Q_ASSERT(height >= 0);
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
edge->setBorder(border);
|
|
|
|
edge->setGeometry(QRect(x, y, width, height));
|
2014-02-20 11:39:23 +00:00
|
|
|
if (createAction) {
|
|
|
|
const ElectricBorderAction action = actionForEdge(edge);
|
|
|
|
if (action != KWin::ElectricActionNone) {
|
|
|
|
edge->reserve();
|
|
|
|
edge->setAction(action);
|
|
|
|
}
|
2017-03-30 05:08:38 +00:00
|
|
|
const ElectricBorderAction touchAction = actionForTouchEdge(edge);
|
|
|
|
if (touchAction != KWin::ElectricActionNone) {
|
|
|
|
edge->reserve();
|
|
|
|
edge->setTouchAction(touchAction);
|
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
if (isDesktopSwitching()) {
|
|
|
|
if (edge->isCorner()) {
|
|
|
|
edge->reserve();
|
|
|
|
} else {
|
|
|
|
if ((m_virtualDesktopLayout & Qt::Horizontal) && (edge->isLeft() || edge->isRight())) {
|
|
|
|
edge->reserve();
|
|
|
|
}
|
|
|
|
if ((m_virtualDesktopLayout & Qt::Vertical) && (edge->isTop() || edge->isBottom())) {
|
|
|
|
edge->reserve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-23 18:39:59 +00:00
|
|
|
connect(edge, &Edge::approaching, this, &ScreenEdges::approaching);
|
2013-01-31 16:25:03 +00:00
|
|
|
if (edge->isScreenEdge()) {
|
2020-09-23 18:39:59 +00:00
|
|
|
connect(this, &ScreenEdges::checkBlocking, edge, &Edge::checkBlocking);
|
2013-01-31 16:25:03 +00:00
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
return edge;
|
|
|
|
}
|
2011-06-23 10:09:17 +00:00
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
ElectricBorderAction ScreenEdges::actionForEdge(Edge *edge) const
|
|
|
|
{
|
|
|
|
switch (edge->border()) {
|
|
|
|
case ElectricTopLeft:
|
|
|
|
return m_actionTopLeft;
|
|
|
|
case ElectricTop:
|
|
|
|
return m_actionTop;
|
|
|
|
case ElectricTopRight:
|
|
|
|
return m_actionTopRight;
|
|
|
|
case ElectricRight:
|
|
|
|
return m_actionRight;
|
|
|
|
case ElectricBottomRight:
|
|
|
|
return m_actionBottomRight;
|
|
|
|
case ElectricBottom:
|
|
|
|
return m_actionBottom;
|
|
|
|
case ElectricBottomLeft:
|
|
|
|
return m_actionBottomLeft;
|
|
|
|
case ElectricLeft:
|
|
|
|
return m_actionLeft;
|
|
|
|
default:
|
|
|
|
// fall through
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ElectricActionNone;
|
|
|
|
}
|
|
|
|
|
2017-03-30 05:08:38 +00:00
|
|
|
ElectricBorderAction ScreenEdges::actionForTouchEdge(Edge *edge) const
|
|
|
|
{
|
|
|
|
auto it = m_touchActions.find(edge->border());
|
|
|
|
if (it != m_touchActions.end()) {
|
|
|
|
return it.value();
|
|
|
|
}
|
|
|
|
return ElectricActionNone;
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void ScreenEdges::reserveDesktopSwitching(bool isToReserve, Qt::Orientations o)
|
|
|
|
{
|
|
|
|
if (!o)
|
|
|
|
return;
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
Edge *edge = *it;
|
2013-01-21 08:04:06 +00:00
|
|
|
if (edge->isCorner()) {
|
|
|
|
isToReserve ? edge->reserve() : edge->unreserve();
|
|
|
|
} else {
|
|
|
|
if ((m_virtualDesktopLayout & Qt::Horizontal) && (edge->isLeft() || edge->isRight())) {
|
|
|
|
isToReserve ? edge->reserve() : edge->unreserve();
|
|
|
|
}
|
|
|
|
if ((m_virtualDesktopLayout & Qt::Vertical) && (edge->isTop() || edge->isBottom())) {
|
|
|
|
isToReserve ? edge->reserve() : edge->unreserve();
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 11:47:06 +00:00
|
|
|
void ScreenEdges::reserve(ElectricBorder border, QObject *object, const char *slot)
|
2013-01-21 08:04:06 +00:00
|
|
|
{
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2013-01-21 08:04:06 +00:00
|
|
|
if ((*it)->border() == border) {
|
2013-01-22 11:47:06 +00:00
|
|
|
(*it)->reserve(object, slot);
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 11:47:06 +00:00
|
|
|
void ScreenEdges::unreserve(ElectricBorder border, QObject *object)
|
2013-01-21 08:04:06 +00:00
|
|
|
{
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2013-01-21 08:04:06 +00:00
|
|
|
if ((*it)->border() == border) {
|
2013-01-22 11:47:06 +00:00
|
|
|
(*it)->unreserve(object);
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-15 19:03:40 +00:00
|
|
|
void ScreenEdges::reserve(AbstractClient *client, ElectricBorder border)
|
2014-02-20 11:39:23 +00:00
|
|
|
{
|
2015-08-19 09:24:22 +00:00
|
|
|
bool hadBorder = false;
|
2014-02-20 11:39:23 +00:00
|
|
|
auto it = m_edges.begin();
|
|
|
|
while (it != m_edges.end()) {
|
|
|
|
if ((*it)->client() == client) {
|
2015-08-19 09:24:22 +00:00
|
|
|
hadBorder = true;
|
2017-03-08 22:54:58 +00:00
|
|
|
delete *it;
|
|
|
|
it = m_edges.erase(it);
|
2014-02-20 11:39:23 +00:00
|
|
|
} else {
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 09:24:22 +00:00
|
|
|
if (border != ElectricNone) {
|
|
|
|
createEdgeForClient(client, border);
|
|
|
|
} else {
|
|
|
|
if (hadBorder) // show again
|
|
|
|
client->showOnScreenEdge();
|
|
|
|
}
|
2014-02-20 11:39:23 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 05:41:21 +00:00
|
|
|
void ScreenEdges::reserveTouch(ElectricBorder border, QAction *action)
|
|
|
|
{
|
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->reserveTouchCallBack(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdges::unreserveTouch(ElectricBorder border, QAction *action)
|
|
|
|
{
|
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->unreserveTouchCallBack(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-15 19:03:40 +00:00
|
|
|
void ScreenEdges::createEdgeForClient(AbstractClient *client, ElectricBorder border)
|
2014-02-20 11:39:23 +00:00
|
|
|
{
|
|
|
|
int y = 0;
|
|
|
|
int x = 0;
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2019-09-27 10:01:10 +00:00
|
|
|
const QRect geo = client->frameGeometry();
|
2021-08-31 07:19:43 +00:00
|
|
|
const QRect fullArea = workspace()->geometry();
|
|
|
|
|
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
for (const AbstractOutput *output : outputs) {
|
|
|
|
const QRect screen = output->geometry();
|
2014-02-20 11:39:23 +00:00
|
|
|
if (!screen.contains(geo)) {
|
|
|
|
// ignoring Clients having a geometry overlapping with multiple screens
|
|
|
|
// this would make the code more complex. If it's needed in future it can be added
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const bool bordersTop = (screen.y() == geo.y());
|
|
|
|
const bool bordersLeft = (screen.x() == geo.x());
|
|
|
|
const bool bordersBottom = (screen.y() + screen.height() == geo.y() + geo.height());
|
|
|
|
const bool bordersRight = (screen.x() + screen.width() == geo.x() + geo.width());
|
|
|
|
|
|
|
|
if (bordersTop && border == ElectricTop) {
|
|
|
|
if (!isTopScreen(screen, fullArea)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
y = geo.y();
|
|
|
|
x = geo.x();
|
|
|
|
height = 1;
|
|
|
|
width = geo.width();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bordersBottom && border == ElectricBottom) {
|
|
|
|
if (!isBottomScreen(screen, fullArea)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
y = geo.y() + geo.height() - 1;
|
|
|
|
x = geo.x();
|
|
|
|
height = 1;
|
|
|
|
width = geo.width();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bordersLeft && border == ElectricLeft) {
|
|
|
|
if (!isLeftScreen(screen, fullArea)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
x = geo.x();
|
|
|
|
y = geo.y();
|
|
|
|
width = 1;
|
|
|
|
height = geo.height();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bordersRight && border == ElectricRight) {
|
|
|
|
if (!isRightScreen(screen, fullArea)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
x = geo.x() + geo.width() - 1;
|
|
|
|
y = geo.y();
|
|
|
|
width = 1;
|
|
|
|
height = geo.height();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width > 0 && height > 0) {
|
2013-06-26 08:25:17 +00:00
|
|
|
Edge *edge = createEdge(border, x, y, width, height, false);
|
2014-02-20 11:39:23 +00:00
|
|
|
edge->setClient(client);
|
|
|
|
m_edges.append(edge);
|
2015-10-11 20:48:29 +00:00
|
|
|
edge->reserve();
|
2014-02-20 11:39:23 +00:00
|
|
|
} else {
|
|
|
|
// we could not create an edge window, so don't allow the window to hide
|
|
|
|
client->showOnScreenEdge();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-15 19:03:40 +00:00
|
|
|
void ScreenEdges::deleteEdgeForClient(AbstractClient* c)
|
2014-02-20 11:39:23 +00:00
|
|
|
{
|
|
|
|
auto it = m_edges.begin();
|
|
|
|
while (it != m_edges.end()) {
|
|
|
|
if ((*it)->client() == c) {
|
|
|
|
delete *it;
|
|
|
|
it = m_edges.erase(it);
|
|
|
|
} else {
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void ScreenEdges::check(const QPoint &pos, const QDateTime &now, bool forceNoPushBack)
|
|
|
|
{
|
2014-02-20 11:39:23 +00:00
|
|
|
bool activatedForClient = false;
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2014-02-01 09:03:49 +00:00
|
|
|
if (!(*it)->isReserved()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-04-13 05:00:30 +00:00
|
|
|
if (!(*it)->activatesForPointer()) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-01 09:03:49 +00:00
|
|
|
if ((*it)->approachGeometry().contains(pos)) {
|
|
|
|
(*it)->startApproaching();
|
|
|
|
}
|
2014-02-20 11:39:23 +00:00
|
|
|
if ((*it)->client() != nullptr && activatedForClient) {
|
|
|
|
(*it)->markAsTriggered(pos, now);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((*it)->check(pos, now, forceNoPushBack)) {
|
|
|
|
if ((*it)->client()) {
|
|
|
|
activatedForClient = true;
|
|
|
|
}
|
|
|
|
}
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 14:51:25 +00:00
|
|
|
bool ScreenEdges::isEntered(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() != QEvent::MouseMove) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool activated = false;
|
|
|
|
bool activatedForClient = false;
|
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
Edge *edge = *it;
|
|
|
|
if (!edge->isReserved()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-30 05:08:38 +00:00
|
|
|
if (!edge->activatesForPointer()) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-02-11 14:51:25 +00:00
|
|
|
if (edge->approachGeometry().contains(event->globalPos())) {
|
|
|
|
if (!edge->isApproaching()) {
|
|
|
|
edge->startApproaching();
|
|
|
|
} else {
|
|
|
|
edge->updateApproaching(event->globalPos());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (edge->isApproaching()) {
|
|
|
|
edge->stopApproaching();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (edge->geometry().contains(event->globalPos())) {
|
2020-02-03 10:55:46 +00:00
|
|
|
if (edge->check(event->globalPos(), QDateTime::fromMSecsSinceEpoch(event->timestamp(), Qt::UTC))) {
|
2016-02-11 14:51:25 +00:00
|
|
|
if (edge->client()) {
|
|
|
|
activatedForClient = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (activatedForClient) {
|
|
|
|
for (auto it = m_edges.constBegin(); it != m_edges.constEnd(); ++it) {
|
|
|
|
if ((*it)->client()) {
|
2020-02-03 10:55:46 +00:00
|
|
|
(*it)->markAsTriggered(event->globalPos(), QDateTime::fromMSecsSinceEpoch(event->timestamp(), Qt::UTC));
|
2016-02-11 14:51:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return activated;
|
|
|
|
}
|
|
|
|
|
2013-01-28 07:52:21 +00:00
|
|
|
bool ScreenEdges::handleEnterNotifiy(xcb_window_t window, const QPoint &point, const QDateTime ×tamp)
|
|
|
|
{
|
2014-02-20 11:39:23 +00:00
|
|
|
bool activated = false;
|
|
|
|
bool activatedForClient = false;
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2016-04-15 11:19:22 +00:00
|
|
|
Edge *edge = *it;
|
|
|
|
if (!edge || edge->window() == XCB_WINDOW_NONE) {
|
2013-06-26 08:25:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-01-28 07:52:21 +00:00
|
|
|
if (!edge->isReserved()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-30 05:08:38 +00:00
|
|
|
if (!edge->activatesForPointer()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-28 07:52:21 +00:00
|
|
|
if (edge->window() == window) {
|
2014-02-20 11:39:23 +00:00
|
|
|
if (edge->check(point, timestamp)) {
|
|
|
|
if ((*it)->client()) {
|
|
|
|
activatedForClient = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activated = true;
|
|
|
|
break;
|
2013-01-28 07:52:21 +00:00
|
|
|
}
|
|
|
|
if (edge->approachWindow() == window) {
|
|
|
|
edge->startApproaching();
|
|
|
|
// TODO: if it's a corner, it should also trigger for other windows
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-20 11:39:23 +00:00
|
|
|
if (activatedForClient) {
|
|
|
|
for (auto it = m_edges.constBegin(); it != m_edges.constEnd(); ++it) {
|
|
|
|
if ((*it)->client()) {
|
|
|
|
(*it)->markAsTriggered(point, timestamp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return activated;
|
2013-01-28 07:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ScreenEdges::handleDndNotify(xcb_window_t window, const QPoint &point)
|
|
|
|
{
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2016-04-15 11:19:22 +00:00
|
|
|
Edge *edge = *it;
|
|
|
|
if (!edge || edge->window() == XCB_WINDOW_NONE) {
|
2013-06-26 08:25:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-01-28 07:52:21 +00:00
|
|
|
if (edge->isReserved() && edge->window() == window) {
|
|
|
|
updateXTime();
|
2020-02-03 10:55:46 +00:00
|
|
|
edge->check(point, QDateTime::fromMSecsSinceEpoch(xTime(), Qt::UTC), true);
|
2013-01-28 07:52:21 +00:00
|
|
|
return true;
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
void ScreenEdges::ensureOnTop()
|
2011-06-23 10:09:17 +00:00
|
|
|
{
|
2013-01-21 08:04:06 +00:00
|
|
|
Xcb::restackWindowsWithRaise(windows());
|
2011-06-23 10:09:17 +00:00
|
|
|
}
|
2011-06-24 14:20:40 +00:00
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
QVector< xcb_window_t > ScreenEdges::windows() const
|
2011-06-24 14:20:40 +00:00
|
|
|
{
|
2013-01-21 08:04:06 +00:00
|
|
|
QVector<xcb_window_t> wins;
|
2013-06-26 08:25:17 +00:00
|
|
|
for (auto it = m_edges.constBegin();
|
2013-01-21 08:04:06 +00:00
|
|
|
it != m_edges.constEnd();
|
|
|
|
++it) {
|
2016-04-15 11:19:22 +00:00
|
|
|
Edge *edge = *it;
|
2013-06-26 08:25:17 +00:00
|
|
|
xcb_window_t w = edge->window();
|
2013-01-21 08:04:06 +00:00
|
|
|
if (w != XCB_WINDOW_NONE) {
|
|
|
|
wins.append(w);
|
|
|
|
}
|
2013-01-26 10:50:14 +00:00
|
|
|
// TODO: lambda
|
2013-06-26 08:25:17 +00:00
|
|
|
w = edge->approachWindow();
|
2013-01-26 10:50:14 +00:00
|
|
|
if (w != XCB_WINDOW_NONE) {
|
|
|
|
wins.append(w);
|
|
|
|
}
|
2013-01-21 08:04:06 +00:00
|
|
|
}
|
|
|
|
return wins;
|
2011-06-24 14:20:40 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 08:04:06 +00:00
|
|
|
} //namespace
|