Skip to content

feat: add leave_hook symmetric to enter_hook#448

Open
tyvsmith wants to merge 3 commits into
feschber:mainfrom
tyvsmith:feat/leave-hook
Open

feat: add leave_hook symmetric to enter_hook#448
tyvsmith wants to merge 3 commits into
feschber:mainfrom
tyvsmith:feat/leave-hook

Conversation

@tyvsmith

@tyvsmith tyvsmith commented May 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Mirrors the existing enter_hook mechanism with a leave_hook that 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_hook fires deterministically but the only way to detect release today is to poll hyprctl 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 from release_capture() in src/capture.rs. Every release path funnels through that function:

  • release_bind chord
  • peer Leave event over the wire
  • CaptureRequest::Destroy when the active client is being torn down (with an explicit note about hostname-change client recreation)
  • CaptureRequest::Release

Wiring otherwise exactly mirrors enter_hook:

Layer enter_hook leave_hook
src/config.rs enter_hook: Option<String> + leave_hook: Option<String>
lan-mouse-ipc/src/lib.rs enter_cmd on ClientConfig, UpdateEnterHook request + leave_cmd, UpdateLeaveHook
src/client.rs set_enter_hook / get_enter_cmd + set_leave_hook / get_leave_cmd
src/service.rs update_enter_hook, spawn_hook_command, dispatch on ClientEntered + update_leave_hook, spawn_leave_hook_command, dispatch on ClientLeft
lan-mouse-cli/src/lib.rs --enter-hook flag on add-client + --leave-hook flag

Docs

The existing enter_hook has been undocumented since #130. Second commit backfills both in the example config.toml so the per-client hook surface is discoverable.

Out of scope

  • GUI surface in lan-mouse-gtk for the new field (text-config only for now)
  • Unit tests (no test infrastructure exists in the project today; manual smoke-tested with notify-send hooks across crossing + release_bind release on Wayland/Hyprland)

Test plan

  • Builds clean: cargo build --release (1m 20s, no warnings)
  • cargo clippy --all-targets --release -- -D warnings clean
  • Manual smoke: enter_hook and leave_hook set to notify-send strings, daemon restarted from built binary, cross to client and release via chord — both notifications fire as expected
  • Verify behavior with peer-initiated Leave (cross-back from the remote side)
  • Verify behavior on cli deactivate of the active client

@tyvsmith tyvsmith marked this pull request as ready for review May 26, 2026 23:38
Copilot AI review requested due to automatic review settings May 26, 2026 23:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_cmd in config and IPC models, plus CLI flag support.
  • Emit a new ICaptureEvent::ClientLeft on release paths and handle it in the service.
  • Execute configured leave commands via sh -c when 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.

Comment thread src/capture.rs
Comment thread src/capture.rs
Comment thread src/service.rs Outdated
@tyvsmith

Copy link
Copy Markdown
Contributor Author

Reference implementation for hook driven input changes

Add to ~/.config/lan-mouse/config.toml

enter_hook = "lan-mouse-mode mac"
leave_hook = "lan-mouse-mode default"

Script that swaps super/alt & inverts scrolling for Hyprland host and MacOS client

@feschber

Copy link
Copy Markdown
Owner

Would you mind removing 2804351 from this PR in favor of #449 ?

@tyvsmith

tyvsmith commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Would you mind removing 2804351 from this PR in favor of #449 ?

Sure, it's just here for now to make CI run until we land the other. I've reparented this one on top of #449, so will need to land that first, but then will merge cleanly as is..

tyvsmith and others added 3 commits June 28, 2026 16:23
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>
@tyvsmith

Copy link
Copy Markdown
Contributor Author

Should be good to merge at your leisure now that #449 is landed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants