Changeset View
Changeset View
Standalone View
Standalone View
dbusinterface.cpp
Show All 15 Lines | |||||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | 20 | | |||
21 | // own | 21 | // own | ||
22 | #include "dbusinterface.h" | 22 | #include "dbusinterface.h" | ||
23 | #include "compositingadaptor.h" | 23 | #include "compositingadaptor.h" | ||
24 | #include "virtualdesktopmanageradaptor.h" | ||||
24 | 25 | | |||
25 | // kwin | 26 | // kwin | ||
26 | #include "abstract_client.h" | 27 | #include "abstract_client.h" | ||
27 | #include "atoms.h" | 28 | #include "atoms.h" | ||
28 | #include "composite.h" | 29 | #include "composite.h" | ||
29 | #include "debug_console.h" | 30 | #include "debug_console.h" | ||
30 | #include "main.h" | 31 | #include "main.h" | ||
31 | #include "placement.h" | 32 | #include "placement.h" | ||
▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Line(s) | 308 | #endif | |||
310 | } | 311 | } | ||
311 | if (supportsGlx) { | 312 | if (supportsGlx) { | ||
312 | interfaces << QStringLiteral("glx"); | 313 | interfaces << QStringLiteral("glx"); | ||
313 | } | 314 | } | ||
314 | interfaces << QStringLiteral("egl"); | 315 | interfaces << QStringLiteral("egl"); | ||
315 | return interfaces; | 316 | return interfaces; | ||
316 | } | 317 | } | ||
317 | 318 | | |||
319 | | ||||
320 | | ||||
321 | | ||||
322 | VirtualDesktopManagerDBusInterface::VirtualDesktopManagerDBusInterface(VirtualDesktopManager *parent) | ||||
323 | : QObject(parent) | ||||
324 | , m_manager(parent) | ||||
325 | { | ||||
326 | qDBusRegisterMetaType<KWin::DBusDesktopDataStruct>(); | ||||
327 | qDBusRegisterMetaType<KWin::DBusDesktopDataVector>(); | ||||
328 | | ||||
329 | new VirtualDesktopManagerAdaptor(this); | ||||
davidedmundson: Why don't we have the adaptor directly on the VirtualDesktopManager?
The idea behind… | |||||
the problem would be the custom types DBusDesktopDataStruct, DBusDesktopDataVector, would them be defined in the VirtualDesktopManagerAdaptor subclass? mart: the problem would be the custom types DBusDesktopDataStruct, DBusDesktopDataVector, would them… | |||||
330 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/VirtualDesktopManager"), | ||||
331 | QStringLiteral("org.kde.KWin.VirtualDesktopManager"), | ||||
332 | this | ||||
333 | ); | ||||
334 | | ||||
335 | connect(m_manager, &VirtualDesktopManager::currentChanged, this, | ||||
336 | [this](uint previousDesktop, uint newDesktop) { | ||||
337 | Q_UNUSED(previousDesktop); | ||||
338 | Q_UNUSED(newDesktop); | ||||
339 | emit currentChanged(m_manager->currentDesktop()->id()); | ||||
340 | } | ||||
341 | ); | ||||
342 | | ||||
343 | connect(m_manager, &VirtualDesktopManager::countChanged, this, | ||||
344 | [this](uint previousCount, uint newCount) { | ||||
345 | Q_UNUSED(previousCount); | ||||
346 | emit countChanged(newCount); | ||||
347 | emit desktopsChanged(desktops()); | ||||
348 | } | ||||
349 | ); | ||||
350 | | ||||
351 | connect(m_manager, &VirtualDesktopManager::navigationWrappingAroundChanged, this, | ||||
352 | [this]() { | ||||
353 | emit navigationWrappingAroundChanged(isNavigationWrappingAround()); | ||||
354 | } | ||||
355 | ); | ||||
356 | | ||||
357 | connect(m_manager, &VirtualDesktopManager::rowsChanged, this, &VirtualDesktopManagerDBusInterface::rowsChanged); | ||||
358 | | ||||
359 | for (auto *vd : m_manager->desktops()) { | ||||
360 | connect(vd, &VirtualDesktop::x11DesktopNumberChanged, this, | ||||
361 | [this, vd]() { | ||||
362 | DBusDesktopDataStruct data{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()}; | ||||
363 | emit desktopDataChanged(vd->id(), data); | ||||
364 | emit desktopsChanged(desktops()); | ||||
365 | } | ||||
366 | ); | ||||
367 | connect(vd, &VirtualDesktop::nameChanged, this, | ||||
368 | [this, vd]() { | ||||
369 | DBusDesktopDataStruct data{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()}; | ||||
370 | emit desktopDataChanged(vd->id(), data); | ||||
371 | emit desktopsChanged(desktops()); | ||||
372 | } | ||||
373 | ); | ||||
374 | } | ||||
375 | connect(m_manager, &VirtualDesktopManager::desktopCreated, this, | ||||
376 | [this](VirtualDesktop *vd) { | ||||
377 | connect(vd, &VirtualDesktop::x11DesktopNumberChanged, this, | ||||
378 | [this, vd]() { | ||||
379 | DBusDesktopDataStruct data{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()}; | ||||
380 | emit desktopDataChanged(vd->id(), data); | ||||
381 | emit desktopsChanged(desktops()); | ||||
382 | } | ||||
383 | ); | ||||
384 | connect(vd, &VirtualDesktop::nameChanged, this, | ||||
385 | [this, vd]() { | ||||
386 | DBusDesktopDataStruct data{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()}; | ||||
387 | emit desktopDataChanged(vd->id(), data); | ||||
388 | emit desktopsChanged(desktops()); | ||||
389 | } | ||||
390 | ); | ||||
391 | DBusDesktopDataStruct data{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()}; | ||||
392 | emit desktopCreated(vd->id(), data); | ||||
393 | emit desktopsChanged(desktops()); | ||||
394 | } | ||||
395 | ); | ||||
396 | connect(m_manager, &VirtualDesktopManager::desktopRemoved, this, | ||||
397 | [this](VirtualDesktop *vd) { | ||||
398 | emit desktopRemoved(vd->id()); | ||||
399 | emit desktopsChanged(desktops()); | ||||
400 | } | ||||
401 | ); | ||||
402 | } | ||||
403 | | ||||
404 | uint VirtualDesktopManagerDBusInterface::count() const | ||||
Do we want to expose setCount? We have createDesktop/removeDesktop with IDs and names. Same for enterNewPlasmaVirtualDesktopRequested davidedmundson: Do we want to expose setCount?
We have createDesktop/removeDesktop with IDs and names.
Having… | |||||
405 | { | ||||
406 | return m_manager->count(); | ||||
407 | } | ||||
408 | | ||||
409 | void VirtualDesktopManagerDBusInterface::setRows(uint rows) | ||||
410 | { | ||||
411 | if (static_cast<uint>(m_manager->grid().height()) == rows) { | ||||
412 | return; | ||||
413 | } | ||||
414 | | ||||
415 | m_manager->setRows(rows); | ||||
416 | m_manager->save(); | ||||
417 | } | ||||
418 | | ||||
419 | uint VirtualDesktopManagerDBusInterface::rows() const | ||||
420 | { | ||||
421 | return m_manager->rows(); | ||||
422 | } | ||||
423 | | ||||
424 | void VirtualDesktopManagerDBusInterface::setCurrent(const QString &id) | ||||
425 | { | ||||
426 | if (m_manager->currentDesktop()->id() == id) { | ||||
427 | return; | ||||
428 | } | ||||
429 | | ||||
430 | auto *vd = m_manager->desktopForId(id.toUtf8()); | ||||
431 | if (vd) { | ||||
432 | m_manager->setCurrent(vd); | ||||
433 | } | ||||
434 | } | ||||
435 | | ||||
436 | QString VirtualDesktopManagerDBusInterface::current() const | ||||
437 | { | ||||
438 | return m_manager->currentDesktop()->id(); | ||||
439 | } | ||||
440 | | ||||
441 | void VirtualDesktopManagerDBusInterface::setNavigationWrappingAround(bool wraps) | ||||
442 | { | ||||
443 | if (m_manager->isNavigationWrappingAround() == wraps) { | ||||
444 | return; | ||||
445 | } | ||||
446 | | ||||
447 | m_manager->setNavigationWrappingAround(wraps); | ||||
448 | } | ||||
449 | | ||||
450 | bool VirtualDesktopManagerDBusInterface::isNavigationWrappingAround() const | ||||
451 | { | ||||
452 | return m_manager->isNavigationWrappingAround(); | ||||
453 | } | ||||
454 | | ||||
455 | DBusDesktopDataVector VirtualDesktopManagerDBusInterface::desktops() const | ||||
456 | { | ||||
457 | const auto desks = m_manager->desktops(); | ||||
458 | DBusDesktopDataVector desktopVect; | ||||
459 | desktopVect.reserve(m_manager->count()); | ||||
460 | | ||||
461 | std::transform(desks.constBegin(), desks.constEnd(), | ||||
462 | std::back_inserter(desktopVect), | ||||
463 | [] (const VirtualDesktop *vd) { | ||||
464 | return DBusDesktopDataStruct{.position = vd->x11DesktopNumber() - 1, .id = vd->id(), .name = vd->name()}; | ||||
465 | } | ||||
466 | ); | ||||
467 | | ||||
468 | return desktopVect; | ||||
469 | } | ||||
470 | | ||||
471 | void VirtualDesktopManagerDBusInterface::createDesktop(uint position, const QString &name) | ||||
472 | { | ||||
473 | m_manager->createVirtualDesktop(position + 1, name); | ||||
474 | } | ||||
475 | | ||||
476 | void VirtualDesktopManagerDBusInterface::setDesktopName(const QString &id, const QString &name) | ||||
477 | { | ||||
478 | VirtualDesktop *vd = m_manager->desktopForId(id.toUtf8()); | ||||
479 | if (!vd) { | ||||
480 | return; | ||||
481 | } | ||||
482 | if (vd->name() == name) { | ||||
483 | return; | ||||
484 | } | ||||
485 | | ||||
486 | vd->setName(name); | ||||
487 | m_manager->save(); | ||||
488 | } | ||||
489 | | ||||
490 | void VirtualDesktopManagerDBusInterface::removeDesktop(const QString &id) | ||||
491 | { | ||||
492 | m_manager->removeVirtualDesktop(id.toUtf8()); | ||||
493 | } | ||||
494 | | ||||
318 | } // namespace | 495 | } // namespace |
Why don't we have the adaptor directly on the VirtualDesktopManager?
The idea behind QDBusAbstractAdaptor is that they proxy all the signals/properties/slots from itself into the passed argument. We've come up with a manual layer of indirection which is just duplicating what VirtualDesktopManagerAdaptor does automatically.
If you do need to do mods or extra connects, you can subclass the VirtualDesktopManagerAdaptor rather than proxying.