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
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ jobs:
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"
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: Pack
run: scripts/pack.sh
- uses: actions/upload-artifact@v4
with:
name: smbact-shell-gnome
path: dist/*.zip
path: |
dist/*.zip
dist/smbact-kwin.js
11 changes: 8 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ jobs:
echo "tag $GITHUB_REF_NAME does not match metadata.json version-name ($want)" >&2
exit 1
fi
kwin="v$(sed -n 's/^const VERSION = "\(.*\)";$/\1/p' kwin/smbact-kwin.js)"
if [ "$kwin" != "$GITHUB_REF_NAME" ]; then
echo "tag $GITHUB_REF_NAME does not match kwin/smbact-kwin.js VERSION ($kwin)" >&2
exit 1
fi
- name: Pack
run: |
scripts/pack.sh
(cd dist && sha256sum ./*.zip > SHA256SUMS && cat SHA256SUMS)
(cd dist && sha256sum ./*.zip ./smbact-kwin.js > SHA256SUMS && cat SHA256SUMS)
- name: Release
env:
GH_TOKEN: ${{ github.token }}
run: |
# a tag with a suffix (v1.0.0-alpha.1, -beta.2, -rc.1) is a pre-release
pre=""
case "$GITHUB_REF_NAME" in *-*) pre="--prerelease" ;; esac
gh release create "$GITHUB_REF_NAME" dist/*.zip dist/SHA256SUMS $pre \
gh release create "$GITHUB_REF_NAME" dist/*.zip dist/smbact-kwin.js dist/SHA256SUMS $pre \
--title "smbact-shell $GITHUB_REF_NAME" \
--notes "GNOME Shell extension smbact@giglabo.com, protocol com.giglabo.SMBAct.Shell1 API 1. See PROTOCOL.md."
--notes "GNOME Shell extension smbact@giglabo.com and the KWin script smbact-kwin.js, protocol API 1. See PROTOCOL.md."
46 changes: 43 additions & 3 deletions PROTOCOL.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Protocol: `com.giglabo.SMBAct.Shell1`, API 1

How SMBAct talks to its shell plugins. The GNOME Shell extension implements it today; a KWin script will
implement the same operations. SMBAct (a separate program) is the only intended client.
How SMBAct talks to its shell plugins: the GNOME Shell extension (`gnome-shell/`) and the KWin script (`kwin/`,
Plasma 6) implement the same operations with the same JSON; only the transport differs (see "KWin transport"). SMBAct
(a separate program) is the only intended client.

## D-Bus

Expand Down Expand Up @@ -33,7 +34,8 @@ 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), `FAILED` (the shell threw; `message` has its text).
(`grabAccelerator`: the shell refused the accelerator), `NO_SNAPSHOT` (`snapshot`: none taken yet), `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 @@ -106,6 +108,8 @@ XWayland. Rectangles are `{ "x", "y", "width", "height" }`.
| `pointer` | | `{ x, y }` |
| `grabAccelerator` | `accelerator` (GTK notation, `<Control><Alt>x`) | `{ accelerator, action }` |
| `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 }` |

- `setState` states: `minimized`, `maximized`, `maximizedHorizontally`, `maximizedVertically`, `fullscreen`,
`above`.
Expand All @@ -122,6 +126,13 @@ XWayland. Rectangles are `{ "x", "y", "width", "height" }`.
custom shortcuts: it fires on the desktop and in the overview, never on the lock or login screen. Each press sends
an `accelerator` event. It fails with `GRAB_FAILED` when another shortcut (GNOME's own, a custom one, another
extension's) has the combination, or when Mutter cannot parse it. Grabbing the same string again is a no-op.
- `snapshots` answers at once with the snapshots it has; the ones that are missing, stale (the window was damaged
or resized since) or of another size are taken one at a time when the shell is idle, and each sends a `snapshot`
event; fetch it with `snapshot`. A snapshot costs the compositor about a frame, so they are never taken on a timer.
The window that just lost the focus is taken quietly (no event) a moment later when its snapshot is stale.
Minimized windows keep their last snapshot. A `Snapshot` is `{ id, mime, data, width, height, fresh }`: `data` is
base64 JPEG of the visible window (the frame rect, without a client-side shadow), scaled to fit `maxSize`, over
`background`; `fresh` is false when the window changed since it was taken.
- Grabs belong to the client: the plugin releases all of them when the owner of `com.giglabo.SMBAct` goes away or
changes, and when it is disabled. A client that starts again grabs again.
- GNOME disables every user extension while the screen is locked and enables them again after the unlock (seen on
Expand All @@ -139,9 +150,38 @@ XWayland. Rectangles are `{ "x", "y", "width", "height" }`.
- `focusChanged` with `id` (or `null`).
- `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.

## History

- API 1 (2026-11): window list, geometry, activation, states, close, displays, pointer, events.
- API 1, plugin 1.0.0-alpha.2 (2026-11): `grabAccelerator`, `ungrabAccelerator`, the `accelerator` event (new
operations, same API; clients look for them in `hello`'s `ops`).
- API 1, plugin 1.0.0-alpha.3 (2026-11): `snapshots`, `snapshot`, the `snapshot` event.

## KWin transport

A KWin script cannot own a D-Bus name or serve calls, so the direction turns around. SMBAct owns
`com.giglabo.SMBAct`, serves the interface `com.giglabo.SMBAct.KWin1` on `/com/giglabo/SMBAct/KWin1` and loads
`smbact-kwin.js` into KWin through `org.kde.KWin` `/Scripting` (`loadScript(path, "smbact")`, then
`/Scripting/Script<id>` `run`): no install, no new login. The script calls in:

| method | | |
|---|---|---|
| `Hello(s hello)` | once, when the script runs | `hello` is the `hello` operation's result (`plugin: "smbact-kwin"`) |
| `Next(s reply) -> s request` | in a loop | hands over the reply to the previous request (empty the first time) and gets the next request; SMBAct holds the call until it has one and answers `{"op":"noop"}` after 15 s (Qt's D-Bus timeout is 25 s) |
| `Event(s event)` | fire and forget | the events above (`windowsChanged` at most every 100 ms and after a drag, `focusChanged`) |

Requests and replies carry `seq` (the transport pairs them by it; `id` stays a request argument). SMBAct accepts the
calls only from the owner of `org.kde.KWin`. When SMBAct goes away the script's calls fail and its loop ends; SMBAct
unloads it when it quits and loads it again when it starts or when KWin restarts.

What the KWin script does not have: `snapshots` / `snapshot` (KWin offers window screenshots only through
`org.kde.KWin.ScreenShot2`, which takes a file descriptor and an authorized caller), `grabAccelerator` (on Plasma
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).

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

22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# smbact-shell

Shell plugins for SMBAct, the window management app: a GNOME Shell extension now,
a KWin script later. 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.
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.

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 @@ -24,10 +24,24 @@ On Wayland a newly installed or updated extension starts after you log out and b
Only SMBAct may call it: the extension answers the current owner of the D-Bus name `com.giglabo.SMBAct` and refuses
everyone else.

## KWin script

`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.

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

```bash
qdbus6 org.kde.KWin /Scripting org.kde.kwin.Scripting.loadScript "$PWD/kwin/smbact-kwin.js" smbact
qdbus6 org.kde.KWin /Scripting/Script<id> org.kde.kwin.Script.run
```

## Releases

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` and `SHA256SUMS` as a release. SMBAct pins a tag and checks the sha256.
`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/`).

## License
Expand Down
38 changes: 34 additions & 4 deletions gnome-shell/smbact@giglabo.com/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// - windows come from display.list_all_windows(), not global.get_window_actors() (other extensions patch that one);
// - activation uses the server's current time (time 0 may not get the focus);
// - global hotkeys are Mutter accelerator grabs owned by the current client: released when it goes away;
// - window snapshots cost a frame each: cached, retaken only when stale, one per idle turn (snapshots.js);
// - no synchronous work beyond one frame, every request in try/catch, everything undone in disable(): a hang
// freezes the desktop and a crash ends the session.
import GdkPixbuf from 'gi://GdkPixbuf';
Expand All @@ -17,6 +18,7 @@ import St from 'gi://St';
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as Config from 'resource:///org/gnome/shell/misc/config.js';
import {Snapshots} from './snapshots.js';

const API = 1;
const BUS_NAME = 'com.giglabo.SMBAct.Shell';
Expand Down Expand Up @@ -126,6 +128,8 @@ class Service {
/** accelerator (as the client sent it) -> Mutter action id; action id -> accelerator */
this._grabs = new Map();
this._grabActions = new Map();
this._snapshots = null;
this._focus = null;
this._ops = {
hello: () => this._hello(),
listWindows: req => this._listWindows(req),
Expand All @@ -149,6 +153,18 @@ class Service {
},
grabAccelerator: req => this._grabAccelerator(req),
ungrabAccelerator: req => this._ungrabAccelerator(req),
snapshots: req => {
if (!Array.isArray(req.ids))
throw badRequest('"ids" must be an array of window ids');
const ids = req.ids.filter(id => typeof id === 'number' && Number.isFinite(id));
return {snapshots: this._snapshots.request(ids, req.maxSize, req.background)};
},
snapshot: req => {
const snapshot = this._snapshots.get(this._number(req, 'id'));
if (!snapshot)
throw new ShellError('NO_SNAPSHOT', `no snapshot of window ${req.id} yet`);
return {snapshot};
},
};
}

