-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
WindowList.cxx
79 lines (59 loc) · 2.15 KB
/
WindowList.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
This file is part of liquidshell.
SPDX-FileCopyrightText: 2017 - 2024 Martin Koller <[email protected]>
SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <WindowList.hxx>
#include <PopupMenu.hxx>
#include <QIcon>
#include <QStyle>
#include <QStyleOptionButton>
#include <QPainter>
#include <KWinCompat.hxx>
#include <KWindowInfo>
//--------------------------------------------------------------------------------
WindowList::WindowList(QWidget *parent)
: QPushButton(parent)
{
setIcon(QIcon::fromTheme("arrow-up"));
setMaximumWidth(22);
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
setMenu(new PopupMenu(this));
connect(menu(), &PopupMenu::aboutToShow, this, &WindowList::fillMenu);
}
//--------------------------------------------------------------------------------
void WindowList::fillMenu()
{
menu()->clear();
QList<WId> windows = KWinCompat::windows();
for (int i = 1; i <= KWinCompat::numberOfDesktops(); i++)
{
menu()->addSection(KWinCompat::desktopName(i).isEmpty() ?
QString::number(i) : KWinCompat::desktopName(i));
for (WId wid : windows)
{
KWindowInfo win(wid, NET::WMDesktop | NET::WMWindowType | NET::WMState | NET::WMName | NET::WMIcon);
if ( win.valid(true) && win.isOnDesktop(i) &&
(win.windowType(NET::DesktopMask) != NET::Desktop) &&
(win.windowType(NET::DockMask) != NET::Dock) &&
!(win.state() & NET::SkipTaskbar) )
{
QAction *action =
menu()->addAction(KWinCompat::icon(wid, 22, 22, true), win.name(),
[wid]() { KWinCompat::forceActiveWindow(wid); });
action->setData(static_cast<int>(wid));
}
}
}
}
//--------------------------------------------------------------------------------
void WindowList::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
QStyleOptionButton option;
initStyleOption(&option);
option.features = QStyleOptionButton::None; // avoid menu arrow
style()->drawControl(QStyle::CE_PushButton, &option, &painter, this);
}
//--------------------------------------------------------------------------------