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 | if (m_desktops.contains(virtualDesktop)) { | ||||
488 | return; | 491 | return; | ||
492 | } | ||||
489 | 493 | | |||
490 | int was_desk = m_desktop; | 494 | int was_desk = AbstractClient::desktop(); | ||
491 | const bool wasOnCurrentDesktop = isOnCurrentDesktop(); | 495 | const bool wasOnCurrentDesktop = isOnCurrentDesktop(); | ||
492 | m_desktop = desktop; | 496 | | ||
497 | //can't check windowManagementInterface yet as it gets created only on first show | ||||
498 | //on x11 only one desktop at a time | ||||
499 | if (kwinApp()->operationMode() == Application::OperationModeX11) { | ||||
davidedmundson: check it for what? | |||||
mart: ouch, old comments before operationMode was used to check | |||||
500 | m_desktops.clear(); | ||||
501 | } | ||||
502 | if (desktop == NET::OnAllDesktops) { | ||||
503 | m_desktops.clear(); | ||||
504 | } else { | ||||
505 | //if would become on all desktops, clear the list, as empty == on all desktops | ||||
506 | if (static_cast<uint>(m_desktops.count()) == VirtualDesktopManager::self()->count() - 1) { | ||||
zzag: Use static_cast. :-) | |||||
507 | m_desktops.clear(); | ||||
508 | } else { | ||||
509 | m_desktops << virtualDesktop; | ||||
510 | } | ||||
511 | } | ||||
512 | if (windowManagementInterface()) { | ||||
513 | if (m_desktops.isEmpty()) { | ||||
514 | windowManagementInterface()->setOnAllDesktops(true); | ||||
515 | } else { | ||||
516 | windowManagementInterface()->addPlasmaVirtualDesktop(virtualDesktop->id()); | ||||
517 | } | ||||
518 | } | ||||
493 | 519 | | |||
494 | if (info) { | 520 | if (info) { | ||
495 | info->setDesktop(desktop); | 521 | info->setDesktop(desktop); | ||
496 | } | 522 | } | ||
523 | | ||||
497 | if ((was_desk == NET::OnAllDesktops) != (desktop == NET::OnAllDesktops)) { | 524 | if ((was_desk == NET::OnAllDesktops) != (desktop == NET::OnAllDesktops)) { | ||
498 | // onAllDesktops changed | 525 | // onAllDesktops changed | ||
499 | workspace()->updateOnAllDesktopsOfTransients(this); | 526 | workspace()->updateOnAllDesktopsOfTransients(this); | ||
500 | } | 527 | } | ||
501 | 528 | | |||
502 | auto transients_stacking_order = workspace()->ensureStackingOrder(transients()); | 529 | auto transients_stacking_order = workspace()->ensureStackingOrder(transients()); | ||
503 | for (auto it = transients_stacking_order.constBegin(); | 530 | for (auto it = transients_stacking_order.constBegin(); | ||
504 | it != transients_stacking_order.constEnd(); | 531 | it != transients_stacking_order.constEnd(); | ||
Show All 11 Lines | |||||
516 | doSetDesktop(desktop, was_desk); | 543 | doSetDesktop(desktop, was_desk); | ||
517 | 544 | | |||
518 | FocusChain::self()->update(this, FocusChain::MakeFirst); | 545 | FocusChain::self()->update(this, FocusChain::MakeFirst); | ||
519 | updateWindowRules(Rules::Desktop); | 546 | updateWindowRules(Rules::Desktop); | ||
520 | 547 | | |||
521 | emit desktopChanged(); | 548 | emit desktopChanged(); | ||
522 | if (wasOnCurrentDesktop != isOnCurrentDesktop()) | 549 | if (wasOnCurrentDesktop != isOnCurrentDesktop()) | ||
523 | emit desktopPresenceChanged(this, was_desk); | 550 | emit desktopPresenceChanged(this, was_desk); | ||
551 | emit x11DesktopIdsChanged(); | ||||
524 | } | 552 | } | ||
525 | 553 | | |||
526 | void AbstractClient::doSetDesktop(int desktop, int was_desk) | 554 | void AbstractClient::doSetDesktop(int desktop, int was_desk) | ||
527 | { | 555 | { | ||
528 | Q_UNUSED(desktop) | 556 | Q_UNUSED(desktop) | ||
529 | Q_UNUSED(was_desk) | 557 | Q_UNUSED(was_desk) | ||
530 | } | 558 | } | ||
531 | 559 | | |||
560 | void AbstractClient::unSetDesktop(int desktop) | ||||
561 | { | ||||
562 | 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… | |||||
563 | | ||||
564 | m_desktops.removeAll(virtualDesktop); | ||||
565 | | ||||
566 | if (!windowManagementInterface()) { | ||||
567 | return; | ||||
568 | } | ||||
569 | | ||||
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… | |||||
570 | windowManagementInterface()->removePlasmaVirtualDesktop(virtualDesktop->id()); | ||||
571 | emit x11DesktopIdsChanged(); | ||||
572 | } | ||||
573 | | ||||
532 | void AbstractClient::setOnAllDesktops(bool b) | 574 | void AbstractClient::setOnAllDesktops(bool b) | ||
533 | { | 575 | { | ||
534 | if ((b && isOnAllDesktops()) || | 576 | if ((b && isOnAllDesktops()) || | ||
535 | (!b && !isOnAllDesktops())) | 577 | (!b && !isOnAllDesktops())) | ||
536 | return; | 578 | return; | ||
537 | if (b) | 579 | if (b) | ||
538 | setDesktop(NET::OnAllDesktops); | 580 | setDesktop(NET::OnAllDesktops); | ||
539 | else | 581 | else | ||
540 | setDesktop(VirtualDesktopManager::self()->current()); | 582 | setDesktop(VirtualDesktopManager::self()->current()); | ||
541 | } | 583 | } | ||
542 | 584 | | |||
585 | QList<int> AbstractClient::x11DesktopIds() const | ||||
586 | { | ||||
587 | const auto desks = desktops(); | ||||
588 | QList<int> x11Ids; | ||||
589 | x11Ids.reserve(desks.count()); | ||||
590 | std::transform(desks.constBegin(), desks.constEnd(), | ||||
591 | std::back_inserter(x11Ids), | ||||
592 | [] (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. | |||||
593 | return vd->x11DesktopNumber(); | ||||
594 | } | ||||
595 | ); | ||||
596 | return x11Ids; | ||||
597 | } | ||||
598 | | ||||
543 | bool AbstractClient::isShadeable() const | 599 | bool AbstractClient::isShadeable() const | ||
544 | { | 600 | { | ||
545 | return false; | 601 | return false; | ||
546 | } | 602 | } | ||
547 | 603 | | |||
548 | void AbstractClient::setShade(bool set) | 604 | void AbstractClient::setShade(bool set) | ||
549 | { | 605 | { | ||
550 | set ? setShade(ShadeNormal) : setShade(ShadeNone); | 606 | set ? setShade(ShadeNormal) : setShade(ShadeNone); | ||
▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Line(s) | 850 | connect(this, &AbstractClient::skipTaskbarChanged, w, | |||
797 | } | 853 | } | ||
798 | ); | 854 | ); | ||
799 | connect(this, &AbstractClient::skipSwitcherChanged, w, | 855 | connect(this, &AbstractClient::skipSwitcherChanged, w, | ||
800 | [w, this] { | 856 | [w, this] { | ||
801 | w->setSkipSwitcher(skipSwitcher()); | 857 | w->setSkipSwitcher(skipSwitcher()); | ||
802 | } | 858 | } | ||
803 | ); | 859 | ); | ||
804 | connect(this, &AbstractClient::captionChanged, w, [w, this] { w->setTitle(caption()); }); | 860 | connect(this, &AbstractClient::captionChanged, w, [w, this] { w->setTitle(caption()); }); | ||
805 | connect(this, &AbstractClient::desktopChanged, w, | 861 | | ||
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()); }); | 862 | connect(this, &AbstractClient::activeChanged, w, [w, this] { w->setActive(isActive()); }); | ||
816 | connect(this, &AbstractClient::fullScreenChanged, w, [w, this] { w->setFullscreen(isFullScreen()); }); | 863 | connect(this, &AbstractClient::fullScreenChanged, w, [w, this] { w->setFullscreen(isFullScreen()); }); | ||
817 | connect(this, &AbstractClient::keepAboveChanged, w, &PlasmaWindowInterface::setKeepAbove); | 864 | connect(this, &AbstractClient::keepAboveChanged, w, &PlasmaWindowInterface::setKeepAbove); | ||
818 | connect(this, &AbstractClient::keepBelowChanged, w, &PlasmaWindowInterface::setKeepBelow); | 865 | connect(this, &AbstractClient::keepBelowChanged, w, &PlasmaWindowInterface::setKeepBelow); | ||
819 | connect(this, &AbstractClient::minimizedChanged, w, [w, this] { w->setMinimized(isMinimized()); }); | 866 | connect(this, &AbstractClient::minimizedChanged, w, [w, this] { w->setMinimized(isMinimized()); }); | ||
820 | connect(this, static_cast<void (AbstractClient::*)(AbstractClient*,MaximizeMode)>(&AbstractClient::clientMaximizedStateChanged), w, | 867 | connect(this, static_cast<void (AbstractClient::*)(AbstractClient*,MaximizeMode)>(&AbstractClient::clientMaximizedStateChanged), w, | ||
821 | [w] (KWin::AbstractClient *c, MaximizeMode mode) { | 868 | [w] (KWin::AbstractClient *c, MaximizeMode mode) { | ||
822 | Q_UNUSED(c); | 869 | Q_UNUSED(c); | ||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 945 | [this] (bool set) { | |||
901 | } | 948 | } | ||
902 | } | 949 | } | ||
903 | ); | 950 | ); | ||
904 | connect(w, &PlasmaWindowInterface::shadedRequested, this, | 951 | connect(w, &PlasmaWindowInterface::shadedRequested, this, | ||
905 | [this] (bool set) { | 952 | [this] (bool set) { | ||
906 | setShade(set); | 953 | setShade(set); | ||
907 | } | 954 | } | ||
908 | ); | 955 | ); | ||
956 | | ||||
957 | for (const auto vd : m_desktops) { | ||||
958 | w->addPlasmaVirtualDesktop(vd->id()); | ||||
959 | } | ||||
960 | | ||||
961 | //this is only for the legacy | ||||
962 | connect(this, &AbstractClient::desktopChanged, w, | ||||
963 | [w, this] { | ||||
964 | if (isOnAllDesktops()) { | ||||
965 | w->setOnAllDesktops(true); | ||||
966 | return; | ||||
967 | } | ||||
968 | w->setVirtualDesktop(desktop() - 1); | ||||
969 | w->setOnAllDesktops(false); | ||||
970 | } | ||||
971 | ); | ||||
972 | | ||||
973 | //Plasma Virtual desktop management | ||||
974 | //show/hide when the window enters/exits from desktop | ||||
975 | connect(w, &PlasmaWindowInterface::enterPlasmaVirtualDesktopRequested, this, | ||||
976 | [this] (const QString &desktopId) { | ||||
977 | VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId.toUtf8()); | ||||
978 | if (vd) { | ||||
979 | workspace()->sendClientToDesktop(this, vd->x11DesktopNumber(), false); | ||||
980 | } | ||||
981 | } | ||||
982 | ); | ||||
983 | connect(w, &PlasmaWindowInterface::enterNewPlasmaVirtualDesktopRequested, this, | ||||
984 | [this] () { | ||||
985 | VirtualDesktopManager::self()->setCount(VirtualDesktopManager::self()->count() + 1); | ||||
986 | workspace()->sendClientToDesktop(this, VirtualDesktopManager::self()->count(), false); | ||||
987 | } | ||||
988 | ); | ||||
989 | connect(w, &PlasmaWindowInterface::leavePlasmaVirtualDesktopRequested, this, | ||||
990 | [this] (const QString &desktopId) { | ||||
991 | VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId.toUtf8()); | ||||
992 | if (vd) { | ||||
993 | unSetDesktop(vd->x11DesktopNumber()); | ||||
994 | } | ||||
995 | } | ||||
996 | ); | ||||
997 | | ||||
998 | //set initial visibility | ||||
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… | |||||
999 | if (m_desktops.isEmpty() || m_desktops.contains(VirtualDesktopManager::self()->currentDesktop())) { | ||||
1000 | emit windowShown(this); | ||||
1001 | } else { | ||||
1002 | workspace()->clientHidden(this); | ||||
1003 | } | ||||
1004 | | ||||
909 | m_windowManagementInterface = w; | 1005 | m_windowManagementInterface = w; | ||
910 | } | 1006 | } | ||
911 | 1007 | | |||
912 | void AbstractClient::destroyWindowManagementInterface() | 1008 | void AbstractClient::destroyWindowManagementInterface() | ||
913 | { | 1009 | { | ||
914 | if (m_windowManagementInterface) { | 1010 | if (m_windowManagementInterface) { | ||
915 | m_windowManagementInterface->unmap(); | 1011 | m_windowManagementInterface->unmap(); | ||
916 | m_windowManagementInterface = nullptr; | 1012 | m_windowManagementInterface = nullptr; | ||
▲ Show 20 Lines • Show All 983 Lines • Show Last 20 Lines |
check it for what?