Skip to content

Lua runtime API ​

Use gnoblin runtime methods from an event callback to inspect or change the running session. gnoblinctl calls the same registered Lua API methods, so Lua automation and the command-line client use the same public API.

Runtime calls enqueue an operation and return a positive integer request ID. Gnoblin later dispatches gnoblin.api.operation-completed with the same ID. Callbacks run in the compositor's main thread; keep them short. See Lua events for event names and callback behavior.

lua
local pending = {}

gnoblin.on("gnoblin.workspace.activated", function(event)
    if event.id == "review" then
        pending[gnoblin.workspace.list()] = "list workspaces"
    end
end)

gnoblin.on("gnoblin.api.operation-completed", function(event)
    local purpose = pending[event.request_id]
    if not purpose then return end
    pending[event.request_id] = nil

    if event.ok then
        print(purpose .. ": completed")
    else
        print(purpose .. ": " .. event.error)
    end
end)

The completion event contains request_id, method, and ok. Successful operations include result; failed operations include an error message. Store the returned request ID when an action's result matters, then handle only the completion with that ID. A method can also fail immediately if its Lua arguments are invalid or if it is called outside a runtime event callback.

Workspaces ​

Use {id = "code"} to select a stable ID or {number = 2} to select the current one-based position from 1 to 1024. A selector must contain exactly one of these fields.

IDs declared in gnoblin.configure.workspaces persist across sessions. IDs supplied to runtime create are temporary and last only for the session. Gnoblin-generated @session-N IDs can be selected during that session but should not be saved in configuration. See the workspace configuration reference and the writing workspace recipe.

MethodArgumentsSuccessful result
workspace.list()None{workspaces = {Workspace, ...}}
workspace.create(args)name required; optional id, activateNew Workspace record
workspace.rename(args)Exactly one of id or number, plus nameUpdated Workspace record
workspace.remove(args)Exactly one of id or numberRemoved workspace record
workspace.switch(args)Exactly one of id or numberActivated Workspace record
workspace.next()NoneActivated Workspace record
workspace.previous()NoneActivated Workspace record
workspace.move_active(args)workspace selector; optional follow{workspace, window, follow}
workspace.move_window(args)window ID or "active"; workspace selector; optional follow{workspace, window, follow}

create requires a nonempty name of up to 80 characters. Its optional ID must match ^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$; if omitted, Gnoblin generates a session-only ID. activate defaults to false. Rename also requires a nonempty name of up to 80 characters. follow defaults to false; when true, moving a window also switches to the destination workspace.

A Workspace record has id, number, name, active, windows, and persistent fields. Gnoblin does not remove a declared workspace, the active workspace, or a workspace that still contains windows.

Windows, layers, and monitors ​

MethodArgumentsSuccessful result
window.list(args)Optional app_id, title, focused filters{windows = {Window, ...}}
window.match(args)Optional string window ID; defaults to "active"Window identity and a match rule table
window.action(args)action; optional window, geometry, monitor, workspaceAction result
layer.list()None{surfaces = {Surface, ...}}
monitor.list()None{monitors = {Monitor, ...}}
Filter or fieldAccepted valueMeaning
app_idApplication ID stringExact match in window.list.
titleText stringCase-insensitive substring filter in window.list.
focusedBoolean; set true to filterLists only the focused window when true.
window"active" or stable window IDSelects the window.match or action target.

window.match returns the stable window ID, desktop and GTK application IDs, WM class, and a rule match table containing type, title, focus state, and the rule app ID when available.

window.action accepts this action set:

lua
WindowAction = "menu" | "interactive-move" | "interactive-resize" | "above"
             | "unabove" | "stick" | "unstick" | "focus" | "close"
             | "minimize" | "restore-or-minimize" | "restore" | "maximize"
             | "unmaximize" | "fullscreen" | "unfullscreen" | "move"
             | "resize" | "workspace" | "monitor"
Action fieldsAccepted valueMeaning
x, y for moveIntegers from −100000 to 100000Window position.
width, height for resizeIntegers from 1 to 32768Window size.
monitorIndex from monitor.list()Destination monitor.
workspace{id = ...} or {number = ...}Destination workspace for the workspace action.

Mutter rejects actions that the target window cannot perform in its current state.

Animations ​

MethodArgumentsSuccessful result
animation.list()None{animations = {Animation, ...}}
animation.surfaces()None{surfaces = {Surface, ...}}
animation.inspect(args)name, target; optional event, targetTypeAnimation details and resolved specification
animation.preview(args)Same as inspect; optional autoplayPreview session ID and specification
animation.seek(args)session; progress from 0 to 1Session action result
animation.step(args)session; milliseconds from 1 to 60000Session action result
animation.play(args)sessionSession action result
animation.pause(args)sessionSession action result
animation.stop(args)sessionSession action result
FieldAccepted valueMeaning
targetTypewindow (default), layer, or namespaceSelects how to resolve target.
target"active" or window ID; layer ID; or namespaceIdentifies the preview target.
name1–80 ASCII letters, digits, _ or -Selects an animation.
eventOptional lowercase kebab-case event nameSelects an event supported by that animation.
autoplayBoolean; default falseStarts a preview immediately when true.

See the animation guide for supported animation events.

Features, scripts, and input ​

MethodArgumentsSuccessful result
feature.list()NoneFeature records with id, description, and enabled
feature.show(args)id{id, enabled}
feature.enable(args)id{ok, id, enabled}
feature.disable(args)id{ok, id, enabled}
script.list()None{scripts = {...}}
input.list()NoneInput-source records with type, id, shortName, and name
input.current()NoneCurrent input source record
input.select(args)type, id{ok, type, id}

Use IDs returned by the matching list method for feature and input operations. Input type and id values depend on the sources available in your session.

Privacy and permissions ​

MethodArgumentsSuccessful result
privacy.get()None{screenSharing, microphoneInUse, locationInUse}
permissions.list()NoneCurrent permission policy
permissions.check(args)capability, identityPermission decision with scope details
grant.list()None{grants = {Grant, ...}}
grant.revoke(args)kind, id{ok, id}

Permission capabilities, identities, grant kinds, and scope fields use the same values as session permissions. grant.revoke revokes a listed portal grant; get its kind and id from grant.list().

Launch feedback, shell, and configuration ​

MethodArgumentsSuccessful result
launch.status()None{launches = {...}}
launch.begin(args)token, application; optional milliseconds{ok, token}
launch.end(args)token{ok, token}
shell.ping()None{pong}
shell.version()None{version}
shell.status()NoneShell version, connection state, window count, focused window ID
shell.reload()NoneReload acknowledgement
runtime.reload_config()NoneConfiguration reload acknowledgement

launch.begin accepts a token of up to 128 characters and an application name of up to 512 characters. Its milliseconds value defaults to 3000 and is clamped to 100–10000 ms. Pass the same token to launch.end when the application starts or the launch request is cancelled. shell.reload reloads the GNOME Shell integration; runtime.reload_config reloads Gnoblin configuration.

Shortcut capture ​

MethodArgumentsSuccessful result
shortcut.capture(args)timeout in seconds, from 1 to 60{accelerator}

The capture asks for one keyboard shortcut and returns its accelerator string. It fails if another capture is active, keyboard input is already grabbed, or the session is locked.

See gnoblinctl for command-line forms of these operations.