mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 10:22:49 +00:00
libs: drop unused KWindowListMenu class
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
27b83e2023
commit
b46a7dfc01
3 changed files with 0 additions and 325 deletions
|
@ -1,6 +1,5 @@
|
|||
set(kworkspace_LIB_SRCS
|
||||
kdisplaymanager.cpp
|
||||
kwindowlistmenu.cpp
|
||||
screenpreviewwidget.cpp
|
||||
kworkspace.cpp
|
||||
ktaskmanager.cpp
|
||||
|
@ -45,7 +44,6 @@ install(
|
|||
install(
|
||||
FILES
|
||||
kdisplaymanager.h
|
||||
kwindowlistmenu.h
|
||||
kworkspace.h
|
||||
ktaskmanager.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/kworkspace_export.h
|
||||
|
|
|
@ -1,245 +0,0 @@
|
|||
/*****************************************************************
|
||||
|
||||
Copyright (c) 2000 Matthias Elter <elter@kde.org>
|
||||
Matthias Ettrich <ettrich@kde.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#include "kwindowlistmenu.h"
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QDesktopWidget>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QX11Info>
|
||||
|
||||
#include <QtDBus/QtDBus>
|
||||
#include <klocale.h>
|
||||
#include <kstringhandler.h>
|
||||
#include <kstyle.h>
|
||||
#include <kwindowsystem.h>
|
||||
#include <netwm.h>
|
||||
|
||||
#include "moc_kwindowlistmenu.cpp"
|
||||
#include "kwin_interface.h"
|
||||
|
||||
static bool compareKWinWindowInfo(KWindowInfo *firstInfo, KWindowInfo *secondInfo)
|
||||
{
|
||||
QString firstTitle, secondTitle;
|
||||
|
||||
if (firstInfo) {
|
||||
firstTitle = firstInfo->visibleNameWithState().toLower();
|
||||
}
|
||||
|
||||
if (secondInfo) {
|
||||
secondTitle = secondInfo->visibleNameWithState().toLower();
|
||||
}
|
||||
|
||||
return (firstTitle.compare(secondTitle) >= 0);
|
||||
}
|
||||
|
||||
KWindowListMenu::KWindowListMenu(QWidget *parent)
|
||||
: KMenu(parent)
|
||||
{
|
||||
}
|
||||
|
||||
static bool standaloneDialog(const KWindowInfo *info, const QList<KWindowInfo*> &list)
|
||||
{
|
||||
#ifdef Q_WS_X11
|
||||
const WId group = info->groupLeader();
|
||||
|
||||
if (group == 0) {
|
||||
return info->transientFor() == QX11Info::appRootWindow();
|
||||
}
|
||||
|
||||
foreach (const KWindowInfo *info, list) {
|
||||
if (info->groupLeader() == group) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void KWindowListMenu::init()
|
||||
{
|
||||
int numberOfDesktops = KWindowSystem::numberOfDesktops();
|
||||
int currentDesktop = KWindowSystem::currentDesktop();
|
||||
WId activeWindow = KWindowSystem::activeWindow();
|
||||
|
||||
// Make sure the popup is not too wide, otherwise clicking in the middle of kdesktop
|
||||
// wouldn't leave any place for the popup, and release would activate some menu entry.
|
||||
int maxwidth = qApp->desktop()->screenGeometry(this).width() / 2 - 100;
|
||||
|
||||
clear();
|
||||
|
||||
QAction* unclutter = addAction(
|
||||
i18nc("Action that reorganizes the windows to try to have them less cluttered", "Unclutter Windows"),
|
||||
this, SLOT(slotUnclutterWindows())
|
||||
);
|
||||
QAction* cascade = addAction(
|
||||
i18nc("Action that reorganizes the windows so that they are in cascade", "Cascade Windows"),
|
||||
this, SLOT(slotCascadeWindows())
|
||||
);
|
||||
|
||||
// if there is only one desktop showing titles would not be possible, so put a separator in
|
||||
if (numberOfDesktops == 1) {
|
||||
addSeparator();
|
||||
}
|
||||
|
||||
QList<KWindowInfo> windows;
|
||||
foreach (const 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++) {
|
||||
const 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);
|
||||
|
||||
foreach (const KWindowInfo *info, list) {
|
||||
++i;
|
||||
QString itemText = fontMetrics().elidedText(info->visibleNameWithState(), Qt::ElideMiddle, maxwidth);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
bool KWindowListMenu::canChangePlacement()
|
||||
{
|
||||
org::kde::KWin kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
|
||||
return kwin.isValid();
|
||||
}
|
||||
|
||||
// This popup is much more useful from keyboard if it has the active
|
||||
// window active by default - however, QPopupMenu tries hard to resist.
|
||||
// QPopupMenu::popup() resets the active item, so this needs to be
|
||||
// called after popup().
|
||||
void KWindowListMenu::selectActiveWindow()
|
||||
{
|
||||
foreach (QAction* action, actions()) {
|
||||
if (action->isChecked()) {
|
||||
setActiveAction(action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KWindowListMenu::slotForceActiveWindow()
|
||||
{
|
||||
const QAction* window = qobject_cast<QAction*>(sender());
|
||||
if (!window || !window->data().canConvert(QVariant::ULongLong)) {
|
||||
return;
|
||||
}
|
||||
KWindowSystem::forceActiveWindow((WId)window->data().toULongLong());
|
||||
}
|
||||
|
||||
void KWindowListMenu::slotSetCurrentDesktop()
|
||||
{
|
||||
const QAction* window = qobject_cast<QAction*>(sender());
|
||||
if (!window || !window->data().canConvert(QVariant::UInt)) {
|
||||
return;
|
||||
}
|
||||
KWindowSystem::setCurrentDesktop(window->data().toUInt());
|
||||
}
|
||||
|
||||
void KWindowListMenu::slotUnclutterWindows()
|
||||
{
|
||||
org::kde::KWin kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
|
||||
kwin.unclutterDesktop();
|
||||
}
|
||||
|
||||
void KWindowListMenu::slotCascadeWindows()
|
||||
{
|
||||
org::kde::KWin kwin("org.kde.kwin", "/KWin", QDBusConnection::sessionBus());
|
||||
kwin.cascadeDesktop();
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/*****************************************************************
|
||||
|
||||
Copyright (c) 2000 Matthias Elter <elter@kde.org>
|
||||
Matthias Ettrich <ettrich@kde.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
******************************************************************/
|
||||
|
||||
#ifndef KWINDOWLISTMENU_H
|
||||
#define KWINDOWLISTMENU_H
|
||||
|
||||
#include "kworkspace_export.h"
|
||||
|
||||
#include <kmenu.h>
|
||||
|
||||
/**
|
||||
* This class provides a menu which contains actions
|
||||
* to manage a window. It is used by the window manager
|
||||
* for example an accessable there via the menu button of
|
||||
* the window decoration.
|
||||
*/
|
||||
class KWORKSPACE_EXPORT KWindowListMenu : public KMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a new window list menu.
|
||||
*
|
||||
* @param parent The parent widget.
|
||||
*/
|
||||
explicit KWindowListMenu(QWidget *parent = nullptr);
|
||||
|
||||
/**
|
||||
* Initializes the menu by filling it with actions
|
||||
* for managing a window.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Returns true if window placement can be changed, false otherwise.
|
||||
* If this methods returns false then @p slotUnclutterWindows and
|
||||
* @p slotCascadeWindows do nothing.
|
||||
*/
|
||||
static bool canChangePlacement();
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Pre-selects the active window in the popup menu, for faster
|
||||
* keyboard navigation. Needs to be called after popup().
|
||||
* Should not be used when the popup is invoked using the mouse.
|
||||
*/
|
||||
void selectActiveWindow();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void slotForceActiveWindow();
|
||||
void slotSetCurrentDesktop();
|
||||
void slotUnclutterWindows();
|
||||
void slotCascadeWindows();
|
||||
};
|
||||
|
||||
#endif // KWINDOWLISTMENU_H
|
Loading…
Add table
Reference in a new issue