Skip to content

Commit

Permalink
Merge pull request #3 from PumpedSardines/2-feature-request-separate-…
Browse files Browse the repository at this point in the history
…h-and-x-system-options

Separated "transform sx and sh"
  • Loading branch information
Fritiof Rusck committed Jul 7, 2022
2 parents d2453a0 + 5d53a7c commit 3ebb278
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 33 deletions.
2 changes: 1 addition & 1 deletion AWS/version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.1.2",
"version": "1.2.0",
"url": "https://github.com/PumpedSardines/Tajpi/releases/tag/1.1.2"
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Changelog
## 1.2.0
Separated "transform sx and sh" to two diffrent options "transform sx" and "transform sh"
6 changes: 4 additions & 2 deletions Tajpi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
80B2740F27A3E95F005B451F /* Esperanto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Esperanto.swift; sourceTree = "<group>"; };
80B2741127A3E97E005B451F /* Swedish.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swedish.swift; sourceTree = "<group>"; };
80B2741427A3F1B8005B451F /* version */ = {isa = PBXFileReference; lastKnownFileType = text; path = version; sourceTree = "<group>"; };
80B428EB2876D3B500C62C3F /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -69,6 +70,7 @@
80B273CA27A2AAD2005B451F = {
isa = PBXGroup;
children = (
80B428EB2876D3B500C62C3F /* CHANGELOG.md */,
80B273F927A2B2A0005B451F /* README.md */,
808CDE8927A3F82C00B7ADBF /* GIVE_ACCESS.md */,
808CDE8727A3F44B00B7ADBF /* .gitignore */,
Expand Down Expand Up @@ -414,7 +416,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.1.2;
MARKETING_VERSION = 1.2.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.fritiof-rusck.Tajpi";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -444,7 +446,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.1.2;
MARKETING_VERSION = 1.2.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.fritiof-rusck.Tajpi";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
31 changes: 22 additions & 9 deletions Tajpi/AppDelegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,31 +172,44 @@ class AppDelegate: NSObject, NSApplicationDelegate {
setupMenus()
}

@objc func setAutomaticTransformMode() {
automaticTransform.change(!automaticTransform.value);
@objc func setAutomaticTransformModeX() {
automaticTransformX.change(!automaticTransformX.value);
setupMenus()
}

@objc func setAutomaticTransformModeH() {
automaticTransformH.change(!automaticTransformH.value);
setupMenus()
}

func getModeMenu() -> NSMenu {
let menu = NSMenu();
menu.autoenablesItems = true

// Init eng button
// Init option mode button
let optionButton = NSMenuItem(title: locale.value.modeOption(), action: #selector(setOptionMode) , keyEquivalent: "")
optionButton.state = .off
if(option.value) {
optionButton.state = .on
}

// Init eo button
let automaticTransformButton = NSMenuItem(title: locale.value.modeAutomaticTransform(), action: #selector(setAutomaticTransformMode) , keyEquivalent: "")
automaticTransformButton.state = .off
if(automaticTransform.value) {
automaticTransformButton.state = .on
// Init transform X button
let automaticTransformButtonX = NSMenuItem(title: locale.value.modeAutomaticTransformX(), action: #selector(setAutomaticTransformModeX) , keyEquivalent: "")
automaticTransformButtonX.state = .off
if(automaticTransformX.value) {
automaticTransformButtonX.state = .on
}

// Init transform H button
let automaticTransformButtonH = NSMenuItem(title: locale.value.modeAutomaticTransformH(), action: #selector(setAutomaticTransformModeH) , keyEquivalent: "")
automaticTransformButtonH.state = .off
if(automaticTransformH.value) {
automaticTransformButtonH.state = .on
}

menu.addItem(optionButton);
menu.addItem(automaticTransformButton);
menu.addItem(automaticTransformButtonX);
menu.addItem(automaticTransformButtonH);

return menu
}
Expand Down
3 changes: 2 additions & 1 deletion Tajpi/KeyboardInterception/KeyboardInterception.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import Swift

var paused = BoolState(id: "keyboard.pause", value: false);
var option = BoolState(id: "keyboard.option", value: true);
var automaticTransform = BoolState(id: "keyboard.automaticTransform", value: false);
var automaticTransformX = BoolState(id: "keyboard.automaticTransformX", value: false);
var automaticTransformH = BoolState(id: "keyboard.automaticTransformH", value: false);

private var loop: CFRunLoop? = nil;
private var loopSource: CFRunLoopSource? = nil;
Expand Down
34 changes: 30 additions & 4 deletions Tajpi/KeyboardInterception/keyboardCallback.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func keyboardCallback(proxy : CGEventTapProxy, type : CGEventType, event : CGEve
return Unmanaged.passRetained(event)
}

// MARK: - Change if option key is pressed

// Check for keypress
if [.keyDown , .keyUp].contains(type) && option.value {

Expand All @@ -53,14 +55,37 @@ func keyboardCallback(proxy : CGEventTapProxy, type : CGEventType, event : CGEve
}


// MARK: - Automatic transform sh or sx

// Stores if any transform is enabled
// Since this logic is largely shared, this cleans the code up a bit
let isTransformEnabled = (automaticTransformX.value || automaticTransformH.value);

// Is this a repeatKey aka is this holding down a key for longer.
// This is especially a problem since hh should be transformed
let repeatedKey = event.getIntegerValueField(.keyboardEventAutorepeat) != 0;


// This first if checks if the current event is either a x or a h and replace the last letter if nesseccary
// replace sh -> ŝ
if [.keyDown].contains(type) && !repeatedKey && KeyboardStatus.lastKey != nil && automaticTransform.value {
if [.keyDown].contains(type) && !repeatedKey && KeyboardStatus.lastKey != nil && isTransformEnabled {
let keyCode = event.getIntegerValueField(.keyboardEventKeycode)

if let last = KeyboardStatus.lastKey {
// h and x
if [ 0x04, 0x07 ].contains(keyCode) {

// Add which keycodes should transform automatically
var availbleKeyCodes: [Int64] = [];

if(automaticTransformX.value) {
availbleKeyCodes.append(0x07);
}

if(automaticTransformH.value) {
availbleKeyCodes.append(0x04);
}

// Replace the last key
if availbleKeyCodes.contains(keyCode) {
// One left than delete then one right
replaceCombination(newLetter: last);
KeyboardStatus.lastKey = nil;
Expand All @@ -69,7 +94,8 @@ func keyboardCallback(proxy : CGEventTapProxy, type : CGEventType, event : CGEve
}
}

if type == .keyDown && !repeatedKey && automaticTransform.value {
// This if stores the pressed key as "lastKey"
if type == .keyDown && !repeatedKey && (automaticTransformX.value || automaticTransformH.value) {
let keyCode = event.getIntegerValueField(.keyboardEventKeycode)
KeyboardStatus.lastKey = espTransform(shift: KeyboardStatus.shift, keyCode: keyCode);
return Unmanaged.passRetained(event)
Expand Down
8 changes: 6 additions & 2 deletions Tajpi/LocaleManager/Locales/English.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ struct English: Locale {
return "option + key";
}

func modeAutomaticTransform() -> String {
return "Transform sh and sx";
func modeAutomaticTransformX() -> String {
return "Transform sx";
}

func modeAutomaticTransformH() -> String {
return "Transform sh";
}

func updateAvailable() -> String {
Expand Down
8 changes: 6 additions & 2 deletions Tajpi/LocaleManager/Locales/Esperanto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ struct Esperanto: Locale {
return "option + klavo";
}

func modeAutomaticTransform() -> String {
return "Transformu sh kaj sx";
func modeAutomaticTransformH() -> String {
return "Transformu sh";
}

func modeAutomaticTransformX() -> String {
return "Transformu sx";
}

func updateAvailable() -> String {
Expand Down
21 changes: 11 additions & 10 deletions Tajpi/LocaleManager/Locales/Locale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import Foundation
protocol Locale {
var name: String { get };

func state(paused: Bool) -> String;
func changeState(paused: Bool) -> String;
func state(paused: Bool) -> String;
func changeState(paused: Bool) -> String;

func modes() -> String;
func modeOption() -> String;
func modeAutomaticTransform() -> String;
func modes() -> String;
func modeOption() -> String;
func modeAutomaticTransformX() -> String;
func modeAutomaticTransformH() -> String;

func updateAvailable() -> String;
func currentVersion(version: String) -> String;
func foundABug() -> String;
func changeLanguage() -> String;
func updateAvailable() -> String;
func currentVersion(version: String) -> String;
func foundABug() -> String;
func changeLanguage() -> String;

func quit() -> String;
func quit() -> String;

func missingPermissions() -> String;
func fixMissingPermisions() -> String;
Expand Down
8 changes: 6 additions & 2 deletions Tajpi/LocaleManager/Locales/Swedish.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ struct Swedish: Locale {
return "option + tangent";
}

func modeAutomaticTransform() -> String {
return "Gör om sh and sx";
func modeAutomaticTransformX() -> String {
return "Gör om sx";
}

func modeAutomaticTransformH() -> String {
return "Gör om sh";
}

func updateAvailable() -> String {
Expand Down

0 comments on commit 3ebb278

Please sign in to comment.