Add lua_eval command, lua IPC command, and scroll.context_container API#347
Open
jbms wants to merge 5 commits into
Open
Add lua_eval command, lua IPC command, and scroll.context_container API#347jbms wants to merge 5 commits into
jbms wants to merge 5 commits into
Conversation
1761821 to
4c03191
Compare
5360edb to
157abe0
Compare
Exposes scroll.animating() and scroll.pending_transactions() to Lua to allow external scripts and tests to query whether the compositor has settled. Also includes testing infrastructure updates (pytest.ini config, LSan suppressions, and helper methods in test_utils.py).
When a new view is mapped, criteria rules may configure its
geometry (e.g. `resize set`). This configuration sends a new
configure event to the client.
However, during the map event handling, we are still processing
the initial commit from the client. After the map event is
handled and the rule-configured geometry is applied via a
transaction, the compositor's commit handler (`handle_commit`)
continues.
For floating containers, `handle_commit` resizes the container to
match the client's committed buffer size. If it processes the
initial commit (which has the initial client size, not the
configured one), it overrides the configured geometry back to the
initial size.
To fix this, we introduce `is_commit_stale` helper which checks
if there is a pending or scheduled configure event with a newer
serial than the serial acknowledged by the current commit. If the
commit is stale, we ignore its size for resizing floating
containers, waiting instead for the client to acknowledge and
commit the newly configured size.
How to reproduce:
1. Register the for_window rule:
swaymsg 'for_window [title="Scratchpad Test"] move scratchpad, resize set 500 500'
2. Start the client:
foot -T "Scratchpad Test"
3. Query the scratchpad window geometry:
swaymsg -t get_tree | jq '.. | select(.name? == "__i3_scratch") | .floating_nodes[] | select(.name == "Scratchpad Test") | .rect'
On buggy versions, this will output the client's default size
instead of the configured 500x500.
Additionally:
* Make `wait_for_client_map` test utility robust by searching
all workspaces and the scratchpad for the mapped view, instead
of just checking the focused view. This allows it to be used
for windows that are moved to the scratchpad (and thus
hidden/unfocused) immediately upon mapping.
* Update `wayland-client.c` to support dynamic resizing in tests.
* Add integration test `tests/test_scratchpad_geometry.py` to
verify the fix.
Add a new `lua_eval` compositor command to allow executing a raw inline Lua string as code rather than loading a file. Any optional arguments passed are supplied to the inline Lua block as parameters (accessed via `...`). The empty string is used as the script identifier. Also update the `scroll` manual page and README.md to document the new command.
Add a new `lua` IPC command type (represented by `IPC_LUA_EXEC` = 124) to support evaluating either a Lua script file or inline Lua code. The message accepts arguments as a list of JSON values which are parsed and converted to Lua values, and serializes the return value(s) of the script back to JSON before replying. In the `scrollmsg` client, expose this through separate `lua` (for running a file) and `lua_eval` (for running inline code) command types. Also: - Export and reuse `sway_lua_value_to_json` and `sway_lua_table_to_json` from `sway/lua.c` for Lua-to-JSON serialization in the IPC reply. - Export `sway_lua_push_json_to_lua` for JSON-to-Lua argument conversion. - Fix relative stack index handling in JSON/Lua conversion functions to ensure they function correctly with negative stack indices. - Commit dirty transactions immediately after the script execution on both success and error execution paths. - Rewrite the `execute_lua` test helper to use the new IPC API directly (removing temporary files and the custom Lua runner). - Update man pages (scrollmsg.1, scroll-ipc.7) and README.md.
Exposes the criteria-matched container context to running Lua scripts via a new `scroll.context_container()` function. If a script is run via criteria (e.g., `[class="XTerm"] lua_eval ...`), the function returns the matched container's ID. If executed globally without criteria, it returns `nil`. To prevent nested executions of `scroll.command()` within a script from permanently overwriting the context, the active Lua context is backed up on entry to Lua command handlers (`lua` and `lua_eval`) and restored on exit. Also documents the new API in `scroll.lua` and the `scroll.5` man page, and adds comprehensive pytest coverage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
lua_evalallows inline lua to be evaluated without needing to write it to a file.Compared to just running
luaorlua_evalvia RUN_COMMAND, the new LUA_EXEC command allows a return value to be sent back to the client.The scroll.context_container() API provides access to the context container when
luaorlua_evalis run with criteria.