- Fixed: mousepad unable to perform 2-finger right click in hovering mode
- Minor changes & improvements for mousePad widget
This commit is contained in:
1 parent
32b78d1a4c
commit
d12b83d1ef
1 file changed
+26
-29
@@ -283,15 +283,12 @@ import UIKit
|
|||||||
if self.widgetType == WidgetTypeEnum.button {
|
if self.widgetType == WidgetTypeEnum.button {
|
||||||
self.autoTapTimer = SafeTimer(interval:0.001 * Double(autoTapInterval)) {
|
self.autoTapTimer = SafeTimer(interval:0.001 * Double(autoTapInterval)) {
|
||||||
self.handleButtonDown()
|
self.handleButtonDown()
|
||||||
DispatchQueue.global(qos: .userInteractive).async {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.025) {
|
||||||
usleep(25000)
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.handleButtonUp()
|
self.handleButtonUp()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@objc public func setVibration(style: Int) {
|
@objc public func setVibration(style: Int) {
|
||||||
if #available(iOS 13.0, *) {
|
if #available(iOS 13.0, *) {
|
||||||
@@ -718,14 +715,11 @@ import UIKit
|
|||||||
CATransaction.commit()
|
CATransaction.commit()
|
||||||
|
|
||||||
CATransaction.begin()
|
CATransaction.begin()
|
||||||
// CATransaction.setDisableActions(true)
|
|
||||||
CATransaction.setAnimationDuration(0.15)
|
CATransaction.setAnimationDuration(0.15)
|
||||||
self.stickBallLayer.position = CGPointMake(CGRectGetMidX(self.crossMarkLayer.frame), CGRectGetMidY(self.crossMarkLayer.frame))
|
self.stickBallLayer.position = CGPointMake(CGRectGetMidX(self.crossMarkLayer.frame), CGRectGetMidY(self.crossMarkLayer.frame))
|
||||||
CATransaction.setCompletionBlock {
|
CATransaction.setCompletionBlock {
|
||||||
DispatchQueue.global().async {
|
// 动画结束后执行的代码
|
||||||
// 后台执行耗时操作
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
||||||
usleep(200000)
|
|
||||||
DispatchQueue.main.async { // switch to main thread to update UI
|
|
||||||
if !self.touchBegan {
|
if !self.touchBegan {
|
||||||
CATransaction.begin()
|
CATransaction.begin()
|
||||||
CATransaction.setDisableActions(true)
|
CATransaction.setDisableActions(true)
|
||||||
@@ -735,8 +729,6 @@ import UIKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 动画结束后执行的代码
|
|
||||||
}
|
|
||||||
CATransaction.commit()
|
CATransaction.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -941,8 +933,7 @@ import UIKit
|
|||||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), BUTTON_LEFT)
|
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), BUTTON_LEFT)
|
||||||
|
|
||||||
// Wait 200 ms to simulate a real button press
|
// Wait 200 ms to simulate a real button press
|
||||||
usleep(UInt32(self.QUICK_TAP_TIME_INTERVAL * 1000000))
|
DispatchQueue.global().asyncAfter(deadline: .now() + self.QUICK_TAP_TIME_INTERVAL) {
|
||||||
|
|
||||||
// If quick tap is not detected, release the button
|
// If quick tap is not detected, release the button
|
||||||
if !self.quickDoubleTapDetected {
|
if !self.quickDoubleTapDetected {
|
||||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_RELEASE), BUTTON_LEFT)
|
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_RELEASE), BUTTON_LEFT)
|
||||||
@@ -952,25 +943,25 @@ import UIKit
|
|||||||
// Don't release the button if we're still dragging, this will prevent the dragging from being interrupted.
|
// Don't release the button if we're still dragging, this will prevent the dragging from being interrupted.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func sendShortMouseLeftButtonClickEvent() {
|
private func sendShortMouseLeftButtonClickEvent() {
|
||||||
DispatchQueue.global(qos: .userInteractive).async {
|
DispatchQueue.global().asyncAfter(deadline: .now() + 0.05) {
|
||||||
NSLog("double click: sending short click")
|
|
||||||
usleep(UInt32(50 * 1000))
|
|
||||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), BUTTON_LEFT)
|
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), BUTTON_LEFT)
|
||||||
usleep(UInt32(50 * 1000))
|
DispatchQueue.global().asyncAfter(deadline: .now() + 0.05) {
|
||||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_RELEASE), BUTTON_LEFT)
|
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_RELEASE), BUTTON_LEFT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func sendMouseRightButtonClickEvent() {
|
private func sendMouseRightButtonClickEvent() {
|
||||||
DispatchQueue.global(qos: .userInteractive).async {
|
DispatchQueue.global().asyncAfter(deadline: .now() + 0.05) {
|
||||||
usleep(UInt32(50 * 1000))
|
|
||||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), BUTTON_RIGHT)
|
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), BUTTON_RIGHT)
|
||||||
usleep(UInt32(50 * 1000))
|
DispatchQueue.global().asyncAfter(deadline: .now() + 0.05) {
|
||||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_RELEASE), BUTTON_RIGHT)
|
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_RELEASE), BUTTON_RIGHT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//mousepad-trackball behavior========================================================
|
//mousepad-trackball behavior========================================================
|
||||||
private func startTrackballMomentum() {
|
private func startTrackballMomentum() {
|
||||||
@@ -1151,7 +1142,7 @@ import UIKit
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
private func sendComboButtonsDownEvent(comboStrings: [String]) {
|
private func sendComboButtonsDownEvent(comboStrings: [String]) {
|
||||||
DispatchQueue.global(qos: .userInteractive).async {
|
DispatchQueue.global(qos: .userInteractive).async {
|
||||||
for comboString in comboStrings {
|
for comboString in comboStrings {
|
||||||
@@ -1190,14 +1181,18 @@ import UIKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
// Touch event handling
|
// Touch event handling
|
||||||
|
|
||||||
|
private func getAllSpawnedTouchesCount(with event: UIEvent?)->Int{
|
||||||
|
return event?.allTouches?.filter({ $0.view == self }).count ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
self.touchBegan = true
|
self.touchBegan = true
|
||||||
self.firstTouchMoved = false
|
self.firstTouchMoved = false
|
||||||
super.touchesBegan(touches, with: event)
|
super.touchesBegan(touches, with: event)
|
||||||
// self.isMultipleTouchEnabled = self.touchPadString == "MOUSEPAD" // only enable multi-touch in mousePad mode
|
self.isMultipleTouchEnabled = self.widgetType == WidgetTypeEnum.button || self.touchPadString == "MOUSEPAD";
|
||||||
self.isMultipleTouchEnabled = self.widgetType == WidgetTypeEnum.button
|
|
||||||
|
|
||||||
if !OnScreenWidgetView.editMode && self.touchPadString == "TRACKBALL" {
|
if !OnScreenWidgetView.editMode && self.touchPadString == "TRACKBALL" {
|
||||||
stopTrackballMomentum()
|
stopTrackballMomentum()
|
||||||
@@ -1215,8 +1210,8 @@ import UIKit
|
|||||||
self.latestTouchLocation = touchBeganLocation
|
self.latestTouchLocation = touchBeganLocation
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
let allSpawnedTouchesCount = self.getAllSpawnedTouchesCount(with: event) // this will counts all valid touches within the self widgetView, and excludes touches in other widgetViews
|
||||||
if allCapturedTouchesCount == 2 {
|
if allSpawnedTouchesCount == 2 {
|
||||||
self.twoTouchesDetected = true
|
self.twoTouchesDetected = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1244,7 +1239,7 @@ import UIKit
|
|||||||
self.showl3r3Indicator()
|
self.showl3r3Indicator()
|
||||||
self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)}
|
self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)}
|
||||||
case "DPAD", "WASDPAD", "ARROWPAD":
|
case "DPAD", "WASDPAD", "ARROWPAD":
|
||||||
if allCapturedTouchesCount == 1 {showLrudBall(at: touchBeganLocation)}
|
if allSpawnedTouchesCount == 1 {showLrudBall(at: touchBeganLocation)}
|
||||||
if quickDoubleTapDetected {
|
if quickDoubleTapDetected {
|
||||||
self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)
|
self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)
|
||||||
DispatchQueue.global(qos: .userInteractive).async {
|
DispatchQueue.global(qos: .userInteractive).async {
|
||||||
@@ -1261,7 +1256,7 @@ import UIKit
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.widgetType == WidgetTypeEnum.touchPad && self.touchPadString == "MOUSEPAD" && allCapturedTouchesCount == 1 && !twoTouchesDetected {
|
if self.widgetType == WidgetTypeEnum.touchPad && self.touchPadString == "MOUSEPAD" && allSpawnedTouchesCount == 1 && !twoTouchesDetected {
|
||||||
switch mouseButtonAction{
|
switch mouseButtonAction{
|
||||||
case .leftButtonDown:
|
case .leftButtonDown:
|
||||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), BUTTON_LEFT)
|
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), BUTTON_LEFT)
|
||||||
@@ -1474,9 +1469,11 @@ 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":
|
||||||
DispatchQueue.global(qos: .userInteractive).async {
|
DispatchQueue.global(qos: .userInteractive).async {
|
||||||
@@ -1575,7 +1572,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 == allCapturedTouchesCount { // need to enable multi-touch first
|
||||||
// touches.count == allCapturedTouchesCount means allfingers are lifting
|
// touches.count == allCapturedTouchesCount means allfingers are lifting
|
||||||
self.sendMouseRightButtonClickEvent()
|
if(self.mouseButtonAction == MouseButtonAction.hovering) {self.sendMouseRightButtonClickEvent()}
|
||||||
twoTouchesDetected = false
|
twoTouchesDetected = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user