Skip to content

feat(mcp): iphone_swipe holds before moving with hold, to drag icons - #144

Merged
Derrors merged 3 commits into
Derrors:mainfrom
cosinec:feat/swipe-hold
Nov 17, 2026
Merged

Derrors merged 3 commits into
Derrors:mainfrom
cosinec:feat/swipe-hold

Conversation

@cosinec

@cosinec cosinec commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

What and why

Things that have to be long-pressed before they can be dragged (home-screen icons, files, reorderable list rows) can't be moved with iphone_swipe: the finger moves as soon as it's down, so the screen just scrolls or pages. iphone_long_press followed by iphone_swipe lifts the finger in between. There is no way to hold and then drag in one touch.

iphone_swipe gets an optional hold (seconds, default 0):

  • WDA: drag_steps puts a pointerMove in place for hold ms between the down and the move. I tried a pause first, which is the obvious encoding, and it doesn't work: on the home screen a pause of 0.6–1 s before the move picked the icon up 0/6 times (it just paged), while an in-place move of 0.5 s did 3/3 and 0.3 s did 0/3 (raw /actions probes, same phone). With hold 0 the steps are exactly swipe_steps, so a plain swipe sends the same request as before.
  • HID (native on iOS 27, or the fallback): new HidSession::held_drag presses, re-reports the position every 100 ms for hold seconds like long_press does, then runs the same interpolated drag without lifting.
  • Protocol: Request::Swipe gets hold with #[serde(default, skip_serializing_if = zero)]. A swipe without it is byte-for-byte what it was (asserted in requests_round_trip_as_tagged_json). An older daemon ignores the field and swipes as before (checked with 0.2.7 below).
  • Limits: check_request bounds seconds + hold by the existing MAX_GESTURE_SECONDS (10), since HID sends samples for both parts, and rejects a negative or non-finite hold.
  • MCP: hold in the iphone_swipe schema; its description says when to use it and that under 0.5 s usually picks nothing up. The result line adds ,先按住 0.6 秒 / , held 0.6 s first only when hold > 0.
  • The daemon's swipe now takes a small Stroke { from, to, seconds, hold } instead of a fourth loose parameter (clippy's argument limit).

The viewer's own swipe and unlock swipes are unchanged (hold: 0). Tool names, existing parameters and default output don't change (D10).

Tests

1. Unit tests

  • cargo test --workspace --all-features --locked, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings and cargo fmt --check (per package) pass (Rust 1.99.1, macOS)
  • New or changed behaviour has a unit test:
    • ictl-wda: client::tests::a_held_drag_holds_with_a_move_in_place: down, in-place move for hold, move to the end, up; hold 0 equals swipe_steps.
    • ictl-mcp: tests::swipe_hold_defaults_to_zero: default 0, passed through when given, a non-number is an error.
    • ictl-daemon: core::tests::gesture_seconds_are_bounded now also covers seconds + hold (5+5 ok, 5+5.5 rejected) and negative/NaN hold.
    • ictl-protocol: tests::requests_round_trip_as_tagged_json checks the exact JSON of a plain swipe (no hold key) and round-trips a held one.
  • No existing test removed, ignored or loosened. Existing Request::Swipe { .. } constructions in tests only gained hold: 0.0.
  • #[ignore] tests of the changed area run by hand: none apply

2. Real-device regression

  • Device, iOS version, host (Linux / macOS): iPhone 12 mini (iPhone13,1), iOS 26.4.1, macOS (Apple silicon); WDA 16.14.0 launched in the background by the daemon
  • tests/device/run.py default steps pass on this branch (exit code 0): 16 calls, 0 failed, 15.8s in all
  • The same steps on the latest release, same device: v0.2.7 release binary, 16 calls, 0 failed, 16.7s in all. No step on the branch is clearly slower; the default iphone_swipe step takes 1.80 s on the branch and 1.87 s on 0.2.7.
  • Steps exercising this change: see section 4
  • Longer run: not affected
run.py output
this branch:

