feat: add leave_hook symmetric to enter_hook#448
Open
tyvsmith wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for per-client “leave hooks” that run when capture is released for a client, wiring the new setting through config, IPC, CLI, and capture/service event handling.
Changes:
- Introduce
leave_hook/leave_cmdin config and IPC models, plus CLI flag support. - Emit a new
ICaptureEvent::ClientLefton release paths and handle it in the service. - Execute configured leave commands via
sh -cwhen a client is left.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/service.rs | Handle UpdateLeaveHook, persist leave_hook, and spawn leave-hook commands on ClientLeft. |
| src/config.rs | Add leave_hook to TOML and runtime config conversion paths. |
| src/client.rs | Store and expose per-client leave_cmd in ClientManager. |
| src/capture.rs | Add ClientLeft event and ensure release paths trigger it. |
| lan-mouse-ipc/src/lib.rs | Extend IPC structs/enums with leave-hook fields and requests. |
| lan-mouse-cli/src/lib.rs | Add --leave-hook flag and send UpdateLeaveHook on create. |
| config.toml | Document and example-configure leave_hook. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3 tasks
Contributor
Author
|
Reference implementation for hook driven input changes Add to ~/.config/lan-mouse/config.toml Script that swaps super/alt & inverts scrolling for Hyprland host and MacOS client |
3313b2e to
5889620
Compare
Owner
5889620 to
1477dd0
Compare
Contributor
Author
1477dd0 to
40a4e37
Compare
Per-client leave_hook fires sh -c <cmd> when capture for that client is released. Wired through a single release_capture() chokepoint covering release_bind, network send failure, Destroy-of-active-client, and Release request paths. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The existing enter_hook field has been undocumented since it was added in feschber#130. Add it alongside the new leave_hook to the example config so both per-client hooks are discoverable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The two spawn_*_hook_command functions were ~35 lines of near-byte- identical glue (only the get_*_cmd call and log prefixes differed). Replace with a single spawn_hook_command(handle, HookKind) and let the kind carry the human label into log lines (which now also include the client handle). No behaviour change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40a4e37 to
e44ef68
Compare
Contributor
Author
|
Should be good to merge at your leisure now that #449 is landed. |
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.
Summary
Mirrors the existing
enter_hookmechanism with aleave_hookthat fires when capture for a client is released.Motivation: external scripts that change host state on cross (e.g. swapping keyboard layout, toggling natural scroll, repositioning windows) currently have no symmetric "you're back" signal —
enter_hookfires deterministically but the only way to detect release today is to pollhyprctl cursorpos/ similar, which is fragile because the local cursor isn't actually pinned during capture on Wayland.Design
A single new IPC capture event
ICaptureEvent::ClientLeft(handle)emitted fromrelease_capture()insrc/capture.rs. Every release path funnels through that function:Leaveevent over the wireCaptureRequest::Destroywhen the active client is being torn down (with an explicit note about hostname-change client recreation)CaptureRequest::ReleaseWiring otherwise exactly mirrors
enter_hook:src/config.rsenter_hook: Option<String>leave_hook: Option<String>lan-mouse-ipc/src/lib.rsenter_cmdonClientConfig,UpdateEnterHookrequestleave_cmd,UpdateLeaveHooksrc/client.rsset_enter_hook/get_enter_cmdset_leave_hook/get_leave_cmdsrc/service.rsupdate_enter_hook,spawn_hook_command, dispatch onClientEnteredupdate_leave_hook,spawn_leave_hook_command, dispatch onClientLeftlan-mouse-cli/src/lib.rs--enter-hookflag onadd-client--leave-hookflagDocs
The existing
enter_hookhas been undocumented since #130. Second commit backfills both in the exampleconfig.tomlso the per-client hook surface is discoverable.Out of scope
lan-mouse-gtkfor the new field (text-config only for now)notify-sendhooks across crossing + release_bind release on Wayland/Hyprland)Test plan
cargo build --release(1m 20s, no warnings)cargo clippy --all-targets --release -- -D warningscleanenter_hookandleave_hookset tonotify-sendstrings, daemon restarted from built binary, cross to client and release via chord — both notifications fire as expectedLeave(cross-back from the remote side)cli deactivateof the active client