2021-12-22 23:29:00 +00:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
|
|
|
|
|
* SPDX-FileCopyrightText: 2018 Bhushan Shah <bshah@kde.org>
|
|
|
|
|
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "shellutil.h"
|
|
|
|
|
|
|
|
|
|
#include <KConfigGroup>
|
2022-05-19 23:59:30 +00:00
|
|
|
#include <KFileUtils>
|
2021-12-22 23:29:00 +00:00
|
|
|
#include <KLocalizedString>
|
|
|
|
|
#include <KNotification>
|
2022-10-12 21:00:21 +00:00
|
|
|
#include <KNotificationJobUiDelegate>
|
2021-12-22 23:29:00 +00:00
|
|
|
|
2024-10-25 15:52:49 +00:00
|
|
|
#include <QQuickWindow>
|
|
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
#include <QDBusPendingReply>
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
|
2024-11-07 16:13:06 +00:00
|
|
|
#include <QTextDocumentFragment>
|
|
|
|
|
#include <QtWaylandClient/private/qwaylandwindow_p.h>
|
2024-11-25 17:30:47 +00:00
|
|
|
#include <LayerShellQt/Window>
|
2024-11-07 16:13:06 +00:00
|
|
|
|
|
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
#define FORMAT24H "HH:mm:ss"
|
|
|
|
|
|
panels: Add support for defining device specific panel tweaks
This adds support for specifying options needed to deal with phone
display panel pecularities (ex. screen curves, notches, punch holes)
This is implemented as settings in ~/.config/plasmamobilerc, which can
set panel heights, paddings, and center spacings to duck display
cutouts. The pixel values are scaling independent, and so are not
affected when the display scaling is changed.
This is then exposed over DBus, so that components from outside of
plasmashell (ex. KWin) can access it easily without needing to connect to
kscreen themselves. Each screen is exposed as a single object.
Currently support is only added in the status bar and the navigation
panel.
Currently all screens have the settings applied. In the future, we may
want to limit this just to the internal screen (?)
---
This also adds a "devices" folder (in `devices/configs`) where per-device configs can be set.
This is installed to `/usr/share/plasma-mobile-device-configs`.
In `plasmamobilerc` (installed to `/etc/xdg/plasmamobilerc`, or
`~/.config/plasmamobilerc`), envmanager will read:
```toml
[Device]
device=oneplus-enchilada
```
for the device config to use and write its settings to
`~/.config/plasma-mobile/plasmamobilerc`.
2025-10-05 23:06:52 +00:00
|
|
|
ShellUtil::ShellUtil(QObject *parent)
|
|
|
|
|
: QObject{parent}
|
|
|
|
|
, m_localeConfig{KSharedConfig::openConfig(QStringLiteral("kdeglobals"))}
|
|
|
|
|
{
|
2021-12-22 23:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-07 14:52:12 +00:00
|
|
|
void ShellUtil::stackItemBefore(QQuickItem *item1, QQuickItem *item2)
|
|
|
|
|
{
|
|
|
|
|
if (!item1 || !item2 || item1 == item2 || item1->parentItem() != item2->parentItem()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item1->stackBefore(item2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShellUtil::stackItemAfter(QQuickItem *item1, QQuickItem *item2)
|
|
|
|
|
{
|
|
|
|
|
if (!item1 || !item2 || item1 == item2 || item1->parentItem() != item2->parentItem()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item1->stackAfter(item2);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
void ShellUtil::executeCommand(const QString &command)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << "Executing" << command;
|
|
|
|
|
const QStringList commandAndArguments = QProcess::splitCommand(command);
|
|
|
|
|
QProcess::startDetached(commandAndArguments.front(), commandAndArguments.mid(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ShellUtil::isSystem24HourFormat()
|
|
|
|
|
{
|
2023-03-19 05:43:59 +00:00
|
|
|
// only load the config watcher if this function is actually used once
|
|
|
|
|
if (!m_localeConfigWatcher) {
|
|
|
|
|
m_localeConfigWatcher = KConfigWatcher::create(m_localeConfig);
|
|
|
|
|
|
|
|
|
|
// watch for changes to locale config, to update 12/24 hour time
|
2024-02-16 12:37:26 +00:00
|
|
|
connect(m_localeConfigWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group) -> void {
|
2023-03-19 05:43:59 +00:00
|
|
|
if (group.name() == "Locale") {
|
|
|
|
|
// we have to reparse for new changes (from system settings)
|
|
|
|
|
m_localeConfig->reparseConfiguration();
|
|
|
|
|
Q_EMIT isSystem24HourFormatChanged();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 23:29:00 +00:00
|
|
|
KConfigGroup localeSettings = KConfigGroup(m_localeConfig, "Locale");
|
|
|
|
|
|
|
|
|
|
QString timeFormat = localeSettings.readEntry("TimeFormat", QStringLiteral(FORMAT24H));
|
|
|
|
|
return timeFormat == QStringLiteral(FORMAT24H);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-12 21:00:21 +00:00
|
|
|
void ShellUtil::launchApp(const QString &storageId)
|
2021-12-22 23:29:00 +00:00
|
|
|
{
|
2022-10-12 21:00:21 +00:00
|
|
|
KService::Ptr service = KService::serviceByStorageId(storageId);
|
|
|
|
|
if (!service) {
|
|
|
|
|
qWarning() << "Could not find" << storageId;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto job = new KIO::ApplicationLauncherJob(service, this);
|
|
|
|
|
job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled));
|
2021-12-22 23:29:00 +00:00
|
|
|
job->start();
|
|
|
|
|
}
|
2024-10-25 15:52:49 +00:00
|
|
|
|
|
|
|
|
void ShellUtil::setInputTransparent(QQuickWindow *window, bool transparent) {
|
|
|
|
|
if (window) {
|
|
|
|
|
Qt::WindowFlags flags = window->flags();
|
|
|
|
|
if (transparent) {
|
|
|
|
|
flags |= Qt::WindowTransparentForInput;
|
|
|
|
|
} else {
|
|
|
|
|
flags &= ~Qt::WindowTransparentForInput;
|
|
|
|
|
}
|
|
|
|
|
window->setFlags(flags);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 17:30:47 +00:00
|
|
|
void ShellUtil::setWindowLayer(QQuickWindow *window, LayerShellQt::Window::Layer layer) {
|
|
|
|
|
if (window) {
|
|
|
|
|
auto layerShellWindow = LayerShellQt::Window::get(window);
|
|
|
|
|
layerShellWindow->setLayer(layer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-07 16:13:06 +00:00
|
|
|
void ShellUtil::setInputRegion(QWindow *window, const QRect ®ion) {
|
|
|
|
|
auto waylandWindow = dynamic_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
|
|
|
|
|
if (!waylandWindow) {
|
|
|
|
|
qWarning() << "Failed to retrieve Wayland window handle.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
panels: Add support for defining device specific panel tweaks
This adds support for specifying options needed to deal with phone
display panel pecularities (ex. screen curves, notches, punch holes)
This is implemented as settings in ~/.config/plasmamobilerc, which can
set panel heights, paddings, and center spacings to duck display
cutouts. The pixel values are scaling independent, and so are not
affected when the display scaling is changed.
This is then exposed over DBus, so that components from outside of
plasmashell (ex. KWin) can access it easily without needing to connect to
kscreen themselves. Each screen is exposed as a single object.
Currently support is only added in the status bar and the navigation
panel.
Currently all screens have the settings applied. In the future, we may
want to limit this just to the internal screen (?)
---
This also adds a "devices" folder (in `devices/configs`) where per-device configs can be set.
This is installed to `/usr/share/plasma-mobile-device-configs`.
In `plasmamobilerc` (installed to `/etc/xdg/plasmamobilerc`, or
`~/.config/plasmamobilerc`), envmanager will read:
```toml
[Device]
device=oneplus-enchilada
```
for the device config to use and write its settings to
`~/.config/plasma-mobile/plasmamobilerc`.
2025-10-05 23:06:52 +00:00
|
|
|
|
2024-11-07 16:13:06 +00:00
|
|
|
auto waylandDisplay = dynamic_cast<QtWaylandClient::QWaylandDisplay *>(waylandWindow->display());
|
|
|
|
|
if (!waylandDisplay) {
|
|
|
|
|
qWarning() << "Failed to retrieve Wayland display.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_compositor *compositorResource = static_cast<wl_compositor *>(waylandDisplay->compositor()->object());
|
|
|
|
|
if (!compositorResource) {
|
|
|
|
|
qWarning() << "Failed to retrieve compositor.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_surface *surface = waylandWindow->wlSurface();
|
|
|
|
|
if (!surface) {
|
|
|
|
|
qWarning() << "Failed to retrieve Wayland surface.";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (region.isEmpty()) {
|
|
|
|
|
wl_surface_set_input_region(surface, nullptr);
|
|
|
|
|
} else {
|
|
|
|
|
wl_region *inputRegion = wl_compositor_create_region(compositorResource);
|
|
|
|
|
|
|
|
|
|
wl_region_add(inputRegion, region.x(), region.y(), region.width(), region.height());
|
|
|
|
|
wl_surface_set_input_region(surface, inputRegion);
|
|
|
|
|
wl_region_destroy(inputRegion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wl_surface_commit(surface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ShellUtil::toPlainText(QString htmlString) {
|
|
|
|
|
return QTextDocumentFragment::fromHtml(htmlString).toPlainText();
|
|
|
|
|
}
|