Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion crates/openlogi-desktop/src/features/mouse/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,27 @@ pub(super) struct ActionPickerContext<'a> {
pub shortcut_input: &'a Entity<InputState>,
pub application_input: &'a Entity<InputState>,
pub shortcut_invalid: bool,
pub shortcut_mode: ShortcutMode,
pub application_invalid: bool,
pub view: &'a Entity<MouseModelView>,
}

/// Whether the custom shortcut editor records a tapped or a held chord.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum ShortcutMode {
Tap,
Hold,
}

impl ShortcutMode {
fn action(self, combo: openlogi_core::binding::KeyCombo) -> Action {
match self {
Self::Tap => Action::CustomShortcut(combo),
Self::Hold => Action::HoldShortcut(combo),
}
}
}

pub(super) fn binding_inspector(
data: BindingInspectorData<'_>,
picker: ActionPickerContext<'_>,
Expand Down Expand Up @@ -665,6 +682,7 @@ fn action_library(
id_prefix,
picker.shortcut_input,
picker.shortcut_invalid,
picker.shortcut_mode,
picker.view,
on_pick,
pal,
Expand Down Expand Up @@ -702,16 +720,37 @@ fn custom_shortcut_editor(
id_prefix: &'static str,
input: &Entity<InputState>,
invalid: bool,
mode: ShortcutMode,
view: &Entity<MouseModelView>,
on_pick: &PickFn,
pal: Palette,
) -> impl IntoElement {
let submit_input = input.clone();
let on_pick = on_pick.clone();
let mode_button = |option: ShortcutMode| {
let (id, label) = match option {
ShortcutMode::Tap => ("tap", tr!("actions.shortcut_tap")),
ShortcutMode::Hold => ("hold", tr!("actions.shortcut_hold")),
};
let view = view.clone();
control_button(format!("{id_prefix}-shortcut-{id}"))
.debug_selector(move || format!("{id_prefix}-shortcut-{id}"))
.selected(mode == option)
.label(label)
.on_click(move |_, _, cx| {
view.update(cx, |view, cx| {
view.shortcut_mode = option;
cx.notify();
});
})
};
let tap_button = mode_button(ShortcutMode::Tap);
let hold_button = mode_button(ShortcutMode::Hold);
let view = view.clone();
v_flex()
.gap_1()
.child(editor_section(tr!("action_ring.custom_shortcut"), pal))
.child(h_flex().gap_2().child(tap_button).child(hold_button))
.child(
h_flex()
.gap_2()
Expand All @@ -730,7 +769,7 @@ fn custom_shortcut_editor(
.on_click(move |_, window, cx| {
let shortcut = submit_input.read(cx).value().to_string();
match shortcut.parse::<openlogi_core::binding::KeyCombo>() {
Ok(combo) => (on_pick)(Action::CustomShortcut(combo), window, cx),
Ok(combo) => (on_pick)(mode.action(combo), window, cx),
Err(_) => view.update(cx, |view, cx| {
view.custom_shortcut_invalid = true;
cx.notify();
Expand Down
8 changes: 7 additions & 1 deletion crates/openlogi-desktop/src/features/mouse/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use super::geometry::{
default_labels, labels_from_hotspots,
};
use super::hotspots::{Hotspot, MOUSE_MODEL_SIZE, MouseControlId, default_hotspots};
use super::inspector::{ActionPickerContext, BindingInspectorData, binding_inspector};
use super::inspector::{
ActionPickerContext, BindingInspectorData, ShortcutMode, binding_inspector,
};
use super::leader_lines::{Geometry as LeaderGeometry, Label, paint as paint_leader_lines};
use crate::app::{glow_canvas, keyboard_glow};
use crate::features::profiles::{friendly_app_name, profile_canvas_status};
Expand Down Expand Up @@ -135,6 +137,7 @@ pub struct MouseModelView {
/// Whether the last "Add" attempt on the corresponding custom editor
/// failed to parse, so its caption can show an inline error.
pub(super) custom_shortcut_invalid: bool,
pub(super) shortcut_mode: ShortcutMode,
pub(super) custom_application_invalid: bool,
_state_obs: Subscription,
}
Expand Down Expand Up @@ -194,6 +197,7 @@ impl MouseModelView {
custom_shortcut_input,
custom_application_input,
custom_shortcut_invalid: false,
shortcut_mode: ShortcutMode::Tap,
custom_application_invalid: false,
_state_obs: state_obs,
}
Expand All @@ -213,6 +217,7 @@ impl MouseModelView {
.update(cx, |input, cx| input.set_value("", window, cx));
self.custom_shortcut_invalid = false;
self.custom_application_invalid = false;
self.shortcut_mode = ShortcutMode::Tap;
}

/// Set (or clear, with `None`) the activated gesture direction. Callers must
Expand Down Expand Up @@ -396,6 +401,7 @@ impl Render for MouseModelView {
shortcut_input: &self.custom_shortcut_input,
application_input: &self.custom_application_input,
shortcut_invalid: self.custom_shortcut_invalid,
shortcut_mode: self.shortcut_mode,
application_invalid: self.custom_application_invalid,
view: &view,
},
Expand Down
17 changes: 17 additions & 0 deletions crates/openlogi-desktop/src/features/mouse/view/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ fn action_picker_renders_after_opening_through_the_inspector(cx: &mut TestAppCon
});

click_picker_control(cx, "inspector-current-action");
click_picker_control(cx, "inspector-action-shortcut-hold");
view.read_with(cx, |view, _| {
assert_eq!(view.shortcut_mode, ShortcutMode::Hold);
});
click_picker_control(cx, "inspector-action-custom-shortcut-input");
cx.simulate_input("Cmd+K");
click_picker_control(cx, "inspector-action-custom-shortcut-add");
view.read_with(cx, |view, _| assert!(!view.action_picker_open));
assert_forward_binding(cx, &Action::HoldShortcut("Cmd+K".parse().unwrap()));

click_picker_control(cx, "inspector-current-action");
view.read_with(cx, |view, _| {
assert_eq!(view.shortcut_mode, ShortcutMode::Tap);
});
cx.update(|window, cx| {
view.read(cx)
.action_search
Expand Down Expand Up @@ -214,6 +228,7 @@ fn a_selected_gesture_can_render_in_the_binding_inspector(cx: &mut TestAppContex
shortcut_input: &view.custom_shortcut_input,
application_input: &view.custom_application_input,
shortcut_invalid: view.custom_shortcut_invalid,
shortcut_mode: view.shortcut_mode,
application_invalid: view.custom_application_invalid,
view: &entity,
},
Expand Down Expand Up @@ -261,6 +276,7 @@ fn clearing_custom_action_drafts_resets_text_and_invalid_state(cx: &mut TestAppC
.update(cx, |input, cx| input.set_value("/bin/true", window, cx));
view.custom_shortcut_invalid = true;
view.custom_application_invalid = true;
view.shortcut_mode = ShortcutMode::Hold;

view.clear_custom_action_drafts(window, cx);
});
Expand All @@ -271,6 +287,7 @@ fn clearing_custom_action_drafts_resets_text_and_invalid_state(cx: &mut TestAppC
assert_eq!(view.custom_application_input.read(cx).value(), "");
assert!(!view.custom_shortcut_invalid);
assert!(!view.custom_application_invalid);
assert_eq!(view.shortcut_mode, ShortcutMode::Tap);
});
drop(view);
cx.update(|window, _| window.remove_window());
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/be.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Прывязаць %{name} у %{app}"
unbound = "Не прывязана"
five_directions = "5 кірункаў"
hold_shortcut = "Утрымліваць %{chord}"
shortcut_hold = "Утрымліваць"
shortcut_tap = "Націснуць"
gesture_named = "Жэст %{name}"
left_click = "Левы націск"
right_click = "Правы націск"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/cs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Přiřadit %{name} v aplikaci %{app}"
unbound = "Nepřiřazeno"
five_directions = "5 směrů"
hold_shortcut = "Držet %{chord}"
shortcut_hold = "Podržet"
shortcut_tap = "Klepnout"
gesture_named = "Gesto %{name}"
left_click = "Levé kliknutí"
right_click = "Pravé kliknutí"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/da.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Tildel %{name} i %{app}"
unbound = "Ikke tildelt"
five_directions = "5 retninger"
hold_shortcut = "Hold %{chord} nede"
shortcut_hold = "Hold"
shortcut_tap = "Tryk"
gesture_named = "Bevægelse %{name}"
left_click = "Venstreklik"
right_click = "Højreklik"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "%{name} in %{app} zuweisen"
unbound = "Nicht zugewiesen"
five_directions = "5 Richtungen"
hold_shortcut = "%{chord} halten"
shortcut_hold = "Halten"
shortcut_tap = "Tippen"
gesture_named = "Geste %{name}"
left_click = "Linksklick"
right_click = "Rechtsklick"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/el.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Αντιστοίχιση %{name} στο %{app}"
unbound = "Χωρίς αντιστοίχιση"
five_directions = "5 κατευθύνσεις"
hold_shortcut = "Κράτημα %{chord}"
shortcut_hold = "Κράτημα"
shortcut_tap = "Πάτημα"
gesture_named = "Χειρονομία %{name}"
left_click = "Αριστερό κλικ"
right_click = "Δεξί κλικ"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Bind %{name} in %{app}"
unbound = "Unbound"
five_directions = "5 directions"
hold_shortcut = "Hold %{chord}"
shortcut_hold = "Hold"
shortcut_tap = "Tap"
gesture_named = "Gesture %{name}"
left_click = "Left Click"
right_click = "Right Click"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/es.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Asignar %{name} en %{app}"
unbound = "Sin asignar"
five_directions = "5 direcciones"
hold_shortcut = "Mantener pulsado %{chord}"
shortcut_hold = "Mantener"
shortcut_tap = "Pulsar"
gesture_named = "Gesto %{name}"
left_click = "Clic izquierdo"
right_click = "Clic derecho"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/fi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Määritä %{name} sovelluksessa %{app}"
unbound = "Ei määritetty"
five_directions = "5 suuntaa"
hold_shortcut = "Pidä %{chord}"
shortcut_hold = "Pidä"
shortcut_tap = "Napauta"
gesture_named = "Ele %{name}"
left_click = "Vasen napsautus"
right_click = "Oikea napsautus"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Attribuer %{name} dans %{app}"
unbound = "Non attribué"
five_directions = "5 directions"
hold_shortcut = "Maintenir %{chord}"
shortcut_hold = "Maintenir"
shortcut_tap = "Appuyer"
gesture_named = "Geste %{name}"
left_click = "Clic gauche"
right_click = "Clic droit"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/it.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Associa %{name} in %{app}"
unbound = "Non associato"
five_directions = "5 direzioni"
hold_shortcut = "Tieni premuto %{chord}"
shortcut_hold = "Tieni premuto"
shortcut_tap = "Tocca"
gesture_named = "Gesto %{name}"
left_click = "Click sinistro"
right_click = "Click destro"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/ja.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "%{app} で %{name} を割り当て"
unbound = "未割り当て"
five_directions = "5 方向"
hold_shortcut = "%{chord} を長押し"
shortcut_hold = "長押し"
shortcut_tap = "タップ"
gesture_named = "ジェスチャー %{name}"
left_click = "左クリック"
right_click = "右クリック"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/ko.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "%{app}에서 %{name} 지정"
unbound = "할당되지 않음"
five_directions = "5방향"
hold_shortcut = "%{chord} 길게 누르기"
shortcut_hold = "길게 누르기"
shortcut_tap = "탭"
gesture_named = "제스처 %{name}"
left_click = "왼쪽 클릭"
right_click = "오른쪽 클릭"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/nb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Tilordne %{name} i %{app}"
unbound = "Ikke tildelt"
five_directions = "5 retninger"
hold_shortcut = "Hold %{chord} inne"
shortcut_hold = "Hold"
shortcut_tap = "Trykk"
gesture_named = "Bevegelse %{name}"
left_click = "Venstreklikk"
right_click = "Høyreklikk"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/nl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "%{name} toewijzen in %{app}"
unbound = "Niet toegewezen"
five_directions = "5 richtingen"
hold_shortcut = "%{chord} ingedrukt houden"
shortcut_hold = "Vasthouden"
shortcut_tap = "Tikken"
gesture_named = "Gebaar %{name}"
left_click = "Linkerklik"
right_click = "Rechterklik"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/pl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Przypisz %{name} w %{app}"
unbound = "Nieprzypisane"
five_directions = "5 kierunków"
hold_shortcut = "Przytrzymaj %{chord}"
shortcut_hold = "Przytrzymaj"
shortcut_tap = "Stuknij"
gesture_named = "Gest %{name}"
left_click = "Lewy przycisk"
right_click = "Prawy przycisk"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/pt-BR.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Atribuir %{name} em %{app}"
unbound = "Não atribuído"
five_directions = "5 direções"
hold_shortcut = "Manter %{chord}"
shortcut_hold = "Segurar"
shortcut_tap = "Tocar"
gesture_named = "Gesto %{name}"
left_click = "Clique Esquerdo"
right_click = "Clique Direito"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/pt-PT.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Atribuir %{name} em %{app}"
unbound = "Não atribuído"
five_directions = "5 direções"
hold_shortcut = "Manter %{chord}"
shortcut_hold = "Manter"
shortcut_tap = "Tocar"
gesture_named = "Gesto %{name}"
left_click = "Clique esquerdo"
right_click = "Clique direito"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/ru.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Назначить %{name} в %{app}"
unbound = "Не назначено"
five_directions = "5 направлений"
hold_shortcut = "Удерживать %{chord}"
shortcut_hold = "Удерживать"
shortcut_tap = "Нажать"
gesture_named = "Жест %{name}"
left_click = "Левый щелчок"
right_click = "Правый щелчок"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/sv.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Tilldela %{name} i %{app}"
unbound = "Ej tilldelad"
five_directions = "5 riktningar"
hold_shortcut = "Håll %{chord} nedtryckt"
shortcut_hold = "Håll"
shortcut_tap = "Tryck"
gesture_named = "Gest %{name}"
left_click = "Vänsterklick"
right_click = "Högerklick"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/tr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "%{app} içinde %{name} ata"
unbound = "Atanmamış"
five_directions = "5 yön"
hold_shortcut = "%{chord} basılı tut"
shortcut_hold = "Basılı tut"
shortcut_tap = "Dokun"
gesture_named = "%{name} hareketi"
left_click = "Sol Tıklama"
right_click = "Sağ Tıklama"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/uk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "Прив'язати %{name} в %{app}"
unbound = "Не прив'язано"
five_directions = "5 напрямків"
hold_shortcut = "Утримувати %{chord}"
shortcut_hold = "Утримувати"
shortcut_tap = "Натиснути"
gesture_named = "Жест %{name}"
left_click = "Клацання лівою"
right_click = "Клацання правою"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/zh-CN.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "在 %{app} 中绑定 %{name}"
unbound = "未绑定"
five_directions = "5 个方向"
hold_shortcut = "按住 %{chord}"
shortcut_hold = "按住"
shortcut_tap = "轻按"
gesture_named = "手势 %{name}"
left_click = "左键单击"
right_click = "右键单击"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/zh-HK.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "在 %{app} 中綁定 %{name}"
unbound = "未綁定"
five_directions = "5 個方向"
hold_shortcut = "按住 %{chord}"
shortcut_hold = "按住"
shortcut_tap = "輕按"
gesture_named = "手勢 %{name}"
left_click = "左鍵單擊"
right_click = "右鍵單擊"
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogi-ui/locales/zh-TW.toml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ bind_control_in_app = "在 %{app} 中設定 %{name}"
unbound = "未設定"
five_directions = "5 個方向"
hold_shortcut = "按住 %{chord}"
shortcut_hold = "按住"
shortcut_tap = "輕按"
gesture_named = "手勢 %{name}"
left_click = "左鍵按一下"
right_click = "右鍵按一下"
Expand Down
Loading