Onscreen Widget Tool:

- edit/duplicate function support
- opened from cmd tool by sliding from screen edge
This commit is contained in:
TrueZhuangjia
2025-05-13 23:18:32 +08:00
committed by TrueZhuanjia
parent c8ebdc0a88
commit d3b62e38fc
14 changed files with 573 additions and 229 deletions
+24 -24
View File
@@ -19,29 +19,29 @@ import UIKit
// MARK: - Properties
@objc var keyboardCmdString: String
@objc var cmdString: String
@objc var alias: String
// MARK: - Initialization
init(keyboardCmdString: String, alias: String) {
self.keyboardCmdString = keyboardCmdString
init(cmdString: String, alias: String) {
self.cmdString = cmdString
self.alias = alias
}
// MARK: - NSSecureCoding
required public init?(coder: NSCoder) {
guard let keyboardCmdString = coder.decodeObject(of: NSString.self, forKey: "keyboardCmdString") as String?,
guard let cmdString = coder.decodeObject(of: NSString.self, forKey: "keyboardCmdString") as String?,
let alias = coder.decodeObject(of: NSString.self, forKey: "alias") as String? else {
return nil
}
self.keyboardCmdString = keyboardCmdString
self.cmdString = cmdString
self.alias = alias
}
public func encode(with coder: NSCoder) {
coder.encode(keyboardCmdString, forKey: "keyboardCmdString")
coder.encode(cmdString, forKey: "keyboardCmdString")
coder.encode(alias, forKey: "alias")
}
}
@@ -377,21 +377,21 @@ import UIKit
let defaults = UserDefaults.standard
//if true { // save default entries if the data is empty.
if defaults.data(forKey: "savedCommands") == nil { // save default entries if the data is empty.
let defaultCommands: [RemoteCommand] = [
RemoteCommand(keyboardCmdString: "WIN", alias: "WIN"),
RemoteCommand(keyboardCmdString: "F11", alias: "F11"),
RemoteCommand(keyboardCmdString: "ESC", alias: "ESC"),
RemoteCommand(keyboardCmdString: "CTRL+SHIFT+ESC", alias: "任务管理器(Task Manager)"),
RemoteCommand(keyboardCmdString: "ALT+F1", alias: "N卡截图(Nvidia Screenshot)"),
RemoteCommand(keyboardCmdString: "ALT+F9", alias: "N卡录屏(Nvidia Screen Recording)"),
RemoteCommand(keyboardCmdString: "ALT+F4", alias: "关闭窗口(ALT+F4)"),
RemoteCommand(keyboardCmdString: "CTRL+A", alias: "全选(Select All)"),
RemoteCommand(keyboardCmdString: "CTRL+C", alias: "复制(Copy)"),
RemoteCommand(keyboardCmdString: "CTRL+V", alias: "粘贴(Paste)"),
RemoteCommand(keyboardCmdString: "WIN+D", alias: "切换桌面(Switch to Desktop)"),
RemoteCommand(keyboardCmdString: "WIN+P", alias: "多显模式(Project)"),
RemoteCommand(keyboardCmdString: "WIN+G", alias: "Xbox Game Bar"),
RemoteCommand(keyboardCmdString: "SHIFT+TAB", alias: "Steam Overlay"),
var defaultCommands: [RemoteCommand] = [
RemoteCommand(cmdString: "WIN", alias: "WIN"),
RemoteCommand(cmdString: "F11", alias: "F11"),
RemoteCommand(cmdString: "ESC", alias: "ESC"),
RemoteCommand(cmdString: "CTRL+SHIFT+ESC", alias: "任务管理器(Task Manager)"),
RemoteCommand(cmdString: "ALT+F1", alias: "N卡截图(Nvidia Screenshot)"),
RemoteCommand(cmdString: "ALT+F9", alias: "N卡录屏(Nvidia Screen Recording)"),
RemoteCommand(cmdString: "ALT+F4", alias: "关闭窗口(ALT+F4)"),
RemoteCommand(cmdString: "CTRL+A", alias: "全选(Select All)"),
RemoteCommand(cmdString: "CTRL+C", alias: "复制(Copy)"),
RemoteCommand(cmdString: "CTRL+V", alias: "粘贴(Paste)"),
RemoteCommand(cmdString: "WIN+D", alias: "切换桌面(Switch to Desktop)"),
RemoteCommand(cmdString: "WIN+P", alias: "多显模式(Project)"),
RemoteCommand(cmdString: "WIN+G", alias: "Xbox Game Bar"),
RemoteCommand(cmdString: "SHIFT+TAB", alias: "Steam Overlay"),
]
let data = try? NSKeyedArchiver.archivedData(withRootObject: defaultCommands, requiringSecureCoding: false)
@@ -505,9 +505,9 @@ import UIKit
}
@objc public func addCommand(_ command: RemoteCommand) -> Bool {
command.keyboardCmdString = command.keyboardCmdString.uppercased() // convert all letters to upper case
if(command.alias.trimmingCharacters(in: .whitespacesAndNewlines).count == 0) {command.alias = command.keyboardCmdString} // copy cmd string as alias when alias is empty
let keyStrings = extractKeyStringsFromComboCommand(from: command.keyboardCmdString)
command.cmdString = command.cmdString.uppercased() // convert all letters to upper case
if(command.alias.trimmingCharacters(in: .whitespacesAndNewlines).count == 0) {command.alias = command.cmdString} // copy cmd string as alias when alias is empty
let keyStrings = extractKeyStringsFromComboCommand(from: command.cmdString)
if (keyStrings == nil) {return false} // in case of non-keyboard command strings, return false
commands.append(command)
saveCommands()
+2 -2
View File
@@ -223,14 +223,14 @@ import UIKit
// ======================================================================================================
@objc public func setLocation(xOffset:CGFloat, yOffset:CGFloat) {
@objc public func setLocation(position: CGPoint) {
/*
NSLayoutConstraint.activate([
self.centerXAnchor.constraint(equalTo: self.superview!.leadingAnchor, constant: xOffset),
self.centerYAnchor.constraint(equalTo: self.superview!.topAnchor, constant: yOffset),
])
*/
storedCenter = CGPointMake(xOffset, yOffset)
storedCenter = position
center = storedCenter
}
+1 -1
View File
@@ -417,7 +417,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
// Add the widgetView to the view controller's view
[self->streamFrameTopLayerView addSubview:widgetView]; // add keyboard button to the stream frame view. must add it to the target view before setting location.
buttonState.position = [self denormalizeWidgetPosition:buttonState.position];
[widgetView setLocationWithXOffset:buttonState.position.x yOffset:buttonState.position.y];
[widgetView setLocationWithPosition:buttonState.position];
[widgetView resizeWidgetView]; // resize must be called after relocation
[widgetView adjustTransparencyWithAlpha:buttonState.backgroundAlpha];
[widgetView adjustBorderWithWidth:buttonState.borderWidth];