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
5 changes: 5 additions & 0 deletions KVMConsoleiPad/Input/PointerCaptureView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ final class PointerCaptureUIView: UIView, UIGestureRecognizerDelegate {

let secondaryTap = UITapGestureRecognizer(target: self, action: #selector(handleSecondaryTap(_:)))
secondaryTap.buttonMaskRequired = .secondary
// `buttonMaskRequired` is only evaluated for indirect input devices, so on its own it does
// not stop a finger from matching this recognizer — a direct touch carries no buttons and
// satisfies both tap recognizers. UIKit then lets only one of them recognize, and this one
// wins, turning every tap into a right click. Restrict it to the input it is actually for.
secondaryTap.allowedTouchTypes = [NSNumber(value: UITouch.TouchType.indirectPointer.rawValue)]
addGestureRecognizer(secondaryTap)
}

Expand Down
24 changes: 24 additions & 0 deletions KVMConsoleiPadTests/NanoKVMiPadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ final class KVMConsoleiPadTests: XCTestCase {
)
}

// MARK: Tap button routing

/// A direct touch carries no buttons, and `buttonMaskRequired` is only evaluated for indirect
/// input — so without a touch-type restriction a finger tap matches the secondary recognizer
/// too, and UIKit lets that one win. Every tap then arrives at the host as a right click.
@MainActor
func test_secondaryTapIgnoresDirectTouches() {
let view = PointerCaptureUIView()
let taps = (view.gestureRecognizers ?? []).compactMap { $0 as? UITapGestureRecognizer }
let secondary = taps.first { $0.buttonMaskRequired == .secondary }
let primary = taps.first { $0.buttonMaskRequired == .primary }

XCTAssertEqual(
secondary?.allowedTouchTypes,
[NSNumber(value: UITouch.TouchType.indirectPointer.rawValue)],
"a finger tap must never reach the secondary recognizer"
)
XCTAssertNotNil(primary, "finger taps still need a primary recognizer to land on")
XCTAssertFalse(
primary?.allowedTouchTypes == [NSNumber(value: UITouch.TouchType.indirectPointer.rawValue)],
"the primary recognizer must keep accepting direct touches"
)
}

// MARK: Synthesized tap dwell

@MainActor
Expand Down
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ settings:
# Single source of truth for app version, shared by both targets via
# $(MARKETING_VERSION) / $(CURRENT_PROJECT_VERSION) references in their
# Info.plist. CI overrides CURRENT_PROJECT_VERSION per release (timestamp).
MARKETING_VERSION: "1.0.4"
MARKETING_VERSION: "1.0.5"
CURRENT_PROJECT_VERSION: "1"
targets:
KVMConsole:
Expand Down
Loading