### iPhone13,1, iOS 26.4.1, 375x812 pt, WDA, 00008101-00150D941AD8001E
=== iphone_status {} 0.24s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
=== iphone_tap_element {"text": "不存在的按钮xyz"} 1.34s
没找到包含 "不存在的按钮xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
=== iphone_press_button {"button": "home"} 1.31s
已按 home
=== iphone_launch_app {"app": "时钟"} 0.97s
已启动 com.apple.mobiletimer
=== iphone_list_elements {"limit": 40} 0.25s
StaticText "0秒钟" id="stopwatch-time" @(188,235) 375x106
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
PageIndicator "第1页(共2页), 数码秒表" value="第1页(共2页), 数码秒表" @(188,420) 56x31
Table "空列表" @(188,644) 375x337
TabBar "标签页栏" @(188,770) 375x83
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.63s
已点击 Button "世界时钟" @(72,760) 94x54
画面已静止(0.7 秒);但有一小块还在动(可能是加载圈或小动画),内容可能还没加载完,要等结果用 iphone_wait_for 或稍后再截图
--- 操作后的界面 ---
Button "编辑" @(49,72) 58x36
Button "添加" @(337,72) 36x36
Button "世界时钟" value="1" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "秒表", "then": "elements", "then_filter": "Button"} 1.59s
已点击 Button "秒表" @(226,760) 94x54
画面已静止(0.7 秒)
--- 操作后的界面 ---
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_screenshot {} 0.19s
<image shots/shot1.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_screenshot {"x": 0, "y": 0, "width": 375.0, "height": 60} 0.18s
<image shots/shot2.jpg (1124, 180)>
区域 (0,0) 起 375x60 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
=== iphone_press_button {"button": "home"} 1.83s
已按 home
=== iphone_swipe {"from_x": 188, "from_y": 349, "to_x": 188, "to_y": 609} 1.80s
已滑动 (188,349) → (188,609)
=== iphone_type_text {"text": "设置"} 1.05s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.25s
已出现 Cell "设置" id="Identifier:GridCell,Section:0,Row:0" @(188,143) 330x114(0.2 秒)
=== iphone_screenshot {} 0.40s
<image shots/shot3.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_press_button {"button": "home"} 1.52s
已按 home
=== iphone_status {} 0.19s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
--- 16 calls, 0 failed, 15.8s in all

latest release (v0.2.7):

### iPhone13,1, iOS 26.4.1, 375x812 pt, WDA, 00008101-00150D941AD8001E
=== iphone_status {} 0.23s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
=== iphone_tap_element {"text": "不存在的按钮xyz"} 1.36s
没找到包含 "不存在的按钮xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
=== iphone_press_button {"button": "home"} 1.27s
已按 home
=== iphone_launch_app {"app": "时钟"} 0.95s
已启动 com.apple.mobiletimer
=== iphone_list_elements {"limit": 40} 0.26s
StaticText "0秒钟" id="stopwatch-time" @(188,235) 375x106
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
PageIndicator "第1页(共2页), 数码秒表" value="第1页(共2页), 数码秒表" @(188,420) 56x31
Table "空列表" @(188,644) 375x337
TabBar "标签页栏" @(188,770) 375x83
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.63s
已点击 Button "世界时钟" @(72,760) 94x54
画面已静止(0.7 秒)
--- 操作后的界面 ---
Button "编辑" @(49,72) 58x36
Button "添加" @(337,72) 36x36
Button "世界时钟" value="1" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "秒表", "then": "elements", "then_filter": "Button"} 1.60s
已点击 Button "秒表" @(226,760) 94x54
画面已静止(0.7 秒)
--- 操作后的界面 ---
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_screenshot {} 0.19s
<image shots/shot1.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_screenshot {"x": 0, "y": 0, "width": 375.0, "height": 60} 0.15s
<image shots/shot2.jpg (1124, 180)>
区域 (0,0) 起 375x60 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
=== iphone_press_button {"button": "home"} 1.76s
已按 home
=== iphone_swipe {"from_x": 188, "from_y": 349, "to_x": 188, "to_y": 609} 1.87s
已滑动 (188,349) → (188,609)
=== iphone_type_text {"text": "设置"} 1.69s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.30s
已出现 Cell "设置" id="Identifier:GridCell,Section:0,Row:0" @(188,143) 330x114(0.3 秒)
=== iphone_screenshot {} 0.34s
<image shots/shot3.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_press_button {"button": "home"} 1.53s
已按 home
=== iphone_status {} 0.18s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
--- 16 calls, 0 failed, 16.7s in all

3. Regression cases (docs/dev/regression-cases.md)

