chore(layout): move the files of the repository to where they live in the komorebi monorepo

This commit is contained in:
LGUG2Z committed 2026-11-05 11:48:44 -08:00
1 parent eab0b6af35
commit df35d7b258
28 files changed
-6405

No files matched your search

+91
View File
@@ -0,0 +1,91 @@
# ETW spike: what an ETW tap would tell us about window management
Date 2026-10-28, Windows 11 26200, **not elevated** shell (user is in Performance Log Users). No recorder
code was written. Traces and scripts live in the session scratchpad, not the repo.
## Method
`logman create trace <n> -p <guid> 0xffffffffffffffff 0xff -o <n>.etl -ets` for Win32k, User32, Dwm-Core
and Shell-Core (one file session each, plus a real-time `-rt` Win32k session). Then a throwaway
WinForms window owned by a spawned `pwsh` (hwnd 0x2A80880, pid 10404) was driven with `SetWindowPos`
(move, resize, TOPMOST, NOTOPMOST), `ShowWindow` (minimize, restore, hide, show),
`DwmSetWindowAttribute(DWMWA_CLOAK)` and `SetForegroundWindow` over about 6 s. Sessions stopped, decoded
with `tracerpt <etl> -of CSV`. Nothing outside that window was touched.
## Elevation
- **Every session started without elevation**: Win32k, User32, Dwm-Core, Shell-Core, real-time and file.
Nothing was refused; membership of Performance Log Users is enough for user-mode provider sessions.
(`logman query -ets` listed all five as Running.) We did not try the kernel logger (NT Kernel Logger,
`SystemTraceProvider`); that one does need admin and is out of scope.
- `Microsoft-Windows-User32` {B0AA8734...} started fine but emitted **nothing** (2 header events only; it
has no registered manifest on this machine: `wevtutil gp` cannot find it). It is not a window-API trace.
- If a future machine does refuse, the command to try elevated is the same one:
`logman create trace x -p "{8C416C79-D49B-4F01-A467-E56D3AA8234C}" 0xffffffffffffffff 0xff -o x.etl -ets`.
## What the events contain
| Provider | Events in ~22 s | Notes |
|---|---|---|
| Win32k | 102,911 delivered, **817,109 lost** (default buffers) | about 4.7k/s kept, about 42k/s offered, while the desktop was idle |
| Dwm-Core | 216,834, 0 lost | about 10k/s |
| Shell-Core | 48,123, 0 lost | about 2k/s |
| User32 | 0 | nothing |
- **Win32k** is a graphics and input trace (CreateHandle/DestroyHandle/TransformHandle, FlipManager,
touch targeting, pseudo-device, "Info" ids 164/167/301/65...). 79 events carried our pid in the header
during the run, spread over ids 164, 166, 167, 45, 84-87, 452, 453, 2000, and none of them was a
window-management call. The hwnd 0x2A80880 appears in **no** Win32k payload; neither did our rect
(500x400, 600x450) or SWP flags. Payloads are untyped numbers to `tracerpt` (the manifest is in
win32kbase.sys, see below), so even a mapping would be reverse engineering.
- **Dwm-Core** carried our hwnd in 36 events, only in two kinds, both from `dwm.exe`:
- id 84, task `WINDOWNODE_GDISPRITE_ASSOCIATION`: hwnd, then handles. 26 hits.
- id 209 `Stop` (task 137): hwnd, 0, 0, then a 4x4 identity transform matrix. 10 hits. No rect, no
flags, no cloak bit, no z-order, no show/hide. The 10 hits for roughly 11 API calls cannot be tied to
a call without the timestamp alignment.
- **Shell-Core**: no hwnd or pid match at all for our window.
- **Who called?** Header PID/TID of every Dwm-Core event is `dwm.exe` (0x834) and the thread inside it
(0xA50/0xBFC). That is the *consumer* of the change, never the process that called `SetWindowPos`. For
Win32k the header pid is the process that ran the kernel path (ours, 10404, for our own work), which is
the closest to a caller found, but it showed only graphics events, not "this process moved window X".
Sample (Dwm id 209, trimmed):
`Microsoft-Windows-Dwm-Core, Stop, 209, ..., pid 0x834, tid 0xBFC, ..., 0x2A80880, 0x0, 0, 1.0 0 0 0 | 0 1.0 0 0 | 0 0 1.0 0 | 0 0 0 1.0`
## What WinEvents already give
The existing hook (`EVENT_MIN..EVENT_MAX`, `SetWinEventHook`) yields, per top-level window: hwnd plus
class and program (looked up), `EVENT_OBJECT_LOCATIONCHANGE`, `OBJECT_CLOAKED`/`UNCLOAKED`,
`OBJECT_SHOW`/`HIDE`, `SYSTEM_FOREGROUND`, `SYSTEM_MINIMIZESTART/END`, move/size start/end,
`OBJECT_REORDER`, with the event thread/time. Compared with ETW: WinEvents are *per window* and
semantic, ETW is *per frame* and about DWM internals. ETW added no hwnd-level fact the hook lacks, and
neither source yields the rect or flags (the hook consumer can call `GetWindowRect` at record time, which
is already the cheaper way).
## Cost of a tap
- Behind `platform::trace`, as a third tap beside the hook and Event Log. Crate options: `ferrisetw`
(real-time `UserTrace` and a callback, schema decode through TDH) or the `windows` crate
`StartTraceW/EnableTraceEx2/OpenTraceW/ProcessTrace`. About 1.5 to 2 days including dropping
events on a hot path and a session that must be stopped at crash (a leaked session survives the
process; use a unique name and `ControlTrace(STOP)` on startup).
- It fits the oslog record shape (`ts, source, process, message`), but only by flattening each event to
`provider:id task` plus untyped numbers, which is not useful to read.
- Noise is the problem: 10k to 40k events/s from Win32k and Dwm-Core with nothing happening, almost all
of it frame pacing. It would need a per-id allowlist and still shows nothing we want.
## Recommendation: **don't build it**
None of the four goals (hwnd, rect, flags, caller) come out of the providers that are available without
elevation. What would give them is not an ETW provider but a komorebi-side change:
1. Have komorebi log, at the place it applies a layout (its `WindowManager::update_*` and `Window::set_position`,
`hide`, `cloak` paths), the hwnd, target rect, SWP flags, and `reason` (which event or command caused
it) into its own state/notification stream; the recorder already ingests that stream.
2. If the *foreign* caller is wanted (an app fighting the tiling), the practical method is a `WH_CBT`
or `WH_CALLWNDPROC` hook with `WM_WINDOWPOSCHANGING`, which carries the `WINDOWPOS` struct (hwnd,
rect, flags) and runs in the caller's context. That needs a DLL injected and is a much bigger step
than a trace tap; the cheaper step is to take a `GetWindowRect` snapshot on each ObjectLocationChange
in the recorder (a few extra lines in `win/trace.rs`) and record the flags komorebi sets itself.
3. Revisit ETW only if a Microsoft-Windows-Win32k manifest with window-position events turns up in a
later Windows build, or if we accept the kernel logger (admin) for a one-off diagnostic.
+117
View File
@@ -0,0 +1,117 @@
# KDE checkpoints
`komorebi-recorder` is built and tested on Linux, but with no KWin to talk to: what touches a real Plasma session was
written from KWin's and komorebi for KDE's sources and has not been seen running. Each checkpoint below is a short list
of commands to run on a Plasma 6.8 session that runs komorebi for KDE, what to expect, and what to send back. The point
of each is to replace something read in a source with something observed.
Send back, for any step that does not behave: the exact command, what it printed, the output of
`komorebi-recorder doctor --json`, and the session directory if there is one.
## What has been seen
Against komorebi for KDE's in-memory desktop (`komorebi --fake-backend`, which has no windows) and the Wayland compositor
of WSLg (which has outputs and no screencast):
- `doctor` names komorebi for KDE and finds its socket in `$XDG_RUNTIME_DIR/komorebi`;
- `record --no-video` records its log, its commands as events with the handler of each, and the journal in two streams,
and `events`, `summary` and `findings` read the session with the KDE rules;
- the displays are listed from the compositor, with a size and a position;
- a made-up source of frames is written to an H.264 file, which the decoder reads back, at the size of the display and
at an odd size.
And in the Plasma guest of komorebi for KDE (`nix run .#run-kde`, KWin 6.8.2, komorebi with windows, headless over ssh;
the recorder from `nix build` runs in it, as the guest mounts the host's store):
- **K1:** `doctor` says `permitted: yes` and a recording works with no desktop file written. Whether KWin offers the
screencast to every program, or this guest's configuration allows it, was not found out.
- **K2:** a recording of the output is a playable H.264 file with the windows, the panel and the cursor in it, and its
length is the recording's. The frames' times were wrong at first (the GStreamer pipeline took the clock of the
PipeWire stream, which starts at zero) and are on the master clock now. The log, the events and their handlers line up.
- **K3:** the rule that leaves the recorder's window out of the capture works: a window of the class
`komorebi-recorder` that had the focus and was on top is not in the video, and one of another class is. KWin 6.8
rewrites `kwinrulesrc` with `Order=` in place of `count=` and `rules=`, and the recorder extends whichever the file has.
- **`--probe-windows`:** a window of an event is found in KWin and its facts are read: frame, minimized, the desktops. The
probes of a recording with workspace switches, a new window, a stack and a closed window agree with komorebi, and the
one of a window that was closed says it no longer exists. komorebi's workspaces are KWin's virtual desktops, so a
window of another workspace is not on the desktop that shows; the park desktop holds only windows hidden behind a
front one. What was not seen: a probe that disagrees with komorebi (nothing was broken), and a window that cannot be
told from another by class, title and frame (it has no probe).
## Getting the binary
```sh
nix build .#komorebi-recorder --out-link result
result/bin/komorebi-recorder doctor
```
The package wraps the program so that GStreamer finds its plugins (`gst-libav`, `x264enc`, the PipeWire source) and the
program finds `libwayland-client`. Outside Nix, install the same.
## K0: what komorebi for KDE really sends
Status: **can be run now, and is the most useful one.** The rules that read komorebi for KDE's events, `State` and log
were written from its source and checked against its log and commands, not against windows (the analysis says so in a
warning until they have been).
1. Start komorebi for KDE with debug logging: `komorebi --log-level debug` (or `RUST_LOG=komorebi=debug`).
2. `komorebi-recorder doctor`. Expect `komorebi for KDE`, `running: yes`, the socket under `$XDG_RUNTIME_DIR/komorebi`
answering a state query, the log directory `~/.local/share/komorebi` with a `komorebi_plaintext.log.<date>` in it, your
outputs, and `clock: Monotonic`.
3. Record 60 seconds with `--no-video`, and during them: open and close a few windows of different programs, focus
between them, drag one to a new place and drag-resize one, stack and unstack, switch workspaces
(`komorebic focus-workspace 1` and back), and lock and unlock the screen.
4. `komorebi-recorder events <session>`. Expect each window event with its window id, program and notification
(`WindowAdded`, `InteractiveMoveFinished`, ...), each with a handler. Send back any event named `unreadable` or
classified `other`, any window event with no handler, and any `MoveEnd` that is not classified `drag`.
## K1: the screencast is offered, and what it asks
Status: not run. This is the one the Linux host depends on.
1. `komorebi-recorder doctor`: under `capture`, `permitted: no` and the note with the desktop file.
2. Write `~/.local/share/applications/komorebi-recorder.desktop` as the note says (`Exec=` is the path of the executable
that runs), and start the recorder again. Expect `permitted: yes`. In the Nix package the program
is a wrapper that starts `.komorebi-recorder-wrapped`, and that is the executable the compositor sees, so it is the path
`doctor` prints (it is `current_exe`).
3. If it is still `no`: say where KWin looks for desktop files and how it matches the program to one. Whether a
desktop file in the user's `applications` directory is enough, whether `Exec=` has to be the executable's real path,
and whether a program started from a terminal is matched at all, are what this finds out. If it cannot be made to
work, the screencast portal (`xdg-desktop-portal`) is the way around it, behind the same `CaptureBackend`.
## K2: recording the screen
Status: not run.
1. `komorebi-recorder displays`. Expect each output with its size and position in the layout (logical pixels). Compare the
ids with komorebi's: `komorebic monitor-information` (they agree for a monitor with no serial number).
2. `komorebi-recorder record --duration 20`, and move windows during it. Expect a `video-<id>.mp4` for each output and
`frames-<id>.csv`, and in the session summary no error.
3. Play it with `komorebi-recorder view <session>`. Expect the picture to move with the windows, and the cursor in it.
4. `komorebi-recorder doctor --json`: the clock check (`latency`) of the segments should be near zero. A large number
means the frames' times are not on the master clock, which would be the PipeWire timestamps: send the numbers back.
5. Leave the screen still for ten seconds: the video should still advance (the last frame is repeated).
6. Unplug a monitor, or turn one off, if there is one to spare: the segment ends and a new one starts when it returns.
7. Suspend and resume: every output starts a new segment.
## K3: the program's own window
Status: not run.
1. `komorebi-recorder` with no command opens the window. Expect it to be titled `komorebi-recorder` and not tiled.
2. If it was tiled, `komorebic ignore-rule class komorebi-recorder` was not applied in time, or the window's class is not
what is expected: `komorebic state` says what the window's class is.
3. `record` writes a KWin window rule (`~/.config/kwinrulesrc`, group `komorebi-recorder-exclude-from-capture`) that
forces `excludefromcapture` for the class `komorebi-recorder`. Record with the window open and play the video: the
window should not be in it. If it is, say whether `kwinrulesrc` has the rule, whether System Settings > Window
Rules shows it, and what `qdbus6 org.kde.KWin /KWin supportInformation` says of the window's class.
## K4: the OS trace and the window track
Status: the journal was followed on a machine with no Plasma.
1. `record --duration 30`, and cause some noise: open a program that is not in the session, plug something in.
Expect `oslog/system.ndjson` to have `kwin_wayland` and `plasmashell` entries, and `oslog/eventlog.ndjson` the warnings.
A user who is not in the `systemd-journal` group may see none of the system's: the problems say so.
2. `record --duration 30` (the window track is on by default). Expect `windows.jsonl` with the windows komorebi manages, a window behind a
stack not shown, and a window of another workspace not shown.
+216
View File
@@ -0,0 +1,216 @@
# Windows checkpoints
`komorebi-recorder` is built for Windows from a Mac (and, in CI, on Windows), so nothing that touches a real
Windows desktop has been seen running. Each checkpoint below is a short list of commands to run on a Windows PC or
VM, what to expect, and what to send back. The point of each is to replace something read in
komorebi's source with something observed.
Send back, for any step that does not behave: the exact command, what it printed, the output of
`komorebi-recorder.exe doctor --json`, and the session directory if there is one.
## Getting the binaries
On the Mac, in this repository:
```sh
nix build .#komorebi-recorder-windows --out-link result-windows
ls result-windows/bin
# komorebi-recorder.exe console build: use this one to run commands and read their output
# komorebi-recorder-gui.exe the same program without a console window (shortcuts, the viewer)
```
Copy `komorebi-recorder.exe` to the Windows machine. The `windows` job of CI builds the same executables natively and
uploads them, with the installer, as artifacts of the run. To check that the Windows code still type-checks
without building it: `nix flake check` (the `komorebi-recorder-windows-clippy` check) or
`nix develop .#windows --command cargo clippy --all-targets`.
## W0: what komorebi for Windows really sends
Status: **can be run now, and is the most useful one.** Reading komorebi for Windows' events, state
and logs was written from komorebi's source and has not been checked against a recording of it (the
analysis says so in a warning until it has); this is what checks it.
1. Start komorebi for Windows with debug logging. The default of `RUST_LOG=debug` also prints every
dependency, so name the crate:
```powershell
komorebi.exe --log-level debug
```
(or set `RUST_LOG=komorebi=debug` first).
2. Describe the machine:
```powershell
komorebi-recorder.exe doctor
komorebi-recorder.exe doctor --json > doctor.json
```
Expect: `komorebi for Windows`, `running: yes`, a binary path and version, `log level: debug`,
`answers a state query: yes`, the log directory under `%TEMP%` with a `komorebi_plaintext.log.<date>`
in it, your displays with their scale, and `clock: Qpc`. `can record: yes` and `can decode: yes`
are what this build claims; whether they are true is W1 and W3. Anything under "things to know"
is worth reading. If the state query is
reported as answered with nothing, say what komorebi was doing (paused, another virtual desktop).
3. Record 60 seconds without video, and during them:
- focus a few windows of different programs (click, and with `komorebic.exe focus left|right`);
- drag a window to a new place, and drag-resize one;
- move windows with komorebic (`move`, `stack`, `unstack`, `focus-workspace 1` and back);
- open and close a program, and minimize and restore one;
- if you can: change the display scaling or resolution, connect or disconnect a monitor, switch to
another virtual desktop and back, lock (Win+L) and unlock once.
```powershell
komorebi-recorder.exe record --no-video --duration 60 --out C:\temp\w0
```
Expect a line per second with `events` counting up as you act, `komorebi log` growing and `OS
trace` counting up (WinEvents for every window, so it is busy while you work), then `session:
C:\temp\w0`. If the OS trace is too much or too little, say so: it is folded per window but its
volume on a real machine has not been seen. `--no-oslog` leaves it out.
4. Look at it, to see what the current (macOS-vocabulary) analysis makes of it. It is expected to be
wrong in places, and what is wrong is the point:
```powershell
komorebi-recorder.exe brief C:\temp\w0
komorebi-recorder.exe events C:\temp\w0 --json > events.json
```
5. Send back `doctor.json` and the whole `C:\temp\w0` folder, zipped. It contains the titles and
program names of your windows (`events.jsonl`, `states\*.json`, `komorebi.log`); redact them first
if that matters (they only need to still be valid JSON, and the Windows fixtures are scrubbed by
hand anyway).
Also worth one run, for the checks komorebi's state cannot make (it hides windows by cloaking them
in place): record with the probe on, and switch workspaces a few times (`komorebic.exe
focus-workspace 1`, `2`, `1`) while focusing windows.
```powershell
komorebi-recorder.exe record --probe-windows --no-video --duration 60 --out C:\temp\w0-probe
komorebi-recorder.exe overview C:\temp\w0-probe
```
`overview` should report nothing about hidden windows if komorebi and Windows agree. If it reports
`visible-window-hidden` or `hidden-window-visible`, `komorebi-recorder.exe trace C:\temp\w0-probe
event:<n>` shows what Windows said; say whether it is a real fault or a false alarm (a window mid
transition, say), and how many there were. The probe asks komorebi about a window by `DebugWindow`;
if komorebi stalls while it runs, say so.
Optional, for the part of the plan that stops the recorder window being tiled: for one window komorebi
manages and one it does not (get handles from `komorebic.exe state`), run
```powershell
komorebi-recorder.exe doctor --probe window --hwnd <handle>
```
and send what komorebi says.
## W1: capture and the clock across a sleep
Status: **can be run now.** Windows capture, the power watcher and the OS trace are built but have
never run on Windows; these are the first runs.
1. The clock across a sleep (see above): `doctor --probe clock --seconds 120`, sleeping the machine
for about a minute while it runs.
2. Capture on a static screen. Leave the screen completely still for most of it:
```powershell
komorebi-recorder.exe doctor --probe capture --seconds 20
```
Expect, per display, a segment with a handful of frames, `idle callbacks 0` (Windows says nothing
about a still screen), a file that `plays` for about the length recorded, and `latency` of a few
milliseconds to well under a second, `(NOT on the host clock)` absent. Check it with ffmpeg if you
have it: `ffprobe <session>\video-<id>.mp4`.
3. Two monitors, if you have them: the same again, and say what it printed for each.
4. Kill it and play the file. Start a longer one, then end it without letting it stop:
```powershell
komorebi-recorder.exe doctor --probe capture --seconds 60
# after 15 s, from another window:
taskkill /F /IM komorebi-recorder.exe
```
Then try to play `video-*.mp4` in the session folder (any player), and run
`komorebi-recorder.exe reindex <session>`. This answers whether Media Foundation's fragmented MP4
survives a kill (the part before the last fragment, about a second, should play) and whether
`reindex` can recover the session. Say what the player did and what `reindex` printed.
## W2: a real recording, and the machine doing the things
Status: can be run once W1 shows capture works.
```powershell
komorebi-recorder.exe selftest --seconds 8
komorebi-recorder.exe record --duration 60 --out C:\temp\w2
komorebi-recorder.exe reindex C:\temp\w2
```
`selftest` needs `ffmpeg` on PATH; expect `PASS` with the worst disagreement under 100 ms. During the
60 s recording: dock or undock a display, put the machine to sleep and wake it, lock and unlock
(Win+L), and close the lid if it is a laptop. Afterwards `komorebi-recorder.exe summary C:\temp\w2`
and `komorebi-recorder.exe at C:\temp\w2 <time> --source recorder` should show each as an incident
(`suspend`, `wake`, `lid-closed`, `screen-locked`, ...) next to the video gaps. Send back the session
folder (the video is large; the rest is what matters, say so if you leave it out) and anything that
looked wrong.
## W3: playing it back
Status: can be run once W1 shows capture works.
```powershell
komorebi-recorder.exe doctor --probe decode --file C:\temp\w2\video-<id>.mp4
```
Expect the video's size and duration, a first frame in well under a second, and a speed in frames
per second, then three seeks each answered with a frame at or just before the time asked for. Say
if any answers "no frame" or is far from what was asked.
## W4: our windows
Status: can be run once W1 shows capture works.
1. Start komorebi, then open the viewer on a Windows session: `komorebi-recorder-gui.exe view
C:\temp\w2`. It should open floating (not tiled into your layout) and be usable: moving, resizing,
minimizing and closing it. If komorebi tiles it, say so.
Its taskbar button and Alt+Tab entry should show the watermelon icon.
2. Ask komorebi what it thinks of it. Set `KOMOREBI_RECORDER_PROBE_WINDOW=1` before starting the
viewer (or the recorder window), wait a few seconds, and send back
`%TEMP%\komorebi-recorder-window-probe.txt`.
3. Open the recorder window (`komorebi-recorder-gui.exe`) and the viewer, record 10 s with them
open, and check neither appears in the video (`doctor` warns if this Windows is too old to keep
them out).
4. The OS trace: `komorebi-recorder.exe record --duration 20 --out C:\temp\w4` while moving a
window about, then `komorebi-recorder.exe trace C:\temp\w4 event:<a MoveResizeEnd or FocusChange>
--os`. It should list what Windows told komorebi around that event, grouped by program. Say what
the volume looked like (`summary` shows the counts) and whether it was too much or too little.
## W5: the installer
Status: can be run once CI has built one. WiX only runs on Windows, so what a Mac can check about the installer is
`tests/packaging.rs`; everything below is first seen here. The installer is not signed, so SmartScreen or Defender may
warn on the first run.
1. Download the MSI from the `windows` job's artifact (or the nightly release) and install it. Open a new shell and run
```powershell
komorebi-recorder doctor
```
That it runs proves the `PATH` entry. `Program Files\komorebi-recorder\bin` should hold `komorebi-recorder.exe` and
`komorebi-recorder-gui.exe`.
In Explorer both executables should show the watermelon icon, and so should the entry in Apps & features.
2. Install a second build over it, such as the next nightly. It should upgrade in place: one entry in Apps & features,
not two.
3. Uninstall it. The files and the `PATH` entry should go. If komorebi for Windows is installed from its own MSI, check
that it is untouched: the two installers must not upgrade or uninstall each other.
4. The ARM64 installer has only been cross-built on an x86_64 runner. If you have an ARM64 machine, repeat 1 to 3 with it.