Expand description
OS-level mouse-event hook for OpenLogi.
| Platform | Implementation |
|---|---|
| macOS | CGEventTap (same primitive used by Logi Options+) |
| Linux | evdev grab + uinput re-injection |
| Windows | WH_MOUSE_LL low-level mouse hook (motion is edge-clamped) |
§Usage
use openlogi_hook::{Hook, MouseEvent, EventDisposition};
if !Hook::has_accessibility() {
eprintln!("grant Accessibility access first");
return;
}
let hook = Hook::start(|event| {
println!("{event:?}");
EventDisposition::PassThrough
}).unwrap();
// … later, on shutdown:
hook.stop();Structs§
- Cursor
Position - Cursor position in the operating system’s global screen coordinate space,
scaled so it lines up with GPUI’s own logical (DIP) display bounds — the
Windows backend divides physical
GetCursorPospixels by the cursor’s monitor DPI scale to match; macOSCGEventpoints and Linux root-window coordinates are already resolution-independent. - Event
Device - Best-effort identity for the physical device that produced an OS event.
- Event
TapInfo - A live event tap installed somewhere in the system, as reported by
Hook::list_event_taps. Read-only diagnostic snapshot — enumerating taps needs no Accessibility grant and any process in the session sees them all. - Foreground
App - One application, named the way a per-app profile names it.
- Foreground
Application Observer - RAII owner of the current platform’s foreground-application observer.
- Hook
- A running OS-level mouse hook. Call
Hook::stopto tear down. - KeyEvent
- A keyboard event observed by the hook.
- KeyModifiers
- Which modifier keys were held when a key event fired — the same type a
KeyTriggeris written with, so an event’s modifiers compare against a binding’s without a conversion. Detectable modifier state: what a keyboard trigger requires, and what the OS hook reports with each key event (openlogi-hookre-exports this type).Fnis absent: firmware-internal, never reported on non-function-row keys, and so unusable as a trigger (function-key-remapper spec, Appendix A). - Pointer
Context - Application identity and native window captured by one pointer lookup.
Enums§
- Button
Id - One of the user-rebindable controls on a Logi device: a mouse hotspot, or
a keyboard key addressed by its HID++
0x1b04control ID. - Event
Disposition - What the hook callback wants the OS to do with the captured event.
- Foreground
Application Observer Error - Failure to install or operate a native foreground-application observer.
- Hook
Error - Errors that
Hook::startand related functions can produce. - Hook
Event - Anything the OS hook can observe.
Mousepreserves the existing callback payload;Keyis the keyboard path added by the function-key remapper. Wrapping both in a union meansHook::start’s callback widens once and stays stable as further event classes arrive. - Mouse
Event - An event captured at the OS layer.
- Pointer
Target - Native window identity under the pointer, or an explicit non-window outcome.
- Scroll
Delta - A signed two-axis scroll distance with an explicit unit.
- TapLocation
- Where in the event stream a tap is inserted (macOS
CGEventTapLocation).
Constants§
- LOGITECH_
VENDOR_ ID - Logitech’s USB/Bluetooth vendor id (
0x046D), widened fromopenlogi_core::hid::LOGITECH_VENDOR_IDbecause the hook’s identity sources (IOKit, evdev) hand it back as au32. - SOFTWARE_
SCROLL_ INVERSION - Whether this platform can invert the wheel in software.
Functions§
- cursor_
position - Return the current global cursor position without installing an input hook.
- frontmost_
application - Return the currently frontmost application.
- frontmost_
safari_ pid - Return the Safari process captured by the latest macOS foreground-app observation without querying AppKit on the caller’s thread.
- pointer_
context - Query the window currently under the pointer, without activating anything.
- pointer_
context_ supported - Whether this session has a pointer-window backend; does not probe permissions or connect to the window server. Unsupported Wayland never falls back to X11.
- pointer_
target_ is_ focused - Verify that this exact window, not merely another window of its application, is focused now. Returns false on any lookup failure or non-window target.
- scroll_
inversion - Whether
set_scroll_inversionis currently on. - set_
scroll_ inversion - Turn software scroll inversion on or off for the captured pointers.
- source_
is_ remappable - Whether the OS hook may suppress/remap a button event from this source.
- watch_
frontmost_ application_ changes - Observe native foreground-application changes.