libs: format and indent

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-31 18:34:04 +03:00
parent 9e65f09172
commit 130edd507d
2 changed files with 114 additions and 95 deletions

View file

@ -39,37 +39,42 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "moc_kwindowlistmenu.cpp" #include "moc_kwindowlistmenu.cpp"
#include "kwin_interface.h" #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 ) if (firstInfo) {
firstTitle = firstInfo->visibleNameWithState().toLower(); firstTitle = firstInfo->visibleNameWithState().toLower();
}
if ( secondInfo ) if (secondInfo) {
secondTitle = secondInfo->visibleNameWithState().toLower(); secondTitle = secondInfo->visibleNameWithState().toLower();
}
return firstTitle.compare( secondTitle ) >= 0; return (firstTitle.compare(secondTitle) >= 0);
} }
KWindowListMenu::KWindowListMenu( QWidget *parent ) KWindowListMenu::KWindowListMenu(QWidget *parent)
: KMenu( parent ) : KMenu(parent)
{ {
} }
static bool standaloneDialog( const KWindowInfo* info, const QList<KWindowInfo*>& list ) static bool standaloneDialog(const KWindowInfo *info, const QList<KWindowInfo*> &list)
{ {
#ifdef Q_WS_X11 #ifdef Q_WS_X11
WId group = info->groupLeader(); WId group = info->groupLeader();
if ( group == 0 ) if (group == 0) {
return info->transientFor() == QX11Info::appRootWindow(); return info->transientFor() == QX11Info::appRootWindow();
}
foreach ( KWindowInfo* info, list ) foreach (KWindowInfo *info, list) {
if ( info->groupLeader() == group ) if (info->groupLeader() == group) {
return false; return false;
}
}
#endif #endif
return true; return true;
} }
void KWindowListMenu::init() 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"), QAction* cascade = addAction( i18nc("Action that reorganizes the windows so that they are in cascade", "Cascade Windows"),
this, SLOT(slotCascadeWindows()) ); this, SLOT(slotCascadeWindows()) );
// if we only have one desktop we won't be showing titles, so put a separator in // if there is only one desktop showing titles would not be possible, so put a separator in
if ( numberOfDesktops == 1 ) if (numberOfDesktops == 1) {
addSeparator(); addSeparator();
QList<KWindowInfo> 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<KWindowInfo*> 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 ) );
}
} }
qStableSort( list.begin(), list.end(), compareKWinWindowInfo ); QList<KWindowInfo> windows;
foreach (WId id, KWindowSystem::windows() ) {
windows.append(KWindowSystem::windowInfo(id, NET::WMDesktop));
}
foreach ( KWindowInfo* info, list ) { bool showAllDesktopsGroup = (numberOfDesktops > 1);
++i;
QString itemText = fontMetrics().elidedText(info->visibleNameWithState(), Qt::ElideMiddle, maxwidth);
NET::WindowType windowType = info->windowType( NET::NormalMask | NET::DesktopMask int i = 0;
| NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask for (int j = 1; j <= numberOfDesktops + (showAllDesktopsGroup ? 1 : 0); j++ ) {
| NET::UtilityMask | NET::SplashMask ); bool onAllDesktops = (j > numberOfDesktops);
int items = 0;
if ( (windowType == NET::Normal || windowType == NET::Unknown // KDE4 porting - huh? didn't know you could set an item checked before it's created?
|| (windowType == NET::Dialog && standaloneDialog( info, list ))) // if (!activeWindow && d == cd)
&& !(info->state() & NET::SkipTaskbar) ) { // setItemChecked(1000 + d, true);
QPixmap pm = KWindowSystem::icon( info->win(), 16, 16, true ); QList<KWindowInfo*> list;
items++;
// ok, we have items on this desktop, let's show the title foreach (const KWindowInfo &wi, windows) {
if ( items == 1 && numberOfDesktops > 1 ) { if ( (wi.desktop() == j) || (onAllDesktops && wi.onAllDesktops())
if( !onAllDesktops ) || (!showAllDesktopsGroup && wi.onAllDesktops()))
addTitle( KWindowSystem::desktopName( j ) ); {
else list.append(
addTitle( i18n( "On All Desktops" ) ); new KWindowInfo(
wi.win(),
NET::WMVisibleName | NET::WMState | NET::XAWMState | NET::WMWindowType,
NET::WM2GroupLeader | NET::WM2TransientFor
)
);
}
} }
// Avoid creating unwanted accelerators. qStableSort(list.begin(), list.end(), compareKWinWindowInfo);
itemText.replace( '&', QLatin1String( "&&" ));
QAction* action = addAction( pm, itemText, this, SLOT( slotForceActiveWindow() ) ); foreach (KWindowInfo *info, list) {
action->setData( qulonglong(quintptr(info->win())) ); ++i;
QString itemText = fontMetrics().elidedText(info->visibleNameWithState(), Qt::ElideMiddle, maxwidth);
if ( info->win() == activeWindow ) NET::WindowType windowType = info->windowType(
action->setChecked( true ); 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 ) { // no windows?
unclutter->setEnabled( items > 0 ); if (i == 0) {
cascade->setEnabled( items > 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() bool KWindowListMenu::canChangePlacement()
@ -184,28 +202,29 @@ bool KWindowListMenu::canChangePlacement()
// called after popup(). // called after popup().
void KWindowListMenu::selectActiveWindow() void KWindowListMenu::selectActiveWindow()
{ {
foreach (QAction* action, actions()) foreach (QAction* action, actions()) {
if (action->isChecked()) { if (action->isChecked()) {
setActiveAction(action); setActiveAction(action);
break; break;
} }
}
} }
void KWindowListMenu::slotForceActiveWindow() void KWindowListMenu::slotForceActiveWindow()
{ {
QAction* window = qobject_cast<QAction*>(sender()); QAction* window = qobject_cast<QAction*>(sender());
if (!window || !window->data().canConvert(QVariant::ULongLong)) if (!window || !window->data().canConvert(QVariant::ULongLong)) {
return; return;
}
KWindowSystem::forceActiveWindow((WId)window->data().toULongLong()); KWindowSystem::forceActiveWindow((WId)window->data().toULongLong());
} }
void KWindowListMenu::slotSetCurrentDesktop() void KWindowListMenu::slotSetCurrentDesktop()
{ {
QAction* window = qobject_cast<QAction*>(sender()); QAction* window = qobject_cast<QAction*>(sender());
if (!window || !window->data().canConvert(QVariant::UInt)) if (!window || !window->data().canConvert(QVariant::UInt)) {
return; return;
}
KWindowSystem::setCurrentDesktop(window->data().toUInt()); KWindowSystem::setCurrentDesktop(window->data().toUInt());
} }
@ -220,4 +239,3 @@ void KWindowListMenu::slotCascadeWindows()
org::kde::KWin kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus()); org::kde::KWin kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
kwin.cascadeDesktop(); kwin.cascadeDesktop();
} }

View file

@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define KWINDOWLISTMENU_H #define KWINDOWLISTMENU_H
#include "kworkspace_export.h" #include "kworkspace_export.h"
#include <kmenu.h> #include <kmenu.h>
/** /**
@ -38,13 +39,13 @@ class KWORKSPACE_EXPORT KWindowListMenu : public KMenu
{ {
Q_OBJECT Q_OBJECT
public: public:
/** /**
* Creates a new window list menu. * Creates a new window list menu.
* *
* @param parent The parent widget. * @param parent The parent widget.
*/ */
explicit KWindowListMenu( QWidget *parent = 0 ); explicit KWindowListMenu(QWidget *parent = nullptr);
/** /**
* Initializes the menu by filling it with actions * Initializes the menu by filling it with actions
@ -59,7 +60,7 @@ class KWORKSPACE_EXPORT KWindowListMenu : public KMenu
*/ */
static bool canChangePlacement(); static bool canChangePlacement();
public Q_SLOTS: public Q_SLOTS:
/** /**
* Pre-selects the active window in the popup menu, for faster * Pre-selects the active window in the popup menu, for faster
* keyboard navigation. Needs to be called after popup(). * keyboard navigation. Needs to be called after popup().
@ -67,11 +68,11 @@ class KWORKSPACE_EXPORT KWindowListMenu : public KMenu
*/ */
void selectActiveWindow(); void selectActiveWindow();
protected Q_SLOTS: protected Q_SLOTS:
void slotForceActiveWindow(); void slotForceActiveWindow();
void slotSetCurrentDesktop(); void slotSetCurrentDesktop();
void slotUnclutterWindows(); void slotUnclutterWindows();
void slotCascadeWindows(); void slotCascadeWindows();
}; };
#endif #endif // KWINDOWLISTMENU_H