fixed potential crash in mousePad widget

This commit is contained in:
TrueZhuanjia committed 2025-09-14 03:09:11 +08:00
1 parent 8fb4829aef
commit 2e776baec9
1 file changed
+8 -10
+8 -10
View File
@@ -140,6 +140,7 @@ import UIKit
private var firstTouchMoved: Bool = false private var firstTouchMoved: Bool = false
private var mousePointerMoved: Bool private var mousePointerMoved: Bool
private var twoTouchesDetected: Bool private var twoTouchesDetected: Bool
private var allSpawnedTouchesCount: Int = 0
// trackball // trackball
private var trackballVelocity: CGPoint = .zero private var trackballVelocity: CGPoint = .zero
@@ -1236,7 +1237,7 @@ import UIKit
self.latestTouchLocation = touchBeganLocation self.latestTouchLocation = touchBeganLocation
} }
let allSpawnedTouchesCount = self.getAllSpawnedTouchesCount(with: event) // this will counts all valid touches within the self widgetView, and excludes touches in other widgetViews allSpawnedTouchesCount = self.getAllSpawnedTouchesCount(with: event) // this will counts all valid touches within the self widgetView, and excludes touches in other widgetViews
if allSpawnedTouchesCount == 2 { if allSpawnedTouchesCount == 2 {
self.twoTouchesDetected = true self.twoTouchesDetected = true
} }
@@ -1389,7 +1390,6 @@ import UIKit
} }
} }
private func handleFingerUpAfterSliding(touches: Set<UITouch>) { private func handleFingerUpAfterSliding(touches: Set<UITouch>) {
for touch in touches { for touch in touches {
for subview in self.superview?.subviews ?? [] { for subview in self.superview?.subviews ?? [] {
@@ -1501,10 +1501,8 @@ import UIKit
switch self.touchPadString{ switch self.touchPadString{
case "MOUSEPAD": case "MOUSEPAD":
DispatchQueue.global(qos: .userInteractive).async { DispatchQueue.global(qos: .userInteractive).async {
if self.getAllSpawnedTouchesCount(with: event) == 1 { self.updateTouchLocation(touch: touches.first!)
self.updateTouchLocation(touch: touches.first!) LiSendMouseMoveEvent(Int16(truncatingIfNeeded: Int(self.deltaX * 1.7 * self.sensitivityFactorX)), Int16(truncatingIfNeeded: Int(self.deltaY * 1.7 * self.sensitivityFactorY)))
LiSendMouseMoveEvent(Int16(truncatingIfNeeded: Int(self.deltaX * 1.7 * self.sensitivityFactorX)), Int16(truncatingIfNeeded: Int(self.deltaY * 1.7 * self.sensitivityFactorY)))
}
} }
break break
case "TRACKBALL": case "TRACKBALL":
@@ -1567,11 +1565,11 @@ import UIKit
if self.touchPadString != "MOUSEPAD" {quickDoubleTapDetected = false} //do not reset this flag here in mousePad mode if self.touchPadString != "MOUSEPAD" {quickDoubleTapDetected = false} //do not reset this flag here in mousePad mode
let allCapturedTouchesCount = event?.allTouches?.filter({ $0.view == self }).count // this will counts all valid touches within the self widgetView, and excludes touches in other widgetViews self.allSpawnedTouchesCount = self.getAllSpawnedTouchesCount(with: event) // this will counts all valid touches within the self widgetView, and excludes touches in other widgetViews
// deal with pure MOUSPAD first // deal with pure MOUSPAD first
if !OnScreenWidgetView.editMode && self.widgetType == WidgetTypeEnum.touchPad && self.touchPadString == "MOUSEPAD" && allCapturedTouchesCount == 1 && !twoTouchesDetected { if !OnScreenWidgetView.editMode && self.widgetType == WidgetTypeEnum.touchPad && self.touchPadString == "MOUSEPAD" && allSpawnedTouchesCount == 1 && !twoTouchesDetected {
switch mouseButtonAction{ switch mouseButtonAction{
case .leftButtonDown: case .leftButtonDown:
@@ -1595,7 +1593,7 @@ import UIKit
} }
} }
if !OnScreenWidgetView.editMode && self.widgetType == WidgetTypeEnum.touchPad && self.touchPadString == "TRACKBALL" && allCapturedTouchesCount == 1 && !twoTouchesDetected { if !OnScreenWidgetView.editMode && self.widgetType == WidgetTypeEnum.touchPad && self.touchPadString == "TRACKBALL" && allSpawnedTouchesCount == 1 && !twoTouchesDetected {
if(mousePointerMoved){ if(mousePointerMoved){
self.startTrackballMomentum() self.startTrackballMomentum()
mousePointerMoved = false //reset flag mousePointerMoved = false //reset flag
@@ -1605,7 +1603,7 @@ import UIKit
} }
} }
if !OnScreenWidgetView.editMode && self.widgetType == WidgetTypeEnum.touchPad && self.touchPadString == "MOUSEPAD" && twoTouchesDetected && touches.count == allCapturedTouchesCount { // need to enable multi-touch first if !OnScreenWidgetView.editMode && self.widgetType == WidgetTypeEnum.touchPad && self.touchPadString == "MOUSEPAD" && twoTouchesDetected && touches.count == allSpawnedTouchesCount { // need to enable multi-touch first
// touches.count == allCapturedTouchesCount means allfingers are lifting // touches.count == allCapturedTouchesCount means allfingers are lifting
if(self.mouseButtonAction == MouseButtonAction.hovering) {self.sendMouseRightButtonClickEvent()} if(self.mouseButtonAction == MouseButtonAction.hovering) {self.sendMouseRightButtonClickEvent()}
twoTouchesDetected = false twoTouchesDetected = false