Introduces a new `core/applications` QML/C++ module (`Nebula.Applications`) to discover `.desktop` entries, expose filterable application models, and launch installed apps safely from the shell. The desktop launcher now uses real installed apps with themed icon loading and fallback glyphs, adds output-aware surface sizing via `OutputTracker`, and wires in image/icon providers. It also adds VMware-focused Sway/shell wrapper scripts, updates Sway config/session env defaults, and refreshes README docs to document the new development flow and Desktop 0.1 behavior.
88 lines
2.3 KiB
C++
88 lines
2.3 KiB
C++
#include "DesktopIconProvider.hpp"
|
|
|
|
#include <QFileInfo>
|
|
#include <QIcon>
|
|
#include <QPixmap>
|
|
#include <QUrl>
|
|
|
|
namespace {
|
|
|
|
QIcon resolveDesktopIcon(const QString &name)
|
|
{
|
|
if (name.isEmpty())
|
|
return {};
|
|
|
|
const QFileInfo direct(name);
|
|
if (direct.isAbsolute() && direct.exists())
|
|
return QIcon(name);
|
|
|
|
QIcon themed = QIcon::fromTheme(name);
|
|
if (!themed.isNull())
|
|
return themed;
|
|
|
|
QString base = name;
|
|
if (base.endsWith(QLatin1String(".png"), Qt::CaseInsensitive)
|
|
|| base.endsWith(QLatin1String(".svg"), Qt::CaseInsensitive)
|
|
|| base.endsWith(QLatin1String(".xpm"), Qt::CaseInsensitive)) {
|
|
base = QFileInfo(base).completeBaseName();
|
|
themed = QIcon::fromTheme(base);
|
|
if (!themed.isNull())
|
|
return themed;
|
|
}
|
|
|
|
const QStringList pixmapDirs = {
|
|
QStringLiteral("/usr/share/pixmaps"),
|
|
QStringLiteral("/usr/share/icons/hicolor/48x48/apps"),
|
|
QStringLiteral("/usr/share/icons/hicolor/scalable/apps"),
|
|
};
|
|
const QStringList suffixes = {
|
|
QString(),
|
|
QStringLiteral(".png"),
|
|
QStringLiteral(".svg"),
|
|
QStringLiteral(".xpm"),
|
|
};
|
|
|
|
for (const QString &dir : pixmapDirs) {
|
|
for (const QString &suffix : suffixes) {
|
|
const QString candidate = dir + QLatin1Char('/') + (suffix.isEmpty() ? name : base) + suffix;
|
|
if (QFileInfo::exists(candidate))
|
|
return QIcon(candidate);
|
|
}
|
|
}
|
|
|
|
return {};
|
|
}
|
|
|
|
} // namespace
|
|
|
|
DesktopIconProvider::DesktopIconProvider()
|
|
: QQuickImageProvider(QQuickImageProvider::Pixmap)
|
|
{
|
|
}
|
|
|
|
QPixmap DesktopIconProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
|
|
{
|
|
const QString iconName = QUrl::fromPercentEncoding(id.toUtf8());
|
|
const QIcon icon = resolveDesktopIcon(iconName);
|
|
const QSize target = requestedSize.isValid() && requestedSize.width() > 0 && requestedSize.height() > 0
|
|
? requestedSize
|
|
: QSize(48, 48);
|
|
|
|
if (icon.isNull()) {
|
|
if (size)
|
|
*size = target;
|
|
return {};
|
|
}
|
|
|
|
const QPixmap pixmap = icon.pixmap(target);
|
|
if (pixmap.isNull()) {
|
|
if (size)
|
|
*size = target;
|
|
return {};
|
|
}
|
|
|
|
if (size)
|
|
*size = pixmap.size();
|
|
return pixmap;
|
|
}
|