Changeset View
Changeset View
Standalone View
Standalone View
tabbox/tabbox.cpp
Show First 20 Lines • Show All 592 Lines • ▼ Show 20 Line(s) | 592 | } else if (qstrcmp(qPrintable(action->objectName()), s_desktopsRev) == 0) { | |||
---|---|---|---|---|---|
593 | m_cutWalkThroughDesktopsReverse = seq; | 593 | m_cutWalkThroughDesktopsReverse = seq; | ||
594 | } else if (qstrcmp(qPrintable(action->objectName()), s_desktopList) == 0) { | 594 | } else if (qstrcmp(qPrintable(action->objectName()), s_desktopList) == 0) { | ||
595 | m_cutWalkThroughDesktopList = seq; | 595 | m_cutWalkThroughDesktopList = seq; | ||
596 | } else if (qstrcmp(qPrintable(action->objectName()), s_desktopListRev) == 0) { | 596 | } else if (qstrcmp(qPrintable(action->objectName()), s_desktopListRev) == 0) { | ||
597 | m_cutWalkThroughDesktopListReverse = seq; | 597 | m_cutWalkThroughDesktopListReverse = seq; | ||
598 | } | 598 | } | ||
599 | } | 599 | } | ||
600 | 600 | | |||
601 | /*! | | |||
602 | Sets the current mode to \a mode, either TabBoxDesktopListMode or TabBoxWindowsMode | | |||
603 | | ||||
604 | \sa mode() | | |||
605 | */ | | |||
606 | void TabBox::setMode(TabBoxMode mode) | 601 | void TabBox::setMode(TabBoxMode mode) | ||
607 | { | 602 | { | ||
608 | m_tabBoxMode = mode; | 603 | m_tabBoxMode = mode; | ||
609 | switch(mode) { | 604 | switch(mode) { | ||
610 | case TabBoxWindowsMode: | 605 | case TabBoxWindowsMode: | ||
611 | m_tabBox->setConfig(m_defaultConfig); | 606 | m_tabBox->setConfig(m_defaultConfig); | ||
612 | break; | 607 | break; | ||
613 | case TabBoxWindowsAlternativeMode: | 608 | case TabBoxWindowsAlternativeMode: | ||
Show All 9 Lines | 617 | case TabBoxDesktopMode: | |||
623 | m_tabBox->setConfig(m_desktopConfig); | 618 | m_tabBox->setConfig(m_desktopConfig); | ||
624 | break; | 619 | break; | ||
625 | case TabBoxDesktopListMode: | 620 | case TabBoxDesktopListMode: | ||
626 | m_tabBox->setConfig(m_desktopListConfig); | 621 | m_tabBox->setConfig(m_desktopListConfig); | ||
627 | break; | 622 | break; | ||
628 | } | 623 | } | ||
629 | } | 624 | } | ||
630 | 625 | | |||
631 | /*! | | |||
632 | Resets the tab box to display the active client in TabBoxWindowsMode, or the | | |||
633 | current desktop in TabBoxDesktopListMode | | |||
634 | */ | | |||
635 | void TabBox::reset(bool partial_reset) | 626 | void TabBox::reset(bool partial_reset) | ||
636 | { | 627 | { | ||
637 | switch(m_tabBox->config().tabBoxMode()) { | 628 | switch(m_tabBox->config().tabBoxMode()) { | ||
638 | case TabBoxConfig::ClientTabBox: | 629 | case TabBoxConfig::ClientTabBox: | ||
639 | m_tabBox->createModel(partial_reset); | 630 | m_tabBox->createModel(partial_reset); | ||
640 | if (!partial_reset) { | 631 | if (!partial_reset) { | ||
641 | if (Workspace::self()->activeClient()) | 632 | if (Workspace::self()->activeClient()) | ||
642 | setCurrentClient(Workspace::self()->activeClient()); | 633 | setCurrentClient(Workspace::self()->activeClient()); | ||
Show All 12 Lines | 643 | case TabBoxConfig::DesktopTabBox: | |||
655 | if (!partial_reset) | 646 | if (!partial_reset) | ||
656 | setCurrentDesktop(VirtualDesktopManager::self()->current()); | 647 | setCurrentDesktop(VirtualDesktopManager::self()->current()); | ||
657 | break; | 648 | break; | ||
658 | } | 649 | } | ||
659 | 650 | | |||
660 | emit tabBoxUpdated(); | 651 | emit tabBoxUpdated(); | ||
661 | } | 652 | } | ||
662 | 653 | | |||
663 | /*! | | |||
664 | Shows the next or previous item, depending on \a next | | |||
665 | */ | | |||
666 | void TabBox::nextPrev(bool next) | 654 | void TabBox::nextPrev(bool next) | ||
667 | { | 655 | { | ||
668 | setCurrentIndex(m_tabBox->nextPrev(next), false); | 656 | setCurrentIndex(m_tabBox->nextPrev(next), false); | ||
669 | emit tabBoxUpdated(); | 657 | emit tabBoxUpdated(); | ||
670 | } | 658 | } | ||
671 | 659 | | |||
672 | /*! | | |||
673 | Returns the currently displayed client ( only works in TabBoxWindowsMode ). | | |||
674 | Returns 0 if no client is displayed. | | |||
675 | */ | | |||
676 | AbstractClient* TabBox::currentClient() | 660 | AbstractClient* TabBox::currentClient() | ||
677 | { | 661 | { | ||
678 | if (TabBoxClientImpl* client = static_cast< TabBoxClientImpl* >(m_tabBox->client(m_tabBox->currentIndex()))) { | 662 | if (TabBoxClientImpl* client = static_cast< TabBoxClientImpl* >(m_tabBox->client(m_tabBox->currentIndex()))) { | ||
679 | if (!Workspace::self()->hasClient(client->client())) | 663 | if (!Workspace::self()->hasClient(client->client())) | ||
680 | return nullptr; | 664 | return nullptr; | ||
681 | return client->client(); | 665 | return client->client(); | ||
682 | } else | 666 | } else | ||
683 | return nullptr; | 667 | return nullptr; | ||
684 | } | 668 | } | ||
685 | 669 | | |||
686 | /*! | | |||
687 | Returns the list of clients potentially displayed ( only works in | | |||
688 | TabBoxWindowsMode ). | | |||
689 | Returns an empty list if no clients are available. | | |||
690 | */ | | |||
691 | QList<AbstractClient*> TabBox::currentClientList() | 670 | QList<AbstractClient*> TabBox::currentClientList() | ||
692 | { | 671 | { | ||
693 | TabBoxClientList list = m_tabBox->clientList(); | 672 | TabBoxClientList list = m_tabBox->clientList(); | ||
694 | QList<AbstractClient*> ret; | 673 | QList<AbstractClient*> ret; | ||
695 | foreach (const QWeakPointer<TabBoxClient> &clientPointer, list) { | 674 | foreach (const QWeakPointer<TabBoxClient> &clientPointer, list) { | ||
696 | QSharedPointer<TabBoxClient> client = clientPointer.toStrongRef(); | 675 | QSharedPointer<TabBoxClient> client = clientPointer.toStrongRef(); | ||
697 | if (!client) | 676 | if (!client) | ||
698 | continue; | 677 | continue; | ||
699 | if (const TabBoxClientImpl* c = static_cast< const TabBoxClientImpl* >(client.data())) | 678 | if (const TabBoxClientImpl* c = static_cast< const TabBoxClientImpl* >(client.data())) | ||
700 | ret.append(c->client()); | 679 | ret.append(c->client()); | ||
701 | } | 680 | } | ||
702 | return ret; | 681 | return ret; | ||
703 | } | 682 | } | ||
704 | 683 | | |||
705 | /*! | | |||
706 | Returns the currently displayed virtual desktop ( only works in | | |||
707 | TabBoxDesktopListMode ) | | |||
708 | Returns -1 if no desktop is displayed. | | |||
709 | */ | | |||
710 | int TabBox::currentDesktop() | 684 | int TabBox::currentDesktop() | ||
711 | { | 685 | { | ||
712 | return m_tabBox->desktop(m_tabBox->currentIndex()); | 686 | return m_tabBox->desktop(m_tabBox->currentIndex()); | ||
713 | } | 687 | } | ||
714 | 688 | | |||
715 | /*! | | |||
716 | Returns the list of desktops potentially displayed ( only works in | | |||
717 | TabBoxDesktopListMode ) | | |||
718 | Returns an empty list if no are available. | | |||
719 | */ | | |||
720 | QList< int > TabBox::currentDesktopList() | 689 | QList< int > TabBox::currentDesktopList() | ||
721 | { | 690 | { | ||
722 | return m_tabBox->desktopList(); | 691 | return m_tabBox->desktopList(); | ||
723 | } | 692 | } | ||
724 | 693 | | |||
725 | /*! | | |||
726 | Change the currently selected client, and notify the effects. | | |||
727 | | ||||
728 | \sa setCurrentDesktop() | | |||
729 | */ | | |||
730 | void TabBox::setCurrentClient(AbstractClient *newClient) | 694 | void TabBox::setCurrentClient(AbstractClient *newClient) | ||
731 | { | 695 | { | ||
732 | setCurrentIndex(m_tabBox->index(newClient->tabBoxClient())); | 696 | setCurrentIndex(m_tabBox->index(newClient->tabBoxClient())); | ||
733 | } | 697 | } | ||
734 | 698 | | |||
735 | /*! | | |||
736 | Change the currently selected desktop, and notify the effects. | | |||
737 | | ||||
738 | \sa setCurrentClient() | | |||
739 | */ | | |||
740 | void TabBox::setCurrentDesktop(int newDesktop) | 699 | void TabBox::setCurrentDesktop(int newDesktop) | ||
741 | { | 700 | { | ||
742 | setCurrentIndex(m_tabBox->desktopIndex(newDesktop)); | 701 | setCurrentIndex(m_tabBox->desktopIndex(newDesktop)); | ||
743 | } | 702 | } | ||
744 | 703 | | |||
745 | void TabBox::setCurrentIndex(QModelIndex index, bool notifyEffects) | 704 | void TabBox::setCurrentIndex(QModelIndex index, bool notifyEffects) | ||
746 | { | 705 | { | ||
747 | if (!index.isValid()) | 706 | if (!index.isValid()) | ||
748 | return; | 707 | return; | ||
749 | m_tabBox->setCurrentIndex(index); | 708 | m_tabBox->setCurrentIndex(index); | ||
750 | if (notifyEffects) { | 709 | if (notifyEffects) { | ||
751 | emit tabBoxUpdated(); | 710 | emit tabBoxUpdated(); | ||
752 | } | 711 | } | ||
753 | } | 712 | } | ||
754 | 713 | | |||
755 | /*! | | |||
756 | Notify effects that the tab box is being shown, and only display the | | |||
757 | default tab box QFrame if no effect has referenced the tab box. | | |||
758 | */ | | |||
759 | void TabBox::show() | 714 | void TabBox::show() | ||
760 | { | 715 | { | ||
761 | emit tabBoxAdded(m_tabBoxMode); | 716 | emit tabBoxAdded(m_tabBoxMode); | ||
762 | if (isDisplayed()) { | 717 | if (isDisplayed()) { | ||
763 | m_isShown = false; | 718 | m_isShown = false; | ||
764 | return; | 719 | return; | ||
765 | } | 720 | } | ||
766 | workspace()->setShowingDesktop(false); | 721 | workspace()->setShowingDesktop(false); | ||
767 | reference(); | 722 | reference(); | ||
768 | m_isShown = true; | 723 | m_isShown = true; | ||
769 | m_tabBox->show(); | 724 | m_tabBox->show(); | ||
770 | } | 725 | } | ||
771 | 726 | | |||
772 | /*! | | |||
773 | Notify effects that the tab box is being hidden. | | |||
774 | */ | | |||
775 | void TabBox::hide(bool abort) | 727 | void TabBox::hide(bool abort) | ||
776 | { | 728 | { | ||
777 | m_delayedShowTimer.stop(); | 729 | m_delayedShowTimer.stop(); | ||
778 | if (m_isShown) { | 730 | if (m_isShown) { | ||
779 | m_isShown = false; | 731 | m_isShown = false; | ||
780 | unreference(); | 732 | unreference(); | ||
781 | } | 733 | } | ||
782 | emit tabBoxClosed(); | 734 | emit tabBoxClosed(); | ||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 810 | { | |||
874 | tabBoxConfig.setShowTabBox(config.readEntry<bool>("ShowTabBox", | 826 | tabBoxConfig.setShowTabBox(config.readEntry<bool>("ShowTabBox", | ||
875 | TabBoxConfig::defaultShowTabBox())); | 827 | TabBoxConfig::defaultShowTabBox())); | ||
876 | tabBoxConfig.setHighlightWindows(config.readEntry<bool>("HighlightWindows", | 828 | tabBoxConfig.setHighlightWindows(config.readEntry<bool>("HighlightWindows", | ||
877 | TabBoxConfig::defaultHighlightWindow())); | 829 | TabBoxConfig::defaultHighlightWindow())); | ||
878 | 830 | | |||
879 | tabBoxConfig.setLayoutName(config.readEntry<QString>("LayoutName", TabBoxConfig::defaultLayoutName())); | 831 | tabBoxConfig.setLayoutName(config.readEntry<QString>("LayoutName", TabBoxConfig::defaultLayoutName())); | ||
880 | } | 832 | } | ||
881 | 833 | | |||
882 | /*! | | |||
883 | Rikkus: please document! (Matthias) | | |||
884 | | ||||
885 | Ok, here's the docs :) | | |||
886 | | ||||
887 | You call delayedShow() instead of show() directly. | | |||
888 | | ||||
889 | If the 'ShowDelay' setting is false, show() is simply called. | | |||
890 | | ||||
891 | Otherwise, we start a timer for the delay given in the settings and only | | |||
892 | do a show() when it times out. | | |||
893 | | ||||
894 | This means that you can alt-tab between windows and you don't see the | | |||
895 | tab box immediately. Not only does this make alt-tabbing faster, it gives | | |||
896 | less 'flicker' to the eyes. You don't need to see the tab box if you're | | |||
897 | just quickly switching between 2 or 3 windows. It seems to work quite | | |||
898 | nicely. | | |||
899 | */ | | |||
900 | void TabBox::delayedShow() | 834 | void TabBox::delayedShow() | ||
901 | { | 835 | { | ||
902 | if (isDisplayed() || m_delayedShowTimer.isActive()) | 836 | if (isDisplayed() || m_delayedShowTimer.isActive()) | ||
903 | // already called show - no need to call it twice | 837 | // already called show - no need to call it twice | ||
904 | return; | 838 | return; | ||
905 | 839 | | |||
906 | if (!m_delayShowTime) { | 840 | if (!m_delayShowTime) { | ||
907 | show(); | 841 | show(); | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | |||||
979 | struct KeySymbolsDeleter | 913 | struct KeySymbolsDeleter | ||
980 | { | 914 | { | ||
981 | static inline void cleanup(xcb_key_symbols_t *symbols) | 915 | static inline void cleanup(xcb_key_symbols_t *symbols) | ||
982 | { | 916 | { | ||
983 | xcb_key_symbols_free(symbols); | 917 | xcb_key_symbols_free(symbols); | ||
984 | } | 918 | } | ||
985 | }; | 919 | }; | ||
986 | 920 | | |||
987 | /*! | 921 | /** | ||
988 | Handles alt-tab / control-tab | 922 | * Handles alt-tab / control-tab | ||
989 | */ | 923 | **/ | ||
990 | static bool areKeySymXsDepressed(bool bAll, const uint keySyms[], int nKeySyms) { | 924 | static bool areKeySymXsDepressed(bool bAll, const uint keySyms[], int nKeySyms) { | ||
991 | 925 | | |||
992 | qCDebug(KWIN_TABBOX) << "areKeySymXsDepressed: " << (bAll ? "all of " : "any of ") << nKeySyms; | 926 | qCDebug(KWIN_TABBOX) << "areKeySymXsDepressed: " << (bAll ? "all of " : "any of ") << nKeySyms; | ||
993 | 927 | | |||
994 | Xcb::QueryKeymap keys; | 928 | Xcb::QueryKeymap keys; | ||
995 | 929 | | |||
996 | QScopedPointer<xcb_key_symbols_t, KeySymbolsDeleter> symbols(xcb_key_symbols_alloc(connection())); | 930 | QScopedPointer<xcb_key_symbols_t, KeySymbolsDeleter> symbols(xcb_key_symbols_alloc(connection())); | ||
997 | if (symbols.isNull() || !keys) { | 931 | if (symbols.isNull() || !keys) { | ||
▲ Show 20 Lines • Show All 366 Lines • ▼ Show 20 Line(s) | 1297 | { | |||
1364 | oneStepThroughDesktops(forward, TabBoxDesktopMode); | 1298 | oneStepThroughDesktops(forward, TabBoxDesktopMode); | ||
1365 | } | 1299 | } | ||
1366 | 1300 | | |||
1367 | void TabBox::oneStepThroughDesktopList(bool forward) | 1301 | void TabBox::oneStepThroughDesktopList(bool forward) | ||
1368 | { | 1302 | { | ||
1369 | oneStepThroughDesktops(forward, TabBoxDesktopListMode); | 1303 | oneStepThroughDesktops(forward, TabBoxDesktopListMode); | ||
1370 | } | 1304 | } | ||
1371 | 1305 | | |||
1372 | /*! | | |||
1373 | Handles holding alt-tab / control-tab | | |||
1374 | */ | | |||
1375 | void TabBox::keyPress(int keyQt) | 1306 | void TabBox::keyPress(int keyQt) | ||
1376 | { | 1307 | { | ||
1377 | enum Direction { Backward = -1, Steady = 0, Forward = 1 }; | 1308 | enum Direction { Backward = -1, Steady = 0, Forward = 1 }; | ||
1378 | Direction direction(Steady); | 1309 | Direction direction(Steady); | ||
1379 | 1310 | | |||
1380 | auto contains = [](const QKeySequence &shortcut, int key) -> bool { | 1311 | auto contains = [](const QKeySequence &shortcut, int key) -> bool { | ||
1381 | for (int i = 0; i < shortcut.count(); ++i) { | 1312 | for (int i = 0; i < shortcut.count(); ++i) { | ||
1382 | if (shortcut[i] == key) { | 1313 | if (shortcut[i] == key) { | ||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Line(s) | |||||
1537 | } | 1468 | } | ||
1538 | 1469 | | |||
1539 | int TabBox::previousDesktopStatic(int iDesktop) const | 1470 | int TabBox::previousDesktopStatic(int iDesktop) const | ||
1540 | { | 1471 | { | ||
1541 | DesktopPrevious functor; | 1472 | DesktopPrevious functor; | ||
1542 | return functor(iDesktop, true); | 1473 | return functor(iDesktop, true); | ||
1543 | } | 1474 | } | ||
1544 | 1475 | | |||
1545 | /*! | 1476 | /** | ||
1546 | auxiliary functions to travers all clients according to the static | 1477 | * Auxiliary functions to travers all clients according to the static | ||
1547 | order. Useful for the CDE-style Alt-tab feature. | 1478 | * order. Useful for the CDE-style Alt-tab feature. | ||
1548 | */ | 1479 | **/ | ||
1549 | AbstractClient* TabBox::nextClientStatic(AbstractClient* c) const | 1480 | AbstractClient* TabBox::nextClientStatic(AbstractClient* c) const | ||
1550 | { | 1481 | { | ||
1551 | const auto &list = Workspace::self()->allClientList(); | 1482 | const auto &list = Workspace::self()->allClientList(); | ||
1552 | if (!c || list.isEmpty()) | 1483 | if (!c || list.isEmpty()) | ||
1553 | return 0; | 1484 | return 0; | ||
1554 | int pos = list.indexOf(c); | 1485 | int pos = list.indexOf(c); | ||
1555 | if (pos == -1) | 1486 | if (pos == -1) | ||
1556 | return list.first(); | 1487 | return list.first(); | ||
1557 | ++pos; | 1488 | ++pos; | ||
1558 | if (pos == list.count()) | 1489 | if (pos == list.count()) | ||
1559 | return list.first(); | 1490 | return list.first(); | ||
1560 | return list.at(pos); | 1491 | return list.at(pos); | ||
1561 | } | 1492 | } | ||
1562 | 1493 | | |||
1563 | /*! | 1494 | /** | ||
1564 | auxiliary functions to travers all clients according to the static | 1495 | * Auxiliary functions to travers all clients according to the static | ||
1565 | order. Useful for the CDE-style Alt-tab feature. | 1496 | * order. Useful for the CDE-style Alt-tab feature. | ||
1566 | */ | 1497 | **/ | ||
1567 | AbstractClient* TabBox::previousClientStatic(AbstractClient* c) const | 1498 | AbstractClient* TabBox::previousClientStatic(AbstractClient* c) const | ||
1568 | { | 1499 | { | ||
1569 | const auto &list = Workspace::self()->allClientList(); | 1500 | const auto &list = Workspace::self()->allClientList(); | ||
1570 | if (!c || list.isEmpty()) | 1501 | if (!c || list.isEmpty()) | ||
1571 | return 0; | 1502 | return 0; | ||
1572 | int pos = list.indexOf(c); | 1503 | int pos = list.indexOf(c); | ||
1573 | if (pos == -1) | 1504 | if (pos == -1) | ||
1574 | return list.last(); | 1505 | return list.last(); | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |