Changeset View
Changeset View
Standalone View
Standalone View
abstract_client.cpp
Show First 20 Lines • Show All 483 Lines • ▼ Show 20 Line(s) | |||||
484 | } | 484 | } | ||
485 | 485 | | |||
486 | void AbstractClient::setDesktop(int desktop) | 486 | void AbstractClient::setDesktop(int desktop) | ||
487 | { | 487 | { | ||
488 | const int numberOfDesktops = VirtualDesktopManager::self()->count(); | 488 | const int numberOfDesktops = VirtualDesktopManager::self()->count(); | ||
489 | if (desktop != NET::OnAllDesktops) // Do range check | 489 | if (desktop != NET::OnAllDesktops) // Do range check | ||
490 | desktop = qMax(1, qMin(numberOfDesktops, desktop)); | 490 | desktop = qMax(1, qMin(numberOfDesktops, desktop)); | ||
491 | desktop = qMin(numberOfDesktops, rules()->checkDesktop(desktop)); | 491 | desktop = qMin(numberOfDesktops, rules()->checkDesktop(desktop)); | ||
492 | if (m_desktop == desktop) | 492 | | ||
493 | VirtualDesktop *virtualDesktop = desktop == NET::OnAllDesktops ? nullptr : VirtualDesktopManager::self()->desktopForX11Id(desktop); | ||||
494 | | ||||
495 | // 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. | ||||
496 | if (m_desktops.contains(virtualDesktop) || | ||||
497 | (desktop == NET::OnAllDesktops && m_desktops.isEmpty())) { | ||||
493 | return; | 498 | return; | ||
499 | } | ||||
494 | 500 | | |||
495 | int was_desk = m_desktop; | 501 | int was_desk = AbstractClient::desktop(); | ||
496 | const bool wasOnCurrentDesktop = isOnCurrentDesktop(); | 502 | const bool wasOnCurrentDesktop = isOnCurrentDesktop() && was_desk >= 0; | ||
497 | m_desktop = desktop; | 503 | | ||
504 | //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 | |||||
505 | if (kwinApp()->operationMode() == Application::OperationModeX11) { | ||||
506 | m_desktops.clear(); | ||||
507 | } | ||||
508 | if (desktop == NET::OnAllDesktops) { | ||||
509 | m_desktops.clear(); | ||||
510 | } else { | ||||
511 | //if would become on all desktops, clear the list, as empty == on all desktops | ||||
zzag: Use static_cast. :-) | |||||
512 | if (m_desktops.count() > 1 && static_cast<uint>(m_desktops.count()) == VirtualDesktopManager::self()->count() - 1) { | ||||
513 | m_desktops.clear(); | ||||
514 | } else { | ||||
515 | m_desktops << virtualDesktop; | ||||
516 | } | ||||
517 | } | ||||
518 | if (windowManagementInterface()) { | ||||
519 | if (m_desktops.isEmpty()) { | ||||
520 | windowManagementInterface()->setOnAllDesktops(true); | ||||
521 | } else { | ||||
522 | windowManagementInterface()->addPlasmaVirtualDesktop(virtualDesktop->id()); | ||||
523 | } | ||||
524 | } | ||||
498 | 525 | | |||
499 | if (info) { | 526 | if (info) { | ||
500 | info->setDesktop(desktop); | 527 | info->setDesktop(desktop); | ||
501 | } | 528 | } | ||
529 | | ||||
502 | if ((was_desk == NET::OnAllDesktops) != (desktop == NET::OnAllDesktops)) { | 530 | if ((was_desk == NET::OnAllDesktops) != (desktop == NET::OnAllDesktops)) { | ||
503 | // onAllDesktops changed | 531 | // onAllDesktops changed | ||
504 | workspace()->updateOnAllDesktopsOfTransients(this); | 532 | workspace()->updateOnAllDesktopsOfTransients(this); | ||
505 | } | 533 | } | ||
506 | 534 | | |||
507 | auto transients_stacking_order = workspace()->ensureStackingOrder(transients()); | 535 | auto transients_stacking_order = workspace()->ensureStackingOrder(transients()); | ||
508 | for (auto it = transients_stacking_order.constBegin(); | 536 | for (auto it = transients_stacking_order.constBegin(); | ||
509 | it != transients_stacking_order.constEnd(); | 537 | it != transients_stacking_order.constEnd(); | ||
Show All 11 Lines | |||||
521 | doSetDesktop(desktop, was_desk); | 549 | doSetDesktop(desktop, was_desk); | ||
522 | 550 | | |||
523 | FocusChain::self()->update(this, FocusChain::MakeFirst); | 551 | FocusChain::self()->update(this, FocusChain::MakeFirst); | ||
524 | updateWindowRules(Rules::Desktop); | 552 | updateWindowRules(Rules::Desktop); | ||
525 | 553 | | |||
526 | emit desktopChanged(); | 554 | emit desktopChanged(); | ||
527 | if (wasOnCurrentDesktop != isOnCurrentDesktop()) | 555 | if (wasOnCurrentDesktop != isOnCurrentDesktop()) | ||
528 | emit desktopPresenceChanged(this, was_desk); | 556 | emit desktopPresenceChanged(this, was_desk); | ||
557 | emit x11DesktopIdsChanged(); | ||||
529 | } | 558 | } | ||
530 | 559 | | |||
531 | void AbstractClient::doSetDesktop(int desktop, int was_desk) | 560 | void AbstractClient::doSetDesktop(int desktop, int was_desk) | ||
532 | { | 561 | { | ||
533 | Q_UNUSED(desktop) | 562 | Q_UNUSED(desktop) | ||
534 | Q_UNUSED(was_desk) | 563 | Q_UNUSED(was_desk) | ||
535 | } | 564 | } | ||
536 | 565 | | |||
566 | void AbstractClient::unSetDesktop(int desktop) | ||||
567 | { | ||||
568 | // Case in which we are on all desktops and gets asked to unset | ||||
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… | |||||
569 | if (desktop == NET::OnAllDesktops) { | ||||
570 | if (m_desktops.isEmpty()) { | ||||
571 | setOnAllDesktops(false); | ||||
572 | } | ||||
573 | | ||||
574 | return; | ||||
575 | } | ||||
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… | |||||
576 | | ||||
577 | // Out of range | ||||
578 | if (desktop < 1 || desktop > VirtualDesktopManager::self()->count()) { | ||||
579 | return; | ||||
580 | } | ||||
581 | | ||||
582 | VirtualDesktop *virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desktop); | ||||
583 | | ||||
584 | m_desktops.removeAll(virtualDesktop); | ||||
585 | | ||||
586 | if (!windowManagementInterface()) { | ||||
587 | return; | ||||
588 | } | ||||
589 | | ||||
590 | windowManagementInterface()->removePlasmaVirtualDesktop(virtualDesktop->id()); | ||||
591 | emit x11DesktopIdsChanged(); | ||||
592 | } | ||||
593 | | ||||
537 | void AbstractClient::setOnAllDesktops(bool b) | 594 | void AbstractClient::setOnAllDesktops(bool b) | ||
538 | { | 595 | { | ||
539 | if ((b && isOnAllDesktops()) || | 596 | if ((b && isOnAllDesktops()) || | ||
540 | (!b && !isOnAllDesktops())) | 597 | (!b && !isOnAllDesktops())) | ||
541 | return; | 598 | return; | ||
542 | if (b) | 599 | if (b) | ||
543 | setDesktop(NET::OnAllDesktops); | 600 | setDesktop(NET::OnAllDesktops); | ||
544 | else | 601 | else | ||
545 | setDesktop(VirtualDesktopManager::self()->current()); | 602 | setDesktop(VirtualDesktopManager::self()->current()); | ||
546 | } | 603 | } | ||
547 | 604 | | |||
605 | QList<int> AbstractClient::x11DesktopIds() const | ||||
606 | { | ||||
607 | const auto desks = desktops(); | ||||
608 | QList<int> x11Ids; | ||||
609 | x11Ids.reserve(desks.count()); | ||||
610 | std::transform(desks.constBegin(), desks.constEnd(), | ||||
611 | std::back_inserter(x11Ids), | ||||
612 | [] (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. | |||||
613 | return vd->x11DesktopNumber(); | ||||
614 | } | ||||
615 | ); | ||||
616 | return x11Ids; | ||||
617 | } | ||||
618 | | ||||
548 | bool AbstractClient::isShadeable() const | 619 | bool AbstractClient::isShadeable() const | ||
549 | { | 620 | { | ||
550 | return false; | 621 | return false; | ||
551 | } | 622 | } | ||
552 | 623 | | |||
553 | void AbstractClient::setShade(bool set) | 624 | void AbstractClient::setShade(bool set) | ||
554 | { | 625 | { | ||
555 | set ? setShade(ShadeNormal) : setShade(ShadeNone); | 626 | set ? setShade(ShadeNormal) : setShade(ShadeNone); | ||
▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Line(s) | 871 | connect(this, &AbstractClient::skipTaskbarChanged, w, | |||
803 | } | 874 | } | ||
804 | ); | 875 | ); | ||
805 | connect(this, &AbstractClient::skipSwitcherChanged, w, | 876 | connect(this, &AbstractClient::skipSwitcherChanged, w, | ||
806 | [w, this] { | 877 | [w, this] { | ||
807 | w->setSkipSwitcher(skipSwitcher()); | 878 | w->setSkipSwitcher(skipSwitcher()); | ||
808 | } | 879 | } | ||
809 | ); | 880 | ); | ||
810 | connect(this, &AbstractClient::captionChanged, w, [w, this] { w->setTitle(caption()); }); | 881 | connect(this, &AbstractClient::captionChanged, w, [w, this] { w->setTitle(caption()); }); | ||
811 | connect(this, &AbstractClient::desktopChanged, w, | 882 | | ||
812 | [w, this] { | | |||
813 | if (isOnAllDesktops()) { | | |||
814 | w->setOnAllDesktops(true); | | |||
815 | return; | | |||
816 | } | | |||
817 | w->setVirtualDesktop(desktop() - 1); | | |||
818 | w->setOnAllDesktops(false); | | |||
819 | } | | |||
820 | ); | | |||
821 | connect(this, &AbstractClient::activeChanged, w, [w, this] { w->setActive(isActive()); }); | 883 | connect(this, &AbstractClient::activeChanged, w, [w, this] { w->setActive(isActive()); }); | ||
822 | connect(this, &AbstractClient::fullScreenChanged, w, [w, this] { w->setFullscreen(isFullScreen()); }); | 884 | connect(this, &AbstractClient::fullScreenChanged, w, [w, this] { w->setFullscreen(isFullScreen()); }); | ||
823 | connect(this, &AbstractClient::keepAboveChanged, w, &PlasmaWindowInterface::setKeepAbove); | 885 | connect(this, &AbstractClient::keepAboveChanged, w, &PlasmaWindowInterface::setKeepAbove); | ||
824 | connect(this, &AbstractClient::keepBelowChanged, w, &PlasmaWindowInterface::setKeepBelow); | 886 | connect(this, &AbstractClient::keepBelowChanged, w, &PlasmaWindowInterface::setKeepBelow); | ||
825 | connect(this, &AbstractClient::minimizedChanged, w, [w, this] { w->setMinimized(isMinimized()); }); | 887 | connect(this, &AbstractClient::minimizedChanged, w, [w, this] { w->setMinimized(isMinimized()); }); | ||
826 | connect(this, static_cast<void (AbstractClient::*)(AbstractClient*,MaximizeMode)>(&AbstractClient::clientMaximizedStateChanged), w, | 888 | connect(this, static_cast<void (AbstractClient::*)(AbstractClient*,MaximizeMode)>(&AbstractClient::clientMaximizedStateChanged), w, | ||
827 | [w] (KWin::AbstractClient *c, MaximizeMode mode) { | 889 | [w] (KWin::AbstractClient *c, MaximizeMode mode) { | ||
828 | Q_UNUSED(c); | 890 | Q_UNUSED(c); | ||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 966 | [this] (bool set) { | |||
907 | } | 969 | } | ||
908 | } | 970 | } | ||
909 | ); | 971 | ); | ||
910 | connect(w, &PlasmaWindowInterface::shadedRequested, this, | 972 | connect(w, &PlasmaWindowInterface::shadedRequested, this, | ||
911 | [this] (bool set) { | 973 | [this] (bool set) { | ||
912 | setShade(set); | 974 | setShade(set); | ||
913 | } | 975 | } | ||
914 | ); | 976 | ); | ||
977 | | ||||
978 | for (const auto vd : m_desktops) { | ||||
979 | w->addPlasmaVirtualDesktop(vd->id()); | ||||
980 | } | ||||
981 | | ||||
982 | //this is only for the legacy | ||||
983 | connect(this, &AbstractClient::desktopChanged, w, | ||||
984 | [w, this] { | ||||
985 | if (isOnAllDesktops()) { | ||||
986 | w->setOnAllDesktops(true); | ||||
987 | return; | ||||
988 | } | ||||
989 | w->setVirtualDesktop(desktop() - 1); | ||||
990 | w->setOnAllDesktops(false); | ||||
991 | } | ||||
992 | ); | ||||
993 | | ||||
994 | //Plasma Virtual desktop management | ||||
995 | //show/hide when the window enters/exits from desktop | ||||
996 | connect(w, &PlasmaWindowInterface::enterPlasmaVirtualDesktopRequested, this, | ||||
997 | [this] (const QString &desktopId) { | ||||
998 | VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId.toUtf8()); | ||||
999 | if (vd) { | ||||
1000 | workspace()->sendClientToDesktop(this, vd->x11DesktopNumber(), false); | ||||
1001 | } | ||||
1002 | } | ||||
1003 | ); | ||||
1004 | connect(w, &PlasmaWindowInterface::enterNewPlasmaVirtualDesktopRequested, this, | ||||
1005 | [this] () { | ||||
1006 | VirtualDesktopManager::self()->setCount(VirtualDesktopManager::self()->count() + 1); | ||||
1007 | workspace()->sendClientToDesktop(this, VirtualDesktopManager::self()->count(), false); | ||||
1008 | } | ||||
1009 | ); | ||||
1010 | connect(w, &PlasmaWindowInterface::leavePlasmaVirtualDesktopRequested, this, | ||||
1011 | [this] (const QString &desktopId) { | ||||
1012 | VirtualDesktop *vd = VirtualDesktopManager::self()->desktopForId(desktopId.toUtf8()); | ||||
1013 | if (vd) { | ||||
1014 | unSetDesktop(vd->x11DesktopNumber()); | ||||
1015 | } | ||||
1016 | } | ||||
1017 | ); | ||||
1018 | | ||||
915 | m_windowManagementInterface = w; | 1019 | 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… | |||||
916 | } | 1020 | } | ||
917 | 1021 | | |||
918 | void AbstractClient::destroyWindowManagementInterface() | 1022 | void AbstractClient::destroyWindowManagementInterface() | ||
919 | { | 1023 | { | ||
920 | if (m_windowManagementInterface) { | 1024 | if (m_windowManagementInterface) { | ||
921 | m_windowManagementInterface->unmap(); | 1025 | m_windowManagementInterface->unmap(); | ||
922 | m_windowManagementInterface = nullptr; | 1026 | m_windowManagementInterface = nullptr; | ||
923 | } | 1027 | } | ||
▲ Show 20 Lines • Show All 984 Lines • Show Last 20 Lines |
check it for what?