From 6cc1b30a2c467041d911e13d6a1cb0bdf304d80c Mon Sep 17 00:00:00 2001 From: lint <47455468+lint@users.noreply.github.com> Date: Tue, 19 Nov 2019 00:48:05 -0500 Subject: [PATCH] Initial release --- Makefile | 12 ++++++++ NewTermArrows.plist | 1 + Tweak.xm | 70 +++++++++++++++++++++++++++++++++++++++++++++ control | 9 ++++++ 4 files changed, 92 insertions(+) create mode 100644 Makefile create mode 100644 NewTermArrows.plist create mode 100644 Tweak.xm create mode 100644 control diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..086dcc3 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +ARCHS = arm64 arm64e + +include $(THEOS)/makefiles/common.mk + +TWEAK_NAME = NewTermArrows +NewTermArrows_FILES = Tweak.xm +NewTermArrows_CFLAGS += -fobjc-arc + +include $(THEOS_MAKE_PATH)/tweak.mk + +after-install:: + install.exec "killall -9 NewTerm" diff --git a/NewTermArrows.plist b/NewTermArrows.plist new file mode 100644 index 0000000..2db7093 --- /dev/null +++ b/NewTermArrows.plist @@ -0,0 +1 @@ +{ Filter = { Bundles = ( "ws.hbang.Terminal" ); }; } diff --git a/Tweak.xm b/Tweak.xm new file mode 100644 index 0000000..f6db95e --- /dev/null +++ b/Tweak.xm @@ -0,0 +1,70 @@ + +@interface TerminalKeyInput +-(void)upKeyPressed; +-(void)downKeyPressed; +-(void)leftKeyPressed; +-(void)rightKeyPressed; + +@property(strong, nonatomic) NSTimer *haTimer; +-(void) haHandleLongPress:(UILongPressGestureRecognizer *) arg1; +@end + + +%hook TerminalKeyInput +%property(strong, nonatomic) NSTimer *haTimer; + +-(id) initWithFrame:(CGRect) arg1 { + id orig = %orig; + + UILongPressGestureRecognizer *upLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(haHandleLongPress:)]; + UILongPressGestureRecognizer *downLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(haHandleLongPress:)]; + UILongPressGestureRecognizer *leftLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(haHandleLongPress:)]; + UILongPressGestureRecognizer *rightLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(haHandleLongPress:)]; + + id keyboardToolbar = MSHookIvar(self, "toolbar"); + + [MSHookIvar(keyboardToolbar, "upKey") addGestureRecognizer:upLongPress]; + [MSHookIvar(keyboardToolbar, "downKey") addGestureRecognizer:downLongPress]; + [MSHookIvar(keyboardToolbar, "leftKey") addGestureRecognizer:leftLongPress]; + [MSHookIvar(keyboardToolbar, "rightKey") addGestureRecognizer:rightLongPress]; + + return orig; +} + +%new +-(void) haHandleLongPress:(UILongPressGestureRecognizer *) recognizer { + + NSString *keyName = [[recognizer view] accessibilityLabel]; + + if (recognizer.state == UIGestureRecognizerStateBegan){ + + if (![self haTimer]){ + if ([keyName isEqualToString:@"Up"]){ + [self setHaTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(upKeyPressed) userInfo:nil repeats:YES]]; + } else if ([keyName isEqualToString:@"Down"]){ + [self setHaTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(downKeyPressed) userInfo:nil repeats:YES]]; + } else if ([keyName isEqualToString:@"Left"]){ + [self setHaTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(leftKeyPressed) userInfo:nil repeats:YES]]; + } else if ([keyName isEqualToString:@"Right"]){ + [self setHaTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(rightKeyPressed) userInfo:nil repeats:YES]]; + } + } + + } else if (recognizer.state == UIGestureRecognizerStateEnded){ + + if ([self haTimer]){ + [[self haTimer] invalidate]; + [self setHaTimer:nil]; + } + + } +} + +%end + + +%ctor { + + %init(TerminalKeyInput = objc_getClass("NewTerm.TerminalKeyInput")); + +} diff --git a/control b/control new file mode 100644 index 0000000..7424bac --- /dev/null +++ b/control @@ -0,0 +1,9 @@ +Package: com.lint.ntarrows +Name: NewTermArrows +Depends: mobilesubstrate +Version: 1.0.0 +Architecture: iphoneos-arm +Description: Allows you to hold down the arrow keys to move the cursor in New Term. +Maintainer: lint +Author: lint +Section: Tweaks