Skip to main content

openlogi_core/binding/
button.rs

1//! Rebindable mouse/keyboard button identifiers.
2
3use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7/// One of the user-rebindable hotspots on a Logi mouse. The order matches the
8/// physical layout from front to side; [`ButtonId::ALL`] is consumed by the
9/// default-binding generator and the popover trigger list.
10#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
11pub enum ButtonId {
12    /// The primary button. Rebindable in the config schema, but the OS hook
13    /// never suppresses it — see [`ButtonId::is_os_hook_button`].
14    LeftClick,
15    /// The secondary button. Like [`ButtonId::LeftClick`], it always passes
16    /// through the OS hook.
17    RightClick,
18    /// The wheel click — one of the three buttons the OS hook remaps.
19    MiddleClick,
20    /// The thumb-side "back" button (mouse button 4), remapped by the OS hook.
21    Back,
22    /// The thumb-side "forward" button (mouse button 5), remapped by the OS hook.
23    Forward,
24    /// The "ModeShift" button under the wheel — typically used for SmartShift /
25    /// DPI cycle. Named `DpiToggle` for historical reasons.
26    DpiToggle,
27    /// The horizontal thumb wheel's click. Kept in [`ButtonId::ALL`] so its
28    /// default still seeds and dispatches when the wheel is diverted, even
29    /// though the mouse model surfaces one paired rotation control instead of
30    /// the click (see `mouse_model::geometry`).
31    Thumbwheel,
32    /// Rotating the thumb wheel "up" (positive rotation). Bound, by default, to
33    /// continuous horizontal scroll; see the agent-core `watchers`-side dispatch.
34    ThumbwheelScrollUp,
35    /// Rotating the thumb wheel "down" (negative rotation).
36    ThumbwheelScrollDown,
37    /// The HID++ gesture button on MX-line devices. The press itself
38    /// fires the bound action; swipe directions are P1.5 territory.
39    GestureButton,
40    /// Keyboard F-row "Search" control (`0x1b04` CID `0x00d4`,
41    /// `MultiPlatform_Search`) — F4 on the Signature series.
42    KeySearch,
43    /// Keyboard "Dictation" control (CID `0x0103`) — F5 on the Signature series.
44    KeyDictation,
45    /// Keyboard "Emoji" control (CID `0x0108`) — F6 on the Signature series.
46    KeyEmoji,
47    /// Keyboard "Screen Capture" control (CID `0x010a`) — F7 on the Signature
48    /// series.
49    KeyScreenCapture,
50    /// Keyboard "Mute Microphone" control (CID `0x011c`) — F8 on the Signature
51    /// series.
52    KeyMicMute,
53    /// Keyboard "Play/Pause" control (CID `0x00e5`) — F9 on the Signature series.
54    KeyPlayPause,
55    /// Keyboard "Mute" control (CID `0x00e7`) — F10 on the Signature series.
56    KeyMute,
57    /// Keyboard "Volume Down" control (CID `0x00e8`) — F11 on the Signature
58    /// series.
59    KeyVolumeDown,
60    /// Keyboard "Volume Up" control (CID `0x00e9`) — F12 on the Signature
61    /// series.
62    KeyVolumeUp,
63}
64
65impl ButtonId {
66    /// Every rebindable button in declaration (physical front-to-side) order —
67    /// the iteration source for default-binding seeding and the popover
68    /// trigger list.
69    pub const ALL: [ButtonId; 10] = [
70        ButtonId::LeftClick,
71        ButtonId::RightClick,
72        ButtonId::MiddleClick,
73        ButtonId::Back,
74        ButtonId::Forward,
75        ButtonId::DpiToggle,
76        ButtonId::Thumbwheel,
77        ButtonId::ThumbwheelScrollUp,
78        ButtonId::ThumbwheelScrollDown,
79        ButtonId::GestureButton,
80    ];
81
82    /// The divertable keyboard F-row controls, in F-row order. Kept out of
83    /// [`ButtonId::ALL`]: that array seeds mouse defaults and the mouse
84    /// popover trigger list, while keyboard keys stay native unless the user
85    /// binds them (an unbound key is never diverted).
86    pub const KEYBOARD_KEYS: [ButtonId; 9] = [
87        ButtonId::KeySearch,
88        ButtonId::KeyDictation,
89        ButtonId::KeyEmoji,
90        ButtonId::KeyScreenCapture,
91        ButtonId::KeyMicMute,
92        ButtonId::KeyPlayPause,
93        ButtonId::KeyMute,
94        ButtonId::KeyVolumeDown,
95        ButtonId::KeyVolumeUp,
96    ];
97
98    /// Whether this button is one the OS hook (macOS `CGEventTap` / Linux evdev)
99    /// remaps: Middle, Back, or Forward. The primary L/R clicks always pass
100    /// through (suppressing them would brick the mouse), and the DPI / thumb /
101    /// dedicated gesture controls aren't visible to the OS hook at all (they're
102    /// captured over HID++). These are exactly the buttons that can become an
103    /// OS-hook gesture button, so the hook's remap gate and the gesture-owner
104    /// projection share this one definition.
105    #[must_use]
106    pub fn is_os_hook_button(self) -> bool {
107        matches!(
108            self,
109            ButtonId::MiddleClick | ButtonId::Back | ButtonId::Forward
110        )
111    }
112
113    /// Human-readable label for popovers and tooltips.
114    #[must_use]
115    pub fn label(self) -> &'static str {
116        match self {
117            ButtonId::LeftClick => "Left Click",
118            ButtonId::RightClick => "Right Click",
119            ButtonId::MiddleClick => "Middle Click",
120            ButtonId::Back => "Back",
121            ButtonId::Forward => "Forward",
122            ButtonId::DpiToggle => "DPI Toggle",
123            ButtonId::Thumbwheel => "Thumb Wheel",
124            ButtonId::ThumbwheelScrollUp => "Thumb Wheel Up",
125            ButtonId::ThumbwheelScrollDown => "Thumb Wheel Down",
126            ButtonId::GestureButton => "Gesture Button",
127            ButtonId::KeySearch => "Search Key",
128            ButtonId::KeyDictation => "Dictation Key",
129            ButtonId::KeyEmoji => "Emoji Key",
130            ButtonId::KeyScreenCapture => "Screen Capture Key",
131            ButtonId::KeyMicMute => "Mic Mute Key",
132            ButtonId::KeyPlayPause => "Play/Pause Key",
133            ButtonId::KeyMute => "Mute Key",
134            ButtonId::KeyVolumeDown => "Volume Down Key",
135            ButtonId::KeyVolumeUp => "Volume Up Key",
136        }
137    }
138}
139
140impl fmt::Display for ButtonId {
141    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
142        f.write_str(self.label())
143    }
144}