Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Linux/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Linux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/sw-quickjs", "crates/sw-core", "crates/sw-render", "crates/sw-cli", "crates/sw-host", "crates/sw-studio"]

[workspace.package]
version = "0.1.1"
version = "0.1.2"
edition = "2024"
license = "Apache-2.0"
publish = false
Expand Down
26 changes: 18 additions & 8 deletions Linux/crates/sw-studio/src/ui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,24 @@ impl StudioWindow {
_tasks: vec![preview_task, request_task],
};
this.reload_library(cx);
match page {
Some(StartPage::Library) | None => {}
Some(StartPage::Templates) => this.go(Target::Templates, window, cx),
Some(StartPage::Settings) => this.go(Target::Settings, window, cx),
Some(StartPage::Template(reference)) => this.go(Target::Template(reference), window, cx),
Some(StartPage::Editor(name)) => this.go(Target::Editor(name), window, cx),
}
this.handle_request(first, window, cx);
// Where the program was asked to start. Not done here but once the
// window exists: a start that fails (a widget that is not installed, a
// file that cannot be read) shows a message, and a message needs the
// window's own state, which is only there after this function returns.
// Doing it here made `--edit <unknown name>` end the program.
let start = cx.spawn_in(window, async move |this, cx| {
let _ = this.update_in(cx, |this, window, cx| {
match page {
Some(StartPage::Library) | None => {}
Some(StartPage::Templates) => this.go(Target::Templates, window, cx),
Some(StartPage::Settings) => this.go(Target::Settings, window, cx),
Some(StartPage::Template(reference)) => this.go(Target::Template(reference), window, cx),
Some(StartPage::Editor(name)) => this.go(Target::Editor(name), window, cx),
}
this.handle_request(first, window, cx);
});
});
this._tasks.push(start);
this
}

Expand Down
36 changes: 35 additions & 1 deletion Linux/omarchy-plugin/Service.qml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Item {
sweep.restart()
reportedScreens = ({})
for (var index = 0; index < screenReports.instances.length; index++) screenReports.instances[index].send()
monitorsSoon.restart()
reportTheme()
return
}
Expand Down Expand Up @@ -428,6 +429,37 @@ Item {
stdout: StdioCollector { onStreamFinished: root.readLayers(text) }
}

// The compositor's own word on each monitor. The shell's screen objects
// above did not follow a scale change made while the shell was running, and
// a widget was then drawn at the old scale and looked blurred. Read at
// start, after every reconnect, when the compositor says a monitor or its
// configuration changed, and now and then in case it did not say.
function readMonitors(text) {
var list
try { list = JSON.parse(text) } catch (error) { return }
if (!Array.isArray(list)) return
for (var index = 0; index < list.length && index < 16; index++) {
var monitor = list[index]
if (!monitor || typeof monitor.name !== "string" || monitor.disabled === true || !(monitor.scale > 0)) continue
var turned = monitor.transform % 2 === 1
var width = Math.round((turned ? monitor.height : monitor.width) / monitor.scale)
var height = Math.round((turned ? monitor.width : monitor.height) / monitor.scale)
reportScreen(monitor.name, monitor.scale, width, height)
}
}
function askMonitors() { if (status === "running" && !monitors.running) monitors.running = true }
Process {
id: monitors
command: ["hyprctl", "-j", "monitors"]
stdout: StdioCollector { onStreamFinished: root.readMonitors(text) }
}
Connections {
target: Hyprland
function onRawEvent(event) { if (/monitor|configreloaded/.test(event.name)) monitorsSoon.restart() }
}
Timer { id: monitorsSoon; interval: 500; onTriggered: root.askMonitors() }
Timer { interval: 30000; repeat: true; running: root.status === "running"; onTriggered: root.askMonitors() }

