Skip to content

Commit

Permalink
Build 163
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Dec 3, 2019
1 parent ed0d28d commit ccd0089
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Blink.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2219,7 +2219,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 162;
CURRENT_PROJECT_VERSION = 163;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = HV2S48975V;
Expand Down Expand Up @@ -2264,7 +2264,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 162;
CURRENT_PROJECT_VERSION = 163;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = HV2S48975V;
ENABLE_BITCODE = NO;
Expand Down
22 changes: 9 additions & 13 deletions Blink/SmarterKeys/SmarterTermInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ class SmarterTermInput: KBWebView {
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

var softwareKB: Bool {
get { !_kbView.traits.isHKBAttached }
set { _kbView.traits.isHKBAttached = !newValue }
}


@objc func _updateSettings() {
KBSound.isMutted = BKUserConfigurationManager.userSettingsValue(
Expand Down Expand Up @@ -291,14 +287,14 @@ class SmarterTermInput: KBWebView {

override var canBecomeFirstResponder: Bool { true }

// override func resignFirstResponder() -> Bool {
// let res = super.resignFirstResponder()
// if res {
// device?.blur()
// _kbView.isHidden = true
// }
// return res
// }
override func resignFirstResponder() -> Bool {
let res = super.resignFirstResponder()
if res {
device?.blur()
_kbView.isHidden = true
}
return res
}

// override var canResignFirstResponder: Bool {
// let state = window?.windowScene?.activationState
Expand Down
2 changes: 0 additions & 2 deletions Blink/SpaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,6 @@ extension SpaceController {
_closeCurrentSpace()
}



@objc func _focusOtherWindowAction() {
let sessions = _activeSessions()

Expand Down
2 changes: 1 addition & 1 deletion Blink/TermDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ - (void)prompt:(NSString *)prompt secure:(BOOL)secure shell:(BOOL)shell {
NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:kNilOptions error:nil];
NSString *cmd = [NSString stringWithFormat: @"\x1b]1337;BlinkPrompt=%@\x07", [data base64EncodedStringWithOptions:kNilOptions]];

fprintf(_stream.out, cmd.UTF8String);
fprintf(_stream.out, "%s", cmd.UTF8String);
}

- (NSString *)readline:(NSString *)prompt secure:(BOOL)secure {
Expand Down
2 changes: 2 additions & 0 deletions KB/Native/Model/KBConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class KBConfig: ObservableObject, Codable {
var option: KeyConfigPair
var command: KeyConfigPair

var fnBinding: KeyBinding = KeyBinding(keys: [KeyCode.commandLeft.id], shiftLoc: 0, controlLoc: 0, optionLoc: 0, commandLoc: 0, action: .none)
var cursorBinding: KeyBinding = KeyBinding(keys: [KeyCode.commandLeft.id], shiftLoc: 0, controlLoc: 0, optionLoc: 0, commandLoc: 0, action: .none)
var customBindings: [KeyBinding] = []

private var _cancellable = Set<AnyCancellable>()
Expand Down
44 changes: 26 additions & 18 deletions KB/Native/Model/KeyBinding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ extension KeyToken: Comparable {
}

class KeyBinding: ObservableObject, Codable {
var capturedKeys: Array<String> = []
var keys: Array<String> = []
@Published var shiftLoc: Int8 = 0
@Published var controlLoc: Int8 = 0
@Published var optionLoc: Int8 = 0
@Published var commandLoc: Int8 = 0

@Published var action: KeyBindingAction = .command
@Published var action: KeyBindingAction = .command(.tabNew)

func getTokens() -> [KeyToken] {
var tokens: [KeyToken] = []
for s in capturedKeys {
for s in keys {
var token = KeyToken()

if let code = KeyCode(keyID: s) {
Expand Down Expand Up @@ -129,17 +129,25 @@ class KeyBinding: ObservableObject, Codable {
}
}

func keysDescription(_ last: String = "") -> String {
let res = getTokens().map { $0.label }.joined(separator: "")
if res.isEmpty {
return res
}
return res + last
}

// - MARK: Codable

init(
capturedKeys: [String],
keys: [String],
shiftLoc: Int8,
controlLoc: Int8,
optionLoc: Int8,
commandLoc: Int8,
action: KeyBindingAction
) {
self.capturedKeys = capturedKeys
self.keys = keys
self.shiftLoc = shiftLoc
self.controlLoc = controlLoc
self.optionLoc = optionLoc
Expand All @@ -148,7 +156,7 @@ class KeyBinding: ObservableObject, Codable {
}

enum Keys: CodingKey {
case capturedKeys
case keys
case shiftLoc
case controlLoc
case optionLoc
Expand All @@ -159,7 +167,7 @@ class KeyBinding: ObservableObject, Codable {
public func encode(to encoder: Encoder) throws {
var c = encoder.container(keyedBy: Keys.self)

try c.encode(capturedKeys, forKey: .capturedKeys)
try c.encode(keys, forKey: .keys)
try c.encode(shiftLoc, forKey: .shiftLoc)
try c.encode(controlLoc, forKey: .controlLoc)
try c.encode(optionLoc, forKey: .optionLoc)
Expand All @@ -170,15 +178,15 @@ class KeyBinding: ObservableObject, Codable {
required convenience init(from decoder: Decoder) throws {
let c = try decoder.container(keyedBy: Keys.self)

let capturedKyes = try c.decode(Array<String>.self, forKey: .capturedKeys)
let shiftLoc = try c.decode(Int8.self, forKey: .shiftLoc)
let controlLoc = try c.decode(Int8.self, forKey: .controlLoc)
let optionLoc = try c.decode(Int8.self, forKey: .optionLoc)
let commandLoc = try c.decode(Int8.self, forKey: .commandLoc)
let action = try c.decode(KeyBindingAction.self, forKey: .action)
let keys = try c.decode(Array<String>.self, forKey: .keys)
let shiftLoc = try c.decode(Int8.self, forKey: .shiftLoc)
let controlLoc = try c.decode(Int8.self, forKey: .controlLoc)
let optionLoc = try c.decode(Int8.self, forKey: .optionLoc)
let commandLoc = try c.decode(Int8.self, forKey: .commandLoc)
let action = try c.decode(KeyBindingAction.self, forKey: .action)

self.init(
capturedKeys: capturedKyes,
keys: keys,
shiftLoc: shiftLoc,
controlLoc: controlLoc,
optionLoc: optionLoc,
Expand All @@ -188,20 +196,20 @@ class KeyBinding: ObservableObject, Codable {
}

static var cmdC: KeyBinding {
let capturedKeys: [String] = [
let keys: [String] = [
KeyCode.commandLeft.id,
"67:0-KeyC"
]

return KeyBinding(capturedKeys: capturedKeys, shiftLoc: 0, controlLoc: 0, optionLoc: 0, commandLoc: 0, action: .command)
return KeyBinding(keys: keys, shiftLoc: 0, controlLoc: 0, optionLoc: 0, commandLoc: 0, action: .command(.clipboardCopy))
}

static var cmdV: KeyBinding {
let capturedKeys: [String] = [
let keys: [String] = [
KeyCode.commandLeft.id,
"68:0-KeyV"
]

return KeyBinding(capturedKeys: capturedKeys, shiftLoc: 0, controlLoc: 0, optionLoc: 0, commandLoc: 0, action: .command)
return KeyBinding(keys: keys, shiftLoc: 0, controlLoc: 0, optionLoc: 0, commandLoc: 0, action: .command(.clipboardPaste))
}
}
27 changes: 23 additions & 4 deletions KB/Native/Model/KeyBindingAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,34 @@

import SwiftUI

enum Command: String, Codable {
case windowNew
case windowClose
case windowFocusOther
case tabNew
case tabClose
case tabNext
case tabPrev
case tabMoveToOtherWindow
case zoomIn
case zoomOut
case zoomReset
case clipboardCopy
case clipboardPaste
case configShow
}

enum KeyBindingAction: Codable {
case ouput(hex: String)
case command

case hex(String)
case key(KeyCode)
case command(Command)
case none

func encode(to encoder: Encoder) throws {

}

init(from decoder: Decoder) throws {
self = Self.command
self = Self.command(.tabNew)
}
}
56 changes: 54 additions & 2 deletions KB/Native/Model/KeyCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ enum KeyCode: String, Codable, CaseIterable, Identifiable {
case optionRight = "AltRight"
case commandLeft = "MetaLeft"
case commandRight = "MetaRight"
case f1 = "F1"
case f2 = "F2"
case f3 = "F3"
case f4 = "F4"
case f5 = "F5"
case f6 = "F6"
case f7 = "F7"
case f8 = "F8"
case f9 = "F9"
case f10 = "F10"
case f11 = "F11"
case f12 = "F12"
case pageDown = "PageDown"
case pageUp = "PageUp"
case home = "Home"
case end = "End"

var isOption: Bool {
switch self {
Expand All @@ -62,15 +78,28 @@ enum KeyCode: String, Codable, CaseIterable, Identifiable {
case .controlLeft, .controlRight: return "⌃ Control"
case .optionLeft, .optionRight: return "⌥ Option"
case .commandLeft, .commandRight: return "⌘ Command"
case .pageUp: return "⇞ PageUp"
case .pageDown: return "⇟ PageDown"
case .home: return "↖︎ Home"
case .end: return "↘︎ End"
default: return rawValue
}
}

var code: String { rawValue }

var single: Bool {
switch self {
case .tab, .escape, .capsLock: return true
default: return false
case .shiftLeft,
.shiftRight,
.controlLeft,
.controlRight,
.optionLeft,
.optionRight,
.commandLeft,
.commandRight:
return false
default: return true
}
}

Expand All @@ -83,6 +112,7 @@ enum KeyCode: String, Codable, CaseIterable, Identifiable {
case .controlLeft, .controlRight: return "Control"
case .optionLeft, .optionRight: return "Alt"
case .commandLeft, .commandRight: return "Meta"
default: return rawValue
}
}

Expand All @@ -96,6 +126,22 @@ enum KeyCode: String, Codable, CaseIterable, Identifiable {
case .optionLeft, .optionRight: return 18
case .commandLeft: return 91
case .commandRight: return 93
case .f1: return 112
case .f2: return 113
case .f3: return 114
case .f4: return 115
case .f5: return 116
case .f6: return 117
case .f7: return 118
case .f8: return 119
case .f9: return 120
case .f10: return 121
case .f11: return 122
case .f12: return 123
case .home: return 36
case .pageUp: return 33
case .pageDown: return 34
case .end: return 35
}
}

Expand All @@ -108,6 +154,11 @@ enum KeyCode: String, Codable, CaseIterable, Identifiable {
case .controlLeft, .controlRight: return ""
case .optionLeft, .optionRight: return ""
case .commandLeft, .commandRight: return ""
case .pageUp: return ""
case .pageDown: return ""
case .home: return "↖︎"
case .end: return "↘︎"
default: return rawValue
}
}

Expand All @@ -134,6 +185,7 @@ enum KeyCode: String, Codable, CaseIterable, Identifiable {
.controlRight,
.optionRight: return 2
case .commandRight: return 0
default: return 0
}
}

Expand Down
4 changes: 2 additions & 2 deletions KB/Native/Views/BindingsConfigView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ struct BindingsConfigView: View {
HStack {
Text("Copy")
Spacer()
Text(copy.getTokens().map { $0.label }.joined(separator: "")).foregroundColor(.secondary)
Text(copy.keysDescription()).foregroundColor(.secondary)
Chevron()
}
HStack {
Text("Paste")
Spacer()
Text(paste.getTokens().map { $0.label }.joined(separator: "")).foregroundColor(.secondary)
Text(paste.keysDescription()).foregroundColor(.secondary)
Chevron()
}

Expand Down
22 changes: 22 additions & 0 deletions KB/Native/Views/KBConfigView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ private func _pairRow(_ pair: KeyConfigPair) -> some View {
}
}

private func _bindingRow(_ binding: KeyBinding, title: String, last: String) -> some View {
DefaultRow(title: title, description: binding.keysDescription(last)) {
BindingConfigView(title: title, binding: binding)
}
}

struct BindingConfigView: View {
var title: String
var binding: KeyBinding

var body: some View {
EmptyView()
.navigationBarTitle(title)
}
}


struct KBConfigView: View {
@ObservedObject var config: KBConfig

Expand All @@ -55,6 +72,8 @@ struct KBConfigView: View {
_pairRow(config.control)
_pairRow(config.option)
_pairRow(config.command)
_bindingRow(config.fnBinding, title: "Functional Keys", last: "[0-9]")
_bindingRow(config.cursorBinding, title: "Cursor Keys", last: "[Arrow]")
}
Section(header: Text("Blink")) {
DefaultRow(title: "Bindings") {
Expand All @@ -64,6 +83,9 @@ struct KBConfigView: View {
}
.listStyle(GroupedListStyle())
.navigationBarTitle("Keyboard")
.navigationBarItems(trailing: Button(action: {
SmarterTermInput.shared.saveAndApply(config: self.config)
}, label: {Text("Save")}))
.onReceive(config.objectWillChange) { _ in
DispatchQueue.main.async {
SmarterTermInput.shared.saveAndApply(config: self.config)
Expand Down

0 comments on commit ccd0089

Please sign in to comment.