openlogi_core/binding/defaults.rs
1//! Default bindings for a fresh device / gesture map.
2
3use super::action::Action;
4use super::button::ButtonId;
5use super::gesture::GestureDirection;
6use super::value::Binding;
7
8/// Sensible defaults for a fresh device so the panel isn't empty on first run.
9///
10/// Thumbwheel / GestureButton defaults match what Logi Options+ ships for
11/// MX-line devices: thumb wheel click → App Exposé, gesture button →
12/// Mission Control. The thumb wheel isn't captured yet; the dedicated gesture button is
13/// (per-direction, see [`default_gesture_binding`]). The bindings persist
14/// regardless so the user only configures once.
15///
16/// `GestureButton`'s entry here is vestigial: in the merged [`Binding`] model
17/// the gesture button defaults to [`Binding::Gesture`] (see
18/// [`default_binding_for`]), so this single-action value is never the source of
19/// truth for it. It is retained only so the per-button-`Action` callers (the
20/// hook map, scroll defaults, labels) stay total.
21#[must_use]
22pub fn default_binding(button: ButtonId) -> Action {
23 match button {
24 ButtonId::LeftClick => Action::LeftClick,
25 ButtonId::RightClick => Action::RightClick,
26 ButtonId::MiddleClick => Action::MiddleClick,
27 ButtonId::Back => Action::BrowserBack,
28 ButtonId::Forward => Action::BrowserForward,
29 ButtonId::DpiToggle => Action::CycleDpiPresets,
30 ButtonId::Thumbwheel => Action::AppExpose,
31 // The thumb wheel scrolls horizontally by default: rotating it produces
32 // continuous horizontal scroll, with "up" → right and "down" → left.
33 // The wheel watcher renders these two actions as smooth, sensitivity-
34 // scaled scrolling rather than the discrete per-press burst a button
35 // would get (see `watchers::gesture`).
36 ButtonId::ThumbwheelScrollUp => Action::HorizontalScrollRight,
37 ButtonId::ThumbwheelScrollDown => Action::HorizontalScrollLeft,
38 ButtonId::GestureButton => Action::MissionControl,
39 // Keyboard keys stay on their native firmware function until the user
40 // explicitly binds them; an unbound key is never diverted, so a
41 // `None` default keeps the projection total without capturing anything.
42 ButtonId::KeySearch
43 | ButtonId::KeyDictation
44 | ButtonId::KeyEmoji
45 | ButtonId::KeyScreenCapture
46 | ButtonId::KeyMicMute
47 | ButtonId::KeyPlayPause
48 | ButtonId::KeyMute
49 | ButtonId::KeyVolumeDown
50 | ButtonId::KeyVolumeUp => Action::None,
51 }
52}
53
54/// Per-direction defaults for the gesture button. These are captured live over
55/// HID++ `0x1b04` (raw-XY diversion) and dispatched like any other binding; the
56/// defaults give the picker something sensible to show on first run.
57#[must_use]
58pub fn default_gesture_binding(direction: GestureDirection) -> Action {
59 match direction {
60 GestureDirection::Up => Action::MissionControl,
61 GestureDirection::Down => Action::ShowDesktop,
62 GestureDirection::Left => Action::PrevTab,
63 GestureDirection::Right => Action::NextTab,
64 GestureDirection::Click => Action::AppExpose,
65 }
66}
67
68/// The canonical default [`Binding`] for a fresh button in the merged model.
69///
70/// [`ButtonId::GestureButton`] defaults to [`Binding::Gesture`] populated from
71/// [`default_gesture_binding`] — preserving the existing per-direction swipe
72/// behavior — so the GUI mode toggle and the runtime agree it starts in gesture
73/// mode. Every other button defaults to [`Binding::Single`] of its
74/// [`default_binding`].
75///
76/// This is the seed when a button is first promoted to a gesture binding (see
77/// [`Config::set_gesture_direction`](crate::config::Config::set_gesture_direction)),
78/// so a freshly-customized gesture button always carries a full default
79/// direction map — including a [`GestureDirection::Click`] — rather than a sparse
80/// map whose click would project to a no-op [`Action::None`].
81#[must_use]
82pub fn default_binding_for(button: ButtonId) -> Binding {
83 match button {
84 ButtonId::GestureButton => Binding::Gesture(
85 GestureDirection::ALL
86 .into_iter()
87 .map(|d| (d, default_gesture_binding(d)))
88 .collect(),
89 ),
90 other => Binding::Single(default_binding(other)),
91 }
92}