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
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ object InputPrefs {
p.getString(CUSTOM_DOUBLE_HOLD, "none") == "keys" ||
p.getString(CUSTOM_HOLD_DRAG_CONTACT, "raw") == "step_zoom" ||
p.getString(CUSTOM_HOLD_DRAG_HOVER, "raw") == "step_zoom" ||
p.getString(CUSTOM_HOLD_DRAG_CONTACT, "raw") == "pan"
p.getString(CUSTOM_HOLD_DRAG_CONTACT, "raw") in setOf("pan", "pan_zoom")
else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class Trigger(val key: String, val label: Int, val default: String, val actions:

/**
* One key-combo editor: where it is stored ([prefKey]), its [title], and the Custom [triggerKeys] that enable it
* when any of them is set to [action].
* when any of them is set to one of [actions].
*/
class KeyEditorSpec(
val prefKey: String,
val title: Int,
val triggerKeys: List<String>,
val action: String = "keys",
val actions: Set<String> = setOf("keys"),
) {
constructor(prefKey: String, title: Int, triggerKey: String) : this(prefKey, title, listOf(triggerKey))
}
Expand All @@ -48,6 +48,7 @@ val ActionLabels = mapOf(
"step_zoom" to R.string.action_step_zoom,
"wheel_zoom" to R.string.action_wheel_zoom,
"pan" to R.string.action_pan,
"pan_zoom" to R.string.action_pan_zoom,
"none" to R.string.action_none,
"keys" to R.string.action_keys,
)
Expand All @@ -70,7 +71,7 @@ val Triggers = listOf(
Trigger(InputPrefs.CUSTOM_DOUBLE_HOLD, R.string.trigger_double_hold, "none",
listOf("eraser", "keys", "none")),
Trigger(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT, R.string.trigger_hold_drag_contact, "raw",
listOf("raw", "scroll", "pc_zoom", "step_zoom", "wheel_zoom", "pan", "none")),
listOf("raw", "scroll", "pc_zoom", "step_zoom", "wheel_zoom", "pan", "pan_zoom", "none")),
Trigger(InputPrefs.CUSTOM_HOLD_DRAG_HOVER, R.string.trigger_hold_drag_hover, "raw",
listOf("raw", "scroll", "pc_zoom", "step_zoom", "wheel_zoom", "none")),
)
Expand All @@ -83,15 +84,15 @@ val KeyEditors = listOf(
KeyEditorSpec(InputPrefs.KEYS_DOUBLE_HOLD, R.string.keys_title_double_hold, InputPrefs.CUSTOM_DOUBLE_HOLD),
KeyEditorSpec(
InputPrefs.KEYS_ZOOM_IN, R.string.keys_title_zoom_in,
listOf(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT, InputPrefs.CUSTOM_HOLD_DRAG_HOVER), "step_zoom",
listOf(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT, InputPrefs.CUSTOM_HOLD_DRAG_HOVER), setOf("step_zoom"),
),
KeyEditorSpec(
InputPrefs.KEYS_ZOOM_OUT, R.string.keys_title_zoom_out,
listOf(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT, InputPrefs.CUSTOM_HOLD_DRAG_HOVER), "step_zoom",
listOf(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT, InputPrefs.CUSTOM_HOLD_DRAG_HOVER), setOf("step_zoom"),
),
KeyEditorSpec(
InputPrefs.KEYS_PAN, R.string.keys_title_pan,
listOf(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT), "pan",
listOf(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT), setOf("pan", "pan_zoom"),
),
)

Expand Down Expand Up @@ -132,7 +133,7 @@ fun visibleKeyEditors(state: SettingsState): List<String> = when (state.profile)
"graphics_tablet" -> listOf(InputPrefs.KEYS_HOLD, InputPrefs.KEYS_DOUBLE_HOLD)
"custom" -> KeyEditors.filter { e ->
// The drag triggers are unused while hold sends keys.
e.triggerKeys.any { state.custom[it] == e.action && !(it in DragTriggerKeys && dragsDisabled(state)) }
e.triggerKeys.any { state.custom[it] in e.actions && !(it in DragTriggerKeys && dragsDisabled(state)) }
}.map { it.prefKey }
else -> emptyList()
}
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<string name="action_step_zoom">Zoom in Stufen</string>
<string name="action_wheel_zoom">Zoom mit dem Mausrad, in Stufen</string>
<string name="action_pan">Arbeitsfläche verschieben</string>
<string name="action_pan_zoom">Verschieben oder zoomen</string>
<string name="action_none">Keine</string>
<string name="settings_zoom_factor">Zoomstufe</string>
<string name="settings_air_actions_on">Die Air-Aktionen von Samsung sind aktiviert. Sie können auf Tastendrücke reagieren, die bei aufgesetzter Stiftspitze beginnen. Deaktiviere sie unter Einstellungen → Erweiterte Funktionen → S Pen → Air-Aktionen.</string>
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<string name="action_step_zoom">Zoom por pasos</string>
<string name="action_wheel_zoom">Zoom con la rueda, por pasos</string>
<string name="action_pan">Mover el lienzo</string>
<string name="action_pan_zoom">Mover o hacer zoom</string>
<string name="action_none">Nada</string>
<string name="settings_zoom_factor">Nivel de zoom</string>
<string name="settings_air_actions_on">Las acciones aéreas de Samsung están activadas. Pueden reaccionar a pulsaciones del botón que empiezan con la punta apoyada. Desactivalas en Ajustes → Funciones avanzadas → S Pen → Acciones aéreas.</string>
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<string name="action_step_zoom">Zoom par paliers</string>
<string name="action_wheel_zoom">Zoom par molette, par paliers</string>
<string name="action_pan">Déplacer le canevas</string>
<string name="action_pan_zoom">Déplacer ou zoomer</string>
<string name="action_none">Aucune</string>
<string name="settings_zoom_factor">Niveau de zoom</string>
<string name="settings_air_actions_on">Les actions aériennes de Samsung sont activées. Elles peuvent réagir aux appuis sur le bouton qui commencent avec la pointe posée. Désactivez-les dans Paramètres → Fonctions avancées → S Pen → Actions aériennes.</string>
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<string name="action_step_zoom">Zoom a scatti</string>
<string name="action_wheel_zoom">Zoom con la rotellina, a scatti</string>
<string name="action_pan">Sposta la tela</string>
<string name="action_pan_zoom">Sposta o ingrandisci</string>
<string name="action_none">Nessuna</string>
<string name="settings_zoom_factor">Livello di zoom</string>
<string name="settings_air_actions_on">Le azioni aeree di Samsung sono attive. Possono reagire alle pressioni del pulsante che iniziano con la punta appoggiata. Disattivale in Impostazioni → Funzioni avanzate → S Pen → Azioni aeree.</string>
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<string name="action_step_zoom">Zoom em etapas</string>
<string name="action_wheel_zoom">Zoom com a roda, em etapas</string>
<string name="action_pan">Mover a tela</string>
<string name="action_pan_zoom">Mover ou dar zoom</string>
<string name="action_none">Nada</string>
<string name="settings_zoom_factor">Nível de zoom</string>
<string name="settings_air_actions_on">As ações aéreas da Samsung estão ativadas. Elas podem reagir a pressionamentos do botão que começam com a ponta apoiada. Desative-as em Configurações → Recursos avançados → S Pen → Ações aéreas.</string>
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<string name="action_step_zoom">Zoom in steps</string>
<string name="action_wheel_zoom">Zoom with the wheel, in steps</string>
<string name="action_pan">Pan the canvas</string>
<string name="action_pan_zoom">Pan or zoom</string>
<string name="action_none">Nothing</string>
<string name="settings_zoom_factor">Zoom level</string>
<string name="settings_air_actions_on">Samsung Air actions are on. They may react to button presses that start with the pen tip down. Turn them off in Settings → Advanced features → S Pen → Air actions.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class SettingsRulesTest {

@Test fun panOnTheContactDragShowsThePanEditor() {
assertEquals(listOf(InputPrefs.KEYS_PAN), visibleKeyEditors(custom(contact = "pan")))
assertEquals(listOf(InputPrefs.KEYS_PAN), visibleKeyEditors(custom(contact = "pan_zoom")))
assertEquals(emptyList<String>(), visibleKeyEditors(custom(hover = "pan")))
assertEquals(emptyList<String>(), visibleKeyEditors(custom(contact = "wheel_zoom", hover = "wheel_zoom")))
assertEquals(listOf(InputPrefs.KEYS_HOLD), visibleKeyEditors(custom(hold = "keys", contact = "pan")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ class SettingsStoreTest {
assertEquals("raw", s.custom[InputPrefs.CUSTOM_HOLD])
}

@Test fun panZoomIsOnlyAcceptedByTheContactDragAndUsesKeys() {
store.setProfile("custom")
store.setCustomAction(InputPrefs.CUSTOM_HOLD_DRAG_HOVER, "pan_zoom")
store.setCustomAction(InputPrefs.CUSTOM_HOLD, "pan_zoom")
assertEquals("raw", s.custom[InputPrefs.CUSTOM_HOLD_DRAG_HOVER])
assertEquals("raw", s.custom[InputPrefs.CUSTOM_HOLD])
assertFalse(InputPrefs.usesKeys(context))
store.setCustomAction(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT, "pan_zoom")
assertEquals("pan_zoom", prefs.getString(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT, null))
assertTrue(InputPrefs.usesKeys(context))
assertEquals(
"pan_zoom",
JSONObject(InputPrefs.toJson(context)).getJSONObject("custom").getString("hold_drag_contact"),
)
}

@Test fun panShortcutDefaultsToSpaceAndReachesTheJson() {
assertEquals(KeyCombo(0, 0x2C), s.keys[InputPrefs.KEYS_PAN])
store.setKey(InputPrefs.KEYS_PAN, 0x04)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SettingsWideTest : SettingsUiTestBase() {
@Test fun customPanShowsThePanShortcut() {
launch(AirActions.On) {
putString(InputPrefs.PROFILE, "custom")
putString(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT, "pan")
putString(InputPrefs.CUSTOM_HOLD_DRAG_CONTACT, "pan_zoom")
putString(InputPrefs.CUSTOM_HOLD_DRAG_HOVER, "wheel_zoom")
}
tag("shortcut_keys_zoom_in").assertDoesNotExist()
Expand Down
9 changes: 8 additions & 1 deletion crates/ezd-input/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ pub enum ButtonAction {
/// ([`KeyBindings::pan`], Space by default) is kept pressed while the tip
/// touches, so a drag with the pen pans in many drawing apps.
Pan,
/// Pan or zoom the canvas of the host by dragging with the tip (contact
/// drag only), like a graphics-tablet pan/zoom button: a mostly vertical
/// drag zooms with the wheel (as [`ButtonAction::WheelZoom`]), any other
/// drag pans (as [`ButtonAction::Pan`]). The first drag past the slop
/// decides, until the lift. With an empty pan combination the pan branch
/// just forwards the contact.
PanZoom,
/// Toggle the local zoom of the view.
LocalZoom,
/// Switch to the eraser while held (hold trigger only).
Expand Down Expand Up @@ -246,7 +253,7 @@ impl ButtonMap {
_ => None,
},
hold_drag_contact: match self.hold_drag_contact {
Pan => Pan,
Pan | PanZoom => self.hold_drag_contact,
a => drag(a),
},
hold_drag_hover: drag(self.hold_drag_hover),
Expand Down
139 changes: 137 additions & 2 deletions crates/ezd-input/src/gesture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ const STEP_ZOOM_GAP_US: u64 = 60_000;
/// Zoom steps that can be queued by fast travel; the rest is dropped.
const STEP_ZOOM_BACKLOG: f32 = 3.0;

/// Decision of the [`Held::PanZoom`] drag, taken once per touch.
#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) enum PanZoomMode {
/// The travel from the anchor has not passed the slop yet.
Classify,
/// Wheel zoom steps; `rem` holds the upward travel not yet turned into steps.
Zoom,
/// The pan combination is pressed and the contact is forwarded.
Pan,
}

/// A resolved gesture whose barrel button is still down.
#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) enum Held {
Expand All @@ -60,6 +71,16 @@ pub(crate) enum Held {
/// pressed (`PenState::keys_held`) while the tip touches and released at
/// the lift. The pen reports contact and motion as usual.
PanDrag,
/// Pan or zoom drag. The tip touch is reported as hover until the drag
/// picks a mode; `Pan` then forwards the contact (starting at `anchor`, the
/// first touch point) and `Zoom` keeps reporting hover. After a lift the
/// state waits for the next touch (barrel still held).
PanZoom {
anchor: (f32, f32),
touching: bool,
mode: PanZoomMode,
rem: f32,
},
/// The hold key combination is pressed (`PenState::keys_held`); the pen
/// reports contact and motion as usual.
Keys,
Expand Down Expand Up @@ -208,7 +229,10 @@ impl InputEngine {
!matches!(m.hold, ButtonAction::Keys | ButtonAction::None)
&& (drag_effect(m.hold_drag_hover)
|| drag_effect(m.hold_drag_contact)
|| m.hold_drag_contact == ButtonAction::Pan)
|| matches!(
m.hold_drag_contact,
ButtonAction::Pan | ButtonAction::PanZoom
))
}

/// Hold action fired by the release of a barrel that was held still past the
Expand Down Expand Up @@ -323,6 +347,35 @@ impl InputEngine {
self.set_held(Held::PanDrag);
}

/// Starts the pan or zoom drag at the tip touch: contact is reported as
/// hover until the drag picks a mode.
fn start_pan_zoom(&mut self) {
self.pen.suppress = true;
self.set_held(Held::PanZoom {
anchor: self.cur_pos(),
touching: true,
mode: PanZoomMode::Classify,
rem: 0.0,
});
}

/// The barrel went down with the tip already touching, and the contact drag
/// is a pan or pan/zoom: ends the stroke with a lift sample, then goes on as
/// if the tip had just touched with the barrel held.
fn barrel_while_touching(&mut self, t: u64, out: &mut Vec<Message>) {
self.pen.suppress = true;
let f = self.base_flags();
self.emit_flush(t, f, out);
if self.p.map.hold_drag_contact == ButtonAction::Pan {
self.start_pan(t, out);
self.pen.suppress = false;
let f = self.base_flags();
self.emit_flush(t, f, out);
} else {
self.start_pan_zoom();
}
}

/// Starts the double-hold action: presses its combination and keeps it
/// pressed until the barrel is released, or switches to the eraser.
fn resolve_double_hold(&mut self, t: u64, out: &mut Vec<Message>) {
Expand Down Expand Up @@ -441,6 +494,16 @@ impl InputEngine {
let g = self.pen.gesture;
if down {
match g {
Gesture::Idle
if self.pen.contact
&& self.p.map.hold != ButtonAction::Keys
&& matches!(
self.p.map.hold_drag_contact,
ButtonAction::Pan | ButtonAction::PanZoom
) =>
{
self.barrel_while_touching(t, out);
}
Gesture::Idle if self.pen.contact => {
// Pressed with the tip already down: forward raw.
self.pen.barrel_fwd = true;
Expand Down Expand Up @@ -474,7 +537,17 @@ impl InputEngine {
} else {
// The held keys are released whatever the gesture state is, except
// the pan keys of a touching tip: they stay until the lift.
if !(g == Gesture::Held(Held::PanDrag) && self.pen.contact) {
let pan_keys = matches!(
g,
Gesture::Held(
Held::PanDrag
| Held::PanZoom {
mode: PanZoomMode::Pan,
..
}
)
);
if !(pan_keys && self.pen.contact) {
self.release_keys(t, out);
}
self.pen.gesture = Gesture::Idle;
Expand Down Expand Up @@ -598,6 +671,12 @@ impl InputEngine {
{
self.start_pan(t, out);
}
Gesture::Pending { .. }
| Gesture::Held(Held::HoverDrag { .. } | Held::PanZoom { .. })
if self.p.map.hold_drag_contact == ButtonAction::PanZoom =>
{
self.start_pan_zoom();
}
Gesture::Pending { past_t: true, .. }
if self.defers_hold() && !drag_effect(self.p.map.hold_drag_contact) =>
{
Expand Down Expand Up @@ -685,6 +764,14 @@ impl InputEngine {
self.instant(click, Trigger::Click, t, out);
}
}
if let Gesture::Held(Held::PanZoom { anchor, .. }) = self.pen.gesture {
self.set_held(Held::PanZoom {
anchor,
touching: false,
mode: PanZoomMode::Classify,
rem: 0.0,
});
}
if self.pen.eraser_switch_pending {
self.eraser_end(t, out);
}
Expand Down Expand Up @@ -732,6 +819,45 @@ impl InputEngine {
}
let prev = self.pen.prev;
let d = (cur.0 - prev.0, cur.1 - prev.1);
if let Gesture::Held(Held::PanZoom {
anchor,
touching: true,
mode: PanZoomMode::Classify,
..
}) = self.pen.gesture
&& dist(cur, anchor) > self.p.slop
{
let (dx, dy) = (cur.0 - anchor.0, cur.1 - anchor.1);
if dy.abs() >= 2.0 * dx.abs() {
// The travel up to the previous sample; this sample's delta is
// added below, so the slop distance counts for the first step.
self.set_held(Held::PanZoom {
anchor,
touching: true,
mode: PanZoomMode::Zoom,
rem: anchor.1 - prev.1,
});
} else {
let c = self.p.keys.pan;
if self.pen.keys_held.is_none() {
Self::press_combo(c, t, out);
self.pen.keys_held = Some(c);
}
self.pen.suppress = false;
self.set_held(Held::PanZoom {
anchor,
touching: true,
mode: PanZoomMode::Pan,
rem: 0.0,
});
// The app pans from where the tip first touched.
let saved = (self.pen.cur.x, self.pen.cur.y);
(self.pen.cur.x, self.pen.cur.y) = anchor;
let f = self.base_flags();
self.emit_flush(t, f, out);
(self.pen.cur.x, self.pen.cur.y) = saved;
}
}
let n = self.p.scroll_n;
let slop = self.p.slop;
let mut emit: Option<((f32, f32), Units)> = None;
Expand Down Expand Up @@ -766,6 +892,15 @@ impl InputEngine {
}
}
}
Gesture::Held(Held::PanZoom {
anchor,
touching: true,
mode: PanZoomMode::Zoom,
rem,
}) => {
zoom = step_zoom_dir(rem, d.1, zstep, &mut self.pen.step_last, t)
.map(|up| (*anchor, up, true));
}
Gesture::Held(Held::Pan) => {
self.view = crate::view::ViewTransform {
tx: self.view.tx + d.0,
Expand Down
Loading
Loading