Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/virtualdesktopinfo.cpp
Show All 36 Lines | |||||
37 | 37 | | |||
38 | namespace TaskManager | 38 | namespace TaskManager | ||
39 | { | 39 | { | ||
40 | class Q_DECL_HIDDEN VirtualDesktopInfo::Private : public QObject | 40 | class Q_DECL_HIDDEN VirtualDesktopInfo::Private : public QObject | ||
41 | { | 41 | { | ||
42 | Q_OBJECT | 42 | Q_OBJECT | ||
43 | 43 | | |||
44 | public: | 44 | public: | ||
45 | Private(VirtualDesktopInfo *q); | 45 | Private(); | ||
46 | virtual ~Private() {} | 46 | virtual ~Private() {} | ||
47 | 47 | | |||
48 | uint refCount = 1; | 48 | uint refCount = 1; | ||
49 | 49 | | |||
50 | virtual void init() = 0; | 50 | virtual void init() = 0; | ||
51 | virtual QVariant currentDesktop() const = 0; | 51 | virtual QVariant currentDesktop() const = 0; | ||
52 | virtual int numberOfDesktops() const = 0; | 52 | virtual int numberOfDesktops() const = 0; | ||
53 | virtual QVariantList desktopIds() const = 0; | 53 | virtual QVariantList desktopIds() const = 0; | ||
54 | virtual QStringList desktopNames() const = 0; | 54 | virtual QStringList desktopNames() const = 0; | ||
55 | virtual quint32 position(const QVariant &desktop) const = 0; | 55 | virtual quint32 position(const QVariant &desktop) const = 0; | ||
56 | virtual int desktopLayoutRows() const = 0; | 56 | virtual int desktopLayoutRows() const = 0; | ||
57 | virtual void requestActivate(const QVariant &desktop) = 0; | 57 | virtual void requestActivate(const QVariant &desktop) = 0; | ||
58 | virtual void requestCreateDesktop(quint32 position) = 0; | 58 | virtual void requestCreateDesktop(quint32 position) = 0; | ||
59 | virtual void requestRemoveDesktop(quint32 position) = 0; | 59 | virtual void requestRemoveDesktop(quint32 position) = 0; | ||
60 | 60 | | |||
61 | Q_SIGNALS: | 61 | Q_SIGNALS: | ||
62 | void currentDesktopChanged() const; | 62 | void currentDesktopChanged() const; | ||
63 | void numberOfDesktopsChanged() const; | 63 | void numberOfDesktopsChanged() const; | ||
64 | void desktopIdsChanged() const; | 64 | void desktopIdsChanged() const; | ||
65 | void desktopNamesChanged() const; | 65 | void desktopNamesChanged() const; | ||
66 | void desktopLayoutRowsChanged() const; | 66 | void desktopLayoutRowsChanged() const; | ||
67 | | ||||
68 | protected: | | |||
69 | VirtualDesktopInfo *q; | | |||
70 | }; | 67 | }; | ||
71 | 68 | | |||
72 | VirtualDesktopInfo::Private::Private(VirtualDesktopInfo *q) | 69 | VirtualDesktopInfo::Private::Private() | ||
73 | : q(q) | | |||
74 | { | 70 | { | ||
75 | } | 71 | } | ||
76 | 72 | | |||
77 | #if HAVE_X11 | 73 | #if HAVE_X11 | ||
78 | class Q_DECL_HIDDEN VirtualDesktopInfo::XWindowPrivate : public VirtualDesktopInfo::Private | 74 | class Q_DECL_HIDDEN VirtualDesktopInfo::XWindowPrivate : public VirtualDesktopInfo::Private | ||
79 | { | 75 | { | ||
76 | Q_OBJECT | ||||
80 | public: | 77 | public: | ||
81 | XWindowPrivate(VirtualDesktopInfo *q); | 78 | XWindowPrivate(); | ||
82 | 79 | | |||
83 | void init() override; | 80 | void init() override; | ||
84 | QVariant currentDesktop() const override; | 81 | QVariant currentDesktop() const override; | ||
85 | int numberOfDesktops() const override; | 82 | int numberOfDesktops() const override; | ||
86 | QVariantList desktopIds() const override; | 83 | QVariantList desktopIds() const override; | ||
87 | QStringList desktopNames() const override; | 84 | QStringList desktopNames() const override; | ||
88 | quint32 position(const QVariant &desktop) const override; | 85 | quint32 position(const QVariant &desktop) const override; | ||
89 | int desktopLayoutRows() const override; | 86 | int desktopLayoutRows() const override; | ||
90 | void requestActivate(const QVariant &desktop) override; | 87 | void requestActivate(const QVariant &desktop) override; | ||
91 | void requestCreateDesktop(quint32 position) override; | 88 | void requestCreateDesktop(quint32 position) override; | ||
92 | void requestRemoveDesktop(quint32 position) override; | 89 | void requestRemoveDesktop(quint32 position) override; | ||
93 | }; | 90 | }; | ||
94 | 91 | | |||
95 | VirtualDesktopInfo::XWindowPrivate::XWindowPrivate(VirtualDesktopInfo *q) | 92 | VirtualDesktopInfo::XWindowPrivate::XWindowPrivate() | ||
96 | : VirtualDesktopInfo::Private(q) | 93 | : VirtualDesktopInfo::Private() | ||
97 | { | 94 | { | ||
98 | init(); | 95 | init(); | ||
99 | } | 96 | } | ||
100 | 97 | | |||
101 | void VirtualDesktopInfo::XWindowPrivate::init() | 98 | void VirtualDesktopInfo::XWindowPrivate::init() | ||
102 | { | 99 | { | ||
103 | connect(KWindowSystem::self(), &KWindowSystem::currentDesktopChanged, | 100 | connect(KWindowSystem::self(), &KWindowSystem::currentDesktopChanged, | ||
104 | this, &VirtualDesktopInfo::XWindowPrivate::currentDesktopChanged); | 101 | this, &VirtualDesktopInfo::XWindowPrivate::currentDesktopChanged); | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 186 | { | |||
194 | if (info.numberOfDesktops() > 1) { | 191 | if (info.numberOfDesktops() > 1) { | ||
195 | info.setNumberOfDesktops(info.numberOfDesktops() - 1); | 192 | info.setNumberOfDesktops(info.numberOfDesktops() - 1); | ||
196 | } | 193 | } | ||
197 | } | 194 | } | ||
198 | #endif | 195 | #endif | ||
199 | 196 | | |||
200 | class Q_DECL_HIDDEN VirtualDesktopInfo::WaylandPrivate : public VirtualDesktopInfo::Private | 197 | class Q_DECL_HIDDEN VirtualDesktopInfo::WaylandPrivate : public VirtualDesktopInfo::Private | ||
201 | { | 198 | { | ||
199 | Q_OBJECT | ||||
202 | public: | 200 | public: | ||
203 | WaylandPrivate(VirtualDesktopInfo *q); | 201 | WaylandPrivate(); | ||
204 | 202 | | |||
205 | QVariant currentVirtualDesktop; | 203 | QVariant currentVirtualDesktop; | ||
206 | QStringList virtualDesktops; | 204 | QStringList virtualDesktops; | ||
207 | KWayland::Client::PlasmaVirtualDesktopManagement *virtualDesktopManagement = nullptr; | 205 | KWayland::Client::PlasmaVirtualDesktopManagement *virtualDesktopManagement = nullptr; | ||
208 | 206 | | |||
209 | void init() override; | 207 | void init() override; | ||
210 | void addDesktop(const QString &id, quint32 position); | 208 | void addDesktop(const QString &id, quint32 position); | ||
211 | QVariant currentDesktop() const override; | 209 | QVariant currentDesktop() const override; | ||
212 | int numberOfDesktops() const override; | 210 | int numberOfDesktops() const override; | ||
213 | QVariantList desktopIds() const override; | 211 | QVariantList desktopIds() const override; | ||
214 | QStringList desktopNames() const override; | 212 | QStringList desktopNames() const override; | ||
215 | quint32 position(const QVariant &desktop) const override; | 213 | quint32 position(const QVariant &desktop) const override; | ||
216 | int desktopLayoutRows() const override; | 214 | int desktopLayoutRows() const override; | ||
217 | void requestActivate(const QVariant &desktop) override; | 215 | void requestActivate(const QVariant &desktop) override; | ||
218 | void requestCreateDesktop(quint32 position) override; | 216 | void requestCreateDesktop(quint32 position) override; | ||
219 | void requestRemoveDesktop(quint32 position) override; | 217 | void requestRemoveDesktop(quint32 position) override; | ||
220 | }; | 218 | }; | ||
221 | 219 | | |||
222 | VirtualDesktopInfo::WaylandPrivate::WaylandPrivate(VirtualDesktopInfo *q) | 220 | VirtualDesktopInfo::WaylandPrivate::WaylandPrivate() | ||
223 | : VirtualDesktopInfo::Private(q) | 221 | : VirtualDesktopInfo::Private() | ||
224 | { | 222 | { | ||
225 | init(); | 223 | init(); | ||
226 | } | 224 | } | ||
227 | 225 | | |||
228 | void VirtualDesktopInfo::WaylandPrivate::init() | 226 | void VirtualDesktopInfo::WaylandPrivate::init() | ||
229 | { | 227 | { | ||
230 | if (!KWindowSystem::isPlatformWayland()) { | 228 | if (!KWindowSystem::isPlatformWayland()) { | ||
231 | return; | 229 | return; | ||
232 | } | 230 | } | ||
233 | 231 | | |||
234 | KWayland::Client::ConnectionThread *connection = KWayland::Client::ConnectionThread::fromApplication(q); | 232 | KWayland::Client::ConnectionThread *connection = KWayland::Client::ConnectionThread::fromApplication(this); | ||
235 | 233 | | |||
236 | if (!connection) { | 234 | if (!connection) { | ||
237 | return; | 235 | return; | ||
238 | } | 236 | } | ||
239 | 237 | | |||
240 | KWayland::Client::Registry *registry = new KWayland::Client::Registry(q); | 238 | KWayland::Client::Registry *registry = new KWayland::Client::Registry(this); | ||
241 | registry->create(connection); | 239 | registry->create(connection); | ||
242 | 240 | | |||
243 | QObject::connect(registry, &KWayland::Client::Registry::plasmaVirtualDesktopManagementAnnounced, | 241 | QObject::connect(registry, &KWayland::Client::Registry::plasmaVirtualDesktopManagementAnnounced, | ||
244 | [this, registry] (quint32 name, quint32 version) { | 242 | [this, registry] (quint32 name, quint32 version) { | ||
245 | virtualDesktopManagement = registry->createPlasmaVirtualDesktopManagement(name, version, q); | 243 | virtualDesktopManagement = registry->createPlasmaVirtualDesktopManagement(name, version, this); | ||
246 | 244 | | |||
247 | const QList<KWayland::Client::PlasmaVirtualDesktop *> &desktops = virtualDesktopManagement->desktops(); | 245 | const QList<KWayland::Client::PlasmaVirtualDesktop *> &desktops = virtualDesktopManagement->desktops(); | ||
248 | 246 | | |||
249 | QObject::connect(virtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopCreated, q, | 247 | QObject::connect(virtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopCreated, this, | ||
250 | [this](const QString &id, quint32 position) { | 248 | [this](const QString &id, quint32 position) { | ||
251 | addDesktop(id, position); | 249 | addDesktop(id, position); | ||
252 | } | 250 | } | ||
253 | ); | 251 | ); | ||
254 | 252 | | |||
255 | QObject::connect(virtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopRemoved, q, | 253 | QObject::connect(virtualDesktopManagement, &KWayland::Client::PlasmaVirtualDesktopManagement::desktopRemoved, this, | ||
256 | [this](const QString &id) { | 254 | [this](const QString &id) { | ||
257 | virtualDesktops.removeOne(id); | 255 | virtualDesktops.removeOne(id); | ||
258 | 256 | | |||
259 | emit numberOfDesktopsChanged(); | 257 | emit numberOfDesktopsChanged(); | ||
260 | emit desktopIdsChanged(); | 258 | emit desktopIdsChanged(); | ||
261 | emit desktopNamesChanged(); | 259 | emit desktopNamesChanged(); | ||
262 | 260 | | |||
263 | if (currentVirtualDesktop == id) { | 261 | if (currentVirtualDesktop == id) { | ||
Show All 20 Lines | 277 | { | |||
284 | virtualDesktops.insert(position, id); | 282 | virtualDesktops.insert(position, id); | ||
285 | 283 | | |||
286 | emit numberOfDesktopsChanged(); | 284 | emit numberOfDesktopsChanged(); | ||
287 | emit desktopIdsChanged(); | 285 | emit desktopIdsChanged(); | ||
288 | emit desktopNamesChanged(); | 286 | emit desktopNamesChanged(); | ||
289 | 287 | | |||
290 | const KWayland::Client::PlasmaVirtualDesktop *desktop = virtualDesktopManagement->getVirtualDesktop(id); | 288 | const KWayland::Client::PlasmaVirtualDesktop *desktop = virtualDesktopManagement->getVirtualDesktop(id); | ||
291 | 289 | | |||
292 | QObject::connect(desktop, &KWayland::Client::PlasmaVirtualDesktop::activated, q, | 290 | QObject::connect(desktop, &KWayland::Client::PlasmaVirtualDesktop::activated, this, | ||
293 | [desktop, this]() { | 291 | [desktop, this]() { | ||
294 | currentVirtualDesktop = desktop->id(); | 292 | currentVirtualDesktop = desktop->id(); | ||
295 | emit currentDesktopChanged(); | 293 | emit currentDesktopChanged(); | ||
296 | } | 294 | } | ||
297 | ); | 295 | ); | ||
298 | 296 | | |||
299 | QObject::connect(desktop, &KWayland::Client::PlasmaVirtualDesktop::done, q, | 297 | QObject::connect(desktop, &KWayland::Client::PlasmaVirtualDesktop::done, this, | ||
300 | [this]() { | 298 | [this]() { | ||
301 | emit desktopNamesChanged(); | 299 | emit desktopNamesChanged(); | ||
302 | } | 300 | } | ||
303 | ); | 301 | ); | ||
304 | 302 | | |||
305 | if (desktop->isActive()) { | 303 | if (desktop->isActive()) { | ||
306 | currentVirtualDesktop = id; | 304 | currentVirtualDesktop = id; | ||
307 | emit currentDesktopChanged(); | 305 | emit currentDesktopChanged(); | ||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | |||||
399 | 397 | | |||
400 | VirtualDesktopInfo::Private* VirtualDesktopInfo::d = nullptr; | 398 | VirtualDesktopInfo::Private* VirtualDesktopInfo::d = nullptr; | ||
401 | 399 | | |||
402 | VirtualDesktopInfo::VirtualDesktopInfo(QObject *parent) : QObject(parent) | 400 | VirtualDesktopInfo::VirtualDesktopInfo(QObject *parent) : QObject(parent) | ||
403 | { | 401 | { | ||
404 | if (!d) { | 402 | if (!d) { | ||
405 | #if HAVE_X11 | 403 | #if HAVE_X11 | ||
406 | if (KWindowSystem::isPlatformX11()) { | 404 | if (KWindowSystem::isPlatformX11()) { | ||
407 | d = new VirtualDesktopInfo::XWindowPrivate(this); | 405 | d = new VirtualDesktopInfo::XWindowPrivate; | ||
408 | } else | 406 | } else | ||
409 | #endif | 407 | #endif | ||
410 | { | 408 | { | ||
411 | d = new VirtualDesktopInfo::WaylandPrivate(this); | 409 | d = new VirtualDesktopInfo::WaylandPrivate; | ||
412 | } | 410 | } | ||
413 | } else { | 411 | } else { | ||
414 | ++d->refCount; | 412 | ++d->refCount; | ||
415 | } | 413 | } | ||
416 | 414 | | |||
417 | connect(d, &VirtualDesktopInfo::Private::currentDesktopChanged, | 415 | connect(d, &VirtualDesktopInfo::Private::currentDesktopChanged, | ||
418 | this, &VirtualDesktopInfo::currentDesktopChanged); | 416 | this, &VirtualDesktopInfo::currentDesktopChanged); | ||
419 | connect(d, &VirtualDesktopInfo::Private::numberOfDesktopsChanged, | 417 | connect(d, &VirtualDesktopInfo::Private::numberOfDesktopsChanged, | ||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |