Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LeaveNha Description #2

Open
wants to merge 6 commits into
base: testing_lanuch
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion Frameworks/ParsecSDK.framework

This file was deleted.

32 changes: 25 additions & 7 deletions OpenParsec.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
27E61AA8292994B500FF6563 /* ActivityIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E61AA7292994B500FF6563 /* ActivityIndicator.swift */; };
27E61AAA2929B92200FF6563 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E61AA92929B92200FF6563 /* MainView.swift */; };
27ED36FF292D4F9800B1BE3D /* NetworkHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27ED36FE292D4F9800B1BE3D /* NetworkHandler.swift */; };
FC16A7AD29A97BDA00BB70A7 /* Shared.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC16A7AC29A97BDA00BB70A7 /* Shared.swift */; };
FC8A3CD529DF0B4C006B3B7B /* KeyboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC8A3CD429DF0B4C006B3B7B /* KeyboardViewController.swift */; };
FC8A3CD929DF54C2006B3B7B /* UIViewControllerWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC8A3CD829DF54C2006B3B7B /* UIViewControllerWrapper.swift */; };
FCA3307329DE3F70002B2948 /* TouchHandlingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCA3307229DE3F70002B2948 /* TouchHandlingView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -48,7 +52,7 @@
27899AC5292FE2A9001ACA33 /* audio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = audio.c; sourceTree = "<group>"; };
27899AC6292FE2A9001ACA33 /* audio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = audio.h; sourceTree = "<group>"; };
27B8D563292DC7A000A324AD /* CParsec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CParsec.swift; sourceTree = "<group>"; };
27B8D56F292DCA5800A324AD /* ParsecSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ParsecSDK.framework; path = "../../../../../Users/mike/Documents/Repositories/parsec-sdk/sdk/ios/ParsecSDK.framework"; sourceTree = "<group>"; };
27B8D56F292DCA5800A324AD /* ParsecSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = ParsecSDK.framework; sourceTree = "<group>"; };
27E61A8E292965FC00FF6563 /* OpenParsec.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OpenParsec.app; sourceTree = BUILT_PRODUCTS_DIR; };
27E61A91292965FC00FF6563 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
27E61A93292965FC00FF6563 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -61,6 +65,11 @@
27E61AA7292994B500FF6563 /* ActivityIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityIndicator.swift; sourceTree = "<group>"; };
27E61AA92929B92200FF6563 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
27ED36FE292D4F9800B1BE3D /* NetworkHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkHandler.swift; sourceTree = "<group>"; };
FC16A7AC29A97BDA00BB70A7 /* Shared.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shared.swift; sourceTree = "<group>"; };
FC746E7A2981A920003D191A /* parsec.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = parsec.h; path = "../../parsec-sdk/sdk/parsec.h"; sourceTree = "<group>"; };
FC8A3CD429DF0B4C006B3B7B /* KeyboardViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardViewController.swift; sourceTree = "<group>"; };
FC8A3CD829DF54C2006B3B7B /* UIViewControllerWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewControllerWrapper.swift; sourceTree = "<group>"; };
FCA3307229DE3F70002B2948 /* TouchHandlingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchHandlingView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -78,6 +87,7 @@
27B8D56A292DC98B00A324AD /* Frameworks */ = {
isa = PBXGroup;
children = (
FC746E7A2981A920003D191A /* parsec.h */,
27B8D56F292DCA5800A324AD /* ParsecSDK.framework */,
);
path = Frameworks;
Expand All @@ -103,6 +113,7 @@
27E61A90292965FC00FF6563 /* OpenParsec */ = {
isa = PBXGroup;
children = (
FC8A3CD829DF54C2006B3B7B /* UIViewControllerWrapper.swift */,
27899AC5292FE2A9001ACA33 /* audio.c */,
27899AC6292FE2A9001ACA33 /* audio.h */,
271D14FA292EAA3600D7F1D6 /* ParsecGLKRenderer.swift */,
Expand All @@ -121,6 +132,9 @@
27B8D563292DC7A000A324AD /* CParsec.swift */,
271D14F8292E90EB00D7F1D6 /* ParsecView.swift */,
27899AC4292FE2A8001ACA33 /* OpenParsec-Bridging-Header.h */,
FC16A7AC29A97BDA00BB70A7 /* Shared.swift */,
FCA3307229DE3F70002B2948 /* TouchHandlingView.swift */,
FC8A3CD429DF0B4C006B3B7B /* KeyboardViewController.swift */,
);
path = OpenParsec;
sourceTree = "<group>";
Expand Down Expand Up @@ -205,9 +219,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FC16A7AD29A97BDA00BB70A7 /* Shared.swift in Sources */,
FC8A3CD529DF0B4C006B3B7B /* KeyboardViewController.swift in Sources */,
FCA3307329DE3F70002B2948 /* TouchHandlingView.swift in Sources */,
27E61A92292965FC00FF6563 /* AppDelegate.swift in Sources */,
27E61AAA2929B92200FF6563 /* MainView.swift in Sources */,
271D14FD292EAA3600D7F1D6 /* ParsecGLKViewController.swift in Sources */,
FC8A3CD929DF54C2006B3B7B /* UIViewControllerWrapper.swift in Sources */,
27E61AA8292994B500FF6563 /* ActivityIndicator.swift in Sources */,
271D14FC292EAA3600D7F1D6 /* ParsecGLKRenderer.swift in Sources */,
27E61A94292965FC00FF6563 /* SceneDelegate.swift in Sources */,
Expand Down Expand Up @@ -358,15 +376,15 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"OpenParsec/Preview Content\"";
DEVELOPMENT_TEAM = NMU32WR5KZ;
DEVELOPMENT_TEAM = 7EVW949E9Y;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = OpenParsec/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = io.github.AngelDTF.OpenParsec;
PRODUCT_BUNDLE_IDENTIFIER = io.github.LeaveNhA.OpenParsec;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "OpenParsec/OpenParsec-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -385,15 +403,15 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"OpenParsec/Preview Content\"";
DEVELOPMENT_TEAM = NMU32WR5KZ;
DEVELOPMENT_TEAM = 7EVW949E9Y;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = OpenParsec/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = io.github.AngelDTF.OpenParsec;
PRODUCT_BUNDLE_IDENTIFIER = io.github.LeaveNhA.OpenParsec;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "OpenParsec/OpenParsec-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
191 changes: 191 additions & 0 deletions OpenParsec/CParsec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class CParsec
private static var _parsec:OpaquePointer!
private static var _audio:OpaquePointer!
private static let _audioPtr:UnsafeRawPointer = UnsafeRawPointer(_audio)

public static var _hostWidth:Float = 0
public static var _hostHeight:Float = 0

static let PARSEC_VER:UInt32 = UInt32((PARSEC_VER_MAJOR << 16) | PARSEC_VER_MINOR)

Expand Down Expand Up @@ -60,6 +63,9 @@ class CParsec
static func setFrame(_ width:CGFloat, _ height:CGFloat, _ scale:CGFloat)
{
ParsecClientSetDimensions(_parsec, UInt8(DEFAULT_STREAM), UInt32(width), UInt32(height), Float(scale))

_hostWidth = Float(width)
_hostHeight = Float(height)
}

static func renderFrame(_ type:RendererType, timeout:UInt32 = 16) // timeout in ms, 16 == 60 FPS, 8 == 120 FPS
Expand All @@ -80,4 +86,189 @@ class CParsec
{
audio_mute(muted)
}

static func sendMouseMessage(_ button: ParsecMouseButton, _ x: Int32, _ y: Int32, _ pressed: Bool) {
// debug the values for measurements and calculations:
// Send the mouse position
var motionMessage = ParsecMessage()
motionMessage.type = MESSAGE_MOUSE_MOTION
motionMessage.mouseMotion.x = x
motionMessage.mouseMotion.y = y
ParsecClientSendMessage(_parsec, &motionMessage)

// Send the mouse button state
var buttonMessage = ParsecMessage()
buttonMessage.type = MESSAGE_MOUSE_BUTTON
buttonMessage.mouseButton.button = button
buttonMessage.mouseButton.pressed = pressed ? true : false
ParsecClientSendMessage(_parsec, &buttonMessage)
}

static func sendMousePosition(_ x: Int32, _ y: Int32){
var motionMessage = ParsecMessage()
motionMessage.type = MESSAGE_MOUSE_MOTION
motionMessage.mouseMotion.x = x
motionMessage.mouseMotion.y = y
ParsecClientSendMessage(_parsec, &motionMessage)
}

static func sendKeyboardMessage(sender: UIKeyCommand){
var key = sender.input ?? ""

switch sender.modifierFlags.rawValue {
case 131072:
key = "SHIFT"
break
case 262144:
key = "CONTROL"
break

default:
break
}

print("Keyboard Message: \(key)")
print("KeyboardViewController keyboard modifier info \(sender.modifierFlags.rawValue)")

var keyboardMessagePress = ParsecMessage()
keyboardMessagePress.type = MESSAGE_KEYBOARD
keyboardMessagePress.keyboard.code = parsecKeyCodeTranslator(key)
keyboardMessagePress.keyboard.pressed = true
ParsecClientSendMessage(_parsec, &keyboardMessagePress)

var keyboardMessageRelease = ParsecMessage()
keyboardMessageRelease.type = MESSAGE_KEYBOARD
keyboardMessageRelease.keyboard.code = parsecKeyCodeTranslator(key)
keyboardMessageRelease.keyboard.pressed = false
ParsecClientSendMessage(_parsec, &keyboardMessageRelease)
}

static func parsecKeyCodeTranslator(_ str: String) -> ParsecKeycode {
switch str {
case "A": return ParsecKeycode(4)
case "B": return ParsecKeycode(5)
case "C": return ParsecKeycode(6)
case "D": return ParsecKeycode(7)
case "E": return ParsecKeycode(8)
case "F": return ParsecKeycode(9)
case "G": return ParsecKeycode(10)
case "H": return ParsecKeycode(11)
case "I": return ParsecKeycode(12)
case "J": return ParsecKeycode(13)
case "K": return ParsecKeycode(14)
case "L": return ParsecKeycode(15)
case "M": return ParsecKeycode(16)
case "N": return ParsecKeycode(17)
case "O": return ParsecKeycode(18)
case "P": return ParsecKeycode(19)
case "Q": return ParsecKeycode(20)
case "R": return ParsecKeycode(21)
case "S": return ParsecKeycode(22)
case "T": return ParsecKeycode(23)
case "U": return ParsecKeycode(24)
case "V": return ParsecKeycode(25)
case "W": return ParsecKeycode(26)
case "X": return ParsecKeycode(27)
case "Y": return ParsecKeycode(28)
case "Z": return ParsecKeycode(29)
case "1": return ParsecKeycode(30)
case "2": return ParsecKeycode(31)
case "3": return ParsecKeycode(32)
case "4": return ParsecKeycode(33)
case "5": return ParsecKeycode(34)
case "6": return ParsecKeycode(35)
case "7": return ParsecKeycode(36)
case "8": return ParsecKeycode(37)
case "9": return ParsecKeycode(38)
case "0": return ParsecKeycode(39)
case "ENTER": return ParsecKeycode(40)
case "UIKeyInputEscape": return ParsecKeycode(41) // ESCAPE with re-factored
case "BACKSPACE": return ParsecKeycode(42)
case "TAB": return ParsecKeycode(43)
case "SPACE": return ParsecKeycode(44)
case "MINUS": return ParsecKeycode(45)
case "EQUALS": return ParsecKeycode(46)
case "LBRACKET": return ParsecKeycode(47)
case "RBRACKET": return ParsecKeycode(48)
case "BACKSLASH": return ParsecKeycode(49)
case "SEMICOLON": return ParsecKeycode(51)
case "APOSTROPHE": return ParsecKeycode(52)
case "BACKTICK": return ParsecKeycode(53)
case "COMMA": return ParsecKeycode(54)
case "PERIOD": return ParsecKeycode(55)
case "SLASH": return ParsecKeycode(56)
case "CAPSLOCK": return ParsecKeycode(57)
case "F1": return ParsecKeycode(58)
case "F2": return ParsecKeycode(59)
case "F3": return ParsecKeycode(60)
case "F4": return ParsecKeycode(61)
case "F5": return ParsecKeycode(62)
case "F6": return ParsecKeycode(63)
case "F7": return ParsecKeycode(64)
case "F8": return ParsecKeycode(65)
case "F9": return ParsecKeycode(66)
case "F10": return ParsecKeycode(67)
case "F11": return ParsecKeycode(68)
case "F12": return ParsecKeycode(69)
case "PRINTSCREEN": return ParsecKeycode(70)
case "SCROLLLOCK": return ParsecKeycode(71)
case "PAUSE": return ParsecKeycode(72)
case "INSERT": return ParsecKeycode(73)
case "HOME": return ParsecKeycode(74)
case "PAGEUP": return ParsecKeycode(75)
case "DELETE": return ParsecKeycode(76)
case "END": return ParsecKeycode(77)
case "PAGEDOWN": return ParsecKeycode(78)
case "RIGHT": return ParsecKeycode(79)
case "LEFT": return ParsecKeycode(80)
case "DOWN": return ParsecKeycode(81)
case "UP": return ParsecKeycode(82)
case "NUMLOCK": return ParsecKeycode(83)
case "KP_DIVIDE": return ParsecKeycode(84)
case "KP_MULTIPLY": return ParsecKeycode(85)
case "KP_MINUS": return ParsecKeycode(86)
case "KP_PLUS": return ParsecKeycode(87)
case "KP_ENTER": return ParsecKeycode(88)
case "KP_1": return ParsecKeycode(89)
case "KP_2": return ParsecKeycode(90)
case "KP_3": return ParsecKeycode(91)
case "KP_4": return ParsecKeycode(92)
case "KP_5": return ParsecKeycode(93)
case "KP_6": return ParsecKeycode(94)
case "KP_7": return ParsecKeycode(95)
case "KP_8": return ParsecKeycode(96)
case "KP_9": return ParsecKeycode(97)
case "KP_0": return ParsecKeycode(98)
case "KP_PERIOD": return ParsecKeycode(99)
case "APPLICATION": return ParsecKeycode(101)
case "F13": return ParsecKeycode(104)
case "F14": return ParsecKeycode(105)
case "F15": return ParsecKeycode(106)
case "F16": return ParsecKeycode(107)
case "F17": return ParsecKeycode(108)
case "F18": return ParsecKeycode(109)
case "F19": return ParsecKeycode(110)
case "MENU": return ParsecKeycode(118)
case "MUTE": return ParsecKeycode(127)
case "VOLUMEUP": return ParsecKeycode(128)
case "VOLUMEDOWN": return ParsecKeycode(129)
case "CONTROL": return ParsecKeycode(224)
case "SHIFT": return ParsecKeycode(225)
case "LALT": return ParsecKeycode(226)
case "LGUI": return ParsecKeycode(227)
case "RCTRL": return ParsecKeycode(228)
case "RSHIFT": return ParsecKeycode(229)
case "RALT": return ParsecKeycode(230)
case "RGUI": return ParsecKeycode(231)
case "AUDIONEXT": return ParsecKeycode(258)
case "AUDIOPREV": return ParsecKeycode(259)
case "AUDIOSTOP": return ParsecKeycode(260)
case "AUDIOPLAY": return ParsecKeycode(261)
case "AUDIOMUTE": return ParsecKeycode(262)
case "MEDIASELECT": return ParsecKeycode(263)

default:
return ParsecKeycode(UInt32(0))
}
}
}
2 changes: 1 addition & 1 deletion OpenParsec/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum ViewType

struct ContentView:View
{
@State var curView:ViewType = .login
@State var curView:ViewType = .main

let defaultTransition = AnyTransition.move(edge:.trailing)

Expand Down
63 changes: 63 additions & 0 deletions OpenParsec/KeyboardViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// KeyboardViewController.swift
// OpenParsec
//
// Created by Seçkin KÜKRER on 6.04.2023.
//

import ParsecSDK
import UIKit

class KeyboardViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
print("KeyboardViewController did load!")
}

@objc func handleKeyCommand(sender: UIKeyCommand) {
print("KeyboardViewController keyboard info: \(sender)")

CParsec.sendKeyboardMessage(sender: sender)
}

@objc func handleModifierKeyCommand(sender: UIKeyCommand){
print("KeyboardViewController keyboard modifier info \(sender.modifierFlags.rawValue)")
}

override var keyCommands:[UIKeyCommand]? {
// Create an array to hold the key commands
var commands = [UIKeyCommand]()

// Add a key command for each printable ASCII character
for scalar in (Unicode.Scalar(32)...Unicode.Scalar(255)).makeIterator() {
let input = String(scalar)
let keyCommand = UIKeyCommand(action: #selector(handleKeyCommand(sender:)), input: input, modifierFlags: [], propertyList: input)
print("Key added to the Commands: \(input)")
commands.append(keyCommand)
}

// ESC Key
let escKeyCommand = UIKeyCommand(action: #selector(handleKeyCommand(sender:)), input: UIKeyCommand.inputEscape, modifierFlags: [], propertyList: nil)

// TAB Key
let tabKeyCommand = UIKeyCommand(action: #selector(handleKeyCommand(sender:)), input: "\t", modifierFlags: [], propertyList: nil)

// Shift Keys
let shiftKeyCommand = UIKeyCommand(action: #selector(handleKeyCommand(sender:)), input: "", modifierFlags: .shift, propertyList: nil)

// CTRL Key
let ctrlKeyCommand = UIKeyCommand(action: #selector(handleKeyCommand(sender:)), input: "", modifierFlags: .control, propertyList: nil)

let commandKey = UIKeyCommand(action: #selector(handleKeyCommand(sender:)), input: "", modifierFlags: .command, propertyList: nil)

// Return the array of key commands
return commands + [
escKeyCommand,
tabKeyCommand,
shiftKeyCommand,
ctrlKeyCommand,
commandKey
]
}
}
Loading