-
Event System
EventCallback
trait defines how events are handled- Three main event types:
MouseEvent
: Tracks mouse movements, clicks, and scrollingKeyboardEvent
: Tracks keyboard activity (key codes only, not keystrokes)WindowEvent
: Tracks window focus changes and titles
-
Platform-Specific Implementation
- Uses conditional compilation (
#[cfg(target_os = "...")]
) for platform-specific code - Separated into platform modules:
platform/macos.rs
: macOS implementationplatform/windows.rs
: Windows implementation
- Uses conditional compilation (
-
Native Bindings
- Uses FFI to interface with native APIs
- macOS: Objective-C code in
bindings/macos/
- Windows: Win32 API code in
bindings/windows/
The monitor achieves cross-platform compatibility through several layers:
-
Common Interface Layer (
src/monitor.rs
)- Defines platform-agnostic traits and types
EventCallback
trait standardizes event handling
-
Platform Abstraction (
src/platform/mod.rs
)- Provides unified functions that delegate to platform-specific implementations
- Key functions:
detect_changes()
: Polls for new eventsinitialize_callback()
: Sets up event monitoring
-
Native Bindings (
src/bindings.rs
)- Defines FFI interfaces for both platforms
- Uses conditional compilation to select appropriate bindings
-
Event Collection
- Events are collected in batches (30-second intervals by default)
- Uses thread-safe
AccumulatedEvents
structure - Events are stored in memory until batch interval is reached
-
Event Processing
- Mouse events include position, event type, and scroll information
- Keyboard events capture key codes only (not actual keystrokes)
- Window events track application name and window title changes
-
Callback System
- Implements the Observer pattern through
EventCallback
- Callbacks are thread-safe and can be shared across threads
- Events are delivered in batches to reduce overhead
- Implements the Observer pattern through