마우스 오른쪽 클릭 = 즉시 길게 누르기
- TOUCH_EVENT 오프셋 2..4를 flags로: 0x0001 LONG_PRESS (DOWN에만 의미) - 호스트: 오른쪽 버튼 누름을 길게 누르기 터치로 보내고, 같은 버튼을 뗄 때 UP - 데몬: 누르는 동안만 long_press_timeout을 120ms로 줄였다가 떼면 복원 (줄인 채 종료되면 다음 시작 때 복원), DEEP_PRESS 분류 MOVE도 함께 주입, 짧게 떼도 길게 누르기가 되도록 UP을 미룸 - 실기기: 홈 화면 아이콘 메뉴 0.5초 -> 약 0.17초 - probe: --rclick
- 작성자
- LeeJunyoung
- 작성 시각
- 커밋
fe8ddc3d747c10fcf8ae5df6272e86f18f87501c- 부모
- 70804a9
변경된 파일 7개
+305-23| @@ -42,6 +42,7 @@ object DaemonMain { | ||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | val identity = DeviceIdentity.loadOrCreate(dataDir) |
| 45 | 추가: LongPress.recover(dataDir) | |
| 45 | 46 | val whitelist = Whitelist(File(dataDir, "whitelist")) |
| 46 | 47 | Log.i("android-remote daemon v$DAEMON_VERSION uid=${android.os.Process.myUid()}") |
| 47 | 48 | Log.i("인증서 SHA-256: ${Hex.encode(identity.fingerprint)}") |
| @@ -35,7 +35,57 @@ class InputInjector { | ||
| 35 | 35 | return (x + 0.5f) * dw / fw to (y + 0.5f) * dh / fh |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 삭제: fun touch(t: Messages.TouchEvent) { | |
| 38 | 추가: /** | |
| 39 | 추가: * 오른쪽 버튼 길게 누르기 (기획서 7.3 4항). 시작 시각과, 너무 일찍 뗐을 때 미뤄 둔 UP. | |
| 40 | 추가: * 세게 누르기(DEEP_PRESS)를 모르는 앱도 길게 누르기로 판정하도록 UP을 길게 누르기 시간 뒤로 미룬다. | |
| 41 | 추가: */ | |
| 42 | 추가: private var longPressAt = 0L | |
| 43 | 추가: private var deferredUp: Messages.TouchEvent? = null | |
| 44 | 추가: private val lock = Any() | |
| 45 | 추가: | |
| 46 | 추가: fun touch(t: Messages.TouchEvent) = synchronized(lock) { | |
| 47 | 추가: // 미뤄 둔 UP이 있으면 다음 터치보다 먼저 보낸다. | |
| 48 | 추가: deferredUp?.let { deferredUp = null; finishUp(it) } | |
| 49 | 추가: if (t.action == TouchAction.UP && longPressAt != 0L && pointers.size == 1 && pointers[0].id == t.pointerId) { | |
| 50 | 추가: val wait = longPressAt + LongPress.holdMs() - SystemClock.uptimeMillis() | |
| 51 | 추가: if (wait > 0) { | |
| 52 | 추가: // 너무 일찍 떼면 길게 누르기로 판정되기 전에 끝나므로 UP을 미룬다. | |
| 53 | 추가: deferredUp = t | |
| 54 | 추가: scheduler.schedule({ | |
| 55 | 추가: synchronized(lock) { if (deferredUp === t) { deferredUp = null; finishUp(t) } } | |
| 56 | 추가: }, wait, java.util.concurrent.TimeUnit.MILLISECONDS) | |
| 57 | 추가: } else { | |
| 58 | 추가: finishUp(t) | |
| 59 | 추가: } | |
| 60 | 추가: return@synchronized | |
| 61 | 추가: } | |
| 62 | 추가: if (t.action == TouchAction.DOWN && t.longPress && pointers.isEmpty()) { | |
| 63 | 추가: // 시스템 길게 누르기 시간을 잠깐 줄여 바로 길게 누르기가 되게 한다. 앱은 DOWN을 받을 때 | |
| 64 | 추가: // 이 값을 읽으므로 DOWN보다 먼저 바꾼다. | |
| 65 | 추가: LongPress.shorten() | |
| 66 | 추가: touchNow(t) | |
| 67 | 추가: longPressAt = touchDownTime | |
| 68 | 추가: // 세게 누르기(DEEP_PRESS)를 아는 View는 시간과 상관없이 바로 길게 누르기를 한다. | |
| 69 | 추가: injectMotion(MotionEvent.ACTION_MOVE, SystemClock.uptimeMillis(), LongPress.CLASSIFICATION_DEEP_PRESS) | |
| 70 | 추가: return@synchronized | |
| 71 | 추가: } | |
| 72 | 추가: touchNow(t) | |
| 73 | 추가: if (pointers.isEmpty()) endLongPress() | |
| 74 | 추가: } | |
| 75 | 추가: | |
| 76 | 추가: private fun finishUp(t: Messages.TouchEvent) { | |
| 77 | 추가: touchNow(t) | |
| 78 | 추가: if (pointers.isEmpty()) endLongPress() | |
| 79 | 추가: } | |
| 80 | 추가: | |
| 81 | 추가: private fun endLongPress() { | |
| 82 | 추가: if (longPressAt != 0L) { | |
| 83 | 추가: longPressAt = 0L | |
| 84 | 추가: LongPress.restore() | |
| 85 | 추가: } | |
| 86 | 추가: } | |
| 87 | 추가: | |
| 88 | 추가: private fun touchNow(t: Messages.TouchEvent) { | |
| 39 | 89 | val (x, y) = toDisplay(t.x, t.y, t.frameWidth, t.frameHeight) |
| 40 | 90 | val now = SystemClock.uptimeMillis() |
| 41 | 91 | val pressure = t.pressure / 65535f |
| @@ -76,7 +126,9 @@ class InputInjector { | ||
| 76 | 126 | } |
| 77 | 127 | |
| 78 | 128 | /** 연결이 끊길 때 눌린 채로 남은 터치를 정리한다. */ |
| 79 | 삭제: fun releaseAll() { | |
| 129 | 추가: fun releaseAll() = synchronized(lock) { | |
| 130 | 추가: deferredUp = null | |
| 131 | 추가: endLongPress() | |
| 80 | 132 | if (pointers.isNotEmpty()) { |
| 81 | 133 | injectMotion(MotionEvent.ACTION_CANCEL, SystemClock.uptimeMillis()) |
| 82 | 134 | pointers.clear() |
| @@ -84,7 +136,7 @@ class InputInjector { | ||
| 84 | 136 | for (keycode in keyDownTimes.keys.toList()) key(KeyAction.UP, keycode, 0, 0, 0) |
| 85 | 137 | } |
| 86 | 138 | |
| 87 | 삭제: private fun injectMotion(action: Int, now: Long) { | |
| 139 | 추가: private fun injectMotion(action: Int, now: Long, classification: Int = 0) { | |
| 88 | 140 | val props = Array(pointers.size) { i -> |
| 89 | 141 | MotionEvent.PointerProperties().apply { |
| 90 | 142 | id = pointers[i].id |
| @@ -99,14 +151,22 @@ class InputInjector { | ||
| 99 | 151 | size = 1f |
| 100 | 152 | } |
| 101 | 153 | } |
| 102 | 삭제: val e = MotionEvent.obtain( | |
| 103 | 삭제: touchDownTime, now, action, pointers.size, props, coords, | |
| 104 | 삭제: 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0, | |
| 105 | 삭제: ) | |
| 154 | 추가: val e = LongPress.obtainClassified(touchDownTime, now, action, props, coords, classification) | |
| 155 | 추가: ?: MotionEvent.obtain( | |
| 156 | 추가: touchDownTime, now, action, pointers.size, props, coords, | |
| 157 | 추가: 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0, | |
| 158 | 추가: ) | |
| 106 | 159 | SystemAccess.injectEvent(e) |
| 107 | 160 | e.recycle() |
| 108 | 161 | } |
| 109 | 162 | |
| 163 | 추가: companion object { | |
| 164 | 추가: /** 미룬 UP을 보내는 타이머. 데몬 전체에서 하나만 쓴다. */ | |
| 165 | 추가: private val scheduler = java.util.concurrent.Executors.newSingleThreadScheduledExecutor { r -> | |
| 166 | 추가: Thread(r, "deferred-touch").apply { isDaemon = true } | |
| 167 | 추가: } | |
| 168 | 추가: } | |
| 169 | 추가: | |
| 110 | 170 | fun scroll(s: Messages.ScrollEvent) { |
| 111 | 171 | val (x, y) = toDisplay(s.x, s.y, s.frameWidth, s.frameHeight) |
| 112 | 172 | val now = SystemClock.uptimeMillis() |
| @@ -180,3 +240,107 @@ class InputInjector { | ||
| 180 | 240 | const val CLICK = 2 |
| 181 | 241 | } |
| 182 | 242 | } |
| 243 | 추가: | |
| 244 | 추가: /** | |
| 245 | 추가: * 즉시 길게 누르기. MotionEvent에 세게 누르기(CLASSIFICATION_DEEP_PRESS, Android 10+) 분류를 달려면 | |
| 246 | 추가: * 숨은 `MotionEvent.obtain(..., displayId, flags, classification)`을 써야 한다. 없으면 null을 돌려주고 | |
| 247 | 추가: * 호출 측은 분류 없는 이벤트를 쓴다(그래도 UP을 미뤄 길게 누르기는 된다). | |
| 248 | 추가: */ | |
| 249 | 추가: object LongPress { | |
| 250 | 추가: const val CLASSIFICATION_DEEP_PRESS = 2 | |
| 251 | 추가: /** 오른쪽 클릭 동안 쓰는 길게 누르기 시간. */ | |
| 252 | 추가: private const val SHORT_MS = 120L | |
| 253 | 추가: private const val KEY = "long_press_timeout" | |
| 254 | 추가: | |
| 255 | 추가: /** 원래 값을 적어 두는 파일. 줄인 채로 데몬이 죽어도 다음 시작 때 되돌린다. */ | |
| 256 | 추가: private var marker: java.io.File? = null | |
| 257 | 추가: /** 줄이기 전 값. 설정에 없었으면 "null". 줄여 둔 동안만 null이 아니다. */ | |
| 258 | 추가: private var original: String? = null | |
| 259 | 추가: | |
| 260 | 추가: /** 데몬 시작 시 호출. 지난번에 줄인 채로 끝났으면 원래 값으로 되돌린다. */ | |
| 261 | 추가: fun recover(dataDir: java.io.File) { | |
| 262 | 추가: val f = java.io.File(dataDir, "long_press_timeout.orig") | |
| 263 | 추가: marker = f | |
| 264 | 추가: if (f.exists()) { | |
| 265 | 추가: val v = f.readText().trim() | |
| 266 | 추가: Log.i("길게 누르기 시간 복원: $v") | |
| 267 | 추가: put(v) | |
| 268 | 추가: f.delete() | |
| 269 | 추가: } | |
| 270 | 추가: } | |
| 271 | 추가: | |
| 272 | 추가: /** 원래 길게 누르기 시간 + 여유. 줄여 둔 동안은 짧은 값 기준. */ | |
| 273 | 추가: fun holdMs(): Long = | |
| 274 | 추가: (if (original != null) SHORT_MS else (original ?: current()).toLongOrNull() ?: 500L) + 80 | |
| 275 | 추가: | |
| 276 | 추가: @Synchronized | |
| 277 | 추가: fun shorten() { | |
| 278 | 추가: if (original != null) return | |
| 279 | 추가: val cur = current() | |
| 280 | 추가: runCatching { marker?.writeText(cur) } | |
| 281 | 추가: original = cur | |
| 282 | 추가: put(SHORT_MS.toString()) | |
| 283 | 추가: // 바뀐 값이 앱 프로세스에 전달될 시간을 준다. | |
| 284 | 추가: Thread.sleep(40) | |
| 285 | 추가: } | |
| 286 | 추가: | |
| 287 | 추가: @Synchronized | |
| 288 | 추가: fun restore() { | |
| 289 | 추가: val v = original ?: return | |
| 290 | 추가: original = null | |
| 291 | 추가: put(v) | |
| 292 | 추가: runCatching { marker?.delete() } | |
| 293 | 추가: } | |
| 294 | 추가: | |
| 295 | 추가: private fun current(): String = cmd("get", KEY).ifEmpty { "null" } | |
| 296 | 추가: | |
| 297 | 추가: private fun put(value: String) { | |
| 298 | 추가: if (value == "null") cmd("delete", KEY) else cmd("put", KEY, value) | |
| 299 | 추가: } | |
| 300 | 추가: | |
| 301 | 추가: /** `cmd settings`는 앱 프로세스를 띄우지 않아 `settings`보다 빠르다 (약 25ms). */ | |
| 302 | 추가: private fun cmd(vararg args: String): String = try { | |
| 303 | 추가: val p = Runtime.getRuntime().exec(arrayOf("cmd", "settings", args[0], "secure", *args.drop(1).toTypedArray())) | |
| 304 | 추가: val out = p.inputStream.bufferedReader().readText().trim() | |
| 305 | 추가: p.waitFor() | |
| 306 | 추가: out | |
| 307 | 추가: } catch (e: Exception) { | |
| 308 | 추가: Log.w("설정 명령 실패 (${args.joinToString(" ")}): $e") | |
| 309 | 추가: "" | |
| 310 | 추가: } | |
| 311 | 추가: | |
| 312 | 추가: private val obtain: java.lang.reflect.Method? by lazy { | |
| 313 | 추가: try { | |
| 314 | 추가: MotionEvent::class.java.getMethod( | |
| 315 | 추가: "obtain", | |
| 316 | 추가: Long::class.javaPrimitiveType, Long::class.javaPrimitiveType, Int::class.javaPrimitiveType, | |
| 317 | 추가: Int::class.javaPrimitiveType, Array<MotionEvent.PointerProperties>::class.java, | |
| 318 | 추가: Array<MotionEvent.PointerCoords>::class.java, Int::class.javaPrimitiveType, | |
| 319 | 추가: Int::class.javaPrimitiveType, Float::class.javaPrimitiveType, Float::class.javaPrimitiveType, | |
| 320 | 추가: Int::class.javaPrimitiveType, Int::class.javaPrimitiveType, Int::class.javaPrimitiveType, | |
| 321 | 추가: Int::class.javaPrimitiveType, Int::class.javaPrimitiveType, Int::class.javaPrimitiveType, | |
| 322 | 추가: ) | |
| 323 | 추가: } catch (e: Exception) { | |
| 324 | 추가: Log.w("분류 지정 MotionEvent.obtain 없음, 즉시 길게 누르기는 시간 대기로 대신함: $e") | |
| 325 | 추가: null | |
| 326 | 추가: } | |
| 327 | 추가: } | |
| 328 | 추가: | |
| 329 | 추가: fun obtainClassified( | |
| 330 | 추가: downTime: Long, eventTime: Long, action: Int, | |
| 331 | 추가: props: Array<MotionEvent.PointerProperties>, coords: Array<MotionEvent.PointerCoords>, | |
| 332 | 추가: classification: Int, | |
| 333 | 추가: ): MotionEvent? { | |
| 334 | 추가: if (classification == 0) return null | |
| 335 | 추가: val m = obtain ?: return null | |
| 336 | 추가: return try { | |
| 337 | 추가: m.invoke( | |
| 338 | 추가: null, downTime, eventTime, action, props.size, props, coords, | |
| 339 | 추가: 0, 0, 1f, 1f, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0, 0, classification, | |
| 340 | 추가: ) as MotionEvent | |
| 341 | 추가: } catch (e: Exception) { | |
| 342 | 추가: Log.w("분류 지정 MotionEvent 생성 실패: ${e.cause ?: e}") | |
| 343 | 추가: null | |
| 344 | 추가: } | |
| 345 | 추가: } | |
| 346 | 추가: } |
| @@ -206,9 +206,11 @@ object Messages { | ||
| 206 | 206 | return p[0].toInt() and 0xFF |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 추가: /** [longPress]: flags 0x0001. DOWN을 바로 길게 누르기로 처리한다 (마우스 오른쪽 버튼). */ | |
| 209 | 210 | class TouchEvent( |
| 210 | 211 | val action: Int, val pointerId: Int, val x: Int, val y: Int, |
| 211 | 212 | val frameWidth: Int, val frameHeight: Int, val pressure: Int, |
| 213 | 추가: val longPress: Boolean = false, | |
| 212 | 214 | ) |
| 213 | 215 | |
| 214 | 216 | fun decodeTouchEvent(p: ByteArray): TouchEvent { |
| @@ -216,7 +218,7 @@ object Messages { | ||
| 216 | 218 | val b = ByteBuffer.wrap(p) |
| 217 | 219 | val action = b.get().toInt() and 0xFF |
| 218 | 220 | val pointerId = b.get().toInt() and 0xFF |
| 219 | 삭제: b.short | |
| 221 | 추가: val flags = b.short.toInt() and 0xFFFF | |
| 220 | 222 | val x = b.int |
| 221 | 223 | val y = b.int |
| 222 | 224 | val fw = b.short.toInt() and 0xFFFF |
| @@ -224,7 +226,7 @@ object Messages { | ||
| 224 | 226 | val pressure = b.short.toInt() and 0xFFFF |
| 225 | 227 | if (action > 3) throw ProtocolException("TOUCH_EVENT action 오류: $action") |
| 226 | 228 | if (fw == 0 || fh == 0) throw ProtocolException("TOUCH_EVENT 프레임 크기 0") |
| 227 | 삭제: return TouchEvent(action, pointerId, x, y, fw, fh, pressure) | |
| 229 | 추가: return TouchEvent(action, pointerId, x, y, fw, fh, pressure, flags and 0x0001 != 0) | |
| 228 | 230 | } |
| 229 | 231 | |
| 230 | 232 | class ScrollEvent(val x: Int, val y: Int, val frameWidth: Int, val frameHeight: Int, val hScroll: Int, val vScroll: Int) |
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | //! `--record`를 주면 영상 채널로 받은 Annex-B 스트림을 파일로 저장한다(ffprobe/ffplay로 확인). |
| 6 | 6 | //! |
| 7 | 7 | //! 입력 주입 점검(좌표는 영상 프레임 기준, 주어진 순서대로 실행): |
| 8 | 삭제: //! `--tap x,y`, `--swipe x1,y1,x2,y2`, `--scroll x,y,v120`, `--text 문자열`, `--keycode N`, `--wait ms`, | |
| 8 | 추가: //! `--tap x,y`, `--rclick x,y`(오른쪽 클릭 = 즉시 길게 누르기), `--swipe x1,y1,x2,y2`, `--scroll x,y,v120`, `--text 문자열`, `--keycode N`, `--wait ms`, | |
| 9 | 9 | //! `--action back|home|recents|rotate|screenoff|screenon|copy|paste|selectall`, |
| 10 | 10 | //! `--clip 문자열`(호스트 클립보드로 보내고 붙여넣기), `--clip-image 파일.png|jpg`(이미지 클립보드), |
| 11 | 11 | //! `--clip-out 경로`(--listen 중 받은 클립보드 이미지를 저장), `--send-file 경로`(파일 전송), `--listen ms`(그동안 받은 제어 메시지 출력), |
| @@ -187,6 +187,7 @@ async fn run_input_ops( | ||
| 187 | 187 | frame_width: fw, |
| 188 | 188 | frame_height: fh, |
| 189 | 189 | pressure: if action == TouchAction::Up { 0 } else { 0xFFFF }, |
| 190 | 추가: long_press: false, | |
| 190 | 191 | }) |
| 191 | 192 | }; |
| 192 | 193 | let nums = |
| @@ -202,6 +203,18 @@ async fn run_input_ops( | ||
| 202 | 203 | control.send(&touch(TouchAction::Up, v[0], v[1])).await?; |
| 203 | 204 | println!("탭 {},{}", v[0], v[1]); |
| 204 | 205 | } |
| 206 | 추가: "--rclick" => { | |
| 207 | 추가: // 마우스 오른쪽 클릭: 길게 누르기 DOWN 뒤 바로 UP. | |
| 208 | 추가: let v = nums(value); | |
| 209 | 추가: let mut down = touch(TouchAction::Down, v[0], v[1]); | |
| 210 | 추가: if let Message::TouchEvent(t) = &mut down { | |
| 211 | 추가: t.long_press = true; | |
| 212 | 추가: } | |
| 213 | 추가: control.send(&down).await?; | |
| 214 | 추가: tokio::time::sleep(Duration::from_millis(60)).await; | |
| 215 | 추가: control.send(&touch(TouchAction::Up, v[0], v[1])).await?; | |
| 216 | 추가: println!("오른쪽 클릭 {},{}", v[0], v[1]); | |
| 217 | 추가: } | |
| 205 | 218 | "--swipe" => { |
| 206 | 219 | let v = nums(value); |
| 207 | 220 | control.send(&touch(TouchAction::Down, v[0], v[1])).await?; |
| @@ -753,16 +753,24 @@ pub struct TouchEvent { | ||
| 753 | 753 | pub frame_width: u16, |
| 754 | 754 | pub frame_height: u16, |
| 755 | 755 | pub pressure: u16, |
| 756 | 추가: /// flags 0x0001: DOWN을 바로 길게 누르기로 처리한다 (마우스 오른쪽 버튼). | |
| 757 | 추가: pub long_press: bool, | |
| 756 | 758 | } |
| 757 | 759 | |
| 758 | 760 | impl TouchEvent { |
| 759 | 761 | pub const LEN: usize = 20; |
| 762 | 추가: /// `flags` 비트: 길게 누르기. | |
| 763 | 추가: pub const FLAG_LONG_PRESS: u16 = 0x0001; | |
| 760 | 764 | |
| 761 | 765 | pub fn encode(&self, dst: &mut BytesMut) { |
| 762 | 766 | dst.reserve(Self::LEN); |
| 763 | 767 | dst.put_u8(self.action.into()); |
| 764 | 768 | dst.put_u8(self.pointer_id); |
| 765 | 삭제: dst.put_bytes(0, 2); | |
| 769 | 추가: dst.put_u16(if self.long_press { | |
| 770 | 추가: Self::FLAG_LONG_PRESS | |
| 771 | 추가: } else { | |
| 772 | 추가: 0 | |
| 773 | 추가: }); | |
| 766 | 774 | dst.put_u32(self.x); |
| 767 | 775 | dst.put_u32(self.y); |
| 768 | 776 | dst.put_u16(self.frame_width); |
| @@ -778,7 +786,7 @@ impl TouchEvent { | ||
| 778 | 786 | let action = |
| 779 | 787 | TouchAction::try_from(b.get_u8()).map_err(|_| invalid(T, "알 수 없는 action"))?; |
| 780 | 788 | let pointer_id = b.get_u8(); |
| 781 | 삭제: b.advance(2); | |
| 789 | 추가: let flags = b.get_u16(); | |
| 782 | 790 | Ok(Self { |
| 783 | 791 | action, |
| 784 | 792 | pointer_id, |
| @@ -787,6 +795,7 @@ impl TouchEvent { | ||
| 787 | 795 | frame_width: b.get_u16(), |
| 788 | 796 | frame_height: b.get_u16(), |
| 789 | 797 | pressure: b.get_u16(), |
| 798 | 추가: long_press: flags & Self::FLAG_LONG_PRESS != 0, | |
| 790 | 799 | }) |
| 791 | 800 | } |
| 792 | 801 | } |
| @@ -1448,6 +1457,7 @@ mod tests { | ||
| 1448 | 1457 | frame_width: 1080, |
| 1449 | 1458 | frame_height: 2400, |
| 1450 | 1459 | pressure: 0xFFFF, |
| 1460 | 추가: long_press: false, | |
| 1451 | 1461 | }), |
| 1452 | 1462 | Message::ScrollEvent(ScrollEvent { |
| 1453 | 1463 | x: 10, |
| @@ -1545,6 +1555,7 @@ mod tests { | ||
| 1545 | 1555 | frame_width: 0x090A, |
| 1546 | 1556 | frame_height: 0x0B0C, |
| 1547 | 1557 | pressure: 0x0D0E, |
| 1558 | 추가: long_press: false, | |
| 1548 | 1559 | }); |
| 1549 | 1560 | assert_eq!( |
| 1550 | 1561 | enc(&m), |
| @@ -49,6 +49,8 @@ impl VideoTarget { | ||
| 49 | 49 | /// 누르고 있는 터치 하나 (pointer_id 0). |
| 50 | 50 | #[derive(Debug, Clone, Copy)] |
| 51 | 51 | struct Touch { |
| 52 | 추가: /// 이 터치를 시작한 마우스 버튼. 같은 버튼을 떼야 끝난다. | |
| 53 | 추가: button: PointerButton, | |
| 52 | 54 | /// 마지막으로 보낸 좌표. |
| 53 | 55 | last: (u32, u32), |
| 54 | 56 | /// 누를 때의 프레임 크기. 바뀌면 취소한다. |
| @@ -118,18 +120,21 @@ impl InputState { | ||
| 118 | 120 | } |
| 119 | 121 | } |
| 120 | 122 | Event::PointerGone => self.pointer = None, |
| 123 | 추가: // 왼쪽 버튼은 터치, 오른쪽 버튼은 바로 길게 누르기(누른 채 움직이면 끌기). | |
| 121 | 124 | Event::PointerButton { |
| 122 | 125 | pos, |
| 123 | 삭제: button: PointerButton::Primary, | |
| 126 | 추가: button: button @ (PointerButton::Primary | PointerButton::Secondary), | |
| 124 | 127 | pressed, |
| 125 | 128 | .. |
| 126 | 129 | } => { |
| 127 | 130 | self.pointer = Some(*pos); |
| 128 | 131 | match (*pressed, target) { |
| 129 | 132 | (true, Some(v)) if self.touch.is_none() && v.rect.contains(*pos) => { |
| 130 | 삭제: self.touch_down(v, *pos, out); | |
| 133 | 추가: self.touch_down(v, *pos, *button, out); | |
| 134 | 추가: } | |
| 135 | 추가: (false, Some(v)) if self.touch.is_some_and(|t| t.button == *button) => { | |
| 136 | 추가: self.touch_up(v, *pos, out) | |
| 131 | 137 | } |
| 132 | 삭제: (false, Some(v)) if self.touch.is_some() => self.touch_up(v, *pos, out), | |
| 133 | 138 | _ => {} |
| 134 | 139 | } |
| 135 | 140 | } |
| @@ -180,10 +185,21 @@ impl InputState { | ||
| 180 | 185 | } |
| 181 | 186 | } |
| 182 | 187 | |
| 183 | 삭제: fn touch_down(&mut self, v: VideoTarget, pos: Pos2, out: &mut Vec<Message>) { | |
| 188 | 추가: fn touch_down( | |
| 189 | 추가: &mut self, | |
| 190 | 추가: v: VideoTarget, | |
| 191 | 추가: pos: Pos2, | |
| 192 | 추가: button: PointerButton, | |
| 193 | 추가: out: &mut Vec<Message>, | |
| 194 | 추가: ) { | |
| 184 | 195 | let last = v.to_frame(pos); |
| 185 | 삭제: out.push(touch_message(TouchAction::Down, last, (v.width, v.height))); | |
| 196 | 추가: let mut msg = touch_message(TouchAction::Down, last, (v.width, v.height)); | |
| 197 | 추가: if let Message::TouchEvent(t) = &mut msg { | |
| 198 | 추가: t.long_press = button == PointerButton::Secondary; | |
| 199 | 추가: } | |
| 200 | 추가: out.push(msg); | |
| 186 | 201 | self.touch = Some(Touch { |
| 202 | 추가: button, | |
| 187 | 203 | last, |
| 188 | 204 | frame: (v.width, v.height), |
| 189 | 205 | pending: None, |
| @@ -334,6 +350,7 @@ fn touch_message(action: TouchAction, (x, y): (u32, u32), frame: (u16, u16)) -> | ||
| 334 | 350 | TouchAction::Down | TouchAction::Move => FULL_PRESSURE, |
| 335 | 351 | TouchAction::Up | TouchAction::Cancel => 0, |
| 336 | 352 | }, |
| 353 | 추가: long_press: false, | |
| 337 | 354 | }) |
| 338 | 355 | } |
| 339 | 356 | |
| @@ -482,6 +499,72 @@ mod tests { | ||
| 482 | 499 | )); |
| 483 | 500 | } |
| 484 | 501 | |
| 502 | 추가: #[test] | |
| 503 | 추가: fn right_button_is_immediate_long_press_until_released() { | |
| 504 | 추가: let v = target(); | |
| 505 | 추가: let mut s = InputState::default(); | |
| 506 | 추가: let mut out = Vec::new(); | |
| 507 | 추가: let btn = |button, pressed| Event::PointerButton { | |
| 508 | 추가: pos: v.rect.center(), | |
| 509 | 추가: button, | |
| 510 | 추가: pressed, | |
| 511 | 추가: modifiers: Modifiers::NONE, | |
| 512 | 추가: }; | |
| 513 | 추가: s.process( | |
| 514 | 추가: &[btn(PointerButton::Secondary, true)], | |
| 515 | 추가: true, | |
| 516 | 추가: Some(v), | |
| 517 | 추가: &mut out, | |
| 518 | 추가: ); | |
| 519 | 추가: assert!(matches!( | |
| 520 | 추가: out.as_slice(), | |
| 521 | 추가: [Message::TouchEvent(TouchEvent { | |
| 522 | 추가: action: TouchAction::Down, | |
| 523 | 추가: long_press: true, | |
| 524 | 추가: .. | |
| 525 | 추가: })] | |
| 526 | 추가: )); | |
| 527 | 추가: out.clear(); | |
| 528 | 추가: // 오른쪽으로 누른 터치는 왼쪽 버튼을 떼도 끝나지 않는다. | |
| 529 | 추가: s.process( | |
| 530 | 추가: &[btn(PointerButton::Primary, false)], | |
| 531 | 추가: true, | |
| 532 | 추가: Some(v), | |
| 533 | 추가: &mut out, | |
| 534 | 추가: ); | |
| 535 | 추가: assert!(out.is_empty()); | |
| 536 | 추가: s.process( | |
| 537 | 추가: &[btn(PointerButton::Secondary, false)], | |
| 538 | 추가: true, | |
| 539 | 추가: Some(v), | |
| 540 | 추가: &mut out, | |
| 541 | 추가: ); | |
| 542 | 추가: assert!(matches!( | |
| 543 | 추가: out.as_slice(), | |
| 544 | 추가: [Message::TouchEvent(TouchEvent { | |
| 545 | 추가: action: TouchAction::Up, | |
| 546 | 추가: long_press: false, | |
| 547 | 추가: .. | |
| 548 | 추가: })] | |
| 549 | 추가: )); | |
| 550 | 추가: out.clear(); | |
| 551 | 추가: // 왼쪽 버튼 터치는 일반 터치다. | |
| 552 | 추가: s.process( | |
| 553 | 추가: &[btn(PointerButton::Primary, true)], | |
| 554 | 추가: true, | |
| 555 | 추가: Some(v), | |
| 556 | 추가: &mut out, | |
| 557 | 추가: ); | |
| 558 | 추가: assert!(matches!( | |
| 559 | 추가: out.as_slice(), | |
| 560 | 추가: [Message::TouchEvent(TouchEvent { | |
| 561 | 추가: action: TouchAction::Down, | |
| 562 | 추가: long_press: false, | |
| 563 | 추가: .. | |
| 564 | 추가: })] | |
| 565 | 추가: )); | |
| 566 | 추가: } | |
| 567 | 추가: | |
| 485 | 568 | #[test] |
| 486 | 569 | fn lost_target_cancels_touch() { |
| 487 | 570 | let v = target(); |
| @@ -404,20 +404,28 @@ fn press_outside_video_sends_no_touch() { | ||
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | #[test] |
| 407 | 삭제: fn right_and_middle_click_send_nothing() { | |
| 407 | 추가: fn middle_and_forward_click_send_nothing() { | |
| 408 | 408 | let mut h = harness_with_video(); |
| 409 | 409 | let l = layout_of(&h); |
| 410 | 삭제: for button in [ | |
| 411 | 삭제: egui::PointerButton::Secondary, | |
| 412 | 삭제: egui::PointerButton::Middle, | |
| 413 | 삭제: egui::PointerButton::Extra2, | |
| 414 | 삭제: ] { | |
| 410 | 추가: for button in [egui::PointerButton::Middle, egui::PointerButton::Extra2] { | |
| 415 | 411 | side_button(&mut h, l.viewport.center(), button); |
| 416 | 412 | } |
| 417 | 413 | assert!(h.state().rec.input.is_empty(), "{:?}", h.state().rec.input); |
| 418 | 414 | assert_eq!(h.state().rec.system, None); |
| 419 | 415 | } |
| 420 | 416 | |
| 417 | 추가: #[test] | |
| 418 | 추가: fn right_click_on_video_sends_long_press_touch() { | |
| 419 | 추가: let mut h = harness_with_video(); | |
| 420 | 추가: let l = layout_of(&h); | |
| 421 | 추가: side_button(&mut h, l.viewport.center(), egui::PointerButton::Secondary); | |
| 422 | 추가: let t = touches(&h); | |
| 423 | 추가: assert_eq!(t.len(), 2, "{t:?}"); | |
| 424 | 추가: assert!(t[0].long_press && t[0].action == TouchAction::Down); | |
| 425 | 추가: assert!(!t[1].long_press && t[1].action == TouchAction::Up); | |
| 426 | 추가: assert_eq!(h.state().rec.system, None); | |
| 427 | 추가: } | |
| 428 | 추가: | |
| 421 | 429 | #[test] |
| 422 | 430 | fn wheel_up_scrolls_positive() { |
| 423 | 431 | let mut h = harness_with_video(); |