diff --git a/displaywright/__init__.py b/displaywright/__init__.py index ee0c94c..b65693f 100644 --- a/displaywright/__init__.py +++ b/displaywright/__init__.py @@ -12,7 +12,7 @@ ``omarchy-shell`` plugin that draws it. """ -__version__ = "0.7.3" +__version__ = "0.7.4" APP_ID = "ai.bkblab.displaywright" APP_NAME = "displaywright" diff --git a/plugin/Arrange.qml b/plugin/Arrange.qml index d000874..e996531 100644 --- a/plugin/Arrange.qml +++ b/plugin/Arrange.qml @@ -53,8 +53,13 @@ Item { readonly property string configHome: Quickshell.env("XDG_CONFIG_HOME") || (home + "/.config") readonly property string monitorsPath: configHome + "/hypr/monitors.lua" //: Where this plugin was loaded from, for the scripts shipped beside it. - readonly property string pluginDir: manifest && manifest.__sourceDir - ? String(manifest.__sourceDir) : "" + //: Third-party manifests do not carry the host's private `__sourceDir` + //: (Omarchy 4.0.3 sanitizes it), so resolve from this file at the root. + readonly property string pluginDir: { + var url = String(Qt.resolvedUrl(".")) + if (url.indexOf("file://") !== 0) return "" + try { return decodeURIComponent(url.substring(7)).replace(/\/$/, "") } catch (e) { return "" } + } function touch() { revision += 1 } diff --git a/plugin/LauncherEntry.qml b/plugin/LauncherEntry.qml index ea3e67d..9c6a1d3 100644 --- a/plugin/LauncherEntry.qml +++ b/plugin/LauncherEntry.qml @@ -17,6 +17,7 @@ QtObject { id: root property var manifest: null + property string pluginDir: "" readonly property string dest: Quickshell.env("HOME") + "/.local/share/applications/displaywright.desktop" @@ -53,7 +54,7 @@ QtObject { // Component.onCompleted, so the paths are built when it arrives rather than // bound -- a binding has not re-evaluated by the time that fires. onManifestChanged: { - var dir = manifest && manifest.__sourceDir + var dir = root.pluginDir if (installed || !dir) return installed = true //: execDetached reports nothing back, so this line is the only evidence @@ -66,11 +67,10 @@ QtObject { Component.onDestruction: { if (!installed) return - var dir = manifest && manifest.__sourceDir //: No folder to test means no way to tell a reload from a removal, and //: keeping the entry is the half that cannot lose one. - if (!dir) return + if (!root.pluginDir) return Quickshell.execDetached(["sh", "-c", removeScript, "sh", - dest, marker, dir + "/manifest.json"]) + dest, marker, root.pluginDir + "/manifest.json"]) } } diff --git a/plugin/Wallpaper.qml b/plugin/Wallpaper.qml index 0112574..1ebab14 100644 --- a/plugin/Wallpaper.qml +++ b/plugin/Wallpaper.qml @@ -51,7 +51,7 @@ Item { //: A plain child rather than a typed property: resolving a sibling .qml as //: a property *type* is stricter than instantiating it, and this file is //: the one whose failure takes every wallpaper on the desktop with it. - LauncherEntry { manifest: root.manifest } + LauncherEntry { manifest: root.manifest; pluginDir: root.pluginDir } //: A plain-value snapshot of the shell theme, for the same reason. readonly property var palette: ({ @@ -67,11 +67,16 @@ Item { readonly property string configHome: Quickshell.env("XDG_CONFIG_HOME") || (home + "/.config") readonly property string configPath: configHome + "/displaywright/wallpapers.json" - // Where this plugin was loaded from. The shell stamps it into the manifest; - // hardcoding an install path would break a symlinked checkout and anyone who - // installed by hand somewhere else. - readonly property string pluginDir: manifest && manifest.__sourceDir - ? String(manifest.__sourceDir) : "" + // Where this plugin was loaded from: this file sits at the plugin root, so + // the directory resolves from here. Third-party manifests do not carry the + // host's private `__sourceDir` (Omarchy 4.0.3 sanitizes it), and hardcoding + // an install path would break a symlinked checkout and anyone who installed + // by hand somewhere else. + readonly property string pluginDir: { + var url = String(Qt.resolvedUrl(".")) + if (url.indexOf("file://") !== 0) return "" + try { return decodeURIComponent(url.substring(7)).replace(/\/$/, "") } catch (e) { return "" } + } // ---------------------------------------------------------------- config @@ -134,6 +139,16 @@ Item { function reloadConfig() { if (!root.pluginDir || configReader.running) return + //: The first call comes from onPluginDirChanged, which fires while this + //: object is still being built: the engine evaluates the root's bindings + //: before its children's, so configReader exists but its command binding + //: has not run yet. When pluginDir still arrived late, off the manifest, + //: the same handler ran ahead of the re-evaluation and started the ["true"] + //: placeholder instead -- it collected nothing, and every output sat on + //: the theme background until wallpapers.json was next written + //: (displaywright-shell-plugin#2). Set the command outright, so the read + //: is against the path whichever binding pass got there first. + configReader.command = [root.pluginDir + "/read-config.sh", root.configPath] configReader.running = true } @@ -203,7 +218,7 @@ Item { target: "displaywright" function reload(): string { - configFile.reload() + root.reloadConfig() root.refreshSpanBox() return "ok" } diff --git a/plugin/icon.png b/plugin/icon.png index 9625646..38957c5 100644 Binary files a/plugin/icon.png and b/plugin/icon.png differ diff --git a/plugin/manifest.json b/plugin/manifest.json index 1db0bf8..7f4bf50 100644 --- a/plugin/manifest.json +++ b/plugin/manifest.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "id": "ai.bkblab.displaywright", "name": "Displaywright", - "version": "0.7.3", + "version": "0.7.4", "author": "bkblab.ai", "license": "MIT", "description": "Per-display wallpapers and a display arrangement editor, inside omarchy-shell. Open it from the Apps menu: SUPER+ALT+SPACE, then type Displays. Or double-click one display's background to give just that display a wallpaper.", diff --git a/tools/tst_icon.qml b/tools/tst_icon.qml index 472d4cb..b349c08 100644 --- a/tools/tst_icon.qml +++ b/tools/tst_icon.qml @@ -2,8 +2,9 @@ // // make icon // -// Drawn rather than sourced so there is nothing to lose track of, and kept to -// three shapes because the launcher renders it at 32px as often as 256. +// Drawn rather than sourced so there is nothing to lose track of. The app +// menu shows it at around 24px, so it is one silhouette: two display frames +// standing in front of a dusk wallpaper, each framing its own piece of it. import QtQuick import QtTest @@ -16,37 +17,99 @@ TestCase { width: 256 height: 256 - Component { + Canvas { id: art - Rectangle { - width: 256; height: 256 - radius: 56 - gradient: Gradient { - GradientStop { position: 0.0; color: "#4a90e2" } - GradientStop { position: 1.0; color: "#2b5fa8" } - } - - // Two landscape displays side by side and one turned portrait: the - // arrangement is the product, so the icon is an arrangement. - Rectangle { - x: 34; y: 96; width: 92; height: 60; radius: 7 - color: "#ffffff"; opacity: 0.95 - } - Rectangle { - x: 134; y: 74; width: 88; height: 56; radius: 7 - color: "#ffffff"; opacity: 0.72 - } - Rectangle { - x: 150; y: 140; width: 44; height: 68; radius: 7 - color: "#ffffff"; opacity: 0.45 - } + width: 256; height: 256 + renderStrategy: Canvas.Immediate + renderTarget: Canvas.Image + + function roundRect(ctx, x, y, w, h, r) { + ctx.beginPath() + ctx.moveTo(x + r, y) + ctx.arcTo(x + w, y, x + w, y + h, r) + ctx.arcTo(x + w, y + h, x, y + h, r) + ctx.arcTo(x, y + h, x, y, r) + ctx.arcTo(x, y, x + w, y, r) + ctx.closePath() + } + + // A display: glass that lifts the scene behind it, a bright bezel, and a + // stand. Drawn heavy on purpose -- at 24px anything thinner vanishes. + function display(ctx, x, y, w, h) { + ctx.save() + ctx.shadowColor = "rgba(20, 10, 40, 0.45)" + ctx.shadowBlur = 18 + ctx.shadowOffsetY = 8 + roundRect(ctx, x, y, w, h, 12) + ctx.fillStyle = "rgba(255, 255, 255, 0.2)" + ctx.fill() + ctx.restore() + + roundRect(ctx, x, y, w, h, 12) + ctx.lineWidth = 11 + ctx.strokeStyle = "#fff8f0" + ctx.stroke() + + // stand + var cx = x + w / 2 + roundRect(ctx, cx - 5, y + h + 4, 10, 14, 4) + ctx.fillStyle = "#fff8f0" + ctx.fill() + roundRect(ctx, cx - 22, y + h + 16, 44, 9, 4.5) + ctx.fill() + } + + onPaint: { + var ctx = getContext("2d") + ctx.reset() + ctx.clearRect(0, 0, width, height) + + // The plate, and everything after it clipped to it. + roundRect(ctx, 0, 0, 256, 256, 58) + ctx.clip() + + // The wallpaper: night at the top down to a warm horizon. + var sky = ctx.createLinearGradient(0, 0, 0, 256) + sky.addColorStop(0.00, "#1b1f5e") + sky.addColorStop(0.45, "#6a3fb5") + sky.addColorStop(0.72, "#e9647a") + sky.addColorStop(1.00, "#ffb05a") + ctx.fillStyle = sky + ctx.fillRect(0, 0, 256, 256) + + // The sun, framed by the wide display, with its glow. + var glow = ctx.createRadialGradient(96, 122, 10, 96, 122, 70) + glow.addColorStop(0, "rgba(255, 225, 150, 0.5)") + glow.addColorStop(1, "rgba(255, 225, 150, 0)") + ctx.fillStyle = glow + ctx.fillRect(0, 0, 256, 256) + ctx.beginPath() + ctx.arc(96, 122, 24, 0, Math.PI * 2) + ctx.fillStyle = "#ffe08a" + ctx.fill() + + // Hills along the bottom. + ctx.fillStyle = "#2a1a4a" + ctx.beginPath() + ctx.moveTo(0, 256) + ctx.lineTo(0, 212) + ctx.bezierCurveTo(50, 190, 110, 228, 168, 200) + ctx.bezierCurveTo(200, 184, 232, 196, 256, 214) + ctx.lineTo(256, 256) + ctx.closePath() + ctx.fill() + + // Two displays: one landscape, one turned portrait. The arrangement is + // the product, so the icon is an arrangement. + display(ctx, 30, 76, 124, 84) + display(ctx, 170, 52, 58, 108) } } function test_shoot() { - const item = art.createObject(suite) + art.requestPaint() wait(300) - const shot = grabImage(item) + const shot = grabImage(art) shot.save(String(Qt.resolvedUrl("../plugin/icon.png")).replace("file://", "")) verify(true) }