Changeset View
Changeset View
Standalone View
Standalone View
abstract_client.cpp
Show First 20 Lines • Show All 478 Lines • ▼ Show 20 Line(s) | |||||
479 | } | 479 | } | ||
480 | 480 | | |||
481 | void AbstractClient::setDesktop(int desktop) | 481 | void AbstractClient::setDesktop(int desktop) | ||
482 | { | 482 | { | ||
483 | const int numberOfDesktops = VirtualDesktopManager::self()->count(); | 483 | const int numberOfDesktops = VirtualDesktopManager::self()->count(); | ||
484 | if (desktop != NET::OnAllDesktops) // Do range check | 484 | if (desktop != NET::OnAllDesktops) // Do range check | ||
485 | desktop = qMax(1, qMin(numberOfDesktops, desktop)); | 485 | desktop = qMax(1, qMin(numberOfDesktops, desktop)); | ||
486 | desktop = qMin(numberOfDesktops, rules()->checkDesktop(desktop)); | 486 | desktop = qMin(numberOfDesktops, rules()->checkDesktop(desktop)); | ||
487 | if (m_desktop == desktop) | 487 | | ||
488 | VirtualDesktop *virtualDesktop = desktop == NET::OnAllDesktops ? nullptr : VirtualDesktopManager::self()->desktopForX11Id(desktop); | ||||
489 | | ||||
490 | // Don't do anything if we're already there, if the desktop is already in desktops or if the desktop is NET::OnAllDesktops and m_desktops is already empty. | ||||
491 | if (m_desktops.contains(virtualDesktop) || | ||||
492 | (desktop == NET::OnAllDesktops && m_desktops.isEmpty())) { | ||||
488 | return; | 493 | return; | ||
494 | } | ||||
489 | 495 | | |||
490 | int was_desk = m_desktop; | 496 | int was_desk = AbstractClient::desktop(); | ||
491 | const bool wasOnCurrentDesktop = isOnCurrentDesktop(); | 497 | const bool wasOnCurrentDesktop = isOnCurrentDesktop() && was_desk >= 0; | ||
492 | m_desktop = desktop; | 498 | | ||
499 | //on x11 we can have only one desktop at a time | ||||
davidedmundson: check it for what? | |||||
mart: ouch, old comments before operationMode was used to check | |||||
500 | if (kwinApp()->operationMode() == Application::OperationModeX11) { | ||||
501 | m_desktops.clear(); | ||||
502 | } | ||||
503 | if (desktop == NET::OnAllDesktops) { | ||||
504 | m_desktops.clear(); | ||||
505 | } else { | ||||
506 | //if would become on all desktops, clear the list, as empty == on all desktops | ||||
zzag: Use static_cast. :-) | |||||
507 | if (m_desktops.count() > 1 && static_cast<uint>(m_desktops.count()) == VirtualDesktopManager::self()->count() - 1) { | ||||
508 | m_desktops.clear(); | ||||
509 | } else { | ||||
510 | m_desktops << virtualDesktop; | ||||
511 | } | ||||
512 | } | ||||
513 | if (windowManagementInterface()) { | ||||
514 | if (m_desktops.isEmpty()) { | ||||
515 | windowManagementInterface()->setOnAllDesktops(true); | ||||
516 | } else { | ||||
517 | windowManagementInterface()->addPlasmaVirtualDesktop(virtualDesktop->id()); | ||||
518 | } | ||||
519 | } | ||||
493 | 520 | | |||
494 | if (info) { | 521 | if (info) { | ||
495 | info->setDesktop(desktop); | 522 | info->setDesktop(desktop); | ||
496 | } | 523 | } | ||
524 | | ||||
497 | if ((was_desk == NET::OnAllDesktops) != (desktop == NET::OnAllDesktops)) { | 525 | if ((was_desk == NET::OnAllDesktops) != (desktop == NET::OnAllDesktops)) { | ||
498 | // onAllDesktops changed | 526 | // onAllDesktops changed | ||
499 | workspace()->updateOnAllDesktopsOfTransients(this); | 527 | workspace()->updateOnAllDesktopsOfTransients(this); | ||
500 | } | 528 | } | ||
501 | 529 | | |||
502 | auto transients_stacking_order = workspace()->ensureStackingOrder(transients()); | 530 | auto transients_stacking_order = workspace()->ensureStackingOrder(transients()); | ||
503 | for (auto it = transients_stacking_order.constBegin(); | 531 | for (auto it = transients_stacking_order.constBegin(); | ||
504 | it != transients_stacking_order.constEnd(); | 532 | it != transients_stacking_order.constEnd(); | ||
Show All 11 Lines | |||||
516 | doSetDesktop(desktop, was_desk); | 544 | doSetDesktop(desktop, was_desk); | ||
517 | 545 | | |||
518 | FocusChain::self()->update(this, FocusChain::MakeFirst); | 546 | FocusChain::self()->update(this, FocusChain::MakeFirst); | ||
519 | updateWindowRules(Rules::Desktop); | 547 | updateWindowRules(Rules::Desktop); | ||
520 | 548 | | |||
521 | emit desktopChanged(); | 549 | emit desktopChanged(); | ||
522 | if (wasOnCurrentDesktop != isOnCurrentDesktop()) | 550 | if (wasOnCurrentDesktop != isOnCurrentDesktop()) | ||
523 | emit desktopPresenceChanged(this, was_desk); | 551 | emit desktopPresenceChanged(this, was_desk); | ||
552 | emit x11DesktopIdsChanged(); | ||||
524 | } | 553 | } | ||
525 | 554 | | |||
526 | void AbstractClient::doSetDesktop(int desktop, int was_desk) | 555 | void AbstractClient::doSetDesktop(int desktop, int was_desk) | ||
527 | { | 556 | { | ||
528 | Q_UNUSED(desktop) | 557 | Q_UNUSED(desktop) | ||
529 | Q_UNUSED(was_desk) | 558 | Q_UNUSED(was_desk) | ||
530 | } | 559 | } | ||
531 | 560 | | |||
561 | void AbstractClient::unSetDesktop(int desktop) | ||||
562 | { | ||||
563 | VirtualDesktop *virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desktop); | ||||
set Desktop had a range check so there was a guard. This has not guard that desktop is in bounds. Given it's invoked from effects, we should. davidedmundson: set Desktop had a range check so there was a guard.
This has not guard that desktop is in… | |||||
564 | | ||||
565 | m_desktops.removeAll(virtualDesktop); | ||||
566 | | ||||
567 | if (!windowManagementInterface()) { | ||||
568 | return; | ||||
569 | } | ||||
570 | | ||||
The add code has if (m_desktops.isEmpty()) { this does not. Either the windowManagementInterface should be responsible for it in both add and remove, or kwin should in both add and remove. davidedmundson: The add code has
if (m_desktops.isEmpty()) {
windowManagementInterface()->setOnAllDesktops… | |||||
571 | windowManagementInterface()->removePlasmaVirtualDesktop(virtualDesktop->id()); | ||||
572 | emit x11DesktopIdsChanged(); | ||||
573 | } | ||||
574 | | ||||
532 | void AbstractClient::setOnAllDesktops(bool b) | 575 | void AbstractClient::setOnAllDesktops(bool b) | ||
533 | { | 576 | { | ||
534 | if ((b && isOnAllDesktops()) || | 577 | if ((b && isOnAllDesktops()) || | ||
535 | (!b && !isOnAllDesktops())) | 578 | (!b && !isOnAllDesktops())) | ||
536 | return; | 579 | return; | ||
537 | if (b) | 580 | if (b) | ||
538 | setDesktop(NET::OnAllDesktops); | 581 | setDesktop(NET::OnAllDesktops); | ||
539 | else | 582 | else | ||
540 | setDesktop(VirtualDesktopManager::self()->current()); | 583 | setDesktop(VirtualDesktopManager::self()->current()); | ||
541 | } | 584 | } | ||
542 | 585 | | |||
586 | QList<int> AbstractClient::x11DesktopIds() const | ||||
587 | { | ||||
588 | const auto desks = desktops(); | ||||
589 | QList<int> x11Ids; | ||||
590 | x11Ids.reserve(desks.count()); | ||||
591 | std::transform(desks.constBegin(), desks.constEnd(), | ||||
592 | std::back_inserter(x11Ids), | ||||
593 | [] (const VirtualDesktop *vd) { | ||||
const auto desks = desktops(); // is desks a good name? QList<int> x11Ids; x11Ids.reserve(desks.count()); std::transform(desks.constBegin(), desks.constEnd(), std::back_inserter(x11Ids), [](const VirtualDesktop *vd) { return vd->x11DesktopNumber(); }); return x11Ids; zzag: ```lang=cpp
const auto desks = desktops(); // is desks a good name?
QList<int> x11Ids;
x11Ids. | |||||
594 | return vd->x11DesktopNumber(); | ||||
595 | } | ||||
596 | ); | ||||
597 | return x11Ids; | ||||
598 | } | ||||
599 | | ||||
543 | bool AbstractClient::isShadeable() const | 600 | bool AbstractClient::isShadeable() const | ||
544 | { | 601 | { | ||
545 | return false; | 602 | return false; | ||
546 | } | 603 | } | ||
547 | 604 | | |||
548 | void AbstractClient::setShade(bool set) | 605 | void AbstractClient::setShade(bool set) | ||
549 | { | 606 | { | ||
550 | set ? setShade(ShadeNormal) : setShade(ShadeNone); | 607 | set ? setShade(ShadeNormal) : setShade(ShadeNone); | ||
▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Line(s) | 851 | connect(this, &AbstractClient::skipTaskbarChanged, w, | |||
797 | } | 854 | } | ||
798 | ); | 855 | ); | ||
799 | connect(this, &AbstractClient::skipSwitcherChanged, w, | 856 | connect(this, &AbstractClient::skipSwitcherChanged, w, | ||
800 | [w, this] { | 857 | [w, this] { | ||
801 | w->setSkipSwitcher(skipSwitcher()); | 858 | w->setSkipSwitcher(skipSwitcher()); | ||
802 | } | 859 | } | ||
803 | ); | 860 | ); | ||
804 | connect(this, &AbstractClient::captionChanged, w, [w, this] { w->setTitle(caption()); }); | 861 | connect(this, &AbstractClient::captionChanged, w, [w, this] { w->setTitle(caption()); }); | ||
805 | connect(this, &AbstractClient::desktopChanged, w, | 862 | | ||
806 | [w, this] { | | |||
807 | if (isOnAllDesktops()) { | | |||
808 | w->setOnAllDesktops(true); | | |||
809 | return; | | |||
810 | } | | |||
811 | w->setVirtualDesktop(desktop() - 1); | | |||
812 | w->setOnAllDesktops(false); | | |||
813 | } | | |||
814 | ); | | |||
815 | connect(this, &AbstractClient::activeChanged, w, [w, this] { w->setActive(isActive()); }); | 863 | connect(this, &AbstractClient::activeChanged, w, [w, this] { w->setActive(isActive()); }); | ||
816 | connect(this, &AbstractClient::fullScreenChanged, w, [w, this] { w->setFullscreen(isFullScreen()); }); | 864 | connect(this, &AbstractClient::fullScreenChanged, w, [w, this] { w->setFullscreen(isFullScreen()); }); | ||
817 | connect(this, &AbstractClient::keepAboveChanged, w, &PlasmaWindowInterface::setKeepAbove); | 865 | connect(this, &AbstractClient::keepAboveChanged, w, &PlasmaWindowInterface::setKeepAbove); | ||
818 | connect(this, &AbstractClient::keepBelowChanged, w, &PlasmaWindowInterface::setKeepBelow); | 866 | connect(this, &AbstractClient::keepBelowChanged, w, &PlasmaWindowInterface::setKeepBelow); | ||
819 | connect(this, &AbstractClient::minimizedChanged, w, [w, this] { w->setMinimized(isMinimized()); }); | 867 | connect(this, &AbstractClient::minimizedChanged, w, [w, this] { w->setMinimized(isMinimized()); }); | ||
820 | connect(this, static_cast<void (AbstractClient::*)(AbstractClient*,MaximizeMode)>(&AbstractClient::clientMaximizedStateChanged), w, | 868 | connect(this, static_cast<void (AbstractClient::*)(AbstractClient*,MaximizeMode)>(&AbstractClient::clientMaximizedStateChanged), w, | ||
821 | [w] (KWin::AbstractClient *c, MaximizeMode mode) { | 869 | [w] (KWin::AbstractClient *c, MaximizeMode mode) { | ||
822 | Q_UNUSED(c); | 870 | Q_UNUSED(c); | ||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 946 | [this] (bool set) { | |||
901 | } | 949 | } | ||
902 | } | 950 | } | ||
903 | ); | 951 | ); | ||
904 | connect(w, &PlasmaWindowInterface::shadedRequested, this, | 952 | connect(w, &PlasmaWindowInterface::shadedRequested, this, | ||
905 | [this] (bool set) { | 953 | [this] (bool set) { | ||
906 | setShade(set); | 954 | setShade(set); | ||
907 | } | 955 | } | ||
908 | ); | 956 | ); | ||
957 | | ||||
958 | for (const auto vd : m_desktops) { | ||||
959 | w->addPlasmaVirtualDesktop(vd->id()); | ||||
960 | } | ||||
961 | | ||||
962 | //this is only for the legacy | ||||
963 | connect(this, &AbstractClient::desktopChanged, w, | ||||
964 | [w, this] { | ||||
965 | if (isOnAllDesktops()) { | ||||
966 | w->setOnAllDesktops(true); | ||||
967 | return; | ||||
968 | } | ||||
969 | w->setVirtualDesktop(desktop() - 1); | ||||
970 | w->setOnAllDesktops(false); | ||||
971 | } | ||||
972 | ); | ||||
973 | | ||||
974 | //Plasma Virtual desktop management | ||||
975 | //show/hide when the window enters/exits from desktop | ||||
976 | connect(w, &PlasmaWindowInterface::enterPlasmaVirtualDesktopRequested, this, | ||||
977 | [this] (const QString &desktopId) { | ||||
978 | VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId.toUtf8()); | ||||
979 | if (vd) { | ||||
980 | workspace()->sendClientToDesktop(this, vd->x11DesktopNumber(), false); | ||||
981 | } | ||||
982 | } | ||||
983 | ); | ||||
984 | connect(w, &PlasmaWindowInterface::enterNewPlasmaVirtualDesktopRequested, this, | ||||
985 | [this] () { | ||||
986 | VirtualDesktopManager::self()->setCount(VirtualDesktopManager::self()->count() + 1); | ||||
987 | workspace()->sendClientToDesktop(this, VirtualDesktopManager::self()->count(), false); | ||||
988 | } | ||||
989 | ); | ||||
990 | connect(w, &PlasmaWindowInterface::leavePlasmaVirtualDesktopRequested, this, | ||||
991 | [this] (const QString &desktopId) { | ||||
992 | VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId.toUtf8()); | ||||
993 | if (vd) { | ||||
994 | unSetDesktop(vd->x11DesktopNumber()); | ||||
995 | } | ||||
996 | } | ||||
997 | ); | ||||
998 | | ||||
909 | m_windowManagementInterface = w; | 999 | m_windowManagementInterface = w; | ||
This seems wrong. shellclient has already just emitted windowShown regardless before setting up the windowManagement iface. X clients still have doSetDesktop(int,int) called much earlier which in turn calls updateVisibility and sets these. davidedmundson: This seems wrong.
shellclient has already just emitted windowShown regardless before setting… | |||||
910 | } | 1000 | } | ||
911 | 1001 | | |||
912 | void AbstractClient::destroyWindowManagementInterface() | 1002 | void AbstractClient::destroyWindowManagementInterface() | ||
913 | { | 1003 | { | ||
914 | if (m_windowManagementInterface) { | 1004 | if (m_windowManagementInterface) { | ||
915 | m_windowManagementInterface->unmap(); | 1005 | m_windowManagementInterface->unmap(); | ||
916 | m_windowManagementInterface = nullptr; | 1006 | m_windowManagementInterface = nullptr; | ||
917 | } | 1007 | } | ||
▲ Show 20 Lines • Show All 982 Lines • Show Last 20 Lines |
check it for what?