Replies: 2 comments
|
This could be interesting, and if you want to implement it, probably the easiest way would be through a Lua script. If you want to try to do it, you would need some API support to read spaces information (there is already JSON support). I would be open to help you there: propose some Lua API functions you would like to have, and we can discuss them. Moving from that to persistent sessions, like you said, would need some protocol support which doesn't fully exist yet. |
|
Thanks! I agree that a LUA script is the best starting point for this feature; Lua can own persistence, application launching, and matching. Scroll would only need to expose enough of its current space implementation to serialize/apply it to newly selected views. So something like: -- Return a Lua table describing an existing saved Space.
scroll.space_get(name) -> table|nil
-- Apply a template to workspace, substituting named slots with live views.
scroll.space_apply(workspace, template, bindings) -> boolean, error?
Lua could then add durable slot names to leaf nodes before writing the table with the existing JSON helpers. local template = scroll.space_get("work")
-- Script assigns stable slot names before persisting JSON:
-- "mail", "terminal", "editor", etc.
write_template(template)On restore, a user script would launch/wait for applications, use its own matching logic, and then provide some selected live views: local bindings = {
mail = mail_view,
terminal = terminal_view,
editor = editor_view,
}
local ok, err = scroll.space_apply(
scroll.focused_workspace(),
template,
bindings
)
This keeps Scroll independent of application-specific session restoration. A script can match windows by title, app_id, parent process, environment, or whatever convention its user prefers so that Scroll doesn't have to. What do you think? |
Uh oh!
There was an error while loading. Please reload this page.
Concept
Scroll Spaces is single-handedly my most favorite feature about Scroll. Today, however, a Space refers to live containers/views. Those are necessarily transient: after a compositor restart, crash, shutdown, or application exit, the original views no longer exist. This is expected on Wayland, where there is no general-purpose protocol for a compositor to recreate arbitrary application windows and restore them to a prior layout. I am interested in discussing the groundwork for a partial, user-implemented solution in Scroll.
I am not proposing general Wayland session restoration. Instead, I would like to discuss support for a partial, user-defined workflow: a durable Space template that saves a Space’s layout while replacing its views with named placeholders (which I will refer to here as a "space template"). A space template is effectively a Space where the containers are placeholders.
Example
Here's a mockup of what a space template would look like (probably a JSON file; more on that later):
After a restart, the user would launch their applications and use a Lua script to bind live windows to template slots. The script would own the matching policy (for example, matching Firefox and terminal windows by predictable app IDs and titles) then ask Scroll to apply the template using the existing Space-loading behavior.
This keeps application/session logic outside the compositor. Different users have different applications and restoration mechanisms, and Scroll would not need to guess how a particular window should be recreated or identified.
Possible API shape
scrollmsg -t get_spacesalready exposes a saved Space’s hierarchy and live-view metadata, but it does not include enough state to faithfully export its layout. A template would need at least:{ "version": 1, "name": "work", "workspace": { "layout": "horizontal", "scroller": { "mode": "horizontal", "insert": "after", "reorder": "auto" } }, "tiling": [ { "layout": "horizontal", "children": [ { "slot": "mail", "size": { "width_fraction": 0.5, "height_fraction": 1.0 }, "view_hint": { "app_id": "firefox", "title": "firefox@email@layout1" } }, { "slot": "terminal", "size": { "width_fraction": 0.5, "height_fraction": 1.0 }, "view_hint": { "app_id": "kitty", "title": "~/work" } } ] } ], "floating": [], "focused_slot": "mail" }The exact JSON schema is not the important part; slot is. Unlike con_id or PID, a slot is durable and can be explicitly bound to a newly created live view.
Implementation questions
One option would be to enrich
get_spacesso scripts can export the current in-memory Space. Another would be a dedicated, versioned template export/import IPC API, leavingget_spacesas a description of live saved Spaces. I think this might be better long-term, otherwise every script would require the user to query all spaces every time they want to query one or more spaces (via inspecting the IPC json withjqor some other json parser).Either way, a Lua-facing binding API would be needed, conceptually:
I think loading should require every required slot to be bound by default, avoiding a partially applied or destructive restore. Matching logic, launch order, retries, and application-specific restoration should remain entirely user-defined.
Would this be a useful direction for Spaces, and would a dedicated template API be preferable to extending
get_spaces?All reactions