diff --git a/libs/kworkspace/kwindowlistmenu.cpp b/libs/kworkspace/kwindowlistmenu.cpp index c327855a..7c395608 100644 --- a/libs/kworkspace/kwindowlistmenu.cpp +++ b/libs/kworkspace/kwindowlistmenu.cpp @@ -39,37 +39,42 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "moc_kwindowlistmenu.cpp" #include "kwin_interface.h" -static bool compareKWinWindowInfo( KWindowInfo* firstInfo, KWindowInfo* secondInfo ) +static bool compareKWinWindowInfo(KWindowInfo *firstInfo, KWindowInfo *secondInfo) { - QString firstTitle, secondTitle; + QString firstTitle, secondTitle; - if ( firstInfo ) - firstTitle = firstInfo->visibleNameWithState().toLower(); + if (firstInfo) { + firstTitle = firstInfo->visibleNameWithState().toLower(); + } - if ( secondInfo ) - secondTitle = secondInfo->visibleNameWithState().toLower(); + if (secondInfo) { + secondTitle = secondInfo->visibleNameWithState().toLower(); + } - return firstTitle.compare( secondTitle ) >= 0; + return (firstTitle.compare(secondTitle) >= 0); } -KWindowListMenu::KWindowListMenu( QWidget *parent ) - : KMenu( parent ) +KWindowListMenu::KWindowListMenu(QWidget *parent) + : KMenu(parent) { } -static bool standaloneDialog( const KWindowInfo* info, const QList& list ) +static bool standaloneDialog(const KWindowInfo *info, const QList &list) { #ifdef Q_WS_X11 - WId group = info->groupLeader(); + WId group = info->groupLeader(); - if ( group == 0 ) - return info->transientFor() == QX11Info::appRootWindow(); + if (group == 0) { + return info->transientFor() == QX11Info::appRootWindow(); + } - foreach ( KWindowInfo* info, list ) - if ( info->groupLeader() == group ) - return false; + foreach (KWindowInfo *info, list) { + if (info->groupLeader() == group) { + return false; + } + } #endif - return true; + return true; } void KWindowListMenu::init() @@ -89,87 +94,100 @@ void KWindowListMenu::init() QAction* cascade = addAction( i18nc("Action that reorganizes the windows so that they are in cascade", "Cascade Windows"), this, SLOT(slotCascadeWindows()) ); - // if we only have one desktop we won't be showing titles, so put a separator in - if ( numberOfDesktops == 1 ) - addSeparator(); - - QList windows; - foreach ( WId id, KWindowSystem::windows() ) - windows.append( KWindowSystem::windowInfo( id, NET::WMDesktop ) ); - - bool showAllDesktopsGroup = ( numberOfDesktops > 1 ); - - int i = 0; - for ( int j = 1; j <= numberOfDesktops + (showAllDesktopsGroup ? 1 : 0); j++ ) { - bool onAllDesktops = ( j > numberOfDesktops ); - int items = 0; - - // KDE4 porting - huh? didn't know you could set an item checked before it's created? - //if (!activeWindow && d == cd) - //setItemChecked(1000 + d, true); - - QList list; - - foreach (const KWindowInfo &wi, windows) { - if ( (wi.desktop() == j) || (onAllDesktops && wi.onAllDesktops()) - || (!showAllDesktopsGroup && wi.onAllDesktops()) ) { - list.append( new KWindowInfo( wi.win(), - NET::WMVisibleName | NET::WMState | NET::XAWMState | NET::WMWindowType, - NET::WM2GroupLeader | NET::WM2TransientFor ) ); - } + // if there is only one desktop showing titles would not be possible, so put a separator in + if (numberOfDesktops == 1) { + addSeparator(); } - qStableSort( list.begin(), list.end(), compareKWinWindowInfo ); + QList windows; + foreach (WId id, KWindowSystem::windows() ) { + windows.append(KWindowSystem::windowInfo(id, NET::WMDesktop)); + } - foreach ( KWindowInfo* info, list ) { - ++i; - QString itemText = fontMetrics().elidedText(info->visibleNameWithState(), Qt::ElideMiddle, maxwidth); + bool showAllDesktopsGroup = (numberOfDesktops > 1); - NET::WindowType windowType = info->windowType( NET::NormalMask | NET::DesktopMask - | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask - | NET::UtilityMask | NET::SplashMask ); + int i = 0; + for (int j = 1; j <= numberOfDesktops + (showAllDesktopsGroup ? 1 : 0); j++ ) { + bool onAllDesktops = (j > numberOfDesktops); + int items = 0; - if ( (windowType == NET::Normal || windowType == NET::Unknown - || (windowType == NET::Dialog && standaloneDialog( info, list ))) - && !(info->state() & NET::SkipTaskbar) ) { + // KDE4 porting - huh? didn't know you could set an item checked before it's created? + // if (!activeWindow && d == cd) + // setItemChecked(1000 + d, true); - QPixmap pm = KWindowSystem::icon( info->win(), 16, 16, true ); - items++; + QList list; - // ok, we have items on this desktop, let's show the title - if ( items == 1 && numberOfDesktops > 1 ) { - if( !onAllDesktops ) - addTitle( KWindowSystem::desktopName( j ) ); - else - addTitle( i18n( "On All Desktops" ) ); + foreach (const KWindowInfo &wi, windows) { + if ( (wi.desktop() == j) || (onAllDesktops && wi.onAllDesktops()) + || (!showAllDesktopsGroup && wi.onAllDesktops())) + { + list.append( + new KWindowInfo( + wi.win(), + NET::WMVisibleName | NET::WMState | NET::XAWMState | NET::WMWindowType, + NET::WM2GroupLeader | NET::WM2TransientFor + ) + ); + } } - // Avoid creating unwanted accelerators. - itemText.replace( '&', QLatin1String( "&&" )); + qStableSort(list.begin(), list.end(), compareKWinWindowInfo); - QAction* action = addAction( pm, itemText, this, SLOT( slotForceActiveWindow() ) ); - action->setData( qulonglong(quintptr(info->win())) ); + foreach (KWindowInfo *info, list) { + ++i; + QString itemText = fontMetrics().elidedText(info->visibleNameWithState(), Qt::ElideMiddle, maxwidth); - if ( info->win() == activeWindow ) - action->setChecked( true ); - } + NET::WindowType windowType = info->windowType( + NET::NormalMask | NET::DesktopMask + | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask + | NET::UtilityMask | NET::SplashMask + ); + + if ((windowType == NET::Normal || windowType == NET::Unknown + || (windowType == NET::Dialog && standaloneDialog(info, list))) + && !(info->state() & NET::SkipTaskbar)) + { + QPixmap pm = KWindowSystem::icon(info->win(), 16, 16, true); + items++; + + // ok, we have items on this desktop, let's show the title + if (items == 1 && numberOfDesktops > 1) { + if (!onAllDesktops) { + addTitle(KWindowSystem::desktopName(j)); + } else { + addTitle(i18n("On All Desktops")); + } + } + + // Avoid creating unwanted accelerators. + itemText.replace('&', QLatin1String("&&")); + + QAction* action = addAction(pm, itemText, this, SLOT(slotForceActiveWindow())); + action->setData(qulonglong(quintptr(info->win())) ); + + if (info->win() == activeWindow) { + action->setChecked(true); + } + } + } + + if (j == currentDesktop) { + unclutter->setEnabled(items > 0); + cascade->setEnabled(items > 0); + } + + qDeleteAll(list); } - if ( j == currentDesktop ) { - unclutter->setEnabled( items > 0 ); - cascade->setEnabled( items > 0 ); + // no windows? + if (i == 0) { + if (numberOfDesktops > 1) { + // because we don't have any titles, nor a separator + addSeparator(); + } + + addAction(i18n("No Windows"))->setEnabled(false); } - - qDeleteAll( list ); - } - - // no windows? - if ( i == 0 ) { - if ( numberOfDesktops > 1 ) - addSeparator(); // because we don't have any titles, nor a separator - - addAction( i18n( "No Windows" ) )->setEnabled( false ); - } } bool KWindowListMenu::canChangePlacement() @@ -184,28 +202,29 @@ bool KWindowListMenu::canChangePlacement() // called after popup(). void KWindowListMenu::selectActiveWindow() { - foreach (QAction* action, actions()) + foreach (QAction* action, actions()) { if (action->isChecked()) { setActiveAction(action); break; } + } } void KWindowListMenu::slotForceActiveWindow() { QAction* window = qobject_cast(sender()); - if (!window || !window->data().canConvert(QVariant::ULongLong)) + if (!window || !window->data().canConvert(QVariant::ULongLong)) { return; - + } KWindowSystem::forceActiveWindow((WId)window->data().toULongLong()); } void KWindowListMenu::slotSetCurrentDesktop() { QAction* window = qobject_cast(sender()); - if (!window || !window->data().canConvert(QVariant::UInt)) + if (!window || !window->data().canConvert(QVariant::UInt)) { return; - + } KWindowSystem::setCurrentDesktop(window->data().toUInt()); } @@ -220,4 +239,3 @@ void KWindowListMenu::slotCascadeWindows() org::kde::KWin kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus()); kwin.cascadeDesktop(); } - diff --git a/libs/kworkspace/kwindowlistmenu.h b/libs/kworkspace/kwindowlistmenu.h index b221fa03..0fc7b6d8 100644 --- a/libs/kworkspace/kwindowlistmenu.h +++ b/libs/kworkspace/kwindowlistmenu.h @@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define KWINDOWLISTMENU_H #include "kworkspace_export.h" + #include /** @@ -38,13 +39,13 @@ class KWORKSPACE_EXPORT KWindowListMenu : public KMenu { Q_OBJECT - public: +public: /** * Creates a new window list menu. * * @param parent The parent widget. */ - explicit KWindowListMenu( QWidget *parent = 0 ); + explicit KWindowListMenu(QWidget *parent = nullptr); /** * Initializes the menu by filling it with actions @@ -59,7 +60,7 @@ class KWORKSPACE_EXPORT KWindowListMenu : public KMenu */ static bool canChangePlacement(); - public Q_SLOTS: +public Q_SLOTS: /** * Pre-selects the active window in the popup menu, for faster * keyboard navigation. Needs to be called after popup(). @@ -67,11 +68,11 @@ class KWORKSPACE_EXPORT KWindowListMenu : public KMenu */ void selectActiveWindow(); - protected Q_SLOTS: +protected Q_SLOTS: void slotForceActiveWindow(); void slotSetCurrentDesktop(); void slotUnclutterWindows(); void slotCascadeWindows(); }; -#endif +#endif // KWINDOWLISTMENU_H