Files
andrew ab869119cc Fix Qt compatibility and VM script docs
Updates desktop shell and application code for cross-Qt compatibility: uses begin/endFilterChange for Qt 6.10+, gates LayerShell usage to Qt < 6.5, and adds include handling for generated QML type registration files so nebula-shell builds reliably. Also fixes qInfo size formatting casts and updates README commands to invoke run-sway-vm.sh via `sh` for more portable execution.
2026-08-26 17:35:00 +12:00

90 lines
2.5 KiB
C++

#include "DesktopIconProvider.hpp"
#include <QCoreApplication>
#include <QDir>
#include <QGuiApplication>
#include <QIcon>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QUrl>
#include <QtGlobal>
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
#include <LayerShellQt/Shell>
#endif
namespace {
void initializeIconTheme()
{
if (QIcon::themeName().isEmpty()) {
const QStringList candidates = {
QStringLiteral("Adwaita"),
QStringLiteral("Yaru"),
QStringLiteral("ubuntu-mono-dark"),
QStringLiteral("breeze"),
QStringLiteral("hicolor"),
};
const QStringList searchPaths = QIcon::themeSearchPaths();
for (const QString &theme : candidates) {
for (const QString &root : searchPaths) {
if (QDir(root + QLatin1Char('/') + theme).exists()) {
QIcon::setThemeName(theme);
break;
}
}
if (!QIcon::themeName().isEmpty())
break;
}
}
if (QIcon::fallbackThemeName().isEmpty())
QIcon::setFallbackThemeName(QStringLiteral("hicolor"));
}
} // namespace
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
LayerShellQt::Shell::useLayerShell();
#endif
QGuiApplication app(argc, argv);
app.setApplicationName(QStringLiteral("nebula-shell"));
app.setApplicationDisplayName(QStringLiteral("Nebula Desktop"));
app.setOrganizationName(QStringLiteral("NebulaOS"));
app.setDesktopFileName(QStringLiteral("org.nebulaos.shell"));
initializeIconTheme();
QQuickWindow::setDefaultAlphaBuffer(true);
QQmlApplicationEngine engine;
engine.addImportPath(QStringLiteral("qrc:/qt/qml"));
engine.addImageProvider(QStringLiteral("desktopicon"), new DesktopIconProvider);
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
[]() {
qCritical("nebula-shell: failed to load the Nebula QML module.");
QCoreApplication::exit(EXIT_FAILURE);
},
Qt::QueuedConnection);
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
engine.loadFromModule(QStringLiteral("Nebula.Shell"), QStringLiteral("Main"));
#else
engine.load(QUrl(QStringLiteral("qrc:/qt/qml/Nebula/Shell/Main.qml")));
#endif
if (engine.rootObjects().isEmpty()) {
qCritical("nebula-shell: failed to load the Nebula QML module.");
return EXIT_FAILURE;
}
return app.exec();
}