Variants {
id: screenReports
model: Quickshell.screens
Expand All @@ -437,7 +469,9 @@ Item {
readonly property var monitor: Hyprland.monitorFor(modelData)
readonly property real scale: monitor && monitor.scale > 0 ? monitor.scale : modelData.devicePixelRatio
readonly property string figures: modelData.name + " " + scale + " " + modelData.width + " " + modelData.height
function send() { root.reportScreen(modelData.name, scale, modelData.width, modelData.height) }
// These figures only say that something changed; they can be the ones
// from before the change. What is reported is what the compositor says.
function send() { monitorsSoon.restart() }
onFiguresChanged: send()
}
}
Expand Down
8 changes: 7 additions & 1 deletion Linux/omarchy-plugin/WidgetWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ PanelWindow {
readonly property bool animating: visible && frames.length > 1 && !covered && service.status === "running"

screen: service.screenFor(widget.screen)
visible: widget.width > 0 && !service.arranging
visible: widget.width > 0 && !service.arranging && !moving
// When the display a widget is on goes away, its window goes with it and
// does not come up on the display it is given next. Hiding it for a moment
// and showing it again does bring it up there.
property bool moving: false
onScreenChanged: { moving = true; remap.restart() }
Timer { id: remap; interval: 200; onTriggered: panel.moving = false }
anchors { top: true; left: true }
margins { left: widget.x; top: widget.y }
implicitWidth: Math.max(1, widget.width)
Expand Down
2 changes: 1 addition & 1 deletion Linux/omarchy-plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"schemaVersion": 1,
"id": "com.atomsprout.scriptwidget",
"name": "ScriptWidget",
"version": "0.1.1",
"version": "0.1.2",
"author": "AtomSprout",
"description": "Shows the widgets ScriptWidget draws on the desktop layer and passes clicks back to it",
"license": "Apache-2.0",
Expand Down
44 changes: 44 additions & 0 deletions Linux/omarchy-plugin/tests/keyboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
"""Test helper: a virtual keyboard through /dev/uinput, so that key presses go
through the compositor and the input method like a real keyboard's.
Run as root inside the test machine. kbd.py <step>...
Steps: type TEXT (a-z, 0-9, space) | key NAME (enter, space, backspace, esc, end, ctrl+end) | sleep SECONDS"""
import fcntl, os, struct, sys, time

EV_SYN, EV_KEY = 0, 1
UI_SET_EVBIT, UI_SET_KEYBIT, UI_DEV_SETUP, UI_DEV_CREATE, UI_DEV_DESTROY = 0x40045564, 0x40045565, 0x405c5503, 0x5501, 0x5502
ROWS = {"qwertyuiop": 16, "asdfghjkl": 30, "zxcvbnm": 44}
CODES = {letter: base + index for letters, base in ROWS.items() for index, letter in enumerate(letters)}
CODES.update({str(digit): 1 + digit for digit in range(1, 10)})
CODES.update({"0": 11, " ": 57})
NAMED = {"enter": 28, "space": 57, "backspace": 14, "esc": 1, "end": 107, "ctrl": 29, "shift": 42}

fd = os.open("/dev/uinput", os.O_WRONLY | os.O_NONBLOCK)
fcntl.ioctl(fd, UI_SET_EVBIT, EV_KEY)
for code in set(CODES.values()) | set(NAMED.values()):
fcntl.ioctl(fd, UI_SET_KEYBIT, code)
fcntl.ioctl(fd, UI_DEV_SETUP, struct.pack("HHHH80sI", 3, 0x1234, 0x5679, 1, b"scriptwidget-test-keyboard", 0))
fcntl.ioctl(fd, UI_DEV_CREATE)
time.sleep(1.5)

def event(kind, code, value):
os.write(fd, struct.pack("llHHi", 0, 0, kind, code, value))

def press(codes):
for code in codes: event(EV_KEY, code, 1); event(EV_SYN, 0, 0); time.sleep(0.02)
for code in reversed(codes): event(EV_KEY, code, 0); event(EV_SYN, 0, 0); time.sleep(0.02)
time.sleep(0.08)

steps = sys.argv[1:]
index = 0
while index < len(steps):
step, value = steps[index], steps[index + 1]
index += 2
if step == "type":
for letter in value: press([CODES[letter]])
elif step == "key":
press([NAMED[name] for name in value.split("+")])
elif step == "sleep":
time.sleep(float(value))
time.sleep(0.3)
fcntl.ioctl(fd, UI_DEV_DESTROY)
4 changes: 2 additions & 2 deletions docs/linux/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The plan is in [plan.md](plan.md) (Chinese); what was tested is in [testing.md](

## Known limits of the preview

- **Tested on one machine.** Everything a person can see was tested in one aarch64 Omarchy 4.5 virtual machine with a virtual GPU, one 1920×1080 display at scale 1, and a virtual pointer instead of a hand. Not tested: a real computer, a real GPU, display scales above 1, several displays, a light theme, sleep and wake, a restart of the computer with the service enabled (the unit is enabled, the restart was not tried), an input method.
- **Tested on one machine.** Everything a person can see was tested in one aarch64 Omarchy 4.5 virtual machine with a virtual GPU, one 1920×1080 display at scale 1, and a virtual pointer instead of a hand. Display scale 2, a second display with another scale, a display going away, and a light theme were tested there with a virtual second display; a suspend and resume cycle was tested in the kernel's self-resuming test mode, not with real sleep. Not tested: a real computer, a real GPU, a restart of the computer with the service enabled (the unit is enabled, the restart was not tried), and composing Chinese with an input method.
- **The x86_64 archive** was never run on an x86_64 computer. Besides the CI run without a desktop, its programs were run through instruction emulation inside the aarch64 Omarchy 4.5 test machine, against the real desktop there (see [testing.md](testing.md)); that shows the archive is complete and works, not how it behaves on real x86_64 hardware and drivers.
- **ICU.** The programs link the system's ICU 78 by its versioned name. When Arch and Omarchy move to ICU 79 they stop starting until a new archive is built. Fix: link ICU statically, or publish an AUR source package that is rebuilt on the user's machine.
- **Display fonts.** The six display fonts of the other platforms (Apple ][, Larabiefont Free, Monofonto, White Rabbit, OneSlot, Unispace) are not shipped: the repository records no licence for them, and the notice inside `Unispace.ttf` forbids redistribution. Text that asks for one is drawn with Inter. The same files ship in the iPhone, Android and Windows apps; their licences need to be settled there too.
Expand All @@ -14,7 +14,7 @@ The plan is in [plan.md](plan.md) (Chinese); what was tested is in [testing.md](
## Still to do

- **Lock screen.** Omarchy locks through its own shell and sends nothing on logind, and the plugin does not report it, so the service keeps refreshing behind the lock screen.
- **Screens.** No message tells the service a display went away; scales above 1 and moving widgets between displays have code but never ran.
- **Screens.** No message tells the service a display went away: a widget on a display that is gone is shown on the first display at the same coordinates, still drawn at the old display's scale until it is moved. Dragging a widget from one display to another has code but never ran.
- **Time zone changes** are not noticed until the next refresh.
- **Management window:** closing it with unsaved changes does not ask (moving to another page does); no "new file" button; the components and API reference pages of the Windows app are missing; changing the refresh interval writes the setting but does not tell the running service; in the test machine the editor's blinking cursor costs a quarter of a core under software rendering.
- **Plugin:** frames do not pause behind ordinary windows or on the lock screen; the bar entry starts `scriptwidget-studio` without checking that it exists; widgets are not moved when the dock appears later; the Chinese strings were not seen on screen.
Expand Down
2 changes: 1 addition & 1 deletion docs/linux/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ One JSON object a line, UTF-8, each with a string member `event`. A display igno
Examples, exactly as printed:

```
{"event":"hello","protocol":1,"dark":false,"arrange":false,"peek":false,"service":"0.1.1"}
{"event":"hello","protocol":1,"dark":false,"arrange":false,"peek":false,"service":"0.1.2"}
{"event":"widget","id":"5ef2d5c170089ecf","screen":"eDP-1","x":40,"y":40,"width":329,"height":170,"image":"/run/user/1000/scriptwidget/frames/5ef2d5c170089ecf-1d639a55-3.png","version":3,"regions":[{"n":0,"x":16,"y":120,"width":96,"height":34}],"family":"medium","families":["small","medium","large"]}
{"event":"widget","id":"c45467fe6c9c2b4a","screen":"","x":68,"y":68,"width":170,"height":170,"image":"/run/user/1000/scriptwidget/frames/c45467fe6c9c2b4a-1d639a55-1-0.png","version":1,"regions":[],"frames":[{"image":"/run/user/1000/scriptwidget/frames/c45467fe6c9c2b4a-1d639a55-1-0.png","ms":200},{"image":"/run/user/1000/scriptwidget/frames/c45467fe6c9c2b4a-1d639a55-1-1.png","ms":300}],"family":"small","families":["small","medium","large","extraLarge"]}
{"event":"remove","id":"5ef2d5c170089ecf"}
Expand Down
42 changes: 38 additions & 4 deletions docs/linux/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,43 @@ cargo test --locked -p sw-core --test parity -- --nocapture # 只跑一致性

PR 78 的检查(两种架构的 Linux 测试、Apple 平台、编辑器)全部通过后合并。0.1.0 的发布说明里加了"已被 0.1.1 取代"。

## 2026-11-18,第二台测试虚拟机:主题、缩放、第二块显示器、睡眠,以及 0.1.2

- 真实的 Linux 电脑、x86_64、Omarchy 以外的桌面。
机器同上。用的是装好的 0.1.1。这一轮把之前列为"没跑"的项目尽量补上,又发现并修了三个问题。

### 补上的检查

| 检查 | 怎么做的 | 结果 |
| --- | --- | --- |
| 浅色主题 | `omarchy-theme-set "Catppuccin Latte"`,再切回 Tokyo Night | 插件的状态从 `dark: true` 变成 `false` 再变回;每次切换每个小组件运行一次;心情小组件画成了浅色(截图看过),切回后的图和最初的逐字节相同 |
| 缩放 2(修复之后) | 运行中把显示器的缩放改成 2 | 服务按 2 倍画:日历的图从 329×345 像素变成 658×690;截图里文字清晰;点第三个表情有效;摆放模式里拖动 Nyan Cat,位置保存,结束后四个窗口在 `bottom` 层 |
| 缩放来回改 | 1 → 1.5 → 2 → 1 | 每次改完 5 秒内服务里的缩放跟上 |
| 第二块显示器 | `hyprctl output create headless` 加一块虚拟显示器(它的缩放是 2,主屏是 1) | 把日历 `move` 到第二块屏:窗口出现在那块屏的 (100,100),按 2 倍画,主屏上的仍按 1 倍;`grim -o` 截第二块屏,日历清晰;摆放模式在两块屏上各开一个画布 |
| 显示器断开(修复之后) | `hyprctl output remove` | 原来在第二块屏上的日历出现在主屏的同一坐标;再加一块屏、移过去、再断开,同样回到主屏 |
| 睡眠和唤醒 | 这台虚拟机的时钟不能设唤醒闹钟,真的睡下去没法从 SSH 叫醒。改用内核的测试模式:`echo freezer > /sys/power/pm_test` 后 `systemctl suspend`,走完 logind 的睡眠流程,冻结进程 5 秒后自己恢复 | 日志里有完整的 Suspend 流程;恢复后每个小组件的运行次数加 1 |

睡眠测试的局限:没有真的断电睡眠,硬件没有进入低功耗状态。恢复之后 Omarchy 锁了屏;锁屏期间服务仍在刷新(见 [TODO.md](TODO.md))。第二块显示器是虚拟的,没有用测试指针在它上面点过或拖过。

### 发现并修掉的三个问题(都在 0.1.1 里存在)

- **运行中改缩放,小组件仍按旧缩放画,发虚。** 插件用的是外壳自己的屏幕对象,缩放在运行中改变后它不更新,有时还给出改之前的值。现在只报合成器(`hyprctl -j monitors`)说的数:启动时、重连后、外壳的屏幕对象有变化时、合成器报告显示器或配置变化时各问一次,另外每 30 秒问一次以防没有通知。
- **小组件所在的显示器断开后,小组件不见了。** 窗口随显示器一起消失,换到别的显示器后不会重新出现。现在显示器变了就把窗口藏一下再显示,它会出现在主屏的同一坐标。
- **`scriptwidget-studio --edit <不存在的小组件>` 让程序直接退出。** 启动时的请求在窗口建好之前处理,失败时要弹提示,而提示需要窗口自己的状态。现在等窗口建好之后再处理启动请求。从桌面小组件点"编辑"而那个包已经被删掉时会走到这里。

管理窗口这一项是在锁屏期间验证的,真实会话用不了,所以在这台机器上另起了一个无屏的 sway(`WLR_BACKENDS=headless`):0.1.1 的程序在里面以 101 退出,日志里有 panic;修复后的程序开出窗口,停在"我的小组件"页(截图看过)。

修复之后全部测试 512 个通过。插件的检查脚本在这些修改之后没有重跑,因为它需要真实会话。

### 仍然没跑的

- **中文输入法的组字。** 拼音引擎(`fcitx5-chinese-addons`)已经装上,虚拟键盘的脚本也写了(`Linux/omarchy-plugin/tests/keyboard.py`,通过 `/dev/uinput`,按键会经过合成器和输入法)。但睡眠测试之后真实会话锁屏了,解锁要输密码。在无屏的 sway 里用 `wtype` 试过:输入法切到了拼音,但 `wtype` 的按键不经过输入法,进编辑器的是拉丁字母。所以组字还是没有测到。
- **电脑重启后服务自启。** 重启后停在登录界面,要输密码才有图形会话。单元是启用状态,`graphical-session.target` 起来时会拉起它,但没有实际重启验证。
- 真实显卡;真实的 x86_64 电脑。这台 Mac 上做不到。

## 没跑的(汇总)

- 真实的 Linux 电脑、真实的 x86_64 处理器、真实显卡、Omarchy 以外的桌面。
- 画笔和其他平台的图片逐像素对比。
- 后台服务、插件、管理窗口:见上面"阶段 2、3、4"一节里没跑的部分。
- 中文输入法、高分屏缩放、多显示器。
- x86_64 上的窗口和显示:只有 CI 里的无界面测试。
- 中文输入法的组字;电脑重启后服务自启;真的睡眠(只跑过内核的测试模式)。
- 第二块显示器只用虚拟显示器测过;在两块屏之间拖动没有测。
- 后台服务、插件、管理窗口其余没跑的部分,见上面各节。
Loading