Expand All @@ -168,13 +184,20 @@ class Service {
this._clientOwner = null;
});
const d = global.display;
this._snapshots = new Snapshots(event => this._emit(event), id => this._findWindow(id));
this._focus = d.focus_window;
this._displaySignals = [
d.connect('window-created', (_d, w) => {
this._watchWindow(w);
this._windowsChanged();
}),
d.connect('restacked', () => this._windowsChanged()),
d.connect('notify::focus-window', () => this._emit({type: 'focusChanged', id: d.focus_window?.get_id() ?? null})),
d.connect('notify::focus-window', () => {
const left = this._focus;
this._focus = d.focus_window;
this._snapshots?.focusLeft(left);
this._emit({type: 'focusChanged', id: d.focus_window?.get_id() ?? null});
}),
d.connect('accelerator-activated', (_d, action, ...rest) => this._acceleratorActivated(action, rest[rest.length - 1])),
];
for (const w of allWindows())
Expand All @@ -183,6 +206,9 @@ class Service {

stop() {
this._releaseGrabs();
this._snapshots?.stop();
this._snapshots = null;
this._focus = null;
for (const id of this._displaySignals)
global.display.disconnect(id);
this._displaySignals = [];
Expand Down Expand Up @@ -357,14 +383,18 @@ class Service {
const id = req.id;
if (typeof id !== 'number' || !Number.isFinite(id))
throw badRequest('"id" must be a number');
// the compositor's id, or the X11 id of an XWayland window (SMBAct knows its own windows by that)
const windows = allWindows();
const w = windows.find(x => x.get_id() === id) ?? windows.find(x => x11WindowId(x) === id);
const w = this._findWindow(id);
if (!w)
throw new ShellError('NO_WINDOW', `no window ${id}`);
return w;
}

/** The compositor's id, or the X11 id of an XWayland window (SMBAct knows its own windows by that). */
_findWindow(id) {
const windows = allWindows();
return windows.find(x => x.get_id() === id) ?? windows.find(x => x11WindowId(x) === id) ?? null;
}

_number(req, key) {
const v = req[key];
if (typeof v !== 'number' || !Number.isFinite(v))
Expand Down
6 changes: 3 additions & 3 deletions gnome-shell/smbact@giglabo.com/metadata.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"uuid": "smbact@giglabo.com",
"name": "SMBAct",
"description": "Lets the SMBAct app see and arrange every window on Wayland: the window list, moving and resizing, activation, window states and global hotkeys, over D-Bus. It does nothing on its own; SMBAct installs and uses it.",
"description": "Lets the SMBAct app see and arrange every window on Wayland: the window list, moving and resizing, activation, window states, global hotkeys and window snapshots for its switcher, over D-Bus. It does nothing on its own; SMBAct installs and uses it.",
"shell-version": ["46", "47", "48", "49", "50", "51"],
"url": "https://github.com/GigLaboCom/smbact-shell",
"version": 2,
"version-name": "1.0.0-alpha.2"
"version": 3,
"version-name": "1.0.0-alpha.3"
}
Loading
Loading