2023-09-26 15:33:08 +03:00
|
|
|
/* This file is part of the KDE project
|
|
|
|
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License version 2, as published by the Free Software Foundation.
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
#include "pager.h"
|
|
|
|
|
|
|
|
#include <QX11Info>
|
|
|
|
#include <Plasma/Svg>
|
2014-11-13 19:30:51 +02:00
|
|
|
#include <Plasma/FrameSvg>
|
2023-09-26 15:33:08 +03:00
|
|
|
#include <Plasma/SvgWidget>
|
2014-11-13 19:30:51 +02:00
|
|
|
#include <Plasma/Theme>
|
2023-09-26 21:47:42 +03:00
|
|
|
#include <Plasma/ToolTipManager>
|
2023-09-26 15:33:08 +03:00
|
|
|
#include <KWindowSystem>
|
|
|
|
#include <KIcon>
|
|
|
|
#include <KIconLoader>
|
|
|
|
#include <KDebug>
|
|
|
|
#include <netwm.h>
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
// standard issue margin/spacing
|
|
|
|
static const int s_spacing = 4;
|
|
|
|
// the applet may be hidden unless there are two virtual desktops
|
|
|
|
static const QSizeF s_preferredsize = QSizeF(0, 0);
|
|
|
|
static PagerApplet::PagerMode s_defaultpagermode = PagerApplet::ShowNumber;
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 21:47:42 +03:00
|
|
|
static QString kElementPrefixForDesktop(const int desktop, const bool hovered)
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
if (hovered) {
|
|
|
|
return QString::fromLatin1("hover");
|
|
|
|
} else if (KWindowSystem::currentDesktop() == desktop) {
|
|
|
|
return QString::fromLatin1("active");
|
|
|
|
}
|
|
|
|
return QString::fromLatin1("normal");
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 21:47:42 +03:00
|
|
|
static QRectF kAdjustRect(const QRectF &rect)
|
|
|
|
{
|
|
|
|
QRectF result = rect;
|
|
|
|
result.setWidth(result.width() - (s_spacing * 2));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static QFont kGetFont()
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
QFont font = KGlobalSettings::smallestReadableFont();
|
|
|
|
font.setBold(true);
|
|
|
|
return font;
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 22:29:06 +03:00
|
|
|
static bool kHandleMouseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::MiddleButton) {
|
|
|
|
NETRootInfo netrootinfo(QX11Info::display(), NET::WM2ShowingDesktop | NET::Supported);
|
|
|
|
if (!netrootinfo.isSupported(NET::WM2ShowingDesktop)) {
|
|
|
|
kWarning() << "NET::WM2ShowingDesktop is not supported";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// that is how the showdesktop does it - it tracks the state internally
|
|
|
|
static bool s_didshow = false;
|
|
|
|
if (netrootinfo.showingDesktop() || s_didshow) {
|
|
|
|
s_didshow = false;
|
|
|
|
netrootinfo.setShowingDesktop(false);
|
|
|
|
} else {
|
|
|
|
s_didshow = true;
|
|
|
|
netrootinfo.setShowingDesktop(true);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
class PagerSvg : public Plasma::SvgWidget
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
PagerSvg(const int desktop, QGraphicsItem *parent = nullptr);
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void setup(const PagerApplet::PagerMode pagermode);
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
private Q_SLOTS:
|
|
|
|
void slotClicked(const Qt::MouseButton button);
|
|
|
|
void slotUpdate();
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
protected:
|
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) final;
|
2023-09-26 21:47:42 +03:00
|
|
|
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint) const final;
|
2023-09-26 15:33:08 +03:00
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) final;
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) final;
|
2023-09-26 22:29:06 +03:00
|
|
|
// handled here too
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) final;
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
private Q_SLOTS:
|
2023-09-26 21:47:42 +03:00
|
|
|
void slotUpdateSvgAndToolTip();
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
private:
|
|
|
|
int m_desktop;
|
|
|
|
bool m_hovered;
|
|
|
|
Plasma::FrameSvg* m_framesvg;
|
|
|
|
PagerApplet::PagerMode m_pagermode;
|
|
|
|
};
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
PagerSvg::PagerSvg(const int desktop, QGraphicsItem *parent)
|
|
|
|
: Plasma::SvgWidget(parent),
|
|
|
|
m_desktop(desktop),
|
|
|
|
m_hovered(false),
|
|
|
|
m_framesvg(nullptr),
|
|
|
|
m_pagermode(s_defaultpagermode)
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 21:47:42 +03:00
|
|
|
slotUpdateSvgAndToolTip();
|
2023-09-26 15:33:08 +03:00
|
|
|
setAcceptHoverEvents(true);
|
|
|
|
connect(
|
|
|
|
this, SIGNAL(clicked(Qt::MouseButton)),
|
|
|
|
this, SLOT(slotClicked(Qt::MouseButton))
|
|
|
|
);
|
|
|
|
connect(
|
|
|
|
KWindowSystem::self(), SIGNAL(currentDesktopChanged(int)),
|
|
|
|
this, SLOT(slotUpdate())
|
|
|
|
);
|
|
|
|
connect(
|
|
|
|
KWindowSystem::self(), SIGNAL(desktopNamesChanged()),
|
|
|
|
this, SLOT(slotUpdate())
|
|
|
|
);
|
|
|
|
connect(
|
|
|
|
Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
|
2023-09-26 21:47:42 +03:00
|
|
|
this, SLOT(slotUpdateSvgAndToolTip())
|
2023-09-26 15:33:08 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PagerSvg::setup(const PagerApplet::PagerMode pagermode)
|
|
|
|
{
|
|
|
|
m_pagermode = pagermode;
|
|
|
|
update();
|
|
|
|
}
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerSvg::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(option);
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
const QRectF brect = boundingRect();
|
2023-09-26 21:47:42 +03:00
|
|
|
m_framesvg->setElementPrefix(kElementPrefixForDesktop(m_desktop, m_hovered));
|
2023-09-26 15:33:08 +03:00
|
|
|
m_framesvg->resizeFrame(brect.size());
|
|
|
|
m_framesvg->paintFrame(painter, brect);
|
|
|
|
switch (m_pagermode) {
|
|
|
|
case PagerApplet::ShowNumber: {
|
|
|
|
painter->save();
|
2023-09-26 21:47:42 +03:00
|
|
|
painter->setFont(kGetFont());
|
|
|
|
painter->translate(s_spacing, 0);
|
|
|
|
painter->drawText(kAdjustRect(brect.toRect()), QString::number(m_desktop), QTextOption(Qt::AlignCenter));
|
2023-09-26 15:33:08 +03:00
|
|
|
painter->restore();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PagerApplet::ShowName: {
|
|
|
|
painter->save();
|
2023-09-26 21:47:42 +03:00
|
|
|
painter->setFont(kGetFont());
|
|
|
|
painter->translate(s_spacing, 0);
|
|
|
|
painter->drawText(kAdjustRect(brect.toRect()), KWindowSystem::desktopName(m_desktop), QTextOption(Qt::AlignCenter));
|
2023-09-26 15:33:08 +03:00
|
|
|
painter->restore();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 21:47:42 +03:00
|
|
|
QSizeF PagerSvg::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
|
|
|
{
|
|
|
|
if (m_pagermode == PagerApplet::ShowName) {
|
|
|
|
QSizeF svgwidgethint = Plasma::SvgWidget::sizeHint(which, constraint);
|
|
|
|
svgwidgethint.setWidth(svgwidgethint.width() * 2);
|
|
|
|
return svgwidgethint;
|
|
|
|
}
|
|
|
|
return Plasma::SvgWidget::sizeHint(which, constraint);
|
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerSvg::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
Q_UNUSED(event);
|
|
|
|
m_hovered = true;
|
|
|
|
update();
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerSvg::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
Q_UNUSED(event);
|
|
|
|
m_hovered = false;
|
|
|
|
update();
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 22:29:06 +03:00
|
|
|
void PagerSvg::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (kHandleMouseEvent(event)) {
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Plasma::SvgWidget::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2023-09-26 21:47:42 +03:00
|
|
|
void PagerSvg::slotUpdateSvgAndToolTip()
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
if (m_framesvg) {
|
|
|
|
delete m_framesvg;
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2023-09-26 15:33:08 +03:00
|
|
|
m_framesvg = new Plasma::FrameSvg(this);
|
|
|
|
m_framesvg->setImagePath("widgets/pager");
|
|
|
|
setSvg(m_framesvg);
|
2023-09-26 21:47:42 +03:00
|
|
|
Plasma::ToolTipContent plasmatooltip;
|
|
|
|
plasmatooltip.setMainText(QString::fromLatin1("<center>%1</center>").arg(KWindowSystem::desktopName(m_desktop)));
|
|
|
|
Plasma::ToolTipManager::self()->setContent(this, plasmatooltip);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerSvg::slotClicked(const Qt::MouseButton button)
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
if (button == Qt::LeftButton) {
|
|
|
|
KWindowSystem::setCurrentDesktop(m_desktop);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerSvg::slotUpdate()
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
update();
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
PagerApplet::PagerApplet(QObject *parent, const QVariantList &args)
|
|
|
|
: Plasma::Applet(parent, args),
|
|
|
|
m_layout(nullptr),
|
|
|
|
m_adddesktopaction(nullptr),
|
|
|
|
m_removedesktopaction(nullptr),
|
|
|
|
m_pagermode(s_defaultpagermode)
|
|
|
|
{
|
|
|
|
KGlobal::locale()->insertCatalog("plasma_applet_pager");
|
|
|
|
setAspectRatioMode(Plasma::AspectRatioMode::IgnoreAspectRatio);
|
|
|
|
setHasConfigurationInterface(true);
|
|
|
|
setPreferredSize(s_preferredsize);
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
m_layout = new QGraphicsLinearLayout(Qt::Horizontal, this);
|
|
|
|
m_layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
m_layout->setSpacing(s_spacing);
|
|
|
|
|
|
|
|
slotUpdateLayout();
|
|
|
|
adjustSize();
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerApplet::init()
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
connect(
|
|
|
|
KWindowSystem::self(), SIGNAL(numberOfDesktopsChanged(int)),
|
|
|
|
this, SLOT(slotUpdateLayout())
|
|
|
|
);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerApplet::createConfigurationInterface(KConfigDialog *parent)
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
// TODO:
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
QList<QAction*> PagerApplet::contextualActions()
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
return m_actions;
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 21:47:42 +03:00
|
|
|
void PagerApplet::wheelEvent(QGraphicsSceneWheelEvent *event)
|
|
|
|
{
|
|
|
|
const int currentdesktop = KWindowSystem::currentDesktop();
|
|
|
|
if (event->delta() < 0) {
|
|
|
|
KWindowSystem::setCurrentDesktop(currentdesktop + 1);
|
|
|
|
} else {
|
|
|
|
KWindowSystem::setCurrentDesktop(currentdesktop - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 22:29:06 +03:00
|
|
|
void PagerApplet::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (kHandleMouseEvent(event)) {
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Plasma::Applet::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
// NOTE: keep in sync with:
|
|
|
|
// plasma/applets/lockout/lockout.cpp
|
|
|
|
void PagerApplet::updateSizes()
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
const int pagersvgssize = m_pagersvgs.size();
|
|
|
|
QSizeF preferredsize = s_preferredsize;
|
|
|
|
foreach (PagerSvg *pagersvg, m_pagersvgs) {
|
|
|
|
preferredsize += pagersvg->preferredSize();
|
|
|
|
}
|
|
|
|
locker.unlock();
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
int iconsize = 0;
|
|
|
|
switch (formFactor()) {
|
|
|
|
case Plasma::FormFactor::Horizontal:
|
|
|
|
case Plasma::FormFactor::Vertical: {
|
|
|
|
// panel
|
|
|
|
iconsize = KIconLoader::global()->currentSize(KIconLoader::Panel);
|
2014-11-13 19:30:51 +02:00
|
|
|
break;
|
2023-09-26 15:33:08 +03:00
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// desktop-like
|
|
|
|
iconsize = (KIconLoader::global()->currentSize(KIconLoader::Desktop) * 2);
|
2014-11-13 19:30:51 +02:00
|
|
|
break;
|
2023-09-26 15:33:08 +03:00
|
|
|
}
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2023-09-26 15:33:08 +03:00
|
|
|
// the width is based on the number of desktops
|
|
|
|
setMinimumSize(iconsize * pagersvgssize, iconsize);
|
|
|
|
emit sizeHintChanged(Qt::MinimumSize);
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
setPreferredSize(preferredsize);
|
|
|
|
switch (m_layout->orientation()) {
|
|
|
|
case Qt::Horizontal: {
|
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
2014-11-13 19:30:51 +02:00
|
|
|
break;
|
2023-09-26 15:33:08 +03:00
|
|
|
}
|
|
|
|
case Qt::Vertical: {
|
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2014-11-13 19:30:51 +02:00
|
|
|
break;
|
2023-09-26 15:33:08 +03:00
|
|
|
}
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2023-09-26 15:33:08 +03:00
|
|
|
emit sizeHintChanged(Qt::PreferredSize);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerApplet::constraintsEvent(Plasma::Constraints constraints)
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
// perfect size finder
|
|
|
|
// qDebug() << Q_FUNC_INFO << size();
|
|
|
|
if (constraints & Plasma::SizeConstraint || constraints & Plasma::FormFactorConstraint) {
|
|
|
|
switch (formFactor()) {
|
|
|
|
case Plasma::FormFactor::Horizontal: {
|
|
|
|
m_layout->setOrientation(Qt::Horizontal);
|
|
|
|
m_layout->setSpacing(0);
|
|
|
|
updateSizes();
|
|
|
|
return;
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2023-09-26 15:33:08 +03:00
|
|
|
case Plasma::FormFactor::Vertical: {
|
|
|
|
m_layout->setOrientation(Qt::Vertical);
|
|
|
|
m_layout->setSpacing(0);
|
|
|
|
updateSizes();
|
|
|
|
return;
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2023-09-26 15:33:08 +03:00
|
|
|
default: {
|
|
|
|
m_layout->setSpacing(s_spacing);
|
|
|
|
break;
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
const QSizeF appletsize = size();
|
|
|
|
if (appletsize.width() >= appletsize.height()) {
|
|
|
|
m_layout->setOrientation(Qt::Horizontal);
|
2014-11-13 19:30:51 +02:00
|
|
|
} else {
|
2023-09-26 15:33:08 +03:00
|
|
|
m_layout->setOrientation(Qt::Vertical);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2023-09-26 15:33:08 +03:00
|
|
|
updateSizes();
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerApplet::slotUpdateLayout()
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
QMutexLocker locker(&m_mutex);
|
|
|
|
foreach (PagerSvg* pagersvg, m_pagersvgs) {
|
|
|
|
m_layout->removeItem(pagersvg);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2023-09-26 15:33:08 +03:00
|
|
|
qDeleteAll(m_pagersvgs);
|
|
|
|
m_pagersvgs.clear();
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
const int numberofdesktops = KWindowSystem::numberOfDesktops();
|
|
|
|
for (int i = 0; i < numberofdesktops; i++) {
|
|
|
|
PagerSvg* pagersvg = new PagerSvg(i + 1, this);
|
|
|
|
m_layout->addItem(pagersvg);
|
|
|
|
m_pagersvgs.append(pagersvg);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
m_actions.clear();
|
|
|
|
if (!m_adddesktopaction) {
|
|
|
|
m_adddesktopaction = new QAction(
|
|
|
|
KIcon("list-add"), i18n("&Add Virtual Desktop"),
|
|
|
|
this
|
|
|
|
);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2023-09-26 15:33:08 +03:00
|
|
|
m_actions.append(m_adddesktopaction);
|
|
|
|
connect(
|
|
|
|
m_adddesktopaction, SIGNAL(triggered(bool)),
|
|
|
|
this , SLOT(slotAddDesktop())
|
|
|
|
);
|
|
|
|
if (numberofdesktops > 1) {
|
|
|
|
if (!m_removedesktopaction) {
|
|
|
|
m_removedesktopaction = new QAction(
|
|
|
|
KIcon("list-remove"), i18n("&Remove Last Virtual Desktop"),
|
|
|
|
this
|
|
|
|
);
|
|
|
|
}
|
|
|
|
m_actions.append(m_removedesktopaction);
|
|
|
|
connect(
|
|
|
|
m_removedesktopaction, SIGNAL(triggered(bool)),
|
|
|
|
this , SLOT(slotRemoveDesktop())
|
|
|
|
);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2023-09-26 15:33:08 +03:00
|
|
|
locker.unlock();
|
2014-11-13 19:30:51 +02:00
|
|
|
updateSizes();
|
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerApplet::slotAddDesktop()
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
NETRootInfo netrootinfo(QX11Info::display(), NET::NumberOfDesktops);
|
|
|
|
netrootinfo.setNumberOfDesktops(netrootinfo.numberOfDesktops() + 1);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-26 15:33:08 +03:00
|
|
|
void PagerApplet::slotRemoveDesktop()
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2023-09-26 15:33:08 +03:00
|
|
|
NETRootInfo netrootinfo(QX11Info::display(), NET::NumberOfDesktops);
|
|
|
|
const int numberofdesktops = netrootinfo.numberOfDesktops();
|
|
|
|
if (numberofdesktops > 1) {
|
|
|
|
netrootinfo.setNumberOfDesktops(netrootinfo.numberOfDesktops() - 1);
|
2014-11-13 19:30:51 +02:00
|
|
|
} else {
|
2023-09-26 15:33:08 +03:00
|
|
|
kWarning() << "there is only one desktop";
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 09:28:46 +00:00
|
|
|
#include "moc_pager.cpp"
|
2023-09-26 15:33:08 +03:00
|
|
|
#include "pager.moc"
|