4. Real-device proof of the fix or feature

  • Device, iOS version, host (Linux / macOS): iPhone 12 mini, iOS 26.4.1, macOS
  • Feature: exercised end to end through the MCP server
  • Untested conditions: the HID path (this phone is below iOS 27 and WDA was up throughout); landscape; iPad; reordering rows in a list (Reminders on iOS 26 opens the detail sheet on a long press instead of lifting the row, so it isn't a test target)
Steps and results

Home screen, the Settings icon alone in row 4 at (62,580); the target is the empty slot at (232,580). Each run: iphone_swipe from the icon to the slot, then iphone_list_elements for the icon's position. When it moved, it was dragged back with hold 0.6 and edit mode was left with Home, and its position was checked before the next run. Times are the iphone_swipe call (it waits for the screen to settle afterwards).

no_hold_s0.7 3.46s 设置 (62, 580) -> (62, 580)
no_hold_s0.7 3.40s 设置 (62, 580) -> (62, 580)
no_hold_s0.7 3.45s 设置 (62, 580) -> (62, 580)
no_hold_s0.7 3.43s 设置 (62, 580) -> (62, 580)
no_hold_s0.7 3.46s 设置 (62, 580) -> (62, 580)
== no_hold_s0.7: 0/5 avg 3.44s
hold0.6_s0.7 3.29s 设置 (62, 580) -> (237, 580)
hold0.6_s0.7 3.14s 设置 (62, 580) -> (237, 580)
hold0.6_s0.7 3.23s 设置 (62, 580) -> (237, 580)
hold0.6_s0.7 3.20s 设置 (62, 580) -> (237, 580)
hold0.6_s0.7 3.29s 设置 (62, 580) -> (237, 580)
== hold0.6_s0.7: 5/5 avg 3.23s
hold1.0_s0.7 3.64s 设置 (62, 580) -> (237, 580)
hold1.0_s0.7 3.61s 设置 (62, 580) -> (237, 580)
hold1.0_s0.7 3.67s 设置 (62, 580) -> (237, 580)
hold1.0_s0.7 3.67s 设置 (62, 580) -> (237, 580)
hold1.0_s0.7 3.66s 设置 (62, 580) -> (237, 580)
== hold1.0_s0.7: 5/5 avg 3.65s
hold0.5_s0.7 3.30s 设置 (62, 580) -> (237, 580)
hold0.5_s0.7 3.17s 设置 (62, 580) -> (237, 580)
hold0.5_s0.7 3.15s 设置 (62, 580) -> (237, 580)
hold0.5_s0.7 3.17s 设置 (62, 580) -> (237, 580)
hold0.5_s0.7 3.16s 设置 (62, 580) -> (237, 580)
== hold0.5_s0.7: 5/5 avg 3.19s

The 20 drags back to the original slot (also with hold 0.6) all landed, so 35/35 held drags worked in total.

v0.2.7 with hold (the field is ignored, a plain swipe):

=== iphone_swipe {"from_x": 62, "from_y": 568, "to_x": 232, "to_y": 568, "seconds": 0.7, "hold": 0.6} 3.35s
已滑动 (62,568) → (232,568)
=== iphone_list_elements {"filter": "设置"} 0.51s
Icon "设置" value="1个新项目" @(62,580) 80x102
--- 2 calls, 0 failed, 4.5s in all

Checklist

  • MCP tool names, parameters and default outputs stay compatible (docs/decisions.md D10): one optional parameter added, nothing else changes
  • New or changed dependencies are pinned to exact versions; vendor changes recorded in THIRD_PARTY.md: no dependency changes

Docs: docs/tools.md, website/guide/tools.md, website/en/guide/tools.md, CHANGELOG.md, CHANGELOG.zh-CN.md.

🤖 Generated with Claude Code

Home-screen icons, files and reorderable rows have to be long-pressed
before they can be dragged. iphone_swipe moves as soon as the finger is
down, so it only scrolls or pages. Holding with a W3C pause before the
move doesn't pick them up either; holding with a pointerMove in place
does. hold (seconds, default 0) adds that in-place move before the
stroke; over HID the finger is held, reporting its position every
100 ms like a long press, and then dragged without lifting.

On an iPhone 12 mini, moving the Settings icon to an empty slot worked
5/5 each with hold 0.5, 0.6 and 1 s, and 0/5 without it. A swipe
without hold is the same request as before, and seconds + hold is
bounded by the existing 10 s gesture limit.

Regression case Derrors#149.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Derrors and others added 2 commits November 17, 2026 23:10
Resolve the conflicts with Derrors#139, Derrors#141 and Derrors#143 by keeping both sides:
drag_steps next to tap_sequence_body, the exports of both, the protocol
helpers, the MCP tests, CHANGELOG lines and regression rows Derrors#146-Derrors#149 in
order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only the sum was checked, so a negative seconds passed when the hold made
up for it (-0.5 + 1), and a sum over the limit said "seconds must be
between 0 and 10" although seconds alone was fine. Now seconds keeps its
own range, hold can't be negative, and a sum over the limit names both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit 8981d1e into Derrors:main Nov 17, 2026
15 of 16 checks passed
Derrors added a commit to cosinec/iphone-control that referenced this pull request Nov 17, 2026
Resolve the conflicts with Derrors#141, Derrors#143 and Derrors#144: keep both sides (Tap's
count and TapSequence next to TapElement's scroll, the protocol helpers,
the MCP tests, CHANGELOG lines, doc rows with iphone_tap's count and
iphone_tap_element's scroll, regression rows Derrors#146-Derrors#149 then Derrors#151).

The search scroll now builds the Stroke that Derrors#144's swipe takes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants