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 /// The MX Master 4 Haptic Sense Panel — the touch-sensitive thumb rest
64 /// (Logi metadata slot `ASSIGNMENT_NAME_SHOW_RADIAL_MENU`, HID++ CID
65 /// `0x01a0`). A separate physical control from [`ButtonId::GestureButton`];
66 /// captured over HID++ like it, and eligible as the gesture owner.
67 /// Declared last: the TOML config and any serialized form encode the
68 /// variant identifier / index, so new buttons are append-only.
69 HapticPanel,
70}
71
72impl ButtonId {
73 /// Every rebindable button in declaration (physical front-to-side) order —
74 /// the iteration source for default-binding seeding and the popover
75 /// trigger list.
76 pub const ALL: [ButtonId; 11] = [
77 ButtonId::LeftClick,
78 ButtonId::RightClick,
79 ButtonId::MiddleClick,
80 ButtonId::Back,
81 ButtonId::Forward,
82 ButtonId::DpiToggle,
83 ButtonId::Thumbwheel,
84 ButtonId::ThumbwheelScrollUp,
85 ButtonId::ThumbwheelScrollDown,
86 ButtonId::GestureButton,
87 ButtonId::HapticPanel,
88 ];
89
90 /// The divertable keyboard F-row controls, in F-row order. Kept out of
91 /// [`ButtonId::ALL`]: that array seeds mouse defaults and the mouse
92 /// popover trigger list, while keyboard keys stay native unless the user
93 /// binds them (an unbound key is never diverted).
94 pub const KEYBOARD_KEYS: [ButtonId; 9] = [
95 ButtonId::KeySearch,
96 ButtonId::KeyDictation,
97 ButtonId::KeyEmoji,
98 ButtonId::KeyScreenCapture,
99 ButtonId::KeyMicMute,
100 ButtonId::KeyPlayPause,
101 ButtonId::KeyMute,
102 ButtonId::KeyVolumeDown,
103 ButtonId::KeyVolumeUp,
104 ];
105
106 /// Whether this button is one the OS hook (macOS `CGEventTap` / Linux evdev)
107 /// remaps: Middle, Back, or Forward. The primary L/R clicks always pass
108 /// through (suppressing them would brick the mouse), and the DPI / thumb /
109 /// dedicated gesture controls aren't visible to the OS hook at all (they're
110 /// captured over HID++). These are exactly the buttons that can become an
111 /// OS-hook gesture button, so the hook's remap gate and the gesture-owner
112 /// projection share this one definition.
113 #[must_use]
114 pub fn is_os_hook_button(self) -> bool {
115 matches!(
116 self,
117 ButtonId::MiddleClick | ButtonId::Back | ButtonId::Forward
118 )
119 }
120
121 /// Whether this button is a HID++ gesture source — a control that is
122 /// captured over HID++ raw-XY diversion (never the OS hook) and can
123 /// therefore own the gesture role with swipe directions: the dedicated
124 /// gesture button, or the MX Master 4 haptic panel. The capture layer maps
125 /// each to its control ID.
126 #[must_use]
127 pub fn is_hidpp_gesture_source(self) -> bool {
128 matches!(self, ButtonId::GestureButton | ButtonId::HapticPanel)
129 }
130
131 /// Human-readable label for popovers and tooltips.
132 #[must_use]
133 pub fn label(self) -> &'static str {
134 match self {
135 ButtonId::LeftClick => "Left Click",
136 ButtonId::RightClick => "Right Click",
137 ButtonId::MiddleClick => "Middle Click",
138 ButtonId::Back => "Back",
139 ButtonId::Forward => "Forward",
140 ButtonId::DpiToggle => "DPI Toggle",
141 ButtonId::Thumbwheel => "Thumb Wheel",
142 ButtonId::ThumbwheelScrollUp => "Thumb Wheel Up",
143 ButtonId::ThumbwheelScrollDown => "Thumb Wheel Down",
144 ButtonId::GestureButton => "Gesture Button",
145 ButtonId::KeySearch => "Search Key",
146 ButtonId::KeyDictation => "Dictation Key",
147 ButtonId::KeyEmoji => "Emoji Key",
148 ButtonId::KeyScreenCapture => "Screen Capture Key",
149 ButtonId::KeyMicMute => "Mic Mute Key",
150 ButtonId::KeyPlayPause => "Play/Pause Key",
151 ButtonId::KeyMute => "Mute Key",
152 ButtonId::KeyVolumeDown => "Volume Down Key",
153 ButtonId::KeyVolumeUp => "Volume Up Key",
154 ButtonId::HapticPanel => "Haptic Panel",
155 }
156 }
157}
158
159impl fmt::Display for ButtonId {
160 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
161 f.write_str(self.label())
162 }
163}