Skip to content

Commit

Permalink
Added ability to remap to primary and secondary mouse button, because…
Browse files Browse the repository at this point in the history
… my right click broke and I'm poor. Now these are untranslated for the chinese and korean language... Not sure how to handle this localization stuff. But since it's pretty hidden, I think it's okay to ship with this.
  • Loading branch information
noah-nuebling committed Nov 20, 2023
1 parent 577a6fe commit 703faa0
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 27 deletions.
2 changes: 1 addition & 1 deletion App/SupportFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>21782</string>
<string>21798</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>NSHumanReadableCopyright</key>
Expand Down
97 changes: 81 additions & 16 deletions App/UI/Main/Tabs/ButtonTab/RemapTable/RemapTableTranslator.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ + (NSArray *)groupedDataModel {

// MFMouseButtonNumber buttonNumber = ((NSNumber *)rowDict[kMFRemapsKeyTrigger][kMFButtonTriggerKeyButtonNumber]).unsignedIntValue;

NSDictionary *effectDict = rowDict[kMFRemapsKeyEffect];
NSDictionary *selectedEffect = rowDict[kMFRemapsKeyEffect];

NSMutableArray *oneShotEffectsTable = @[
@{@"ui": NSLocalizedString(@"effect.look-up", @"First draft: Look Up & Quick Look"), @"tool": NSLocalizedString(@"effect.look-up.hint", @"First draft: Look up words in the Dictionary, Quick Look files in Finder, and more.\n \nWorks like a Force click on an Apple Trackpad."), @"dict": @{
Expand All @@ -138,6 +138,24 @@ + (NSArray *)groupedDataModel {
@{@"ui": NSLocalizedString(@"effect.smart-zoom", @"First draft: Smart Zoom"), @"tool": NSLocalizedString(@"effect.smart-zoom.hint", @"First draft: Zoom in or out in Safari and other apps.\n \nWorks like a two-finger double tap on an Apple Trackpad."), @"dict": @{
kMFActionDictKeyType: kMFActionDictTypeSmartZoom,
}},
@{@"ui": NSLocalizedString(@"effect.primary-click", @"First draft: Primary Click"),
@"tool": stringf(NSLocalizedString(@"effect.primary-click.hint", @"First draft: Works like clicking %@ on a standard mouse."), [UIStrings getButtonStringToolTip:1]),
@"hideable": @YES,
@"dict": @{
kMFActionDictKeyType: kMFActionDictTypeMouseButtonClicks,
kMFActionDictKeyMouseButtonClicksVariantButtonNumber: @1,
kMFActionDictKeyMouseButtonClicksVariantNumberOfClicks: @1,
}
},
@{@"ui": NSLocalizedString(@"effect.secondary-click", @"First draft: Secondary Click"),
@"tool": stringf(NSLocalizedString(@"effect.secondary-click.hint", @"First draft: Works like clicking %@ on a standard mouse."), [UIStrings getButtonStringToolTip:2]),
@"hideable": @YES,
@"dict": @{
kMFActionDictKeyType: kMFActionDictTypeMouseButtonClicks,
kMFActionDictKeyMouseButtonClicksVariantButtonNumber: @2,
kMFActionDictKeyMouseButtonClicksVariantNumberOfClicks: @1,
}
},
@{@"ui": NSLocalizedString(@"effect.middle-click", @"First draft: Middle Click"),
@"tool": stringf(NSLocalizedString(@"effect.middle-click.hint", @"First draft: Open links in a new tab, paste text in the Terminal, and more.\n \nWorks like clicking %@ on a standard mouse."), [UIStrings getButtonStringToolTip:3]),
@"dict": @{
Expand Down Expand Up @@ -204,6 +222,19 @@ + (NSArray *)groupedDataModel {
// [oneShotEffectsTable insertObject:buttonClickEntry atIndex:10];
// }

/// Make selected entry non-hidden
for (int i = 0; i < oneShotEffectsTable.count; i++) {

NSDictionary *entry = oneShotEffectsTable[i];

if ([entry[@"dict"] isEqual:selectedEffect]) {
NSMutableDictionary *newEntry = entry.mutableCopy;
newEntry[@"hideable"] = @"NO";
newEntry[@"alternate"] = @"NO";
oneShotEffectsTable[i] = newEntry;
}
}

/// Insert entry for keyboard shortcut effect

/// Get keycapture index
Expand All @@ -215,8 +246,8 @@ + (NSArray *)groupedDataModel {

/// Insert entry for keyboard shortcut effect or systemDefined effect

BOOL isKeyShortcut = [effectDict[kMFActionDictKeyType] isEqual:kMFActionDictTypeKeyboardShortcut];
BOOL isSystemEvent = [effectDict[kMFActionDictKeyType] isEqual:kMFActionDictTypeSystemDefinedEvent];
BOOL isKeyShortcut = [selectedEffect[kMFActionDictKeyType] isEqual:kMFActionDictTypeKeyboardShortcut];
BOOL isSystemEvent = [selectedEffect[kMFActionDictKeyType] isEqual:kMFActionDictTypeSystemDefinedEvent];

if (isKeyShortcut || isSystemEvent) {

Expand All @@ -225,15 +256,15 @@ + (NSArray *)groupedDataModel {

/// Get strings

NSAttributedString *shortcutString = getShortcutString(effectDict, isKeyShortcut);
NSAttributedString *shortcutString = getShortcutString(selectedEffect, isKeyShortcut);

NSString *shortcutStringRaw = [shortcutString stringWithAttachmentDescriptions];

/// Create and insert new entry
[oneShotEffectsTable insertObject:@{
@"uiAttributed": shortcutString,
@"tool": stringf(NSLocalizedString(@"effect.shortcut.hint", @"First draft: Works like pressing '%@' on your keyboard"), shortcutStringRaw),
@"dict": effectDict,
@"dict": selectedEffect,
@"indentation": @1,
} atIndex:shortcutIndex];
}
Expand Down Expand Up @@ -386,35 +417,69 @@ + (NSArray *)getEffectsTableForRemapsTableEntry:(NSDictionary *)rowDict {
}

+ (NSMenuItem * _Nullable)getPopUpButtonItemToSelectBasedOnRowDict:(NSPopUpButton * _Nonnull)button rowDict:(NSDictionary * _Nonnull)rowDict {

/// Datamodel -> Button state

NSDictionary *targetEffect = rowDict[kMFRemapsKeyEffect];
NSArray *effectPickerModel = [RemapTableTranslator getEffectsTableForRemapsTableEntry:rowDict];

int itemIndex = -1;
int resultUIIndex = -1;

NSArray *effectsTable = [RemapTableTranslator getEffectsTableForRemapsTableEntry: rowDict];
int uiIndex = 0;
int modelIndex = 0;

int i = 0;
while (true) {
NSDictionary *effectTableEntry = effectsTable[i];
if ([effectTableEntry[@"dict"] isEqual: rowDict[kMFRemapsKeyEffect]]) {
itemIndex = i;
NSDictionary *effect = effectPickerModel[modelIndex];
if ([effect[@"hideable"] isEqual:@YES]) {
uiIndex += 1;
}
if ([effect[@"dict"] isEqual:targetEffect]) {
resultUIIndex = uiIndex;
break;
};
i++;
uiIndex += 1;
modelIndex += 1;
}

if (itemIndex != -1) {
return [button itemAtIndex:i];
if (resultUIIndex != -1) {
return [button itemAtIndex:resultUIIndex];
} else {
return nil;
}
}

+ (NSDictionary * _Nullable)getEffectDictBasedOnSelectedItemInButton:(NSPopUpButton * _Nonnull)button rowDict:(NSDictionary * _Nonnull)rowDict {

/// Button state -> Datamodel

NSArray *effectsTable = [RemapTableTranslator getEffectsTableForRemapsTableEntry:rowDict];
NSInteger selectedIndex = button.indexOfSelectedItem;
NSInteger targetUIIndex = button.indexOfSelectedItem;

int uiIndex = 0;
int modelIndex = 0;

while (true) {

NSDictionary *effect = effectsTable[modelIndex];
if ([effect[@"hideable"] isEqual:@YES]) {
uiIndex += 1;
}

if (uiIndex == targetUIIndex) {
break;
}
if (uiIndex > targetUIIndex) {
assert(false);
break;
}

uiIndex += 1;
modelIndex += 1;
}


return effectsTable[selectedIndex][@"dict"];

return effectsTable[modelIndex][@"dict"];
}

+ (NSMenuItem *)menuItemFromDataModel:(NSDictionary *)itemModel enclosingMenu:(NSMenu *)enclosingMenu tableCell:(NSTableCellView *)tableCell {
Expand Down
2 changes: 1 addition & 1 deletion Helper/SupportFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>21782</string>
<string>21798</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSBackgroundOnly</key>
Expand Down
2 changes: 2 additions & 0 deletions Helper/Utility/ModificationUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ + (void)hideMousePointer:(BOOL)B {

+ (void)postMouseButtonClicks:(MFMouseButtonNumber)button nOfClicks:(int64_t)nOfClicks {

DDLogDebug(@"Posting %lld mouse button %u clicks", nOfClicks, button);

CGEventTapLocation tapLoc = kCGSessionEventTap;

CGPoint mouseLoc = getPointerLocation();
Expand Down
22 changes: 17 additions & 5 deletions Localization/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@
/* First draft: Look up words in the Dictionary, Quick Look files in Finder, and more.\n \nWorks like a Force click on an Apple Trackpad. */
"effect.look-up.hint" = "Schlage Wörter im Wörterbuch nach, werfe einen schnellen Blick auf Dateien im Finder, und mehr\n \nFunktioniert wie ein kräftiger Klick bei einem Apple Trackpad";

/* First draft: Primary Click */
"effect.primary-click" = "Primärklick";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.primary-click.hint" = "Funktioniert wie klicken von %@ bei einer Standard-Maus";

/* First draft: Secondary Click */
"effect.secondary-click" = "Sekundärklick";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.secondary-click.hint" = "Funktioniert wie klicken von %@ bei einer Standard-Maus";

/* First draft: Middle Click */
"effect.middle-click" = "Mittelklick";

Expand Down Expand Up @@ -187,14 +199,14 @@
/* First draft: Mouse Button %@ */
"button-string.tool.numbered" = "Maustaste %@";

/* First draft: the Primary Mouse Button (also called Left Mouse Button or Mouse Button 1) */
"button-string.tool.primary" = "die primäre Maustaste (auch genannt linke Maustaste oder Maustaste 1)";
/* First draft: Primary Mouse Button (also called Left Mouse Button or Mouse Button 1) */
"button-string.tool.primary" = "Primäre Maustaste (auch genannt linke Maustaste oder Maustaste 1)";

/* First draft: the Secondary Mouse Button (also called Right Mouse Button or Mouse Button 2) */
"button-string.tool.secondary" = "die sekundäre Maustaste (auch genannt rechte Maustaste oder Maustaste 2)";
/* First draft: Secondary Mouse Button (also called Right Mouse Button or Mouse Button 2) */
"button-string.tool.secondary" = "Sekundäre Maustaste (auch genannt rechte Maustaste oder Maustaste 2)";

/* First draft: Middle Mouse Button (also called Scroll Wheel Button or Mouse Button 3) || Example usage: Open links in a new tab, paste text in the Terminal, and more.\n \nWorks like clicking the Middle Mouse Button (also called the Scroll Wheel Button or Mouse Button 3) on a standard mouse. */
"button-string.tool.middle" = "mittlere Maustaste (auch genannt Scrollradtaste oder Maustaste 3)";
"button-string.tool.middle" = "Mittlere Maustaste (auch genannt Scrollradtaste oder Maustaste 3)";

/* First draft: Command (⌘) */
"modifer-key.tool.command" = "Befehlstaste (⌘)";
Expand Down
20 changes: 16 additions & 4 deletions Localization/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@
/* First draft: Mouse Button %@ */
"button-string.tool.numbered" = "Mouse Button %@";

/* First draft: the Primary Mouse Button (also called Left Mouse Button or Mouse Button 1) */
"button-string.tool.primary" = "the Primary Mouse Button (also called Left Mouse Button or Mouse Button 1)";
/* First draft: Primary Mouse Button (also called Left Mouse Button or Mouse Button 1) */
"button-string.tool.primary" = "Primary Mouse Button (also called Left Mouse Button or Mouse Button 1)";

/* First draft: the Secondary Mouse Button (also called Right Mouse Button or Mouse Button 2) */
"button-string.tool.secondary" = "the Secondary Mouse Button (also called Right Mouse Button or Mouse Button 2)";
/* First draft: Secondary Mouse Button (also called Right Mouse Button or Mouse Button 2) */
"button-string.tool.secondary" = "Secondary Mouse Button (also called Right Mouse Button or Mouse Button 2)";

/* First draft: Middle Mouse Button (also called Scroll Wheel Button or Mouse Button 3) || Example usage: Open links in a new tab, paste text in the Terminal, and more.\n \nWorks like clicking the Middle Mouse Button (also called the Scroll Wheel Button or Mouse Button 3) on a standard mouse. */
"button-string.tool.middle" = "Middle Mouse Button (also called Scroll Wheel Button or Mouse Button 3)";
Expand Down Expand Up @@ -178,6 +178,18 @@
/* First draft: Look up words in the Dictionary, Quick Look files in Finder, and more.\n \nWorks like a Force click on an Apple Trackpad. */
"effect.look-up.hint" = "Look up words in the Dictionary, Quick Look files in Finder, and more.\n \nWorks like a Force click on an Apple Trackpad.";

/* First draft: Primary Click */
"effect.primary-click" = "Primary Click";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.primary-click.hint" = "Works like clicking %@ on a standard mouse.";

/* First draft: Secondary Click */
"effect.secondary-click" = "Secondary Click";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.secondary-click.hint" = "Works like clicking %@ on a standard mouse.";

/* First draft: Middle Click */
"effect.middle-click" = "Middle Click";

Expand Down
12 changes: 12 additions & 0 deletions Localization/ko.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@
/* First draft: Look up words in the Dictionary, Quick Look files in Finder, and more.\n \nWorks like Force Touch on an Apple Trackpad. */
"effect.look-up.hint" = "사전에서 단어를 찾아보거나, Finder에서 파일을 훑어보는 등의 동작을 수행합니다.\n \n이는 Apple 트랙패드에서 세게 클릭하는 것과 같습니다.";

/* First draft: Primary Click */
"effect.primary-click" = "";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.primary-click.hint" = "";

/* First draft: Secondary Click */
"effect.secondary-click" = "";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.secondary-click.hint" = "";

/* First draft: Middle Click */
"effect.middle-click" = "휠 클릭";

Expand Down
12 changes: 12 additions & 0 deletions Localization/zh-HK.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@
/* First draft: Look up words in the Dictionary, Quick Look files in Finder, and more.\n \nWorks like a Force click on an Apple Trackpad. */
"effect.look-up.hint" = "查詢辭典、在Finder「快速查看」等。\n \n作用相當於在Apple觸控板上用一指用力長按。";

/* First draft: Primary Click */
"effect.primary-click" = "";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.primary-click.hint" = "";

/* First draft: Secondary Click */
"effect.secondary-click" = "";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.secondary-click.hint" = "";

/* First draft: Middle Click */
"effect.middle-click" = "按中鍵";

Expand Down
12 changes: 12 additions & 0 deletions Localization/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@
/* First draft: Look up words in the Dictionary, Quick Look files in Finder, and more.\n \nWorks like a Force click on an Apple Trackpad. */
"effect.look-up.hint" = "查询词典、在Finder中“快速查看”等。\n \n作用相当于在Apple触控板上用单指用力点按。";

/* First draft: Primary Click */
"effect.primary-click" = "";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.primary-click.hint" = "";

/* First draft: Secondary Click */
"effect.secondary-click" = "";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.secondary-click.hint" = "";

/* First draft: Middle Click */
"effect.middle-click" = "按中键";

Expand Down
12 changes: 12 additions & 0 deletions Localization/zh-Hant.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@
/* First draft: Look up words in the Dictionary, Quick Look files in Finder, and more.\n \nWorks like a Force click on an Apple Trackpad. */
"effect.look-up.hint" = "查詢辭典、於Finder中「快速查看」等。\n \n作用相當於在Apple觸控式軌跡板上用一指用力長按。";

/* First draft: Primary Click */
"effect.primary-click" = "";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.primary-click.hint" = "";

/* First draft: Secondary Click */
"effect.secondary-click" = "";

/* First draft: Works like clicking %@ on a standard mouse. */
"effect.secondary-click.hint" = "";

/* First draft: Middle Click */
"effect.middle-click" = "按中鍵";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,5 +476,53 @@
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "4CDEB0E7-0BFE-42BA-8DD4-48693C58FFC4"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Helper/Utility/ModificationUtility.m"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "153"
endingLineNumber = "153"
landmarkName = "+postMouseButtonClicks:nOfClicks:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "0958EA77-C3B9-4985-8CF4-2CAC5B465EB0"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "App/UI/Main/Tabs/ButtonTab/RemapTable/RemapTableTranslator.m"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "420"
endingLineNumber = "420"
landmarkName = "+getPopUpButtonItemToSelectBasedOnRowDict:rowDict:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "5FD5908B-00F2-455C-B014-AD512B023FD9"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "App/UI/Main/Tabs/ButtonTab/RemapTable/RemapTableTranslator.m"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "443"
endingLineNumber = "443"
landmarkName = "+getPopUpButtonItemToSelectBasedOnRowDict:rowDict:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>

0 comments on commit 703faa0

Please sign in to comment.