Changeset View
Changeset View
Standalone View
Standalone View
screenedge.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
43 | #ifdef KWIN_UNIT_TEST | 43 | #ifdef KWIN_UNIT_TEST | ||
44 | #include "plugins/platforms/x11/standalone/edge.h" | 44 | #include "plugins/platforms/x11/standalone/edge.h" | ||
45 | #endif | 45 | #endif | ||
46 | // DBus generated | 46 | // DBus generated | ||
47 | #include "screenlocker_interface.h" | 47 | #include "screenlocker_interface.h" | ||
48 | // frameworks | 48 | // frameworks | ||
49 | #include <KConfigGroup> | 49 | #include <KConfigGroup> | ||
50 | // Qt | 50 | // Qt | ||
51 | #include <QAction> | ||||
51 | #include <QMouseEvent> | 52 | #include <QMouseEvent> | ||
52 | #include <QSharedPointer> | 53 | #include <QSharedPointer> | ||
53 | #include <QTimer> | 54 | #include <QTimer> | ||
54 | #include <QVector> | 55 | #include <QVector> | ||
55 | #include <QTextStream> | 56 | #include <QTextStream> | ||
56 | #include <QtDBus/QDBusInterface> | 57 | #include <QtDBus/QDBusInterface> | ||
57 | #include <QtDBus/QDBusPendingCall> | 58 | #include <QtDBus/QDBusPendingCall> | ||
58 | #include <QWidget> | 59 | #include <QWidget> | ||
Show All 22 Lines | 81 | connect(m_gesture, &Gesture::triggered, this, | |||
81 | [this] { | 82 | [this] { | ||
82 | stopApproaching(); | 83 | stopApproaching(); | ||
83 | if (m_client) { | 84 | if (m_client) { | ||
84 | m_client->showOnScreenEdge(); | 85 | m_client->showOnScreenEdge(); | ||
85 | unreserve(); | 86 | unreserve(); | ||
86 | return; | 87 | return; | ||
87 | } | 88 | } | ||
88 | handleTouchAction(); | 89 | handleTouchAction(); | ||
90 | handleTouchCallback(); | ||||
89 | }, Qt::QueuedConnection | 91 | }, Qt::QueuedConnection | ||
90 | ); | 92 | ); | ||
91 | connect(m_gesture, &SwipeGesture::started, this, &Edge::startApproaching); | 93 | connect(m_gesture, &SwipeGesture::started, this, &Edge::startApproaching); | ||
92 | connect(m_gesture, &SwipeGesture::cancelled, this, &Edge::stopApproaching); | 94 | connect(m_gesture, &SwipeGesture::cancelled, this, &Edge::stopApproaching); | ||
93 | connect(m_gesture, &SwipeGesture::progress, this, | 95 | connect(m_gesture, &SwipeGesture::progress, this, | ||
94 | [this] (qreal progress) { | 96 | [this] (qreal progress) { | ||
95 | int factor = progress * 256.0f; | 97 | int factor = progress * 256.0f; | ||
96 | if (m_lastApproachingFactor != factor) { | 98 | if (m_lastApproachingFactor != factor) { | ||
Show All 30 Lines | |||||
127 | 129 | | |||
128 | void Edge::reserve(QObject *object, const char *slot) | 130 | void Edge::reserve(QObject *object, const char *slot) | ||
129 | { | 131 | { | ||
130 | connect(object, SIGNAL(destroyed(QObject*)), SLOT(unreserve(QObject*))); | 132 | connect(object, SIGNAL(destroyed(QObject*)), SLOT(unreserve(QObject*))); | ||
131 | m_callBacks.insert(object, QByteArray(slot)); | 133 | m_callBacks.insert(object, QByteArray(slot)); | ||
132 | reserve(); | 134 | reserve(); | ||
133 | } | 135 | } | ||
134 | 136 | | |||
137 | void Edge::reserveTouchCallBack(QAction *action) | ||||
138 | { | ||||
139 | if (m_touchActions.contains(action)) { | ||||
140 | return; | ||||
141 | } | ||||
142 | connect(action, &QAction::destroyed, this, | ||||
143 | [this, action] { | ||||
144 | unreserveTouchCallBack(action); | ||||
145 | } | ||||
146 | ); | ||||
147 | m_touchActions << action; | ||||
148 | reserve(); | ||||
149 | } | ||||
150 | | ||||
151 | void Edge::unreserveTouchCallBack(QAction *action) | ||||
152 | { | ||||
153 | auto it = std::find_if(m_touchActions.begin(), m_touchActions.end(), [action] (QAction *a) { return a == action; }); | ||||
154 | if (it != m_touchActions.end()) { | ||||
155 | m_touchActions.erase(it); | ||||
156 | unreserve(); | ||||
157 | } | ||||
158 | } | ||||
159 | | ||||
135 | void Edge::unreserve() | 160 | void Edge::unreserve() | ||
136 | { | 161 | { | ||
137 | m_reserved--; | 162 | m_reserved--; | ||
138 | if (m_reserved == 0) { | 163 | if (m_reserved == 0) { | ||
139 | // got deactivated | 164 | // got deactivated | ||
140 | stopApproaching(); | 165 | stopApproaching(); | ||
141 | deactivate(); | 166 | deactivate(); | ||
142 | } | 167 | } | ||
Show All 30 Lines | 197 | if (!isScreenEdge()) { | |||
173 | return false; | 198 | return false; | ||
174 | } | 199 | } | ||
175 | if (m_client) { | 200 | if (m_client) { | ||
176 | return true; | 201 | return true; | ||
177 | } | 202 | } | ||
178 | if (m_touchAction != ElectricActionNone) { | 203 | if (m_touchAction != ElectricActionNone) { | ||
179 | return true; | 204 | return true; | ||
180 | } | 205 | } | ||
206 | if (!m_touchActions.isEmpty()) { | ||||
207 | return true; | ||||
208 | } | ||||
181 | return false; | 209 | return false; | ||
182 | } | 210 | } | ||
183 | 211 | | |||
184 | bool Edge::triggersFor(const QPoint &cursorPos) const | 212 | bool Edge::triggersFor(const QPoint &cursorPos) const | ||
185 | { | 213 | { | ||
186 | if (isBlocked()) { | 214 | if (isBlocked()) { | ||
187 | return false; | 215 | return false; | ||
188 | } | 216 | } | ||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Line(s) | 384 | for (QHash<QObject *, QByteArray>::iterator it = m_callBacks.begin(); | |||
360 | QMetaObject::invokeMethod(it.key(), it.value().constData(), Q_RETURN_ARG(bool, retVal), Q_ARG(ElectricBorder, m_border)); | 388 | QMetaObject::invokeMethod(it.key(), it.value().constData(), Q_RETURN_ARG(bool, retVal), Q_ARG(ElectricBorder, m_border)); | ||
361 | if (retVal) { | 389 | if (retVal) { | ||
362 | return true; | 390 | return true; | ||
363 | } | 391 | } | ||
364 | } | 392 | } | ||
365 | return false; | 393 | return false; | ||
366 | } | 394 | } | ||
367 | 395 | | |||
396 | void Edge::handleTouchCallback() | ||||
397 | { | ||||
398 | if (m_touchActions.isEmpty()) { | ||||
399 | return; | ||||
400 | } | ||||
401 | m_touchActions.first()->trigger(); | ||||
402 | } | ||||
403 | | ||||
368 | void Edge::switchDesktop(const QPoint &cursorPos) | 404 | void Edge::switchDesktop(const QPoint &cursorPos) | ||
369 | { | 405 | { | ||
370 | QPoint pos(cursorPos); | 406 | QPoint pos(cursorPos); | ||
371 | VirtualDesktopManager *vds = VirtualDesktopManager::self(); | 407 | VirtualDesktopManager *vds = VirtualDesktopManager::self(); | ||
372 | const uint oldDesktop = vds->current(); | 408 | const uint oldDesktop = vds->current(); | ||
373 | uint desktop = oldDesktop; | 409 | uint desktop = oldDesktop; | ||
374 | const int OFFSET = 2; | 410 | const int OFFSET = 2; | ||
375 | if (isLeft()) { | 411 | if (isLeft()) { | ||
▲ Show 20 Lines • Show All 621 Lines • ▼ Show 20 Line(s) | 1032 | if (oldEdge->border() != edge->border()) { | |||
997 | continue; | 1033 | continue; | ||
998 | } | 1034 | } | ||
999 | const QHash<QObject *, QByteArray> &callbacks = oldEdge->callBacks(); | 1035 | const QHash<QObject *, QByteArray> &callbacks = oldEdge->callBacks(); | ||
1000 | for (QHash<QObject *, QByteArray>::const_iterator callback = callbacks.begin(); | 1036 | for (QHash<QObject *, QByteArray>::const_iterator callback = callbacks.begin(); | ||
1001 | callback != callbacks.end(); | 1037 | callback != callbacks.end(); | ||
1002 | ++callback) { | 1038 | ++callback) { | ||
1003 | edge->reserve(callback.key(), callback.value().constData()); | 1039 | edge->reserve(callback.key(), callback.value().constData()); | ||
1004 | } | 1040 | } | ||
1041 | const auto touchCallBacks = oldEdge->touchCallBacks(); | ||||
1042 | for (auto a : touchCallBacks) { | ||||
1043 | edge->reserveTouchCallBack(a); | ||||
1044 | } | ||||
1005 | } | 1045 | } | ||
1006 | } | 1046 | } | ||
1007 | qDeleteAll(oldEdges); | 1047 | qDeleteAll(oldEdges); | ||
1008 | } | 1048 | } | ||
1009 | 1049 | | |||
1010 | void ScreenEdges::createVerticalEdge(ElectricBorder border, const QRect &screen, const QRect &fullArea) | 1050 | void ScreenEdges::createVerticalEdge(ElectricBorder border, const QRect &screen, const QRect &fullArea) | ||
1011 | { | 1051 | { | ||
1012 | if (border != ElectricRight && border != KWin::ElectricLeft) { | 1052 | if (border != ElectricRight && border != KWin::ElectricLeft) { | ||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Line(s) | 1210 | { | |||
1183 | if (border != ElectricNone) { | 1223 | if (border != ElectricNone) { | ||
1184 | createEdgeForClient(client, border); | 1224 | createEdgeForClient(client, border); | ||
1185 | } else { | 1225 | } else { | ||
1186 | if (hadBorder) // show again | 1226 | if (hadBorder) // show again | ||
1187 | client->showOnScreenEdge(); | 1227 | client->showOnScreenEdge(); | ||
1188 | } | 1228 | } | ||
1189 | } | 1229 | } | ||
1190 | 1230 | | |||
1231 | void ScreenEdges::reserveTouch(ElectricBorder border, QAction *action) | ||||
1232 | { | ||||
1233 | for (auto it = m_edges.begin(); it != m_edges.end(); ++it) { | ||||
1234 | if ((*it)->border() == border) { | ||||
1235 | (*it)->reserveTouchCallBack(action); | ||||
1236 | } | ||||
1237 | } | ||||
1238 | } | ||||
1239 | | ||||
1240 | void ScreenEdges::unreserveTouch(ElectricBorder border, QAction *action) | ||||
1241 | { | ||||
1242 | for (auto it = m_edges.begin(); it != m_edges.end(); ++it) { | ||||
1243 | if ((*it)->border() == border) { | ||||
1244 | (*it)->unreserveTouchCallBack(action); | ||||
1245 | } | ||||
1246 | } | ||||
1247 | } | ||||
1248 | | ||||
1191 | void ScreenEdges::createEdgeForClient(AbstractClient *client, ElectricBorder border) | 1249 | void ScreenEdges::createEdgeForClient(AbstractClient *client, ElectricBorder border) | ||
1192 | { | 1250 | { | ||
1193 | int y = 0; | 1251 | int y = 0; | ||
1194 | int x = 0; | 1252 | int x = 0; | ||
1195 | int width = 0; | 1253 | int width = 0; | ||
1196 | int height = 0; | 1254 | int height = 0; | ||
1197 | const QRect geo = client->geometry(); | 1255 | const QRect geo = client->geometry(); | ||
1198 | const QRect fullArea = workspace()->clientArea(FullArea, 0, 1); | 1256 | const QRect fullArea = workspace()->clientArea(FullArea, 0, 1); | ||
▲ Show 20 Lines • Show All 242 Lines • Show Last 20 Lines |