Changeset View
Changeset View
Standalone View
Standalone View
applets/pager/plugin/windowmodel.cpp
Show All 22 Lines | |||||
23 | #include <abstracttasksmodel.h> | 23 | #include <abstracttasksmodel.h> | ||
24 | 24 | | |||
25 | #include <QApplication> | 25 | #include <QApplication> | ||
26 | #include <QDesktopWidget> | 26 | #include <QDesktopWidget> | ||
27 | #include <QMetaEnum> | 27 | #include <QMetaEnum> | ||
28 | 28 | | |||
29 | #include <KWindowSystem> | 29 | #include <KWindowSystem> | ||
30 | 30 | | |||
31 | #include <algorithm> | ||||
32 | | ||||
31 | using namespace TaskManager; | 33 | using namespace TaskManager; | ||
32 | 34 | | |||
33 | class WindowModel::Private | 35 | class WindowModel::Private | ||
34 | { | 36 | { | ||
35 | public: | 37 | public: | ||
36 | Private(WindowModel *q); | 38 | Private(WindowModel *q); | ||
37 | 39 | | |||
38 | PagerModel *pagerModel = nullptr; | 40 | PagerModel *pagerModel = nullptr; | ||
Show All 31 Lines | 65 | { | |||
70 | } | 72 | } | ||
71 | 73 | | |||
72 | return roles; | 74 | return roles; | ||
73 | } | 75 | } | ||
74 | 76 | | |||
75 | QVariant WindowModel::data(const QModelIndex &index, int role) const | 77 | QVariant WindowModel::data(const QModelIndex &index, int role) const | ||
76 | { | 78 | { | ||
77 | if (role == AbstractTasksModel::Geometry) { | 79 | if (role == AbstractTasksModel::Geometry) { | ||
78 | const QRect &windowGeo = TaskFilterProxyModel::data(index, role).toRect(); | 80 | QRect windowGeo = TaskFilterProxyModel::data(index, role).toRect(); | ||
79 | | ||||
80 | if (KWindowSystem::mapViewport()) { | | |||
81 | const QRect &desktopGeo = d->desktopWidget->geometry(); | 81 | const QRect &desktopGeo = d->desktopWidget->geometry(); | ||
82 | 82 | | |||
83 | if (KWindowSystem::mapViewport()) { | ||||
83 | int x = windowGeo.center().x() % desktopGeo.width(); | 84 | int x = windowGeo.center().x() % desktopGeo.width(); | ||
84 | int y = windowGeo.center().y() % desktopGeo.height(); | 85 | int y = windowGeo.center().y() % desktopGeo.height(); | ||
85 | 86 | | |||
86 | if (x < 0) { | 87 | if (x < 0) { | ||
87 | x = x + desktopGeo.width(); | 88 | x = x + desktopGeo.width(); | ||
88 | } | 89 | } | ||
89 | 90 | | |||
90 | if (y < 0) { | 91 | if (y < 0) { | ||
91 | y = y + desktopGeo.height(); | 92 | y = y + desktopGeo.height(); | ||
92 | } | 93 | } | ||
93 | 94 | | |||
94 | const QRect mappedGeo(x - windowGeo.width() / 2, y - windowGeo.height() / 2, | 95 | const QRect mappedGeo(x - windowGeo.width() / 2, y - windowGeo.height() / 2, | ||
95 | windowGeo.width(), windowGeo.height()); | 96 | windowGeo.width(), windowGeo.height()); | ||
96 | 97 | | |||
97 | if (filterByScreen() && screenGeometry().isValid()) { | 98 | if (filterByScreen() && screenGeometry().isValid()) { | ||
98 | const QPoint &screenOffset = screenGeometry().topLeft(); | 99 | const QPoint &screenOffset = screenGeometry().topLeft(); | ||
99 | 100 | | |||
100 | return mappedGeo.translated(0 - screenOffset.x(), 0 - screenOffset.y()); | 101 | windowGeo = mappedGeo.translated(0 - screenOffset.x(), 0 - screenOffset.y()); | ||
101 | } | 102 | } | ||
103 | } else if (filterByScreen() && screenGeometry().isValid()) { | ||||
104 | const QPoint &screenOffset = screenGeometry().topLeft(); | ||||
105 | | ||||
106 | windowGeo.translate(0 - screenOffset.x(), 0 - screenOffset.y()); | ||||
102 | } | 107 | } | ||
103 | 108 | | |||
104 | if (filterByScreen() && screenGeometry().isValid()) { | 109 | // Clamp to desktop rect. | ||
105 | const QPoint &screenOffset = screenGeometry().topLeft(); | 110 | // TODO: Switch from qBound to std::clamp once we use C++17. | ||
111 | windowGeo.setX(qBound(0, windowGeo.x(), desktopGeo.width())); | ||||
112 | windowGeo.setY(qBound(0, windowGeo.y(), desktopGeo.height())); | ||||
113 | | ||||
114 | if ((windowGeo.x() + windowGeo.width()) > desktopGeo.width()) { | ||||
115 | windowGeo.setWidth(desktopGeo.width() - windowGeo.x()); | ||||
116 | } | ||||
106 | 117 | | |||
107 | return windowGeo.translated(0 - screenOffset.x(), 0 - screenOffset.y()); | 118 | if ((windowGeo.y() + windowGeo.height()) > desktopGeo.height()) { | ||
119 | windowGeo.setHeight(desktopGeo.height() - windowGeo.y()); | ||||
108 | } | 120 | } | ||
109 | 121 | | |||
110 | return windowGeo; | 122 | return windowGeo; | ||
111 | } else if (role == StackingOrder) { | 123 | } else if (role == StackingOrder) { | ||
112 | #if HAVE_X11 | 124 | #if HAVE_X11 | ||
113 | const QVariantList &winIds = TaskFilterProxyModel::data(index, AbstractTasksModel::LegacyWinIdList).toList(); | 125 | const QVariantList &winIds = TaskFilterProxyModel::data(index, AbstractTasksModel::LegacyWinIdList).toList(); | ||
114 | 126 | | |||
115 | if (winIds.count()) { | 127 | if (winIds.count()) { | ||
Show All 21 Lines |