File indexing completed on 2024-04-14 15:49:45
0001 // SPDX-License-Identifier: GPL-3.0-or-later 0002 /* 0003 Copyright 2017 - 2023 Martin Koller, kollix@aon.at 0004 0005 This file is part of liquidshell. 0006 0007 liquidshell is free software: you can redistribute it and/or modify 0008 it under the terms of the GNU General Public License as published by 0009 the Free Software Foundation, either version 3 of the License, or 0010 (at your option) any later version. 0011 0012 liquidshell is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 GNU General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with liquidshell. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include <DesktopPanel.hxx> 0022 #include <StartMenu.hxx> 0023 #include <QuickLaunch.hxx> 0024 #include <AppMenu.hxx> 0025 #include <Pager.hxx> 0026 #include <TaskBar.hxx> 0027 #include <LockLogout.hxx> 0028 #include <SysLoad.hxx> 0029 #include <SysTray.hxx> 0030 #include <ClockWidget.hxx> 0031 #include <WindowList.hxx> 0032 #include <KWinCompat.hxx> 0033 0034 #include <netwm.h> 0035 0036 #include <QHBoxLayout> 0037 #include <QResizeEvent> 0038 #include <QX11Info> 0039 #include <QDBusConnection> 0040 #include <QDebug> 0041 0042 //-------------------------------------------------------------------------------- 0043 0044 DesktopPanel::DesktopPanel(QWidget *parent) 0045 : QFrame(parent, Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus) 0046 { 0047 setAttribute(Qt::WA_AlwaysShowToolTips); 0048 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); 0049 setWindowIcon(QIcon::fromTheme("liquidshell")); 0050 0051 KWindowSystem::setState(winId(), NET::KeepAbove); 0052 KWinCompat::setOnAllDesktops(winId(), true); 0053 KWindowSystem::setType(winId(), NET::Dock); 0054 0055 setFrameShape(QFrame::StyledPanel); 0056 0057 QHBoxLayout *hboxLayout = new QHBoxLayout(this); 0058 hboxLayout->setContentsMargins(QMargins()); 0059 hboxLayout->setSpacing(2); 0060 0061 hboxLayout->addWidget(new StartMenu(this)); 0062 hboxLayout->addWidget(new QuickLaunch(this)); 0063 hboxLayout->addWidget(new AppMenu(this)); 0064 hboxLayout->addWidget(new Pager(this)); 0065 hboxLayout->addWidget(new WindowList(this)); 0066 hboxLayout->addWidget(new TaskBar(this)); 0067 hboxLayout->addWidget(new LockLogout(this)); 0068 hboxLayout->addWidget(new SysLoad(this)); 0069 hboxLayout->addWidget(new SysTray(this)); 0070 hboxLayout->addWidget(new ClockWidget(this)); 0071 0072 // to get notified about num-of-rows changed 0073 updateRowCount(); 0074 QDBusConnection dbus = QDBusConnection::sessionBus(); 0075 dbus.connect(QString(), "/KWin", "org.kde.KWin", "reloadConfig", this, SLOT(updateRowCount())); 0076 connect(KWinCompat::self(), &KWinCompat::numberOfDesktopsChanged, this, &DesktopPanel::updateRowCount); 0077 } 0078 0079 //-------------------------------------------------------------------------------- 0080 0081 void DesktopPanel::updateRowCount() 0082 { 0083 #if QT_VERSION >= QT_VERSION_CHECK(5,15,0) 0084 NETRootInfo ri(QX11Info::connection(), NET::Property(), NET::WM2DesktopLayout); 0085 #else 0086 NETRootInfo ri(QX11Info::connection(), 0, NET::WM2DesktopLayout); 0087 #endif 0088 0089 int newRows = std::max(1, ri.desktopLayoutColumnsRows().height()); 0090 0091 if ( newRows != rows ) 0092 { 0093 rows = newRows; 0094 emit rowsChanged(rows); 0095 } 0096 } 0097 0098 //-------------------------------------------------------------------------------- 0099 0100 bool DesktopPanel::event(QEvent *ev) 0101 { 0102 bool ret = QFrame::event(ev); 0103 0104 if ( ev->type() == QEvent::LayoutRequest ) 0105 { 0106 if ( sizeHint().height() != height() ) 0107 emit resized(); 0108 } 0109 0110 return ret; 0111 } 0112 0113 //-------------------------------------------------------------------------------- 0114 0115 void DesktopPanel::resizeEvent(QResizeEvent *event) 0116 { 0117 Q_UNUSED(event); 0118 0119 emit resized(); 0120 } 0121 0122 //--------------------------------------------------------------------------------