Move the existing launcher into legacy/
git mv of everything (web/ android/ qt/ wasi/ android-wasm/ tests/ ci/ pixi.toml README) so history follows; legacy/ keeps its own .gitignore and a new root .gitignore starts for the MoonBit project. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7d2bf5996f
commit
66e8e90da1
88 files changed
+138
-10
No files matched your search
@@ -0,0 +1,302 @@
|
||||
#include "backend.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QGuiApplication>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QScreen>
|
||||
#include <QSettings>
|
||||
#include <QTimer>
|
||||
#include <cmath>
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include <QJniEnvironment>
|
||||
#include <QJniObject>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
Backend *g_backend = nullptr;
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
constexpr char kActivity[] = "dev/ultra/launcher/HomeActivity";
|
||||
|
||||
QString callString(const char *method) {
|
||||
return QJniObject::callStaticObjectMethod(kActivity, method, "()Ljava/lang/String;").toString();
|
||||
}
|
||||
|
||||
void callWithString(const char *method, const QString &s) {
|
||||
QJniObject::callStaticMethod<void>(kActivity, method, "(Ljava/lang/String;)V",
|
||||
QJniObject::fromString(s).object<jstring>());
|
||||
}
|
||||
|
||||
void callVoid(const char *method) {
|
||||
QJniObject::callStaticMethod<void>(kActivity, method, "()V");
|
||||
}
|
||||
|
||||
// Called by HomeActivity on Android's main thread: hop over to Qt's.
|
||||
template <typename F>
|
||||
void post(F f) {
|
||||
if (g_backend) QMetaObject::invokeMethod(g_backend, f, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void jAppsChanged(JNIEnv *env, jclass, jstring packages) {
|
||||
const char *c = env->GetStringUTFChars(packages, nullptr);
|
||||
const QString s = QString::fromUtf8(c);
|
||||
env->ReleaseStringUTFChars(packages, c);
|
||||
post([=] { emit g_backend->appsChanged(s); });
|
||||
}
|
||||
void jHomePressed(JNIEnv *, jclass) { post([] { emit g_backend->homePressed(); }); }
|
||||
void jBackPressed(JNIEnv *, jclass) { post([] { emit g_backend->backPressed(); }); }
|
||||
void jInsets(JNIEnv *, jclass, jint top, jint bottom) { post([=] { g_backend->setInsets(top, bottom); }); }
|
||||
void jWidgetAdded(JNIEnv *, jclass, jint id) { post([=] { emit g_backend->widgetAdded(id); }); }
|
||||
void jWidgetMenu(JNIEnv *, jclass, jint id) { post([=] { emit g_backend->widgetMenu(id); }); }
|
||||
void jWidgetGrab(JNIEnv *, jclass, jint id) { post([=] { emit g_backend->widgetGrab(id); }); }
|
||||
void jWidgetDrag(JNIEnv *, jclass, jint x, jint y) {
|
||||
post([=] {
|
||||
const qreal r = QGuiApplication::primaryScreen()->devicePixelRatio();
|
||||
emit g_backend->widgetDrag(x / r, y / r);
|
||||
});
|
||||
}
|
||||
void jWidgetDrop(JNIEnv *, jclass, jboolean moved) { post([=] { emit g_backend->widgetDrop(moved); }); }
|
||||
|
||||
void jLegacyHome(JNIEnv *env, jclass, jstring json) {
|
||||
const char *c = env->GetStringUTFChars(json, nullptr);
|
||||
const QString s = QString::fromUtf8(c);
|
||||
env->ReleaseStringUTFChars(json, c);
|
||||
post([=] { emit g_backend->legacyHome(s); });
|
||||
}
|
||||
|
||||
void jAppList(JNIEnv *env, jclass, jstring json) {
|
||||
const char *c = env->GetStringUTFChars(json, nullptr);
|
||||
const QByteArray s(c);
|
||||
env->ReleaseStringUTFChars(json, c);
|
||||
post([=] { g_backend->takeAppList(s); });
|
||||
}
|
||||
|
||||
void registerNatives() {
|
||||
static bool done = false;
|
||||
if (done) return;
|
||||
done = true;
|
||||
const JNINativeMethod methods[] = {
|
||||
{"appsChanged", "(Ljava/lang/String;)V", reinterpret_cast<void *>(jAppsChanged)},
|
||||
{"homePressed", "()V", reinterpret_cast<void *>(jHomePressed)},
|
||||
{"backPressed", "()V", reinterpret_cast<void *>(jBackPressed)},
|
||||
{"insets", "(II)V", reinterpret_cast<void *>(jInsets)},
|
||||
{"widgetAdded", "(I)V", reinterpret_cast<void *>(jWidgetAdded)},
|
||||
{"widgetMenu", "(I)V", reinterpret_cast<void *>(jWidgetMenu)},
|
||||
{"widgetGrab", "(I)V", reinterpret_cast<void *>(jWidgetGrab)},
|
||||
{"widgetDrag", "(II)V", reinterpret_cast<void *>(jWidgetDrag)},
|
||||
{"widgetDrop", "(Z)V", reinterpret_cast<void *>(jWidgetDrop)},
|
||||
{"appList", "(Ljava/lang/String;)V", reinterpret_cast<void *>(jAppList)},
|
||||
{"legacyHome", "(Ljava/lang/String;)V", reinterpret_cast<void *>(jLegacyHome)},
|
||||
};
|
||||
QJniEnvironment env;
|
||||
env.registerNativeMethods("dev/ultra/launcher/Native", methods, int(std::size(methods)));
|
||||
}
|
||||
#endif
|
||||
|
||||
QJsonDocument demo(const QString &name) {
|
||||
QFile f(QStringLiteral(":/qt/qml/Launcher/demo/") + name);
|
||||
if (!f.open(QIODevice::ReadOnly)) return {};
|
||||
return QJsonDocument::fromJson(f.readAll());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Backend::Backend(QObject *parent) : QObject(parent) { g_backend = this; }
|
||||
|
||||
Backend *Backend::instance() { return g_backend; }
|
||||
|
||||
bool Backend::isAndroid() const {
|
||||
#ifdef Q_OS_ANDROID
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
qreal Backend::dpr() const {
|
||||
QScreen *s = QGuiApplication::primaryScreen();
|
||||
return s ? s->devicePixelRatio() : 1.0;
|
||||
}
|
||||
|
||||
void Backend::setInsets(int top, int bottom) {
|
||||
m_insetTop = top / dpr();
|
||||
m_insetBottom = bottom / dpr();
|
||||
emit insetsChanged();
|
||||
}
|
||||
|
||||
void Backend::ready() {
|
||||
#ifdef Q_OS_ANDROID
|
||||
registerNatives();
|
||||
callVoid("ready");
|
||||
#endif
|
||||
}
|
||||
|
||||
static QVariantList appList(const QJsonDocument &doc) {
|
||||
QVariantList out;
|
||||
for (const QJsonValue &v : doc.object().value(QStringLiteral("apps")).toArray()) {
|
||||
const QJsonObject o = v.toObject();
|
||||
out.append(QVariantMap{{"label", o.value("label").toString()},
|
||||
{"component", o.value("component").toString()},
|
||||
{"system", o.value("system").toBool()}});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// The app list, and a copy kept for the next start: listing (and labelling) every app
|
||||
// takes a while on a phone, so the home screen starts from the copy meanwhile.
|
||||
QVariantList Backend::apps() const {
|
||||
#ifdef Q_OS_ANDROID
|
||||
const QByteArray json = callString("apps").toUtf8();
|
||||
#else
|
||||
const QByteArray json = demo(QStringLiteral("apps.json")).toJson(QJsonDocument::Compact);
|
||||
#endif
|
||||
const QVariantList out = appList(QJsonDocument::fromJson(json));
|
||||
if (!out.isEmpty()) QSettings().setValue(QStringLiteral("apps"), QString::fromUtf8(json));
|
||||
return out;
|
||||
}
|
||||
|
||||
// apps(), without holding up the UI thread meanwhile: the list arrives as appsLoaded.
|
||||
void Backend::requestApps() {
|
||||
#ifdef Q_OS_ANDROID
|
||||
callVoid("listApps");
|
||||
#else
|
||||
QTimer::singleShot(0, this, [this] { takeAppList(demo(QStringLiteral("apps.json")).toJson(QJsonDocument::Compact)); });
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::takeAppList(const QByteArray &json) {
|
||||
const QVariantList out = appList(QJsonDocument::fromJson(json));
|
||||
if (!out.isEmpty()) QSettings().setValue(QStringLiteral("apps"), QString::fromUtf8(json));
|
||||
emit appsLoaded(out);
|
||||
}
|
||||
|
||||
QVariantList Backend::savedApps() const {
|
||||
return appList(QJsonDocument::fromJson(QSettings().value(QStringLiteral("apps")).toString().toUtf8()));
|
||||
}
|
||||
|
||||
QVariantList Backend::widgetProviders() const {
|
||||
#ifdef Q_OS_ANDROID
|
||||
const QJsonDocument doc = QJsonDocument::fromJson(callString("widgetProviders").toUtf8());
|
||||
#else
|
||||
const QJsonDocument doc = demo(QStringLiteral("widgets.json"));
|
||||
#endif
|
||||
QVariantList out;
|
||||
for (const QJsonValue &v : doc.object().value(QStringLiteral("widgets")).toArray()) {
|
||||
const QJsonObject o = v.toObject();
|
||||
out.append(QVariantMap{{"label", o.value("label").toString()},
|
||||
{"app", o.value("app").toString()},
|
||||
{"provider", o.value("provider").toString()},
|
||||
{"h", o.value("h").toInt(120)}});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
void Backend::launch(const QString &c) { callWithString("launch", c); }
|
||||
void Backend::appInfo(const QString &c) { callWithString("appInfo", c); }
|
||||
void Backend::uninstall(const QString &c) { callWithString("uninstall", c); }
|
||||
void Backend::openSettings() { callVoid("openSettings"); }
|
||||
void Backend::pickWallpaper() { callVoid("pickWallpaper"); }
|
||||
void Backend::openRecents() { callVoid("openRecents"); }
|
||||
void Backend::checkUpdates() { callVoid("checkUpdates"); }
|
||||
void Backend::haptic() { callVoid("haptic"); }
|
||||
void Backend::addWidget(const QString &p) { callWithString("addWidget", p); }
|
||||
void Backend::removeWidget(int id) { QJniObject::callStaticMethod<void>(kActivity, "removeWidget", "(I)V", jint(id)); }
|
||||
#else
|
||||
void Backend::launch(const QString &c) { emit toast("Open " + c); }
|
||||
void Backend::appInfo(const QString &c) { emit toast("App info for " + c); }
|
||||
void Backend::uninstall(const QString &c) { emit toast("Uninstall " + c); }
|
||||
void Backend::openSettings() { emit toast("Open system settings"); }
|
||||
void Backend::pickWallpaper() { emit toast("Pick a wallpaper"); }
|
||||
void Backend::openRecents() { emit toast("Show open windows"); }
|
||||
void Backend::checkUpdates() { emit toast("Check for updates"); }
|
||||
void Backend::haptic() {}
|
||||
void Backend::addWidget(const QString &) {
|
||||
const int id = m_demoWidget++;
|
||||
QTimer::singleShot(0, this, [this, id] { emit widgetAdded(id); });
|
||||
}
|
||||
void Backend::removeWidget(int) {}
|
||||
#endif
|
||||
|
||||
void Backend::placeWidgets(const QVariantList &list) {
|
||||
#ifdef Q_OS_ANDROID
|
||||
const qreal r = dpr();
|
||||
QJsonArray out;
|
||||
for (const QVariant &v : list) {
|
||||
const QVariantMap m = v.toMap();
|
||||
const qreal x = m.value("x").toReal() * r, y = m.value("y").toReal() * r;
|
||||
const qreal w = m.value("w").toReal() * r, h = m.value("h").toReal() * r;
|
||||
out.append(QJsonArray{m.value("id").toInt(), qRound(x), qRound(y), qRound(x + w) - qRound(x),
|
||||
qRound(y + h) - qRound(y), m.value("editing").toBool() ? 1 : 0});
|
||||
}
|
||||
callWithString("placeWidgets", QString::fromUtf8(QJsonDocument(out).toJson(QJsonDocument::Compact)));
|
||||
#else
|
||||
Q_UNUSED(list);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::coverWidgets(qreal y) {
|
||||
#ifdef Q_OS_ANDROID
|
||||
const int py = y <= 0 ? int(y) : int(std::ceil(y * dpr()));
|
||||
QJniObject::callStaticMethod<void>(kActivity, "coverWidgets", "(I)V", jint(py));
|
||||
#else
|
||||
Q_UNUSED(y);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::sheetWidgets(qreal y, bool dim) {
|
||||
#ifdef Q_OS_ANDROID
|
||||
const int py = y <= 0 ? 0 : int(std::floor(y * dpr()));
|
||||
QJniObject::callStaticMethod<void>(kActivity, "sheetWidgets", "(IZ)V", jint(py), jboolean(dim));
|
||||
#else
|
||||
Q_UNUSED(y);
|
||||
Q_UNUSED(dim);
|
||||
#endif
|
||||
}
|
||||
|
||||
QVariantMap Backend::widgetLimits(int id) const {
|
||||
#ifdef Q_OS_ANDROID
|
||||
const QJsonObject o = QJsonDocument::fromJson(
|
||||
QJniObject::callStaticObjectMethod(kActivity, "widgetLimits", "(I)Ljava/lang/String;", jint(id))
|
||||
.toString().toUtf8()).object();
|
||||
const qreal r = dpr();
|
||||
QVariantMap m;
|
||||
for (const char *k : {"w", "minW", "minH", "maxW", "maxH"}) {
|
||||
if (o.contains(k)) m.insert(k, o.value(k).toDouble() / r);
|
||||
}
|
||||
for (const char *k : {"h", "v"}) {
|
||||
if (o.contains(k)) m.insert(k, o.value(k).toBool());
|
||||
}
|
||||
return m;
|
||||
#else
|
||||
Q_UNUSED(id);
|
||||
return {{"minW", 120}, {"minH", 80}, {"maxW", 0}, {"maxH", 0}, {"h", true}, {"v", true}};
|
||||
#endif
|
||||
}
|
||||
|
||||
void Backend::excludeGestures(const QVariantList &rects) {
|
||||
#ifdef Q_OS_ANDROID
|
||||
const qreal r = dpr();
|
||||
QJsonArray out;
|
||||
for (const QVariant &v : rects) {
|
||||
const QVariantMap m = v.toMap();
|
||||
out.append(QJsonArray{qRound(m.value("x").toReal() * r), qRound(m.value("y").toReal() * r),
|
||||
qRound(m.value("w").toReal() * r), qRound(m.value("h").toReal() * r)});
|
||||
}
|
||||
callWithString("excludeGestures", QString::fromUtf8(QJsonDocument(out).toJson(QJsonDocument::Compact)));
|
||||
#else
|
||||
Q_UNUSED(rects);
|
||||
#endif
|
||||
}
|
||||
|
||||
QString Backend::loadHome() const {
|
||||
QSettings s;
|
||||
return s.value(QStringLiteral("home")).toString();
|
||||
}
|
||||
|
||||
void Backend::saveHome(const QString &json) {
|
||||
QSettings s;
|
||||
s.setValue(QStringLiteral("home"), json);
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QVariantList>
|
||||
#include <QVariantMap>
|
||||
#include <QtQml/qqmlregistration.h>
|
||||
|
||||
// The QML app's window onto Android (HomeActivity.java). On a phone each call goes
|
||||
// through JNI; on a desktop the backend serves demo data from qt/demo and turns the
|
||||
// actions into toasts, so the UI can be tried and tested without a device.
|
||||
//
|
||||
// Geometry in and out of QML is in logical (QML) px; the backend scales it to the
|
||||
// physical screen px HomeActivity works in.
|
||||
class Backend : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool android READ isAndroid CONSTANT)
|
||||
Q_PROPERTY(qreal insetTop READ insetTop NOTIFY insetsChanged)
|
||||
Q_PROPERTY(qreal insetBottom READ insetBottom NOTIFY insetsChanged)
|
||||
|
||||
public:
|
||||
explicit Backend(QObject *parent = nullptr);
|
||||
static Backend *instance();
|
||||
|
||||
bool isAndroid() const;
|
||||
qreal insetTop() const { return m_insetTop; }
|
||||
qreal insetBottom() const { return m_insetBottom; }
|
||||
|
||||
// Lists: [{label, component, system}] and [{label, app, provider, h}].
|
||||
Q_INVOKABLE QVariantList apps() const;
|
||||
Q_INVOKABLE void requestApps(); // answers with appsLoaded
|
||||
Q_INVOKABLE QVariantList savedApps() const; // the last list apps() returned, for a quick start
|
||||
Q_INVOKABLE QVariantList widgetProviders() const;
|
||||
|
||||
Q_INVOKABLE void launch(const QString &component);
|
||||
Q_INVOKABLE void appInfo(const QString &component);
|
||||
Q_INVOKABLE void uninstall(const QString &component);
|
||||
Q_INVOKABLE void openSettings();
|
||||
Q_INVOKABLE void pickWallpaper();
|
||||
Q_INVOKABLE void openRecents();
|
||||
Q_INVOKABLE void checkUpdates();
|
||||
Q_INVOKABLE void haptic();
|
||||
|
||||
// Widgets: addWidget answers with widgetAdded(id) once bound (and configured).
|
||||
Q_INVOKABLE void addWidget(const QString &provider);
|
||||
Q_INVOKABLE void removeWidget(int id);
|
||||
// [{id, x, y, w, h, editing}] in global logical px.
|
||||
Q_INVOKABLE void placeWidgets(const QVariantList &list);
|
||||
// The drawer covers the screen down to global logical y; -1 all of it, 0 none.
|
||||
Q_INVOKABLE void coverWidgets(qreal y);
|
||||
// A sheet covers the screen from global logical y down (0: none) and dims the rest.
|
||||
Q_INVOKABLE void sheetWidgets(qreal y, bool dim);
|
||||
// {w, minW, minH, maxW, maxH (0: no limit), h, v} in logical px.
|
||||
Q_INVOKABLE QVariantMap widgetLimits(int id) const;
|
||||
// [{x, y, w, h}] in global logical px: no system back swipe there.
|
||||
Q_INVOKABLE void excludeGestures(const QVariantList &rects);
|
||||
|
||||
// The home layout, as JSON, kept in the app's settings.
|
||||
Q_INVOKABLE QString loadHome() const;
|
||||
Q_INVOKABLE void saveHome(const QString &json);
|
||||
|
||||
// Tell HomeActivity QML is up (it then adds the widget layer and starts calling back).
|
||||
Q_INVOKABLE void ready();
|
||||
|
||||
// From HomeActivity (on Android's thread; queued to Qt's).
|
||||
void setInsets(int top, int bottom);
|
||||
|
||||
signals:
|
||||
void insetsChanged();
|
||||
void appsLoaded(const QVariantList &apps);
|
||||
void appsChanged(const QString &packages); // comma-separated; empty: any
|
||||
void homePressed();
|
||||
void backPressed();
|
||||
void widgetAdded(int id);
|
||||
void widgetMenu(int id);
|
||||
void widgetGrab(int id);
|
||||
void widgetDrag(qreal x, qreal y); // global logical px
|
||||
void widgetDrop(bool moved);
|
||||
void legacyHome(const QString &json); // the WebView build's saved home, read once
|
||||
void toast(const QString &text); // desktop stand-in for an action
|
||||
|
||||
public:
|
||||
void takeAppList(const QByteArray &json); // HomeActivity's answer to requestApps
|
||||
|
||||
private:
|
||||
qreal dpr() const;
|
||||
qreal m_insetTop = 0, m_insetBottom = 0;
|
||||
mutable int m_demoWidget = 100;
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "iconprovider.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include <QUrl>
|
||||
#include <QElapsedTimer>
|
||||
#include <QLoggingCategory>
|
||||
#include <QThread>
|
||||
|
||||
Q_LOGGING_CATEGORY(lcIcon, "ultra.icon")
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include <QJniEnvironment>
|
||||
#include <QJniObject>
|
||||
#endif
|
||||
|
||||
QImage IconProvider::requestImage(const QString &id, QSize *size, const QSize &requested) {
|
||||
QString key = id;
|
||||
const int q = key.lastIndexOf(QLatin1Char('?'));
|
||||
if (q >= 0) key.truncate(q);
|
||||
key = QUrl::fromPercentEncoding(key.toUtf8());
|
||||
const int px = requested.width() > 0 ? requested.width() : 144;
|
||||
QElapsedTimer took;
|
||||
took.start();
|
||||
QImage img;
|
||||
#ifdef Q_OS_ANDROID
|
||||
// Premultiplied RGBA, side x side, straight from an Android bitmap.
|
||||
QJniObject pixels = QJniObject::callStaticObjectMethod(
|
||||
"dev/ultra/launcher/HomeActivity", "icon", "(Ljava/lang/String;I)[B",
|
||||
QJniObject::fromString(key).object<jstring>(), jint(px));
|
||||
if (pixels.isValid()) {
|
||||
QJniEnvironment env;
|
||||
auto arr = pixels.object<jbyteArray>();
|
||||
const jsize n = env->GetArrayLength(arr);
|
||||
const int side = int(std::lround(std::sqrt(n / 4.0)));
|
||||
if (side > 0 && jsize(side) * side * 4 == n) {
|
||||
img = QImage(side, side, QImage::Format_RGBA8888_Premultiplied);
|
||||
env->GetByteArrayRegion(arr, 0, n, reinterpret_cast<jbyte *>(img.bits()));
|
||||
}
|
||||
}
|
||||
#else
|
||||
// A disc in a colour picked from the key, with the name's first letter.
|
||||
img = QImage(px, px, QImage::Format_ARGB32_Premultiplied);
|
||||
img.fill(Qt::transparent);
|
||||
QPainter p(&img);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
const QColor c = QColor::fromHsv(int(qHash(key) % 360), 160, 220);
|
||||
const bool widget = key.startsWith(QLatin1String("w:"));
|
||||
p.setBrush(c);
|
||||
p.setPen(Qt::NoPen);
|
||||
if (widget) p.drawRoundedRect(QRectF(0, 0, px, px), px / 4.0, px / 4.0);
|
||||
else p.drawEllipse(QRectF(0, 0, px, px));
|
||||
QString name = key.mid(2).section(QLatin1Char('/'), 0, 0).section(QLatin1Char('.'), -1);
|
||||
p.setPen(Qt::white);
|
||||
QFont f;
|
||||
f.setPixelSize(px * 5 / 12);
|
||||
f.setBold(true);
|
||||
p.setFont(f);
|
||||
p.drawText(QRectF(0, 0, px, px), Qt::AlignCenter, name.left(1).toUpper());
|
||||
#endif
|
||||
if (size) *size = img.size();
|
||||
// Timing, to find what holds icons up on a phone: adb logcat -s ultrahome:*
|
||||
qCInfo(lcIcon, "icon %s %dpx %lldms%s", qPrintable(key), px, took.elapsed(), img.isNull() ? " (none)" : "");
|
||||
return img;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <QQuickImageProvider>
|
||||
|
||||
// image://icon/a:COMPONENT is an app's icon, image://icon/w:PROVIDER a widget's.
|
||||
// On a phone HomeActivity draws them; on a desktop they are lettered discs.
|
||||
// QML asks with the key percent-encoded and an optional "?n" suffix that only
|
||||
// busts the pixmap cache after the app list changes.
|
||||
class IconProvider : public QQuickImageProvider {
|
||||
public:
|
||||
IconProvider() : QQuickImageProvider(QQuickImageProvider::Image) {}
|
||||
QImage requestImage(const QString &id, QSize *size, const QSize &requested) override;
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QtQml/qqmlextensionplugin.h>
|
||||
#include <QQuickWindow>
|
||||
#include <QSurfaceFormat>
|
||||
|
||||
#include "backend.h"
|
||||
#include "iconprovider.h"
|
||||
|
||||
Q_IMPORT_QML_PLUGIN(LauncherPlugin)
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// The window is see-through: the wallpaper shows behind the home screen.
|
||||
QQuickWindow::setDefaultAlphaBuffer(true);
|
||||
QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
|
||||
fmt.setAlphaBufferSize(8);
|
||||
QSurfaceFormat::setDefaultFormat(fmt);
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
QGuiApplication::setOrganizationName(QStringLiteral("ultra"));
|
||||
QGuiApplication::setApplicationName(QStringLiteral("home"));
|
||||
|
||||
Backend backend;
|
||||
QQmlApplicationEngine engine;
|
||||
engine.addImageProvider(QStringLiteral("icon"), new IconProvider);
|
||||
qmlRegisterSingletonInstance("Launcher.Host", 1, 0, "Host", &backend);
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
|
||||
[] { QCoreApplication::exit(1); }, Qt::QueuedConnection);
|
||||
engine.loadFromModule("Launcher", "Main");
|
||||
if (engine.rootObjects().isEmpty()) return 1;
|
||||
// Timing of the window's lifecycle, next to the icon timings (category ultra.icon).
|
||||
QObject::connect(&app, &QGuiApplication::applicationStateChanged, [](Qt::ApplicationState s) {
|
||||
qInfo("ultra.state %d", int(s));
|
||||
});
|
||||
if (auto *win = qobject_cast<QQuickWindow *>(engine.rootObjects().first())) {
|
||||
QObject::connect(win, &QQuickWindow::sceneGraphInitialized, [] { qInfo("ultra.sg initialized"); });
|
||||
QObject::connect(win, &QQuickWindow::sceneGraphInvalidated, [] { qInfo("ultra.sg invalidated"); });
|
||||
QObject::connect(win, &QQuickWindow::frameSwapped, win, [win] {
|
||||
static int n = 0;
|
||||
if (n++ < 3) qInfo("ultra.sg frame %d", n);
|
||||
});
|
||||
}
|
||||
return app.exec();
|
||||
}
|
||||
Reference in new issue
Block a user