Skip to content

Commit

Permalink
Fix shift on GBoard and improve stuck key detection
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jan 16, 2020
1 parent 6bf2092 commit 143e93d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
18 changes: 10 additions & 8 deletions Blink/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,17 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
debugPrint("BK:", "stuck!!!")
input.setTrackingModifierFlags([])

let ctrl = UIHostingController(rootView: StuckView(keyCode: key, dismissAction: {
spCtrl.onStuckOpCommand()
}))

ctrl.modalPresentationStyle = .formSheet
spCtrl.stuckKeyCode = key
spCtrl.present(ctrl, animated: false)
if input.isHardwareKB && key == .commandLeft {
let ctrl = UIHostingController(rootView: StuckView(keyCode: key, dismissAction: {
spCtrl.onStuckOpCommand()
}))

ctrl.modalPresentationStyle = .formSheet
spCtrl.stuckKeyCode = key
spCtrl.present(ctrl, animated: false)

return
return
}
}

spCtrl.stuckKeyCode = nil
Expand Down
13 changes: 8 additions & 5 deletions Blink/SmarterKeys/SmarterTermInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class SmarterTermInput: KBWebView {
private var _hideSmartKeysWithHKB = !BKUserConfigurationManager.userSettingsValue(forKey: BKUserConfigShowSmartKeysWithXKeyBoard)
private var _inputAccessoryView: UIView? = nil

var isHardwareKB: Bool { _kbView.traits.isHKBAttached }

var device: TermDevice? = nil {
didSet { reportStateReset() }
}
Expand Down Expand Up @@ -125,7 +127,7 @@ class SmarterTermInput: KBWebView {
private func _reportLang() {
let lang = self.textInputMode?.primaryLanguage ?? ""
_kbView.lang = lang
reportLang(lang)
reportLang(lang, isHardwareKB: _kbView.traits.isHKBAttached)
}

override var inputAssistantItem: UITextInputAssistantItem {
Expand Down Expand Up @@ -513,6 +515,11 @@ extension SmarterTermInput {
func stuckKey() -> KeyCode? {
let mods: UIKeyModifierFlags = [.shift, .control, .alternate, .command]
let stuck = mods.intersection(trackingModifierFlags)

// Return command key first
if stuck.contains(.command) {
return KeyCode.commandLeft
}

if stuck.contains(.shift) {
return KeyCode.shiftLeft
Expand All @@ -525,10 +532,6 @@ extension SmarterTermInput {
return KeyCode.optionLeft
}

if stuck.contains(.command) {
return KeyCode.commandLeft
}

return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion KB/JS/dist/kb.js

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions KB/JS/src/Keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export default class Keyboard implements IKeyboard {

_lang: string = 'en';
_langWithDeletes = false;
_isHKB = false;

hasSelection: boolean = false;

Expand Down Expand Up @@ -522,6 +523,13 @@ export default class Keyboard implements IKeyboard {
return;
}

if (!this._isHKB) {
// Some software KBs doesn't report shift presses (GBoard for instance)
this._output(key);
_blockEvent(e);
return;
}

// TODO: may be remove accents only after options key is pressed.
let out = this._removeAccents ? _removeAccents(key) : key;
this._removeAccents = false;
Expand Down Expand Up @@ -685,11 +693,14 @@ export default class Keyboard implements IKeyboard {
}

// Keyboard language change
_handleLang(lang: string) {
this._lang = lang;
this._langWithDeletes = lang === 'ko-KR';
_handleLang(langAndKB: string) {
let parts = langAndKB.split(':');
this._lang = parts[0];
this._isHKB = parts[1] === 'hw';

this._langWithDeletes = this._lang === 'ko-KR';
this._stateReset(this.hasSelection);
if (lang != 'dictation') {
if (this._lang !== 'dictation') {
op('voice', {data: ''});
}
}
Expand Down
2 changes: 1 addition & 1 deletion KB/Native/Views/KBWebViewBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (readonly) UIKeyModifierFlags trackingModifierFlags;

- (void)reportStateReset:(BOOL)hasSelection;
- (void)reportLang:(NSString *) lang;
- (void)reportLang:(NSString *) lang isHardwareKB: (BOOL)isHardwareKB;
- (void)reportHex:(NSString *) hex;
- (void)reportPress:(UIKeyModifierFlags)mods keyId:(NSString *)keyId;
- (void)reportToolbarPress:(UIKeyModifierFlags)mods keyId:(NSString *)keyId;
Expand Down
4 changes: 2 additions & 2 deletions KB/Native/Views/KBWebViewBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ - (void)setHasSelection:(BOOL)value {
[self report:@"selection" arg:value ? @"true" : @"false"];
}

- (void)reportLang:(NSString *) lang {
[self report:@"lang" arg:[NSString stringWithFormat:@"\"%@\"", lang]];
- (void)reportLang:(NSString *) lang isHardwareKB: (BOOL)isHardwareKB; {
[self report:@"lang" arg:[NSString stringWithFormat:@"\"%@:%@\"", lang, isHardwareKB ? @"hw" : @"sw"]];
}

- (void)_keyDown:(KeyCommand *)cmd {
Expand Down

0 comments on commit 143e93d

Please sign in to comment.