Skip to content

Commit

Permalink
KeyCasts option in Appearance
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Oct 25, 2019
1 parent 417e341 commit d4633e7
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 63 deletions.
4 changes: 2 additions & 2 deletions Blink/TermJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ NSString *term_processKB(NSString *str) {
return [NSString stringWithFormat:@"term_processKB(%@[0]);", _encodeString(str)];
}

NSString *term_displayInput(NSString *str) {
return [NSString stringWithFormat:@"term_displayInput(%@[0]);", _encodeString(str)];
NSString *term_displayInput(NSString *str, BOOL display) {
return [NSString stringWithFormat:@"term_displayInput(%@[0], %@);", _encodeString(str), display ? @"true" : @"false"];
}

NSString *term_apiResponse(NSString *name, NSString *response) {
Expand Down
2 changes: 1 addition & 1 deletion Blink/TermView.m
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ - (void)processKB:(NSString *)str {
}

- (void)displayInput:(NSString *)input {
[self _evalJSScript: term_displayInput(input)];
[self _evalJSScript: term_displayInput(input, BKDefaults.isKeyCastsOn)];
}

// Write data to terminal control
Expand Down
2 changes: 1 addition & 1 deletion Blink/WebKit/WKWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class UIScrollViewWithoutHitTest: UIScrollView {
let point = recognizer.location(in: recognizer.view)
switch recognizer.state {
case .recognized:
_wkWebView?.evaluateJavaScript("term_reportMouseClick(\(point.x), \(point.y), 1);", completionHandler: nil)
_wkWebView?.evaluateJavaScript("term_reportMouseClick(\(point.x), \(point.y), 1, \(BKDefaults.isKeyCastsOn() ? "true" : "false"));", completionHandler: nil)
default: break
}

Expand Down
12 changes: 9 additions & 3 deletions Resources/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ function term_processKB(str) {
}
}

function term_displayInput(str) {
function term_displayInput(str, display) {
t.accessibilityReader_.hasUserGesture = true;
if (!display) {
return;
}
if (str && !t.prompt._secure) {
window.KeystrokeVisualizer.processInput(str);
}
Expand Down Expand Up @@ -278,14 +281,17 @@ function _setTermCoordinates(event, x, y) {
event.terminalColumn = parseInt(x / t.scrollPort_.characterSize.width);
}

function term_reportMouseClick(x, y, buttons) {
function term_reportMouseClick(x, y, buttons, display) {
var event = new MouseEvent(name, {buttons});
_setTermCoordinates(event, x, y);
if (!t.prompt.processMouseClick(event)) {
term_reportMouseEvent('mousedown', x, y, 1);
term_reportMouseEvent('mouseup', x, y, 1);
}
term_displayInput("👆");

if (display) {
term_displayInput("👆", display);
}
}

function term_reportMouseEvent(name, x, y, buttons) {
Expand Down
132 changes: 78 additions & 54 deletions Settings/Base.lproj/Settings.storyboard

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Settings/Model/BKDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ typedef NS_ENUM(NSInteger, BKKeyboardStyle) {
@property (nonatomic) BOOL boldAsBright;
@property (nonatomic) BKKeyboardStyle keyboardStyle;
@property (nonatomic) BOOL alternateAppIcon;
@property (nonatomic) BOOL keycasts;
@property (nonatomic) BKLayoutMode layoutMode;
@property (nonatomic) BKOverscanCompensation overscanCompensation;
@property (nonatomic) BOOL xCallBackURLEnabled;
Expand All @@ -102,6 +103,7 @@ typedef NS_ENUM(NSInteger, BKKeyboardStyle) {
+ (void)setBoldAsBright:(BOOL)state;
+ (void)setEnableBold:(NSUInteger)state;
+ (void)setAlternateAppIcon:(BOOL)state;
+ (void)setKeycasts:(BOOL)state;
+ (void)setXCallBackURLEnabled:(BOOL)state;
+ (void)setXCallBackURLKey:(NSString *)key;
+ (void)setTriggers:(NSArray *)triggers forFunction:(NSString *)func;
Expand All @@ -126,6 +128,7 @@ typedef NS_ENUM(NSInteger, BKKeyboardStyle) {
+ (NSUInteger)enableBold;
+ (BOOL)isBoldAsBright;
+ (BOOL)isAlternateAppIcon;
+ (BOOL)isKeyCastsOn;
+ (BOOL)isXCallBackURLEnabled;
+ (NSString *)xCallBackURLKey;
+ (void)setDefaultUserName:(NSString*)name;
Expand Down
11 changes: 11 additions & 0 deletions Settings/Model/BKDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ - (id)initWithCoder:(NSCoder *)coder
_enableBold = [coder decodeIntegerForKey:@"enableBold"];
_boldAsBright = [coder decodeBoolForKey:@"boldAsBright"];
_keyboardStyle = (BKKeyboardStyle)[coder decodeIntegerForKey:@"keyboardStyle"];
_keycasts = [coder decodeBoolForKey:@"keycasts"];
_alternateAppIcon = [coder decodeBoolForKey:@"alternateAppIcon"];
_layoutMode = (BKLayoutMode)[coder decodeIntegerForKey:@"layoutMode"];
_overscanCompensation = (BKOverscanCompensation)[coder decodeIntegerForKey:@"overscanCompensation"];
Expand All @@ -100,6 +101,7 @@ - (void)encodeWithCoder:(NSCoder *)encoder
[encoder encodeInteger:_enableBold forKey:@"enableBold"];
[encoder encodeBool:_boldAsBright forKey:@"boldAsBright"];
[encoder encodeInteger: _keyboardStyle forKey:@"keyboardStyle"];
[encoder encodeBool: _keycasts forKey:@"keycasts"];
[encoder encodeBool:_alternateAppIcon forKey:@"alternateAppIcon"];
[encoder encodeInteger:_layoutMode forKey:@"layoutMode"];
[encoder encodeInteger:_overscanCompensation forKey:@"overscanCompensation"];
Expand Down Expand Up @@ -230,6 +232,10 @@ + (void)setAlternateAppIcon:(BOOL)state
defaults.alternateAppIcon = state;
}

+ (void)setKeycasts:(BOOL)state {
defaults.keycasts = state;
}

+ (void)setEnableBold:(NSUInteger)state
{
defaults.enableBold = state;
Expand Down Expand Up @@ -372,6 +378,11 @@ + (BOOL)isAlternateAppIcon
return defaults.alternateAppIcon;
}

+ (BOOL)isKeyCastsOn
{
return defaults.keycasts;
}

+ (NSString*)defaultUserName
{
return defaults.defaultUser;
Expand Down
22 changes: 20 additions & 2 deletions Settings/ViewControllers/Appearance/BKAppearanceViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define LAYOUT_MODE_TAG 2008
#define OVERSCAN_COMPENSATION_TAG 2009
#define KEYBOARDSTYLE_TAG 2010
#define KEYCASTS_TAG 2011

typedef NS_ENUM(NSInteger, BKAppearanceSections) {
BKAppearance_Terminal = 0,
Expand Down Expand Up @@ -84,6 +85,9 @@ @implementation BKAppearanceViewController {
UISwitch *_alternateAppIconSwitch;
BOOL _alternateAppIconValue;

UISwitch *_keyCastsSwitch;
BOOL _keyCastsValue;

UISegmentedControl *_defaultLayoutModeSegmentedControl;
BKLayoutMode _defaultLayoutModeValue;

Expand Down Expand Up @@ -140,6 +144,7 @@ - (void)loadDefaultValues
_defaultLayoutModeValue = BKDefaults.layoutMode;
_overscanCompensationValue = BKDefaults.overscanCompensation;
_keyboardStyleValue = BKDefaults.keyboardStyle;
_keyCastsValue = [BKDefaults isKeyCastsOn];
}

- (void)saveDefaultValues
Expand All @@ -163,6 +168,7 @@ - (void)saveDefaultValues
[BKDefaults setLayoutMode:_defaultLayoutModeValue];
[BKDefaults setOversanCompensation:_overscanCompensationValue];
[BKDefaults setKeyboardStyle:_keyboardStyleValue];
[BKDefaults setKeycasts:_keyCastsValue];

[BKDefaults saveDefaults];
[[NSNotificationCenter defaultCenter]
Expand All @@ -186,7 +192,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
} else if (section == BKAppearance_Fonts) {
return [[BKFont all] count] + 1;
} else if (section == BKAppearance_KeyboardAppearance) {
return 1;
return 2;
} else if (section == BKAppearance_AppIcon) {
return 1;
} else if (section == BKAppearance_Layout) {
Expand Down Expand Up @@ -251,7 +257,11 @@ - (NSString *)cellIdentifierForIndexPath:(NSIndexPath *)indexPath
cellIdentifier = @"cursorBlinkCell";
}
} else if (section == BKAppearance_KeyboardAppearance) {
cellIdentifier = @"keyboardStyleCell";
if (indexPath.row == 0) {
cellIdentifier = @"keyboardStyleCell";
} else {
cellIdentifier = @"keycastsCell";
}
} else if (section == BKAppearance_AppIcon) {
cellIdentifier = @"alternateAppIconCell";
} else if (section == BKAppearance_Layout) {
Expand Down Expand Up @@ -327,6 +337,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
} else if (indexPath.section == BKAppearance_KeyboardAppearance && indexPath.row == 0) {
_keyboardStyleSegmentedControl = [cell viewWithTag:KEYBOARDSTYLE_TAG];
_keyboardStyleSegmentedControl.selectedSegmentIndex = [self _keyboardStyleToIndex: _keyboardStyleValue];
} else if (indexPath.section == BKAppearance_KeyboardAppearance && indexPath.row == 1) {
_keyCastsSwitch = [cell viewWithTag:KEYCASTS_TAG];
_keyCastsSwitch.on = _keyCastsValue;
} else if (indexPath.section == BKAppearance_AppIcon && indexPath.row == 0) {
_alternateAppIconSwitch = [cell viewWithTag:APP_ICON_ALTERNATE_TAG];
_alternateAppIconSwitch.on = _alternateAppIconValue;
Expand Down Expand Up @@ -568,6 +581,11 @@ - (IBAction)alternateAppIconSwitchChanged:(id)sender
[[UIApplication sharedApplication] setAlternateIconName:appIcon completionHandler:nil];
}

- (IBAction)keycastsSwitchChanged:(id)sender
{
_keyCastsValue = _keyCastsSwitch.on;
}

#pragma mark - TermViewDeviceProtocol

- (void)viewIsReady
Expand Down

0 comments on commit d4633e7

Please sign in to comment.