From e4b737924aa1ac280890433913a66939f15b8a41 Mon Sep 17 00:00:00 2001 From: Huge_Black Date: Tue, 15 Oct 2024 11:12:02 +0800 Subject: [PATCH] hide status var & mouse scale option, fix scrolling issues --- OpenParsec/Info.plist | 2 +- OpenParsec/ParsecSDKBridge.swift | 2 ++ OpenParsec/ParsecView.swift | 2 +- OpenParsec/ParsecViewController.swift | 16 ++++++++-------- OpenParsec/SettingsHandler.swift | 12 ++++++++---- OpenParsec/SettingsView.swift | 24 ++++++++++++++++-------- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/OpenParsec/Info.plist b/OpenParsec/Info.plist index 71a2987..0c460e1 100644 --- a/OpenParsec/Info.plist +++ b/OpenParsec/Info.plist @@ -82,6 +82,6 @@ UIInterfaceOrientationLandscapeRight UIViewControllerBasedStatusBarAppearance - + diff --git a/OpenParsec/ParsecSDKBridge.swift b/OpenParsec/ParsecSDKBridge.swift index fe89682..c1ce636 100644 --- a/OpenParsec/ParsecSDKBridge.swift +++ b/OpenParsec/ParsecSDKBridge.swift @@ -126,6 +126,8 @@ class ParsecSDKBridge: ParsecService clientWidth = Float(width) clientHeight = Float(height) + mouseInfo.mouseX = Int32(width / 2) + mouseInfo.mouseY = Int32(height / 2) } func renderGLFrame(timeout:UInt32 = 16) // timeout in ms, 16 == 60 FPS, 8 == 120 FPS, etc. diff --git a/OpenParsec/ParsecView.swift b/OpenParsec/ParsecView.swift index 665cb8a..500aeaf 100644 --- a/OpenParsec/ParsecView.swift +++ b/OpenParsec/ParsecView.swift @@ -234,7 +234,7 @@ struct ParsecView:View } .zIndex(2) } - .statusBar(hidden:true) + .statusBarHidden(SettingsHandler.hideStatusBar) .alert(isPresented:$showDCAlert) { Alert(title:Text(DCAlertText), dismissButton:.default(Text("Close"), action:disconnect)) diff --git a/OpenParsec/ParsecViewController.swift b/OpenParsec/ParsecViewController.swift index 83c85ad..21b09ea 100644 --- a/OpenParsec/ParsecViewController.swift +++ b/OpenParsec/ParsecViewController.swift @@ -53,10 +53,10 @@ class ParsecViewController :UIViewController { lastImg = CParsec.mouseInfo.cursorImg! } - u?.frame = CGRect(x: Int(CParsec.mouseInfo.mouseX) - CParsec.mouseInfo.cursorHotX / 2, - y: Int(CParsec.mouseInfo.mouseY) - CParsec.mouseInfo.cursorHotY / 2, - width: CParsec.mouseInfo.cursorWidth / 2, - height: CParsec.mouseInfo.cursorHeight / 2) + u?.frame = CGRect(x: Int(CParsec.mouseInfo.mouseX) - Int(Float(CParsec.mouseInfo.cursorHotX) * SettingsHandler.cursorScale), + y: Int(CParsec.mouseInfo.mouseY) - Int(Float(CParsec.mouseInfo.cursorHotY) * SettingsHandler.cursorScale), + width: Int(Float(CParsec.mouseInfo.cursorWidth) * SettingsHandler.cursorScale), + height: Int(Float(CParsec.mouseInfo.cursorHeight) * SettingsHandler.cursorScale)) } else { u?.image = nil @@ -161,7 +161,7 @@ class ParsecViewController :UIViewController { @objc func keyboardWillShow(_ notification: Notification) { if let keyboardFrame: NSValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { let keyboardRectangle = keyboardFrame.cgRectValue - keyboardHeight = keyboardRectangle.height + keyboardHeight = keyboardRectangle.height - 50 // minus handle button height } } @@ -177,11 +177,11 @@ extension ParsecViewController : UIGestureRecognizerDelegate { { // print("number = \(gestureRecognizer.numberOfTouches) status = \(gestureRecognizer.state.rawValue)") if gestureRecognizer.numberOfTouches == 2 { - let translation = gestureRecognizer.translation(in: gestureRecognizer.view) + let velocity = gestureRecognizer.velocity(in: gestureRecognizer.view) - if abs( gestureRecognizer.velocity(in: gestureRecognizer.view).y) > 2 && abs(translation.y) > 10 { + if abs(velocity.y) > 2 { // Run your function when the user uses two fingers and swipes upwards - CParsec.sendWheelMsg(x: 0, y: Int32(translation.y / 2)) + CParsec.sendWheelMsg(x: 0, y: Int32(velocity.y / 20)) return } if SettingsHandler.cursorMode == .direct { diff --git a/OpenParsec/SettingsHandler.swift b/OpenParsec/SettingsHandler.swift index 53ca2b5..5e6d906 100644 --- a/OpenParsec/SettingsHandler.swift +++ b/OpenParsec/SettingsHandler.swift @@ -6,8 +6,9 @@ struct SettingsHandler public static var resolution : ParsecResolution = ParsecResolution.resolutions[1] public static var decoder:DecoderPref = .h264 public static var cursorMode:CursorMode = .touchpad - //public static var cursorScale:Float = 1 + public static var cursorScale:Float = 0.5 public static var noOverlay:Bool = false + public static var hideStatusBar:Bool = true public static func load() { @@ -17,10 +18,12 @@ struct SettingsHandler { decoder = DecoderPref(rawValue:UserDefaults.standard.integer(forKey:"decoder"))! } if UserDefaults.standard.exists(forKey:"cursorMode") { cursorMode = CursorMode(rawValue:UserDefaults.standard.integer(forKey:"cursorMode"))! } - //if UserDefaults.standard.exists(forKey:"cursorScale") - // { cursorScale = UserDefaults.standard.float(forKey:"cursorScale") } + if UserDefaults.standard.exists(forKey:"cursorScale") + { cursorScale = UserDefaults.standard.float(forKey:"cursorScale") } if UserDefaults.standard.exists(forKey:"noOverlay") { noOverlay = UserDefaults.standard.bool(forKey:"noOverlay") } + if UserDefaults.standard.exists(forKey:"hideStatusBar") + { hideStatusBar = UserDefaults.standard.bool(forKey:"hideStatusBar") } if UserDefaults.standard.exists(forKey:"resolution") { for res in ParsecResolution.resolutions { @@ -37,9 +40,10 @@ struct SettingsHandler //UserDefaults.standard.set(renderer.rawValue, forKey:"renderer") UserDefaults.standard.set(decoder.rawValue, forKey:"decoder") UserDefaults.standard.set(cursorMode.rawValue, forKey:"cursorMode") - //UserDefaults.standard.set(cursorScale, forKey:"cursorScale") + UserDefaults.standard.set(cursorScale, forKey:"cursorScale") UserDefaults.standard.set(noOverlay, forKey:"noOverlay") UserDefaults.standard.set(resolution.desc, forKey:"resolution") + UserDefaults.standard.set(hideStatusBar, forKey: "hideStatusBar") } } diff --git a/OpenParsec/SettingsView.swift b/OpenParsec/SettingsView.swift index 0080978..e60711f 100644 --- a/OpenParsec/SettingsView.swift +++ b/OpenParsec/SettingsView.swift @@ -8,8 +8,9 @@ struct SettingsView:View @State var decoder:DecoderPref = SettingsHandler.decoder @State var cursorMode:CursorMode = SettingsHandler.cursorMode @State var resolution : ParsecResolution = SettingsHandler.resolution - //@State var cursorScale:Float = SettingsHandler.cursorScale + @State var cursorScale:Float = SettingsHandler.cursorScale @State var noOverlay:Bool = SettingsHandler.noOverlay + @State var hideStatusBar:Bool = SettingsHandler.hideStatusBar let resolutionChoices : [Choice] @@ -81,10 +82,12 @@ struct SettingsView:View Choice("Direct", CursorMode.direct) ]) } -// CatItem("Cursor Scale") -// { -// Slider(value: $cursorScale, in:0.1...4, step:0.1) -// } + CatItem("Cursor Scale") + { + Slider(value: $cursorScale, in:0.1...4, step:0.1) + .frame(width: 200) + Text(String(format: "%.1f", cursorScale)) + } } CatTitle("Graphics") CatList() @@ -119,7 +122,12 @@ struct SettingsView:View Toggle("", isOn:$noOverlay) .frame(width:80) } - } + CatItem("Hide Status Bar") + { + Toggle("", isOn:$hideStatusBar) + .frame(width:80) + } + } Text("More options coming soon.") .multilineTextAlignment(.center) .opacity(0.5) @@ -143,9 +151,9 @@ struct SettingsView:View SettingsHandler.decoder = decoder SettingsHandler.resolution = resolution SettingsHandler.cursorMode = cursorMode - //SettingsHandler.cursorScale = cursorScale + SettingsHandler.cursorScale = cursorScale SettingsHandler.noOverlay = noOverlay - + SettingsHandler.hideStatusBar = hideStatusBar SettingsHandler.save() visible = false