Changeset View
Changeset View
Standalone View
Standalone View
abstract_client.cpp
Show First 20 Lines • Show All 484 Lines • ▼ Show 20 Line(s) | |||||
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 | 492 | | |||
493 | VirtualDesktop *virtualDesktop = desktop == NET::OnAllDesktops ? nullptr : VirtualDesktopManager::self()->desktopForX11Id(desktop); | 493 | QList<VirtualDesktop *> desktops; | ||
494 | if (desktop != NET::OnAllDesktops) { | ||||
495 | desktops << VirtualDesktopManager::self()->desktopForX11Id(desktop); | ||||
496 | } | ||||
497 | setDesktops(desktops); | ||||
498 | } | ||||
494 | 499 | | |||
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. | 500 | void AbstractClient::setDesktops(QList<VirtualDesktop*> desktops) | ||
496 | if (m_desktops.contains(virtualDesktop) || | 501 | { | ||
497 | (desktop == NET::OnAllDesktops && m_desktops.isEmpty())) { | 502 | //on x11 we can have only one desktop at a time | ||
503 | if (kwinApp()->operationMode() == Application::OperationModeX11 && desktops.size() > 1) { | ||||
504 | desktops = QList<VirtualDesktop*>({desktops.first()}); | ||||
graesslin: you can simplify this to: {desktops.first()} | |||||
505 | } | ||||
506 | | ||||
507 | if (desktops == m_desktops) { | ||||
498 | return; | 508 | return; | ||
499 | } | 509 | } | ||
500 | 510 | | |||
501 | int was_desk = AbstractClient::desktop(); | 511 | int was_desk = AbstractClient::desktop(); | ||
502 | const bool wasOnCurrentDesktop = isOnCurrentDesktop() && was_desk >= 0; | 512 | const bool wasOnCurrentDesktop = isOnCurrentDesktop() && was_desk >= 0; | ||
503 | 513 | | |||
504 | //on x11 we can have only one desktop at a time | 514 | m_desktops = desktops; | ||
505 | if (kwinApp()->operationMode() == Application::OperationModeX11) { | 515 | | ||
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 | | |||
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()) { | 516 | if (windowManagementInterface()) { | ||
519 | if (m_desktops.isEmpty()) { | 517 | if (m_desktops.isEmpty()) { | ||
520 | windowManagementInterface()->setOnAllDesktops(true); | 518 | windowManagementInterface()->setOnAllDesktops(true); | ||
521 | } else { | 519 | } else { | ||
522 | windowManagementInterface()->addPlasmaVirtualDesktop(virtualDesktop->id()); | 520 | windowManagementInterface()->setOnAllDesktops(false); | ||
521 | auto currentDesktops = windowManagementInterface()->plasmaVirtualDesktops(); | ||||
522 | for (auto desktop: m_desktops) { | ||||
523 | if (!currentDesktops.contains(desktop->id())) { | ||||
524 | windowManagementInterface()->addPlasmaVirtualDesktop(desktop->id()); | ||||
525 | } else { | ||||
526 | currentDesktops.removeOne(desktop->id()); | ||||
527 | } | ||||
528 | } | ||||
529 | for (auto desktopId: currentDesktops) { | ||||
530 | windowManagementInterface()->removePlasmaVirtualDesktop(desktopId); | ||||
531 | } | ||||
523 | } | 532 | } | ||
524 | } | 533 | } | ||
525 | | ||||
526 | if (info) { | 534 | if (info) { | ||
527 | info->setDesktop(desktop); | 535 | info->setDesktop(desktop()); | ||
528 | } | 536 | } | ||
529 | 537 | | |||
530 | if ((was_desk == NET::OnAllDesktops) != (desktop == NET::OnAllDesktops)) { | 538 | if ((was_desk == NET::OnAllDesktops) != (desktop() == NET::OnAllDesktops)) { | ||
531 | // onAllDesktops changed | 539 | // onAllDesktops changed | ||
532 | workspace()->updateOnAllDesktopsOfTransients(this); | 540 | workspace()->updateOnAllDesktopsOfTransients(this); | ||
533 | } | 541 | } | ||
534 | 542 | | |||
535 | auto transients_stacking_order = workspace()->ensureStackingOrder(transients()); | 543 | auto transients_stacking_order = workspace()->ensureStackingOrder(transients()); | ||
536 | for (auto it = transients_stacking_order.constBegin(); | 544 | for (auto it = transients_stacking_order.constBegin(); | ||
537 | it != transients_stacking_order.constEnd(); | 545 | it != transients_stacking_order.constEnd(); | ||
538 | ++it) | 546 | ++it) | ||
539 | (*it)->setDesktop(desktop); | 547 | (*it)->setDesktops(desktops); | ||
540 | 548 | | |||
541 | if (isModal()) // if a modal dialog is moved, move the mainwindow with it as otherwise | 549 | if (isModal()) // if a modal dialog is moved, move the mainwindow with it as otherwise | ||
542 | // the (just moved) modal dialog will confusingly return to the mainwindow with | 550 | // the (just moved) modal dialog will confusingly return to the mainwindow with | ||
543 | // the next desktop change | 551 | // the next desktop change | ||
544 | { | 552 | { | ||
545 | foreach (AbstractClient * c2, mainClients()) | 553 | foreach (AbstractClient * c2, mainClients()) | ||
546 | c2->setDesktop(desktop); | 554 | c2->setDesktops(desktops); | ||
547 | } | 555 | } | ||
548 | 556 | | |||
549 | doSetDesktop(desktop, was_desk); | 557 | doSetDesktop(desktop(), was_desk); | ||
550 | 558 | | |||
551 | FocusChain::self()->update(this, FocusChain::MakeFirst); | 559 | FocusChain::self()->update(this, FocusChain::MakeFirst); | ||
552 | updateWindowRules(Rules::Desktop); | 560 | updateWindowRules(Rules::Desktop); | ||
553 | 561 | | |||
554 | emit desktopChanged(); | 562 | emit desktopChanged(); | ||
555 | if (wasOnCurrentDesktop != isOnCurrentDesktop()) | 563 | if (wasOnCurrentDesktop != isOnCurrentDesktop()) | ||
556 | emit desktopPresenceChanged(this, was_desk); | 564 | emit desktopPresenceChanged(this, was_desk); | ||
557 | emit x11DesktopIdsChanged(); | 565 | emit x11DesktopIdsChanged(); | ||
558 | } | 566 | } | ||
559 | 567 | | |||
560 | void AbstractClient::doSetDesktop(int desktop, int was_desk) | 568 | void AbstractClient::doSetDesktop(int desktop, int was_desk) | ||
561 | { | 569 | { | ||
562 | Q_UNUSED(desktop) | 570 | Q_UNUSED(desktop) | ||
563 | Q_UNUSED(was_desk) | 571 | Q_UNUSED(was_desk) | ||
564 | } | 572 | } | ||
565 | 573 | | |||
566 | void AbstractClient::unSetDesktop(int desktop) | 574 | void AbstractClient::unSetDesktop(int desktop) | ||
567 | { | 575 | { | ||
568 | // Case in which we are on all desktops and gets asked to unset | 576 | // Case in which we are on all desktops and gets asked to unset | ||
569 | if (desktop == NET::OnAllDesktops) { | 577 | if (desktop == NET::OnAllDesktops) { | ||
570 | if (m_desktops.isEmpty()) { | 578 | if (m_desktops.isEmpty()) { | ||
571 | setOnAllDesktops(false); | 579 | setOnAllDesktops(false); | ||
572 | } | 580 | } | ||
573 | | ||||
574 | return; | 581 | return; | ||
575 | } | 582 | } | ||
576 | 583 | | |||
577 | // Out of range | 584 | // Out of range | ||
578 | if (desktop < 1 || desktop > VirtualDesktopManager::self()->count()) { | 585 | if (desktop < 1 || desktop > VirtualDesktopManager::self()->count()) { | ||
579 | return; | 586 | return; | ||
580 | } | 587 | } | ||
581 | 588 | | |||
582 | VirtualDesktop *virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desktop); | 589 | VirtualDesktop *virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desktop); | ||
583 | 590 | Q_ASSERT(virtualDesktop); | |||
584 | m_desktops.removeAll(virtualDesktop); | 591 | auto desktops = m_desktops; | ||
585 | 592 | desktops.removeOne(virtualDesktop); | |||
586 | if (!windowManagementInterface()) { | 593 | setDesktops(desktops); | ||
587 | return; | | |||
588 | } | | |||
589 | | ||||
590 | windowManagementInterface()->removePlasmaVirtualDesktop(virtualDesktop->id()); | | |||
591 | emit x11DesktopIdsChanged(); | | |||
592 | } | 594 | } | ||
593 | 595 | | |||
594 | void AbstractClient::setOnAllDesktops(bool b) | 596 | void AbstractClient::setOnAllDesktops(bool b) | ||
595 | { | 597 | { | ||
596 | if ((b && isOnAllDesktops()) || | 598 | if ((b && isOnAllDesktops()) || | ||
597 | (!b && !isOnAllDesktops())) | 599 | (!b && !isOnAllDesktops())) | ||
598 | return; | 600 | return; | ||
599 | if (b) | 601 | if (b) | ||
▲ Show 20 Lines • Show All 1412 Lines • Show Last 20 Lines |
you can simplify this to: {desktops.first()}