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
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ jobs:
node-version: 22
- name: Syntax
run: |
cp "gnome-shell/smbact@giglabo.com/extension.js" "$RUNNER_TEMP/extension.mjs"
node --check "$RUNNER_TEMP/extension.mjs"
cp "gnome-shell/smbact@giglabo.com/snapshots.js" "$RUNNER_TEMP/snapshots.mjs"
node --check "$RUNNER_TEMP/snapshots.mjs"
for f in extension snapshots dragSource hitTest; do
cp "gnome-shell/smbact@giglabo.com/$f.js" "$RUNNER_TEMP/$f.mjs"
node --check "$RUNNER_TEMP/$f.mjs"
done
node --check kwin/smbact-kwin.js
python3 -m py_compile scripts/call.py
python3 -c "import json; json.load(open('gnome-shell/smbact@giglabo.com/metadata.json'))"
- name: Tests
run: node --test tests/*.test.mjs
- name: Pack
run: scripts/pack.sh
- uses: actions/upload-artifact@v4
Expand Down
142 changes: 139 additions & 3 deletions PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ is not running; GNOME's own allow-lists have the same limit.
```

Error codes: `BAD_REQUEST` (not JSON, missing or wrong arguments), `UNKNOWN_OP`, `NO_WINDOW`, `GRAB_FAILED`
(`grabAccelerator`: the shell refused the accelerator), `NO_SNAPSHOT` (`snapshot`: none taken yet), `FAILED` (the
shell threw; `message` has its text).
(`grabAccelerator`: the shell refused the accelerator), `NO_SNAPSHOT` (`snapshot`: none taken yet),
`TILING_EXTENSION_ACTIVE` (`nativeTiling`: a tiling extension holds the key itself), `FAILED` (the shell threw;
`message` has its text).

Unknown fields in a request are ignored; new optional fields and new operations do not change the API number. A
change that breaks an existing operation does, and `hello` reports which API the plugin speaks.
Expand Down Expand Up @@ -120,6 +121,14 @@ XWayland. Rectangles are `{ "x", "y", "width", "height" }`.
| `ungrabAccelerator` | `accelerator` (as grabbed) | `{ released }` |
| `snapshots` | `ids`, `maxSize?` (px, default 480, at most 1024), `background?` (`#rrggbb`, default white) | `{ snapshots: Snapshot[] }` (the cached ones) |
| `snapshot` | `id` | `{ snapshot }` |
| `dragWatch` | `table` (a zone table, or `null` to stop) | `{ watching, reason?, draws, restoreDuringMove, modifier? }` |
| `dragAnswer` | `drag`, `allow` | `{ ok }` (`false`: no such drag running) |
| `dragRestoreSize` | `drag`, `width`, `height` | `{ ok }` (`false`: no such drag, or the window is maximized) |
| `nativeTiling` (GNOME) | `suppress?` (`true` hold off, `false` give back, absent: read) | `{ edgeTiling, user, held, saved?, tilingExtension }` |
| `nativeTiling` (KWin) | `suppress?` (as above), `options?` (`["electricBorderTiling", "electricBorderMaximize"]`, default both) | `{ electricBorderTiling, electricBorderMaximize, held, saved }` |

The last four come with plugin 2.2.0, in the GNOME Shell extension and the KWin script; see "Window drags", "Mutter's
edge tiling" and "KWin's screen-edge tiling" below.

- `setState` states: `minimized`, `maximized`, `maximizedHorizontally`, `maximizedVertically`, `fullscreen`,
`above`.
Expand Down Expand Up @@ -155,6 +164,127 @@ XWayland. Rectangles are `{ "x", "y", "width", "height" }`.
- `showDesktop` with `show: true` minimizes the visible windows of the active workspace and remembers them; `false`
restores those.

## Window drags (plugin 2.2.0)

SMBAct places a window the user drags to a screen edge or corner (its "positioning with the mouse"). The plugin is
its drag source on GNOME and on KDE Plasma: it reports when a window is dragged and which zone of SMBAct's table the
pointer is in, and nothing else. It draws nothing (SMBAct draws its zone map and the footprint itself, `draws: false`)
and moves no window at the end of a drag (SMBAct's own action does, through `moveResize` / `setState`). The rules
below are the GNOME Shell extension's; the KWin script's differences follow them ("The KWin script's drags").

`dragWatch` gives the table; drags are reported only while one is set:

```json
{ "seq": 3, "space": "logical", "armDelayMs": 0, "sharedEdgeDelayMs": 400, "stickPx": 24, "modifier": "shift",
"zones": [ { "id": "d0/left", "display": "d0", "area": "left", "action": "left-half",
"triggers": [ { "x": 0, "y": 96, "width": 30, "height": 888 } ], "when": "no-modifier", "shared": false } ] }
```

- `triggers` are half-open rectangles in the compositor's coordinates; a zone with two (an L-shaped corner) counts in
either. `when`: `plain` (any drag), `modifier` (only while the modifier is held), `no-modifier` (until the modifier
is pressed once during the drag). `shared` zones (on an edge between two monitors) arm after `sharedEdgeDelayMs`,
the others after `armDelayMs`; moving on to a neighbouring zone while one is armed re-arms at once. An armed zone
holds the pointer up to `stickPx` outside its triggers. The rules are SMBAct's hit-test; `hitTest.js` is a port of it
and runs SMBAct's fixtures (`tests/`).
- A drag is a pointer move of a normal, movable, resizable window that is not fullscreen, with the primary button:
`grab-op-begin` with `(op & ~UNCONSTRAINED) === MOVING` (the title bar, a client-side drag, the top bar, Super+drag).
Keyboard moves, resizes and touch drags are not reported. One drag at a time.
- The pointer and the modifiers are sampled every 16 ms during the drag (`global.get_pointer()`); the modifier bits
are shift 1, ctrl 2, alt 4, super 8.

Events: `{ "type": "drag", "event": <event> }`, where `<event>` is one of

```json
{ "type": "begin", "drag": 7, "window": { "OwnerHandle": 3306, "Handle": 3209482314 }, "frame": { "x": 900, "y": 300, "width": 640, "height": 467 },
"pointer": { "x": 1220, "y": 318 }, "press": { "x": 1220, "y": 318 }, "table": 3, "time": 81234.5, "owner": "gedit" }
{ "type": "zone", "drag": 7, "zone": "d0/left", "pointer": { "x": 8, "y": 500 } }
{ "type": "end", "drag": 7, "zone": "d0/left", "cancelled": false, "frame": { "x": -312, "y": 482, "width": 640, "height": 467 }, "pointer": { "x": 8, "y": 500 } }
{ "type": "end", "drag": 7, "zone": null, "cancelled": true, "reason": "escape", "frame": { "x": 900, "y": 300, "width": 640, "height": 467 }, "pointer": { "x": 8, "y": 500 } }
```

- `window`: `Handle` is the window's `id` (as in `Window`), `OwnerHandle` its pid; `frame` is the frame at the begin;
`table` the `seq` hit against; `time` the shell's monotonic clock in ms.
- `zone` reports transitions only (armed, re-armed, disarmed with `null`), never the pointer stream.
- `end`: `zone` is the zone of the drop (the armed one, or a fast throw into a zone that arms at once), `null` for
none. `cancelled` when the grab ended with the button still down (Escape) or with the window back where it began
(Mutter puts it back on Escape); then `reason` is `escape` or `put-back`. A drag also ends cancelled when its window
goes away (`window-closed`), the monitors change (`displays-changed`), the workspace changes without the window
(`workspace-changed`), a zone would arm while the overview is open (`overview`) or over a monitor showing a
fullscreen window (`fullscreen`), or the watch stops (`stopped`); `frame` is `null` then.

`dragAnswer` is SMBAct's answer to `begin` (may this window be placed); `allow: false` keeps the window as it is.
`dragRestoreSize` gives the dragged window a size back: once the pointer is 12 px off the press, the window gets
`width` x `height` during the move, with the pointer at the same share of its width and at the same height in it where
it grabbed it; once per drag. A window maximized both ways is Mutter's to restore (`{ ok: false }`); a one-axis
maximize (how SMBAct holds a full-height half) is left first.

### The KWin script's drags

The same operations, events and table; what KWin gives a script makes these differences:

- A drag is a window's `interactiveMoveResizeStarted` with `move` set (the same signal starts resizes) of a normal,
movable, resizable window that is not fullscreen; it ends with `interactiveMoveResizeFinished`. A move started from
the keyboard (the window menu's Move, a shortcut) is not reported: KWin puts the pointer on the window's centre for
it, which a title-bar drag past KWin's threshold never is.
- The pointer comes from `workspace.cursorPos` on every `workspace.cursorPosChanged` (connected during a drag only); a
pause of a shared edge ends on a timer, without pointer motion. `begin`'s `press` is the pointer when KWin started the
move (a few pixels past the real press), `time` is `Date.now()`.
- **No modifiers.** KWin tells a script nothing about keys or buttons: every sample carries flags 0, so the table must
hold only `plain` zones, and `dragWatch` answers `modifier: false`. Shift during a drag is KWin's own: it drops the
window into KWin's custom tile under the pointer, whatever its options say.
- `end` comes after KWin applied its own result. Escape: KWin has put the window back where it began after it had left
that place, and the pointer is elsewhere (`cancelled`, reason `escape`). A KWin tile (Shift's custom tile, or KWin's
own edge tiling when it is not held off) or a KWin maximize at the end ends the drag with `zone: null`, cancelled,
reason `tiled` or `maximized`. A window closed (`window-closed`), the outputs changed (`displays-changed`), the
desktop changed without the window (`workspace-changed`; KWin's "Switch desktop on edge" carries the dragged window
along, and the drag goes on there), a zone over an output showing a fullscreen window (`fullscreen`) and the watch
stopped (`stopped`) end it as on GNOME. There is no overview reason.
- `dragRestoreSize` writes `frameGeometry` during KWin's move once the pointer is 12 px off the start: KWin keeps the
size for the rest of the move and keeps the pointer at the same share of the window where it grabbed it. A one-axis
maximize is left first; a window maximized both ways or in a KWin tile at the start is KWin's to restore
(`{ ok: false }`). Written again (at most 3 times) when KWin did not keep it.

## Mutter's edge tiling (GNOME, plugin 2.2.0)

`nativeTiling` holds `org.gnome.mutter edge-tiling` off for the client and gives it back:

- `suppress: true` saves the user's own value (or that there was none), writes `false` and holds it; repeated calls
keep the first saved value. It is refused with `TILING_EXTENSION_ACTIVE` while an extension that holds the key
itself is active (Ubuntu's Tiling Assistant, `tiling-assistant@ubuntu.com` / `@leleat-on-github`, Tiling Shell): the
write would end up in that extension's own restore record.
- `suppress: false` puts the saved value back (resets the key when there was none), only over its own `false` and
never while such an extension is active.
- When somebody else switches the key on during the hold (Settings, another extension being disabled), the hold ends
without a write: no fight over it.
- The hold belongs to the client, like grabs: it is given back when the owner of `com.giglabo.SMBAct` goes away or
changes, and when the extension is disabled (a screen lock). A client that starts again holds again.
- The reply: `edgeTiling` the effective value, `user` the user's own (`null`: none), `held`, `saved` while held,
`tilingExtension` the uuid of an active extension that holds the key, or `null`.

The drag watch belongs to the client too: it stops when the client goes away or changes, and when the extension is
disabled.

## KWin's screen-edge tiling (KWin script, plugin 2.2.0)

`nativeTiling` holds KWin's own drag tiling off for the client and gives it back: System Settings › Screen Edges,
"Tile: Windows dragged to left or right edge" (`kwinrc [Windows] ElectricBorderTiling`) and "Maximize: Windows dragged
to top edge" (`ElectricBorderMaximize`), both on by default.

- The script sets KWin's live `options.electricBorderTiling` / `electricBorderMaximize` (`options`: which, default
both). That is KWin's memory only: kwinrc is not written, so System Settings keeps showing both boxes ticked, and
KWin's next start or `reconfigure` reads kwinrc again.
- `suppress: true` saves the value KWin has now and sets `false`; repeated calls keep the first saved value. KWin
re-reads kwinrc on every reconfigure (any "Apply" in System Settings, `options.configChanged`): the hold saves what
KWin brings (the user's choice now) and sets `false` again.
- `suppress: false` puts the saved values back (only `options` when given).
- The hold belongs to the client: a script's call that fails reaches no callback, so while it holds something (the
tiling hold or the drag watch) the script asks the bus every 2 s whether `com.giglabo.SMBAct` has an owner
(`NameHasOwner`); when it has none, the saved values go back and the drag watch stops. The script itself is loaded
by the client and unloaded by it; unloading leaves KWin's options as they are, so the client gives the hold back
first (or lets KWin re-read kwinrc).
- The reply: `electricBorderTiling` and `electricBorderMaximize` as KWin has them now, `held`, `saved` (per held option,
the value it found).

## Events

`Event` carries `{ "type": ..., ... }`:
Expand All @@ -164,6 +294,7 @@ XWayland. Rectangles are `{ "x", "y", "width", "height" }`.
- `accelerator` with `accelerator` (the string given to `grabAccelerator`) and `time` (the key press's timestamp,
usable as `activate`'s `time`).
- `snapshot` with `id`: a snapshot asked for with `snapshots` is ready.
- `drag` with `event`: a window drag against the client's zone table (see "Window drags").

## History

Expand All @@ -174,6 +305,9 @@ XWayland. Rectangles are `{ "x", "y", "width", "height" }`.
- API 1, plugin 2.0.0 (2026-11): the first full release, with SMBAct 2.0.0; the same API as 1.0.0-alpha.3.
- API 1, plugin 2.1.0 (2026-11): `connector` in `displays`, `onActiveWorkspace` and (KWin) `tiled` in the window
(new optional fields, same API), with SMBAct 2.1.0.
- API 1, plugin 2.2.0 (not released yet): `dragWatch`, `dragAnswer`, `dragRestoreSize`, `nativeTiling`, the `drag`
event, in the GNOME Shell extension and the KWin script (new operations, same API; clients look for them in
`hello`'s `ops`).

## KWin transport

Expand All @@ -197,7 +331,9 @@ What the KWin script does not have: `snapshots` / `snapshot` (KWin offers window
SMBAct's own X11 hotkeys fire with any focus: KWin passes key combinations to XWayland apps), `iconPng` (a window's
icon is a QIcon: the script reports `desktopFile` and SMBAct looks the icon up), and the X11 marks (`client`,
`x11Window` are `null`: KWin's scripting API does not tell X11 from Wayland windows; SMBAct matches them against the X
server's own list). Window ids are the first 32 bits of KWin's UUID for the window (stable across reloads).
server's own list). Window ids are the first 32 bits of KWin's UUID for the window (stable across reloads). The
window drags and `nativeTiling` (plugin 2.2.0) have KWin's differences ("The KWin script's drags", "KWin's
screen-edge tiling"); the drag events go out as `Event` calls like the others.

- API 1, plugin 1.0.0-alpha.3 (2026-11): the KWin script (`kwin/smbact-kwin.js`).

18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Shell plugins for SMBAct, the window management app: a GNOME Shell extension and a KWin script (KDE Plasma 6). On a
Wayland session only the compositor knows every window, so SMBAct asks it through these plugins: the window list,
moving and resizing, activation, window states, displays; on GNOME also global hotkeys and window snapshots.
moving and resizing, activation, window states, displays, the window drags SMBAct places with the mouse; on GNOME also
global hotkeys and window snapshots.

The plugins are thin executors. They hold no product logic and do nothing on their own; SMBAct installs them and
calls them over D-Bus. The protocol is in [PROTOCOL.md](PROTOCOL.md).
Expand All @@ -28,7 +29,9 @@ everyone else.

`kwin/smbact-kwin.js` — KDE Plasma 6 (checked on Plasma 6.6). SMBAct loads it into KWin itself when it starts
(`org.kde.KWin` `/Scripting`), nothing to install and no new login; it unloads it when it quits. A KWin script cannot
serve D-Bus calls, so the script calls SMBAct instead (PROTOCOL.md, "KWin transport"); it answers only to KWin.
serve D-Bus calls, so the script calls SMBAct instead (PROTOCOL.md, "KWin transport"); it answers only to KWin. While
SMBAct handles window drags it holds KWin's screen-edge tiling off in KWin's memory (nothing written to kwinrc) and gives
it back when SMBAct asks or leaves the bus.

By hand, with something serving `com.giglabo.SMBAct.KWin1` (SMBAct does):

Expand All @@ -42,7 +45,16 @@ qdbus6 org.kde.KWin /Scripting/Script<id> org.kde.kwin.Script.run
A tag `vX.Y.Z` (equal to `version-name` in `metadata.json`; `vX.Y.Z-alpha.N`, `-beta.N`, `-rc.N` become pre-releases) makes GitHub Actions publish
`smbact@giglabo.com.shell-extension.zip`, `smbact-kwin.js` and `SHA256SUMS` as a release (the KWin script's `VERSION`
must match too). SMBAct pins a tag and checks the sha256 of both.
Every push to `main` and every pull request runs the checks and packs the zip (`.github/workflows/`).
Every push to `main` and every pull request runs the checks and the tests and packs the zip (`.github/workflows/`).

## Tests

`node --test tests/*.test.mjs`: the drag hit-test (`gnome-shell/smbact@giglabo.com/hitTest.js`) against SMBAct's shared
fixtures (`tests/fixtures/`, see its README for where they come from), and the KWin script (`kwin/smbact-kwin.js`) in a
fake KWin (`tests/kwin.test.mjs`: the same fixtures through its own copy of the hit-test, its drag source, the hold of
KWin's screen-edge tiling, the watchdog). The rest is checked live in SMBAct's test VMs (smbact-app
`scripts/dev/linux/drag-snap/gnome/` and `scripts/dev/linux/drag-snap/kde/`). By hand: `scripts/call.py --drag
table.json 60` prints the GNOME extension's drag events against a zone table.

## License

Expand Down
Loading
Loading