2011-06-23 14:09:17 +04:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
|
2013-01-21 12:04:06 +04:00
|
|
|
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2011-06-23 14:09:17 +04: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.
|
|
|
|
|
|
|
|
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
|
|
|
|
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
|
|
|
|
|
|
|
|
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 "screenedge.h"
|
|
|
|
|
|
|
|
// KWin
|
|
|
|
#include "atoms.h"
|
2014-09-26 16:01:44 +04:00
|
|
|
#include <client.h>
|
2013-02-19 14:25:46 +04:00
|
|
|
#include "cursor.h"
|
2013-06-26 12:25:17 +04:00
|
|
|
#include "input.h"
|
|
|
|
#include "main.h"
|
2013-04-03 14:19:27 +04:00
|
|
|
#include "screens.h"
|
2011-06-23 14:09:17 +04:00
|
|
|
#include "utils.h"
|
2014-09-26 16:01:44 +04:00
|
|
|
#include <workspace.h>
|
2012-11-16 11:23:47 +04:00
|
|
|
#include "virtualdesktops.h"
|
2014-05-15 11:01:51 +04:00
|
|
|
// DBus generated
|
|
|
|
#include "screenlocker_interface.h"
|
2014-09-26 16:01:44 +04:00
|
|
|
// frameworks
|
|
|
|
#include <KConfigGroup>
|
2011-06-23 14:09:17 +04:00
|
|
|
// Qt
|
2014-08-27 23:48:23 +04:00
|
|
|
#include <QSharedPointer>
|
2013-02-26 12:00:51 +04:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QVector>
|
|
|
|
#include <QTextStream>
|
2011-06-23 14:09:17 +04:00
|
|
|
#include <QtDBus/QDBusInterface>
|
2013-01-21 12:04:06 +04:00
|
|
|
#include <QtDBus/QDBusPendingCall>
|
2014-09-26 16:01:44 +04:00
|
|
|
#include <QWidget>
|
2011-06-23 14:09:17 +04:00
|
|
|
|
|
|
|
namespace KWin {
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
// Mouse should not move more than this many pixels
|
|
|
|
static const int DISTANCE_RESET = 30;
|
|
|
|
|
|
|
|
Edge::Edge(ScreenEdges *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_edges(parent)
|
|
|
|
, m_border(ElectricNone)
|
|
|
|
, m_action(ElectricActionNone)
|
|
|
|
, m_reserved(0)
|
2013-01-26 14:50:14 +04:00
|
|
|
, m_approaching(false)
|
2013-04-14 22:04:05 +04:00
|
|
|
, m_lastApproachingFactor(0)
|
2013-01-31 20:25:03 +04:00
|
|
|
, m_blocked(false)
|
2014-08-27 23:48:23 +04:00
|
|
|
, m_pushBackBlocked(false)
|
2014-02-20 15:39:23 +04:00
|
|
|
, m_client(nullptr)
|
2011-06-23 14:09:17 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
Edge::~Edge()
|
2011-06-23 14:09:17 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
void Edge::reserve()
|
2011-06-25 22:08:51 +04:00
|
|
|
{
|
2013-01-21 12:04:06 +04:00
|
|
|
m_reserved++;
|
|
|
|
if (m_reserved == 1) {
|
|
|
|
// got activated
|
|
|
|
activate();
|
|
|
|
}
|
2011-06-25 22:08:51 +04:00
|
|
|
}
|
|
|
|
|
2013-01-22 15:47:06 +04:00
|
|
|
void Edge::reserve(QObject *object, const char *slot)
|
|
|
|
{
|
|
|
|
connect(object, SIGNAL(destroyed(QObject*)), SLOT(unreserve(QObject*)));
|
|
|
|
m_callBacks.insert(object, QByteArray(slot));
|
|
|
|
reserve();
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
void Edge::unreserve()
|
2011-06-23 14:09:17 +04:00
|
|
|
{
|
2013-01-21 12:04:06 +04:00
|
|
|
m_reserved--;
|
|
|
|
if (m_reserved == 0) {
|
|
|
|
// got deactivated
|
2014-02-20 15:39:23 +04:00
|
|
|
stopApproaching();
|
2013-01-21 12:04:06 +04:00
|
|
|
deactivate();
|
|
|
|
}
|
|
|
|
}
|
2013-01-22 15:47:06 +04:00
|
|
|
void Edge::unreserve(QObject *object)
|
|
|
|
{
|
|
|
|
if (m_callBacks.contains(object)) {
|
|
|
|
m_callBacks.remove(object);
|
|
|
|
disconnect(object, SIGNAL(destroyed(QObject*)), this, SLOT(unreserve(QObject*)));
|
|
|
|
unreserve();
|
|
|
|
}
|
|
|
|
}
|
2011-06-23 14:09:17 +04:00
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
bool Edge::triggersFor(const QPoint &cursorPos) const
|
|
|
|
{
|
2013-01-31 20:25:03 +04:00
|
|
|
if (isBlocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-21 12:04:06 +04: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 15:39:23 +04:00
|
|
|
bool Edge::check(const QPoint &cursorPos, const QDateTime &triggerTime, bool forceNoPushBack)
|
2013-01-21 12:04:06 +04:00
|
|
|
{
|
|
|
|
if (!triggersFor(cursorPos)) {
|
2014-02-20 15:39:23 +04:00
|
|
|
return false;
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
2015-08-23 12:56:17 +03:00
|
|
|
if (m_lastTrigger.isValid() && // still in cooldown
|
2015-09-10 22:03:53 +03:00
|
|
|
m_lastTrigger.msecsTo(triggerTime) < edges()->reActivationThreshold() - edges()->timeThreshold()) {
|
2015-08-23 12:56:17 +03:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
// no pushback so we have to activate at once
|
2015-05-26 23:39:29 +03:00
|
|
|
bool directActivate = forceNoPushBack || edges()->cursorPushBackDistance().isNull() || m_client;
|
2013-01-21 12:04:06 +04:00
|
|
|
if (directActivate || canActivate(cursorPos, triggerTime)) {
|
2014-02-20 15:39:23 +04:00
|
|
|
markAsTriggered(cursorPos, triggerTime);
|
2013-01-21 12:04:06 +04:00
|
|
|
handle(cursorPos);
|
2014-02-20 15:39:23 +04:00
|
|
|
return true;
|
2013-01-21 12:04:06 +04:00
|
|
|
} else {
|
|
|
|
pushCursorBack(cursorPos);
|
2014-02-20 15:39:23 +04:00
|
|
|
m_triggeredPoint = cursorPos;
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
2014-02-20 15:39:23 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::markAsTriggered(const QPoint &cursorPos, const QDateTime &triggerTime)
|
|
|
|
{
|
|
|
|
m_lastTrigger = triggerTime;
|
|
|
|
m_lastReset = QDateTime(); // invalidate
|
2013-01-21 12:04:06 +04:00
|
|
|
m_triggeredPoint = cursorPos;
|
2011-06-23 14:09:17 +04:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
bool Edge::canActivate(const QPoint &cursorPos, const QDateTime &triggerTime)
|
2012-11-25 13:13:34 +04:00
|
|
|
{
|
2013-07-17 18:39:58 +04:00
|
|
|
// we check whether either the timer has explicitly been invalidated (successfull trigger) or is
|
|
|
|
// bigger than the reactivation threshold (activation "aborted", usually due to moving away the cursor
|
|
|
|
// from the corner after successfull activation)
|
|
|
|
// 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 12:04:06 +04:00
|
|
|
m_lastReset = triggerTime;
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-10 22:03:53 +03:00
|
|
|
if (m_lastTrigger.isValid() && m_lastTrigger.msecsTo(triggerTime) < edges()->reActivationThreshold() - edges()->timeThreshold()) {
|
2013-01-21 12:04:06 +04: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)
|
|
|
|
{
|
2014-02-20 15:39:23 +04:00
|
|
|
if (m_client) {
|
|
|
|
pushCursorBack(cursorPos);
|
|
|
|
m_client->showOnScreenEdge();
|
|
|
|
unreserve();
|
|
|
|
return;
|
|
|
|
}
|
2015-05-03 15:26:18 +03:00
|
|
|
AbstractClient *movingClient = Workspace::self()->getMovingClient();
|
|
|
|
bool isResize = false;
|
|
|
|
if (Client *movingClientClient = qobject_cast<Client*>(movingClient))
|
|
|
|
isResize = movingClientClient->isResize();
|
|
|
|
if ((edges()->isDesktopSwitchingMovingClients() && movingClient && !isResize) ||
|
2013-01-21 12:04:06 +04: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 13:13:34 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-05-03 15:26:18 +03:00
|
|
|
if (movingClient) {
|
2013-02-13 13:37:10 +04: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;
|
|
|
|
}
|
2013-01-22 15:47:06 +04:00
|
|
|
if (handleAction() || handleByCallback()) {
|
2013-01-21 12:04:06 +04:00
|
|
|
pushCursorBack(cursorPos);
|
|
|
|
return;
|
2012-11-25 13:13:34 +04:00
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
if (edges()->isDesktopSwitching() && isCorner()) {
|
|
|
|
// try again desktop switching for the corner
|
|
|
|
switchDesktop(cursorPos);
|
2012-11-25 13:13:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
bool Edge::handleAction()
|
2012-11-25 13:13:34 +04:00
|
|
|
{
|
2013-01-21 12:04:06 +04:00
|
|
|
switch (m_action) {
|
|
|
|
case ElectricActionDashboard: { // Display Plasma dashboard
|
2014-05-15 10:55:33 +04:00
|
|
|
QDBusInterface plasmaApp(QStringLiteral("org.kde.plasmashell"), QStringLiteral("/PlasmaShell"));
|
2013-07-23 09:02:52 +04:00
|
|
|
plasmaApp.asyncCall(QStringLiteral("toggleDashboard"));
|
2013-01-21 12:04:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case ElectricActionShowDesktop: {
|
|
|
|
Workspace::self()->setShowingDesktop(!Workspace::self()->showingDesktop());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case ElectricActionLockScreen: { // Lock the screen
|
2014-05-15 11:01:51 +04:00
|
|
|
OrgFreedesktopScreenSaverInterface interface(QStringLiteral("org.freedesktop.ScreenSaver"),
|
|
|
|
QStringLiteral("/ScreenSaver"),
|
|
|
|
QDBusConnection::sessionBus());
|
|
|
|
if (interface.isValid()) {
|
|
|
|
interface.Lock();
|
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 15:47:06 +04:00
|
|
|
bool Edge::handleByCallback()
|
2013-01-21 12:04:06 +04:00
|
|
|
{
|
2013-01-22 15:47:06 +04:00
|
|
|
if (m_callBacks.isEmpty()) {
|
2013-01-21 12:04:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-22 15:47:06 +04: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 12:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::switchDesktop(const QPoint &cursorPos)
|
|
|
|
{
|
|
|
|
QPoint pos(cursorPos);
|
|
|
|
VirtualDesktopManager *vds = VirtualDesktopManager::self();
|
|
|
|
const uint oldDesktop = vds->current();
|
2014-04-12 23:38:52 +04:00
|
|
|
uint desktop = oldDesktop;
|
2013-01-21 12:04:06 +04:00
|
|
|
const int OFFSET = 2;
|
|
|
|
if (isLeft()) {
|
2014-04-12 23:38:52 +04:00
|
|
|
const uint interimDesktop = desktop;
|
2013-01-21 12:04:06 +04:00
|
|
|
desktop = vds->toLeft(desktop, vds->isNavigationWrappingAround());
|
2014-04-12 23:38:52 +04:00
|
|
|
if (desktop != interimDesktop)
|
|
|
|
pos.setX(displayWidth() - 1 - OFFSET);
|
|
|
|
} else if (isRight()) {
|
|
|
|
const uint interimDesktop = desktop;
|
2013-01-21 12:04:06 +04:00
|
|
|
desktop = vds->toRight(desktop, vds->isNavigationWrappingAround());
|
2014-04-12 23:38:52 +04:00
|
|
|
if (desktop != interimDesktop)
|
|
|
|
pos.setX(OFFSET);
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
if (isTop()) {
|
2014-04-12 23:38:52 +04:00
|
|
|
const uint interimDesktop = desktop;
|
2013-01-21 12:04:06 +04:00
|
|
|
desktop = vds->above(desktop, vds->isNavigationWrappingAround());
|
2014-04-12 23:38:52 +04:00
|
|
|
if (desktop != interimDesktop)
|
|
|
|
pos.setY(displayHeight() - 1 - OFFSET);
|
|
|
|
} else if (isBottom()) {
|
|
|
|
const uint interimDesktop = desktop;
|
2013-01-21 12:04:06 +04:00
|
|
|
desktop = vds->below(desktop, vds->isNavigationWrappingAround());
|
2014-04-12 23:38:52 +04:00
|
|
|
if (desktop != interimDesktop)
|
|
|
|
pos.setY(OFFSET);
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
2014-09-26 16:01:44 +04:00
|
|
|
#ifndef KWIN_UNIT_TEST
|
2015-03-06 14:38:07 +03:00
|
|
|
if (AbstractClient *c = Workspace::self()->getMovingClient()) {
|
2013-01-21 12:04:06 +04:00
|
|
|
if (c->rules()->checkDesktop(desktop) != int(desktop)) {
|
|
|
|
// user attempts to move a client to another desktop where it is ruleforced to not be
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-09-26 16:01:44 +04:00
|
|
|
#endif
|
2013-01-21 12:04:06 +04:00
|
|
|
vds->setCurrent(desktop);
|
|
|
|
if (vds->current() != oldDesktop) {
|
2014-08-27 23:48:23 +04:00
|
|
|
m_pushBackBlocked = true;
|
2013-02-19 14:25:46 +04:00
|
|
|
Cursor::setPos(pos);
|
2014-08-27 23:48:23 +04: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 12:04:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::pushCursorBack(const QPoint &cursorPos)
|
|
|
|
{
|
2014-08-27 23:48:23 +04:00
|
|
|
if (m_pushBackBlocked)
|
|
|
|
return;
|
2013-01-21 12:04:06 +04: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();
|
|
|
|
}
|
2013-02-19 14:25:46 +04:00
|
|
|
Cursor::setPos(x, y);
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
|
2013-01-26 14:50:14 +04: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();
|
2013-04-14 22:04:05 +04:00
|
|
|
const int size = m_edges->cornerOffset();
|
2013-01-26 14:50:14 +04:00
|
|
|
if (isCorner()) {
|
|
|
|
if (isRight()) {
|
|
|
|
x = x - size +1;
|
|
|
|
}
|
|
|
|
if (isBottom()) {
|
|
|
|
y = y - size +1;
|
|
|
|
}
|
|
|
|
width = size;
|
|
|
|
height = size;
|
|
|
|
} else {
|
|
|
|
if (isLeft()) {
|
|
|
|
y += size + 1;
|
|
|
|
width = size;
|
|
|
|
height = height - size * 2;
|
|
|
|
} else if (isRight()) {
|
|
|
|
x = x - size + 1;
|
|
|
|
y += size;
|
|
|
|
width = size;
|
|
|
|
height = height - size * 2;
|
|
|
|
} else if (isTop()) {
|
|
|
|
x += size;
|
|
|
|
width = width - size * 2;
|
|
|
|
height = size;
|
|
|
|
} else if (isBottom()) {
|
|
|
|
x += size;
|
|
|
|
y = y - size +1;
|
|
|
|
width = width - size * 2;
|
|
|
|
height = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_approachGeometry = QRect(x, y, width, height);
|
|
|
|
doGeometryUpdate();
|
|
|
|
}
|
|
|
|
|
2013-01-31 20:25:03 +04:00
|
|
|
void Edge::checkBlocking()
|
|
|
|
{
|
|
|
|
if (isCorner()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool newValue = false;
|
2015-03-06 15:37:56 +03:00
|
|
|
if (AbstractClient *client = Workspace::self()->activeClient()) {
|
2013-01-31 20:25:03 +04:00
|
|
|
newValue = client->isFullScreen() && client->geometry().contains(m_geometry.center());
|
|
|
|
}
|
|
|
|
if (newValue == m_blocked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_blocked = newValue;
|
|
|
|
doUpdateBlocking();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::doUpdateBlocking()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
void Edge::doGeometryUpdate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::activate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::deactivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-01-26 14:50:14 +04:00
|
|
|
void Edge::startApproaching()
|
|
|
|
{
|
|
|
|
if (m_approaching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_approaching = true;
|
|
|
|
doStartApproaching();
|
2013-04-14 22:04:05 +04:00
|
|
|
m_lastApproachingFactor = 0;
|
2013-01-26 14:50:14 +04:00
|
|
|
emit approaching(border(), 0.0, m_approachGeometry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::doStartApproaching()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::stopApproaching()
|
|
|
|
{
|
|
|
|
if (!m_approaching) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_approaching = false;
|
|
|
|
doStopApproaching();
|
2013-04-14 22:04:05 +04:00
|
|
|
m_lastApproachingFactor = 0;
|
2013-01-26 14:50:14 +04:00
|
|
|
emit approaching(border(), 0.0, m_approachGeometry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::doStopApproaching()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Edge::updateApproaching(const QPoint &point)
|
|
|
|
{
|
|
|
|
if (approachGeometry().contains(point)) {
|
2013-04-14 22:04:05 +04:00
|
|
|
int factor = 0;
|
|
|
|
const int edgeDistance = m_edges->cornerOffset();
|
2013-01-26 14:50:14 +04:00
|
|
|
// manhattan length for our edge
|
2013-04-14 22:04:05 +04:00
|
|
|
const int cornerDistance = 2*edgeDistance;
|
2013-01-26 14:50:14 +04:00
|
|
|
switch (border()) {
|
|
|
|
case ElectricTopLeft:
|
2013-04-14 22:04:05 +04:00
|
|
|
factor = (point.manhattanLength()<<8) / cornerDistance;
|
2013-01-26 14:50:14 +04:00
|
|
|
break;
|
|
|
|
case ElectricTopRight:
|
2013-04-14 22:04:05 +04:00
|
|
|
factor = ((point - approachGeometry().topRight()).manhattanLength()<<8) / cornerDistance;
|
2013-01-26 14:50:14 +04:00
|
|
|
break;
|
|
|
|
case ElectricBottomRight:
|
2013-04-14 22:04:05 +04:00
|
|
|
factor = ((point - approachGeometry().bottomRight()).manhattanLength()<<8) / cornerDistance;
|
2013-01-26 14:50:14 +04:00
|
|
|
break;
|
|
|
|
case ElectricBottomLeft:
|
2013-04-14 22:04:05 +04:00
|
|
|
factor = ((point - approachGeometry().bottomLeft()).manhattanLength()<<8) / cornerDistance;
|
2013-01-26 14:50:14 +04:00
|
|
|
break;
|
|
|
|
case ElectricTop:
|
2013-04-14 22:04:05 +04:00
|
|
|
factor = (qAbs(point.y() - approachGeometry().y())<<8) / edgeDistance;
|
2013-01-26 14:50:14 +04:00
|
|
|
break;
|
|
|
|
case ElectricRight:
|
2013-04-14 22:04:05 +04:00
|
|
|
factor = (qAbs(point.x() - approachGeometry().right())<<8) / edgeDistance;
|
2013-01-26 14:50:14 +04:00
|
|
|
break;
|
|
|
|
case ElectricBottom:
|
2013-04-14 22:04:05 +04:00
|
|
|
factor = (qAbs(point.y() - approachGeometry().bottom())<<8) / edgeDistance;
|
2013-01-26 14:50:14 +04:00
|
|
|
break;
|
|
|
|
case ElectricLeft:
|
2013-04-14 22:04:05 +04:00
|
|
|
factor = (qAbs(point.x() - approachGeometry().x())<<8) / edgeDistance;
|
2013-01-26 14:50:14 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-04-14 22:04:05 +04:00
|
|
|
factor = 256 - factor;
|
2013-01-26 14:50:14 +04:00
|
|
|
if (m_lastApproachingFactor != factor) {
|
|
|
|
m_lastApproachingFactor = factor;
|
2013-04-14 22:04:05 +04:00
|
|
|
emit approaching(border(), m_lastApproachingFactor/256.0f, m_approachGeometry);
|
2013-01-26 14:50:14 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stopApproaching();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
/**********************************************************
|
|
|
|
* ScreenEdges
|
|
|
|
*********************************************************/
|
|
|
|
WindowBasedEdge::WindowBasedEdge(ScreenEdges *parent)
|
|
|
|
: Edge(parent)
|
|
|
|
, m_window(XCB_WINDOW_NONE)
|
2013-01-26 14:50:14 +04:00
|
|
|
, m_approachWindow(XCB_WINDOW_NONE)
|
2013-01-21 12:04:06 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowBasedEdge::~WindowBasedEdge()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowBasedEdge::activate()
|
|
|
|
{
|
|
|
|
createWindow();
|
2013-01-26 14:50:14 +04:00
|
|
|
createApproachWindow();
|
2013-01-31 20:25:03 +04:00
|
|
|
doUpdateBlocking();
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowBasedEdge::deactivate()
|
|
|
|
{
|
2013-02-04 12:46:14 +04:00
|
|
|
m_window.reset();
|
|
|
|
m_approachWindow.reset();
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowBasedEdge::createWindow()
|
|
|
|
{
|
2013-02-04 12:46:14 +04:00
|
|
|
if (m_window.isValid()) {
|
2013-01-21 12:04:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
|
|
|
|
const uint32_t values[] = {
|
|
|
|
true,
|
2014-02-01 13:03:49 +04:00
|
|
|
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION
|
2013-01-21 12:04:06 +04:00
|
|
|
};
|
2013-02-04 12:46:14 +04:00
|
|
|
m_window.create(geometry(), XCB_WINDOW_CLASS_INPUT_ONLY, mask, values);
|
|
|
|
m_window.map();
|
2013-01-21 12:04:06 +04:00
|
|
|
// Set XdndAware on the windows, so that DND enter events are received (#86998)
|
|
|
|
xcb_atom_t version = 4; // XDND version
|
|
|
|
xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, m_window,
|
|
|
|
atoms->xdnd_aware, XCB_ATOM_ATOM, 32, 1, (unsigned char*)(&version));
|
|
|
|
}
|
|
|
|
|
2013-01-26 14:50:14 +04:00
|
|
|
void WindowBasedEdge::createApproachWindow()
|
|
|
|
{
|
2013-02-04 12:46:14 +04:00
|
|
|
if (m_approachWindow.isValid()) {
|
2013-01-26 14:50:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!approachGeometry().isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const uint32_t mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
|
|
|
|
const uint32_t values[] = {
|
|
|
|
true,
|
2014-02-01 13:03:49 +04:00
|
|
|
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_POINTER_MOTION
|
2013-01-26 14:50:14 +04:00
|
|
|
};
|
2013-02-04 12:46:14 +04:00
|
|
|
m_approachWindow.create(approachGeometry(), XCB_WINDOW_CLASS_INPUT_ONLY, mask, values);
|
|
|
|
m_approachWindow.map();
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowBasedEdge::doGeometryUpdate()
|
|
|
|
{
|
2013-02-04 12:46:14 +04:00
|
|
|
m_window.setGeometry(geometry());
|
|
|
|
m_approachWindow.setGeometry(approachGeometry());
|
2013-01-26 14:50:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowBasedEdge::doStartApproaching()
|
|
|
|
{
|
2013-02-04 12:46:14 +04:00
|
|
|
m_approachWindow.unmap();
|
2013-02-19 14:25:46 +04:00
|
|
|
Cursor *cursor = Cursor::self();
|
|
|
|
connect(cursor, SIGNAL(posChanged(QPoint)), SLOT(updateApproaching(QPoint)));
|
|
|
|
cursor->startMousePolling();
|
2013-01-26 14:50:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowBasedEdge::doStopApproaching()
|
|
|
|
{
|
2013-02-19 14:25:46 +04:00
|
|
|
Cursor *cursor = Cursor::self();
|
|
|
|
disconnect(cursor, SIGNAL(posChanged(QPoint)), this, SLOT(updateApproaching(QPoint)));
|
|
|
|
cursor->stopMousePolling();
|
2013-02-04 12:46:14 +04:00
|
|
|
m_approachWindow.map();
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
|
2013-01-31 20:25:03 +04:00
|
|
|
void WindowBasedEdge::doUpdateBlocking()
|
|
|
|
{
|
|
|
|
if (!isReserved()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isBlocked()) {
|
2013-02-04 12:46:14 +04:00
|
|
|
m_window.unmap();
|
|
|
|
m_approachWindow.unmap();
|
2013-01-31 20:25:03 +04:00
|
|
|
} else {
|
2013-02-04 12:46:14 +04:00
|
|
|
m_window.map();
|
|
|
|
m_approachWindow.map();
|
2013-01-31 20:25:03 +04:00
|
|
|
}
|
|
|
|
}
|
2013-06-26 12:25:17 +04:00
|
|
|
/**********************************************************
|
|
|
|
* AreaBasedEdge
|
|
|
|
*********************************************************/
|
|
|
|
AreaBasedEdge::AreaBasedEdge(ScreenEdges* parent)
|
|
|
|
: Edge(parent)
|
|
|
|
{
|
|
|
|
connect(input(), SIGNAL(globalPointerChanged(QPointF)), SLOT(pointerPosChanged(QPointF)));
|
|
|
|
}
|
|
|
|
|
|
|
|
AreaBasedEdge::~AreaBasedEdge()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void AreaBasedEdge::pointerPosChanged(const QPointF &pos)
|
|
|
|
{
|
|
|
|
if (!isReserved()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QPoint p = pos.toPoint();
|
|
|
|
if (approachGeometry().contains(p)) {
|
|
|
|
if (!isApproaching()) {
|
|
|
|
startApproaching();
|
|
|
|
} else {
|
|
|
|
updateApproaching(p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isApproaching()) {
|
|
|
|
stopApproaching();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (geometry().contains(p)) {
|
|
|
|
// we don't push the cursor back as pointer warping is not supported on Wayland
|
|
|
|
// TODO: this clearly needs improving
|
|
|
|
check(p, QDateTime(), true);
|
|
|
|
}
|
|
|
|
}
|
2013-01-31 20:25:03 +04:00
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
/**********************************************************
|
|
|
|
* ScreenEdges
|
|
|
|
*********************************************************/
|
2013-04-05 11:41:25 +04:00
|
|
|
KWIN_SINGLETON_FACTORY(ScreenEdges)
|
2013-01-25 13:15:00 +04:00
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
ScreenEdges::ScreenEdges(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_desktopSwitching(false)
|
|
|
|
, m_desktopSwitchingMovingClients(false)
|
|
|
|
, m_timeThreshold(0)
|
|
|
|
, m_reactivateThreshold(0)
|
|
|
|
, m_virtualDesktopLayout(0)
|
|
|
|
, m_actionTopLeft(ElectricActionNone)
|
|
|
|
, m_actionTop(ElectricActionNone)
|
|
|
|
, m_actionTopRight(ElectricActionNone)
|
|
|
|
, m_actionRight(ElectricActionNone)
|
|
|
|
, m_actionBottomRight(ElectricActionNone)
|
|
|
|
, m_actionBottom(ElectricActionNone)
|
|
|
|
, m_actionBottomLeft(ElectricActionNone)
|
|
|
|
, m_actionLeft(ElectricActionNone)
|
|
|
|
{
|
2013-04-14 22:04:05 +04:00
|
|
|
QWidget w;
|
|
|
|
m_cornerOffset = (w.physicalDpiX() + w.physicalDpiY() + 5) / 6;
|
2014-02-20 15:39:23 +04:00
|
|
|
|
2015-04-30 11:51:58 +03:00
|
|
|
connect(workspace(), &Workspace::clientRemoved, [this](KWin::AbstractClient *c) {
|
|
|
|
Client *client = qobject_cast<Client*>(c);
|
|
|
|
if (!client) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-20 15:39:23 +04:00
|
|
|
deleteEdgeForClient(client);
|
|
|
|
QObject::disconnect(client, &Client::geometryChanged,
|
|
|
|
ScreenEdges::self(), &ScreenEdges::handleClientGeometryChanged);
|
|
|
|
});
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ScreenEdges::~ScreenEdges()
|
|
|
|
{
|
2013-01-25 13:15:00 +04:00
|
|
|
s_self = NULL;
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdges::init()
|
|
|
|
{
|
|
|
|
reconfigure();
|
2012-11-25 13:13:34 +04:00
|
|
|
updateLayout();
|
2013-01-21 12:04:06 +04:00
|
|
|
recreateEdges();
|
|
|
|
}
|
|
|
|
static ElectricBorderAction electricBorderAction(const QString& name)
|
|
|
|
{
|
|
|
|
QString lowerName = name.toLower();
|
2013-07-23 09:02:52 +04:00
|
|
|
if (lowerName == QStringLiteral("dashboard")) {
|
2013-01-21 12:04:06 +04:00
|
|
|
return ElectricActionDashboard;
|
2013-07-23 09:02:52 +04:00
|
|
|
} else if (lowerName == QStringLiteral("showdesktop")) {
|
2013-01-21 12:04:06 +04:00
|
|
|
return ElectricActionShowDesktop;
|
2013-07-23 09:02:52 +04:00
|
|
|
} else if (lowerName == QStringLiteral("lockscreen")) {
|
2013-01-21 12:04:06 +04:00
|
|
|
return ElectricActionLockScreen;
|
2013-07-23 09:02:52 +04:00
|
|
|
} else if (lowerName == QStringLiteral("preventscreenlocking")) {
|
2013-01-21 12:04:06 +04:00
|
|
|
return ElectricActionPreventScreenLocking;
|
|
|
|
}
|
|
|
|
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 21:38:26 +04:00
|
|
|
setReActivationThreshold(qMax(timeThreshold() + 50, windowsConfig.readEntry("ElectricBorderCooldown", 350)));
|
2013-01-21 12:04:06 +04: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")));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdges::setActionForBorder(ElectricBorder border, ElectricBorderAction *oldValue, ElectricBorderAction newValue)
|
|
|
|
{
|
|
|
|
if (*oldValue == newValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*oldValue == ElectricActionNone) {
|
|
|
|
// have to reserve
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2013-01-21 12:04:06 +04:00
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->reserve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newValue == ElectricActionNone) {
|
|
|
|
// have to unreserve
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2013-01-21 12:04:06 +04:00
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->unreserve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*oldValue = newValue;
|
|
|
|
// update action on all Edges for given border
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2013-01-21 12:04:06 +04:00
|
|
|
if ((*it)->border() == border) {
|
|
|
|
(*it)->setAction(newValue);
|
|
|
|
}
|
|
|
|
}
|
2012-11-25 13:13:34 +04:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
void ScreenEdges::updateLayout()
|
2012-11-25 13:13:34 +04:00
|
|
|
{
|
|
|
|
const QSize desktopMatrix = VirtualDesktopManager::self()->grid().size();
|
|
|
|
Qt::Orientations newLayout = 0;
|
|
|
|
if (desktopMatrix.width() > 1) {
|
|
|
|
newLayout |= Qt::Horizontal;
|
|
|
|
}
|
|
|
|
if (desktopMatrix.height() > 1) {
|
|
|
|
newLayout |= Qt::Vertical;
|
|
|
|
}
|
|
|
|
if (newLayout == m_virtualDesktopLayout) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
if (isDesktopSwitching()) {
|
2012-11-25 13:13:34 +04:00
|
|
|
reserveDesktopSwitching(false, m_virtualDesktopLayout);
|
|
|
|
}
|
|
|
|
m_virtualDesktopLayout = newLayout;
|
2013-01-21 12:04:06 +04:00
|
|
|
if (isDesktopSwitching()) {
|
2012-11-25 13:13:34 +04:00
|
|
|
reserveDesktopSwitching(true, m_virtualDesktopLayout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
static bool isLeftScreen(const QRect &screen, const QRect &fullArea)
|
2011-06-23 14:09:17 +04:00
|
|
|
{
|
2013-04-03 14:19:27 +04:00
|
|
|
if (screens()->count() == 1) {
|
2013-01-21 12:04:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (screen.x() == fullArea.x()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// the screen is also on the left in case of a vertical layout with a second screen
|
|
|
|
// more to the left. In that case no screen ends left of screen's x coord
|
2013-04-03 14:19:27 +04:00
|
|
|
for (int i=0; i<screens()->count(); ++i) {
|
|
|
|
const QRect otherGeo = screens()->geometry(i);
|
2013-01-21 12:04:06 +04:00
|
|
|
if (otherGeo == screen) {
|
|
|
|
// that's our screen to test
|
|
|
|
continue;
|
2011-06-23 14:09:17 +04:00
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
if (otherGeo.x() + otherGeo.width() <= screen.x()) {
|
|
|
|
// other screen is completely in the left
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// did not find a screen left of our current screen, so it is the left most
|
|
|
|
return true;
|
2011-06-23 14:09:17 +04:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
static bool isRightScreen(const QRect &screen, const QRect &fullArea)
|
2011-06-23 14:09:17 +04:00
|
|
|
{
|
2013-04-03 14:19:27 +04:00
|
|
|
if (screens()->count() == 1) {
|
2013-01-21 12:04:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (screen.x() + screen.width() == fullArea.x() + fullArea.width()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// the screen is also on the right in case of a vertical layout with a second screen
|
|
|
|
// more to the right. In that case no screen starts right of this screen
|
2013-04-03 14:19:27 +04:00
|
|
|
for (int i=0; i<screens()->count(); ++i) {
|
|
|
|
const QRect otherGeo = screens()->geometry(i);
|
2013-01-21 12:04:06 +04:00
|
|
|
if (otherGeo == screen) {
|
|
|
|
// that's our screen to test
|
|
|
|
continue;
|
2012-05-03 21:48:20 +04:00
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
if (otherGeo.x() >= screen.x() + screen.width()) {
|
|
|
|
// other screen is completely in the right
|
|
|
|
return false;
|
2012-05-03 21:48:20 +04:00
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
// did not find a screen right of our current screen, so it is the right most
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isTopScreen(const QRect &screen, const QRect &fullArea)
|
|
|
|
{
|
2013-04-03 14:19:27 +04:00
|
|
|
if (screens()->count() == 1) {
|
2013-01-21 12:04:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (screen.y() == fullArea.y()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// the screen is also top most in case of a horizontal layout with a second screen
|
|
|
|
// more to the top. In that case no screen ends above screen's y coord
|
2013-04-03 14:19:27 +04:00
|
|
|
for (int i=0; i<screens()->count(); ++i) {
|
|
|
|
const QRect otherGeo = screens()->geometry(i);
|
2013-01-21 12:04:06 +04:00
|
|
|
if (otherGeo == screen) {
|
|
|
|
// that's our screen to test
|
|
|
|
continue;
|
2012-05-03 21:48:20 +04:00
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
if (otherGeo.y() + otherGeo.height() <= screen.y()) {
|
|
|
|
// other screen is completely above
|
|
|
|
return false;
|
2012-05-03 21:48:20 +04:00
|
|
|
}
|
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
// did not find a screen above our current screen, so it is the top most
|
|
|
|
return true;
|
2011-06-23 14:09:17 +04:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
static bool isBottomScreen(const QRect &screen, const QRect &fullArea)
|
2011-06-23 14:09:17 +04:00
|
|
|
{
|
2013-04-03 14:19:27 +04:00
|
|
|
if (screens()->count() == 1) {
|
2013-01-21 12:04:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (screen.y() + screen.height() == fullArea.y() + fullArea.height()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// the screen is also bottom most in case of a horizontal layout with a second screen
|
|
|
|
// more below. In that case no screen starts below screen's y coord + height
|
2013-04-03 14:19:27 +04:00
|
|
|
for (int i=0; i<screens()->count(); ++i) {
|
|
|
|
const QRect otherGeo = screens()->geometry(i);
|
2013-01-21 12:04:06 +04:00
|
|
|
if (otherGeo == screen) {
|
|
|
|
// that's our screen to test
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (otherGeo.y() >= screen.y() + screen.height()) {
|
|
|
|
// other screen is completely below
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// did not find a screen below our current screen, so it is the bottom most
|
|
|
|
return true;
|
2011-06-23 14:09:17 +04:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
void ScreenEdges::recreateEdges()
|
2011-06-23 14:09:17 +04:00
|
|
|
{
|
2013-06-26 12:25:17 +04:00
|
|
|
QList<Edge*> oldEdges(m_edges);
|
2013-01-21 12:04:06 +04:00
|
|
|
m_edges.clear();
|
|
|
|
const QRect fullArea(0, 0, displayWidth(), displayHeight());
|
2014-09-04 23:13:55 +04:00
|
|
|
QRegion processedRegion;
|
2013-04-03 14:19:27 +04:00
|
|
|
for (int i=0; i<screens()->count(); ++i) {
|
2014-09-04 23:13:55 +04:00
|
|
|
const QRegion screen = QRegion(screens()->geometry(i)).subtracted(processedRegion);
|
|
|
|
processedRegion += screen;
|
|
|
|
Q_FOREACH (const QRect &screenPart, screen.rects()) {
|
|
|
|
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 12:04:06 +04:00
|
|
|
}
|
|
|
|
}
|
2013-01-22 15:47:06 +04:00
|
|
|
// copy over the effect/script reservations from the old edges
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
Edge *edge = *it;
|
|
|
|
for (auto oldIt = oldEdges.constBegin();
|
2013-01-22 15:47:06 +04:00
|
|
|
oldIt != oldEdges.constEnd();
|
|
|
|
++oldIt) {
|
2013-06-26 12:25:17 +04:00
|
|
|
Edge *oldEdge = *oldIt;
|
2014-02-20 15:39:23 +04:00
|
|
|
if (oldEdge->client()) {
|
|
|
|
// show the client again and don't recreate the edge
|
|
|
|
oldEdge->client()->showOnScreenEdge();
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-22 15:47:06 +04: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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qDeleteAll(oldEdges);
|
2011-06-23 14:09:17 +04:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
void ScreenEdges::createVerticalEdge(ElectricBorder border, const QRect &screen, const QRect &fullArea)
|
2011-06-23 14:09:17 +04:00
|
|
|
{
|
2013-01-21 12:04:06 +04:00
|
|
|
if (border != ElectricRight && border != KWin::ElectricLeft) {
|
2011-06-23 14:09:17 +04:00
|
|
|
return;
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
int y = screen.y();
|
|
|
|
int height = screen.height();
|
|
|
|
const int x = (border == ElectricLeft) ? screen.x() : screen.x() + screen.width() -1;
|
|
|
|
if (isTopScreen(screen, fullArea)) {
|
|
|
|
// also top most screen
|
2013-04-14 22:04:05 +04:00
|
|
|
height -= m_cornerOffset;
|
|
|
|
y += m_cornerOffset;
|
2013-01-21 12:04:06 +04:00
|
|
|
// create top left/right edge
|
|
|
|
const ElectricBorder edge = (border == ElectricLeft) ? ElectricTopLeft : ElectricTopRight;
|
|
|
|
m_edges << createEdge(edge, x, screen.y(), 1, 1);
|
|
|
|
}
|
|
|
|
if (isBottomScreen(screen, fullArea)) {
|
|
|
|
// also bottom most screen
|
2013-04-14 22:04:05 +04:00
|
|
|
height -= m_cornerOffset;
|
2013-01-21 12:04:06 +04:00
|
|
|
// create bottom left/right edge
|
|
|
|
const ElectricBorder edge = (border == ElectricLeft) ? ElectricBottomLeft : ElectricBottomRight;
|
|
|
|
m_edges << createEdge(edge, x, screen.y() + screen.height() -1, 1, 1);
|
|
|
|
}
|
|
|
|
// create border
|
|
|
|
m_edges << createEdge(border, x, y, 1, height);
|
|
|
|
}
|
2011-06-23 14:09:17 +04:00
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
void ScreenEdges::createHorizontalEdge(ElectricBorder border, const QRect &screen, const QRect &fullArea)
|
|
|
|
{
|
|
|
|
if (border != ElectricTop && border != ElectricBottom) {
|
2011-06-23 14:09:17 +04:00
|
|
|
return;
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
int x = screen.x();
|
|
|
|
int width = screen.width();
|
|
|
|
if (isLeftScreen(screen, fullArea)) {
|
|
|
|
// also left most - adjust only x and width
|
2013-04-14 22:04:05 +04:00
|
|
|
x += m_cornerOffset;
|
|
|
|
width -= m_cornerOffset;
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
if (isRightScreen(screen, fullArea)) {
|
|
|
|
// also right most edge
|
2013-04-14 22:04:05 +04:00
|
|
|
width -= m_cornerOffset;
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
const int y = (border == ElectricTop) ? screen.y() : screen.y() + screen.height() - 1;
|
|
|
|
m_edges << createEdge(border, x, y, width, 1);
|
|
|
|
}
|
2011-06-23 14:09:17 +04:00
|
|
|
|
2013-06-26 12:25:17 +04:00
|
|
|
Edge *ScreenEdges::createEdge(ElectricBorder border, int x, int y, int width, int height, bool createAction)
|
2013-01-21 12:04:06 +04:00
|
|
|
{
|
2013-06-26 12:25:17 +04:00
|
|
|
Edge *edge;
|
|
|
|
if (kwinApp()->operationMode() == Application::OperationModeX11) {
|
|
|
|
edge = new WindowBasedEdge(this);
|
|
|
|
} else {
|
|
|
|
edge = new AreaBasedEdge(this);
|
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
edge->setBorder(border);
|
|
|
|
edge->setGeometry(QRect(x, y, width, height));
|
2014-02-20 15:39:23 +04:00
|
|
|
if (createAction) {
|
|
|
|
const ElectricBorderAction action = actionForEdge(edge);
|
|
|
|
if (action != KWin::ElectricActionNone) {
|
|
|
|
edge->reserve();
|
|
|
|
edge->setAction(action);
|
|
|
|
}
|
2013-01-21 12:04:06 +04: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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-26 14:50:14 +04:00
|
|
|
connect(edge, SIGNAL(approaching(ElectricBorder,qreal,QRect)), SIGNAL(approaching(ElectricBorder,qreal,QRect)));
|
2013-01-31 20:25:03 +04:00
|
|
|
if (edge->isScreenEdge()) {
|
|
|
|
connect(this, SIGNAL(checkBlocking()), edge, SLOT(checkBlocking()));
|
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
return edge;
|
|
|
|
}
|
2011-06-23 14:09:17 +04:00
|
|
|
|
2013-01-21 12:04:06 +04: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdges::reserveDesktopSwitching(bool isToReserve, Qt::Orientations o)
|
|
|
|
{
|
|
|
|
if (!o)
|
|
|
|
return;
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
Edge *edge = *it;
|
2013-01-21 12:04:06 +04: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 14:09:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
|
2013-01-22 15:47:06 +04:00
|
|
|
void ScreenEdges::reserve(ElectricBorder border, QObject *object, const char *slot)
|
2013-01-21 12:04:06 +04:00
|
|
|
{
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2013-01-21 12:04:06 +04:00
|
|
|
if ((*it)->border() == border) {
|
2013-01-22 15:47:06 +04:00
|
|
|
(*it)->reserve(object, slot);
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
2011-06-23 14:09:17 +04:00
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
|
2013-01-22 15:47:06 +04:00
|
|
|
void ScreenEdges::unreserve(ElectricBorder border, QObject *object)
|
2013-01-21 12:04:06 +04:00
|
|
|
{
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2013-01-21 12:04:06 +04:00
|
|
|
if ((*it)->border() == border) {
|
2013-01-22 15:47:06 +04:00
|
|
|
(*it)->unreserve(object);
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 15:39:23 +04:00
|
|
|
void ScreenEdges::reserve(Client *client, ElectricBorder border)
|
|
|
|
{
|
2015-08-19 12:24:22 +03:00
|
|
|
bool hadBorder = false;
|
2014-02-20 15:39:23 +04:00
|
|
|
auto it = m_edges.begin();
|
|
|
|
while (it != m_edges.end()) {
|
|
|
|
if ((*it)->client() == client) {
|
2015-08-19 12:24:22 +03:00
|
|
|
hadBorder = true;
|
2014-02-20 15:39:23 +04:00
|
|
|
if ((*it)->border() == border) {
|
|
|
|
if (client->isHiddenInternal() && !(*it)->isReserved()) {
|
|
|
|
(*it)->reserve();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
delete *it;
|
|
|
|
it = m_edges.erase(it);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-19 12:24:22 +03:00
|
|
|
if (border != ElectricNone) {
|
|
|
|
connect(client, &Client::geometryChanged, this, &ScreenEdges::handleClientGeometryChanged, Qt::UniqueConnection);
|
|
|
|
createEdgeForClient(client, border);
|
|
|
|
} else {
|
|
|
|
disconnect(client, &Client::geometryChanged, this, &ScreenEdges::handleClientGeometryChanged);
|
|
|
|
if (hadBorder) // show again
|
|
|
|
client->showOnScreenEdge();
|
|
|
|
}
|
2014-02-20 15:39:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdges::createEdgeForClient(Client *client, ElectricBorder border)
|
|
|
|
{
|
|
|
|
int y = 0;
|
|
|
|
int x = 0;
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
const QRect geo = client->geometry();
|
|
|
|
const QRect fullArea = workspace()->clientArea(FullArea, 0, 1);
|
|
|
|
for (int i = 0; i < screens()->count(); ++i) {
|
|
|
|
const QRect screen = screens()->geometry(i);
|
|
|
|
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 12:25:17 +04:00
|
|
|
Edge *edge = createEdge(border, x, y, width, height, false);
|
2014-02-20 15:39:23 +04:00
|
|
|
edge->setClient(client);
|
|
|
|
m_edges.append(edge);
|
|
|
|
if (client->isHiddenInternal()) {
|
|
|
|
edge->reserve();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// we could not create an edge window, so don't allow the window to hide
|
|
|
|
client->showOnScreenEdge();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdges::handleClientGeometryChanged()
|
|
|
|
{
|
|
|
|
Client *c = static_cast<Client*>(sender());
|
|
|
|
deleteEdgeForClient(c);
|
|
|
|
c->showOnScreenEdge();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdges::deleteEdgeForClient(Client* c)
|
|
|
|
{
|
|
|
|
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 12:04:06 +04:00
|
|
|
void ScreenEdges::check(const QPoint &pos, const QDateTime &now, bool forceNoPushBack)
|
|
|
|
{
|
2014-02-20 15:39:23 +04:00
|
|
|
bool activatedForClient = false;
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
2014-02-01 13:03:49 +04:00
|
|
|
if (!(*it)->isReserved()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((*it)->approachGeometry().contains(pos)) {
|
|
|
|
(*it)->startApproaching();
|
|
|
|
}
|
2014-02-20 15:39:23 +04: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 14:09:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-01 13:36:38 +04:00
|
|
|
bool ScreenEdges::isEntered(xcb_enter_notify_event_t *event)
|
2011-06-23 14:09:17 +04:00
|
|
|
{
|
2013-08-01 13:36:38 +04:00
|
|
|
return handleEnterNotifiy(event->event,
|
|
|
|
QPoint(event->root_x, event->root_y),
|
|
|
|
QDateTime::fromMSecsSinceEpoch(event->time));
|
2013-01-28 11:52:21 +04:00
|
|
|
}
|
|
|
|
|
2013-08-01 13:36:38 +04:00
|
|
|
bool ScreenEdges::isEntered(xcb_client_message_event_t *event)
|
2013-01-28 11:52:21 +04:00
|
|
|
{
|
2013-08-01 13:36:38 +04:00
|
|
|
if (event->type != atoms->xdnd_position) {
|
|
|
|
return false;
|
2013-01-28 11:52:21 +04:00
|
|
|
}
|
2013-08-01 13:36:38 +04:00
|
|
|
return handleDndNotify(event->window,
|
|
|
|
QPoint(event->data.data32[2] >> 16, event->data.data32[2] & 0xffff));
|
2013-01-28 11:52:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ScreenEdges::handleEnterNotifiy(xcb_window_t window, const QPoint &point, const QDateTime ×tamp)
|
|
|
|
{
|
2014-02-20 15:39:23 +04:00
|
|
|
bool activated = false;
|
|
|
|
bool activatedForClient = false;
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
WindowBasedEdge *edge = dynamic_cast<WindowBasedEdge*>(*it);
|
|
|
|
if (!edge) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-28 11:52:21 +04:00
|
|
|
if (!edge->isReserved()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (edge->window() == window) {
|
2014-02-20 15:39:23 +04:00
|
|
|
if (edge->check(point, timestamp)) {
|
|
|
|
if ((*it)->client()) {
|
|
|
|
activatedForClient = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
activated = true;
|
|
|
|
break;
|
2013-01-28 11:52:21 +04: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 15:39:23 +04: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 11:52:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ScreenEdges::handleDndNotify(xcb_window_t window, const QPoint &point)
|
|
|
|
{
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.begin(); it != m_edges.end(); ++it) {
|
|
|
|
WindowBasedEdge *edge = dynamic_cast<WindowBasedEdge*>(*it);
|
|
|
|
if (!edge) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-28 11:52:21 +04:00
|
|
|
if (edge->isReserved() && edge->window() == window) {
|
|
|
|
updateXTime();
|
|
|
|
edge->check(point, QDateTime::fromMSecsSinceEpoch(xTime()), true);
|
|
|
|
return true;
|
2011-06-23 14:09:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
void ScreenEdges::ensureOnTop()
|
2011-06-23 14:09:17 +04:00
|
|
|
{
|
2013-01-21 12:04:06 +04:00
|
|
|
Xcb::restackWindowsWithRaise(windows());
|
2011-06-23 14:09:17 +04:00
|
|
|
}
|
2011-06-24 18:20:40 +04:00
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
QVector< xcb_window_t > ScreenEdges::windows() const
|
2011-06-24 18:20:40 +04:00
|
|
|
{
|
2013-01-21 12:04:06 +04:00
|
|
|
QVector<xcb_window_t> wins;
|
2013-06-26 12:25:17 +04:00
|
|
|
for (auto it = m_edges.constBegin();
|
2013-01-21 12:04:06 +04:00
|
|
|
it != m_edges.constEnd();
|
|
|
|
++it) {
|
2013-06-26 12:25:17 +04:00
|
|
|
WindowBasedEdge *edge = dynamic_cast<WindowBasedEdge*>(*it);
|
|
|
|
if (!edge) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
xcb_window_t w = edge->window();
|
2013-01-21 12:04:06 +04:00
|
|
|
if (w != XCB_WINDOW_NONE) {
|
|
|
|
wins.append(w);
|
|
|
|
}
|
2013-01-26 14:50:14 +04:00
|
|
|
// TODO: lambda
|
2013-06-26 12:25:17 +04:00
|
|
|
w = edge->approachWindow();
|
2013-01-26 14:50:14 +04:00
|
|
|
if (w != XCB_WINDOW_NONE) {
|
|
|
|
wins.append(w);
|
|
|
|
}
|
2013-01-21 12:04:06 +04:00
|
|
|
}
|
|
|
|
return wins;
|
2011-06-24 18:20:40 +04:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:04:06 +04:00
|
|
|
} //namespace
|