File indexing completed on 2024-05-05 17:42:30
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "taskpanel.h" 0008 0009 #include <QDBusPendingReply> 0010 #include <QDebug> 0011 #include <QQuickItem> 0012 #include <QQuickWindow> 0013 #include <QtQml> 0014 0015 #include <KWayland/Client/connection_thread.h> 0016 #include <KWayland/Client/output.h> 0017 #include <KWayland/Client/plasmashell.h> 0018 #include <KWayland/Client/plasmawindowmanagement.h> 0019 #include <KWayland/Client/registry.h> 0020 #include <KWayland/Client/surface.h> 0021 #include <Plasma/Package> 0022 0023 #include <virtualkeyboardinterface.h> 0024 0025 // register type for Keyboards.KWinVirtualKeyboard.forceActivate(); 0026 Q_DECLARE_METATYPE(QDBusPendingReply<>) 0027 0028 TaskPanel::TaskPanel(QObject *parent, const KPluginMetaData &data, const QVariantList &args) 0029 : Plasma::Containment(parent, data, args) 0030 { 0031 setHasConfigurationInterface(true); 0032 initWayland(); 0033 0034 qmlRegisterUncreatableType<KWayland::Client::Output>("org.kde.plasma.phone.taskpanel", 1, 0, "Output", "nope"); 0035 0036 // register type for Keyboards.KWinVirtualKeyboard.forceActivate(); 0037 qRegisterMetaType<QDBusPendingReply<>>(); 0038 0039 connect(this, &Plasma::Containment::locationChanged, this, &TaskPanel::locationChanged); 0040 connect(this, &Plasma::Containment::locationChanged, this, [this] { 0041 auto l = location(); 0042 setFormFactor(l == Plasma::Types::LeftEdge || l == Plasma::Types::RightEdge ? Plasma::Types::Vertical : Plasma::Types::Horizontal); 0043 }); 0044 } 0045 0046 void TaskPanel::initWayland() 0047 { 0048 if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) { 0049 return; 0050 } 0051 using namespace KWayland::Client; 0052 ConnectionThread *connection = ConnectionThread::fromApplication(this); 0053 0054 if (!connection) { 0055 return; 0056 } 0057 0058 auto *registry = new Registry(this); 0059 registry->create(connection); 0060 0061 connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) { 0062 m_shellInterface = registry->createPlasmaShell(name, version, this); 0063 0064 if (!m_panel) { 0065 return; 0066 } 0067 Surface *s = Surface::fromWindow(m_panel); 0068 if (!s) { 0069 return; 0070 } 0071 m_shellSurface = m_shellInterface->createSurface(s, this); 0072 m_shellSurface->setSkipTaskbar(true); 0073 }); 0074 registry->setup(); 0075 connection->roundtrip(); 0076 } 0077 0078 QWindow *TaskPanel::panel() 0079 { 0080 return m_panel; 0081 } 0082 0083 void TaskPanel::setPanel(QWindow *panel) 0084 { 0085 if (panel == m_panel) { 0086 return; 0087 } 0088 0089 if (m_panel) { 0090 disconnect(m_panel, &QWindow::visibilityChanged, this, &TaskPanel::updatePanelVisibility); 0091 } 0092 m_panel = panel; 0093 connect(m_panel, &QWindow::visibilityChanged, this, &TaskPanel::updatePanelVisibility, Qt::QueuedConnection); 0094 Q_EMIT panelChanged(); 0095 updatePanelVisibility(); 0096 } 0097 0098 void TaskPanel::setPanelHeight(qreal height) 0099 { 0100 if (m_panel) { 0101 m_panel->setHeight(height); 0102 } 0103 } 0104 0105 void TaskPanel::updatePanelVisibility() 0106 { 0107 using namespace KWayland::Client; 0108 if (!m_panel->isVisible()) { 0109 return; 0110 } 0111 0112 Surface *s = Surface::fromWindow(m_panel); 0113 0114 if (!s) { 0115 return; 0116 } 0117 0118 m_shellSurface = m_shellInterface->createSurface(s, this); 0119 if (m_shellSurface) { 0120 m_shellSurface->setSkipTaskbar(true); 0121 } 0122 } 0123 0124 K_PLUGIN_CLASS_WITH_JSON(TaskPanel, "package/metadata.json") 0125 0126 #include "taskpanel.moc"