Files
Nebula-OS/shells/desktop/shell/src/OutputTracker.cpp
T
andrew b0c95b9e78 Add desktop app service and VM dev session tooling
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.
2026-08-26 17:19:30 +12:00

92 lines
2.4 KiB
C++

#include "OutputTracker.hpp"
#include <QCoreApplication>
#include <QGuiApplication>
#include <QJSEngine>
#include <QRect>
OutputTracker::OutputTracker(QObject *parent)
: QObject(parent)
{
if (auto *app = qobject_cast<QGuiApplication *>(QCoreApplication::instance())) {
connect(app, &QGuiApplication::primaryScreenChanged, this, [this](QScreen *screen) {
bindScreen(screen);
});
connect(app, &QGuiApplication::screenAdded, this, [this](QScreen *) {
if (!m_screen)
bindScreen(QGuiApplication::primaryScreen());
});
connect(app, &QGuiApplication::screenRemoved, this, [this](QScreen *screen) {
if (m_screen == screen)
bindScreen(QGuiApplication::primaryScreen());
});
bindScreen(app->primaryScreen());
}
}
OutputTracker *OutputTracker::create(QQmlEngine *engine, QJSEngine *)
{
auto *tracker = new OutputTracker(engine);
QQmlEngine::setObjectOwnership(tracker, QQmlEngine::CppOwnership);
return tracker;
}
void OutputTracker::bindScreen(QScreen *screen)
{
if (m_screen == screen)
return;
if (m_screen) {
disconnect(m_screen, nullptr, this, nullptr);
}
m_screen = screen;
if (m_screen) {
connect(m_screen, &QScreen::geometryChanged, this, [this](const QRect &) {
logGeometry();
emit geometryChanged();
});
connect(m_screen, &QScreen::physicalDotsPerInchChanged, this, &OutputTracker::geometryChanged);
}
logGeometry();
emit geometryChanged();
}
void OutputTracker::logGeometry() const
{
if (!m_screen) {
qWarning("nebula-shell: no Wayland output is available yet");
return;
}
const QRect geo = m_screen->geometry();
qInfo("nebula-shell: output %s %dx%d+%d+%d scale %g",
qPrintable(m_screen->name()),
geo.width(),
geo.height(),
geo.x(),
geo.y(),
m_screen->devicePixelRatio());
}
int OutputTracker::width() const
{
return m_screen ? m_screen->geometry().width() : 0;
}
int OutputTracker::height() const
{
return m_screen ? m_screen->geometry().height() : 0;
}
qreal OutputTracker::devicePixelRatio() const
{
return m_screen ? m_screen->devicePixelRatio() : 1.0;
}
QString OutputTracker::name() const
{
return m_screen ? m_screen->name() : QString();
}