diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-16 07:59:26 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-16 07:59:26 +0300 |
commit | 22ac4c61bdf79e6bc2b6738b9470cfb4f734cfab (patch) | |
tree | 7ef5f208e532c8e9acef5c4a243fc77e86d1b3fb | |
parent | 56b80c25a8512be27669b0e99ac61b07d276df2e (diff) |
macOS: Added basic touch bar buttons
-rw-r--r-- | src/macos.m | 129 |
1 files changed, 54 insertions, 75 deletions
diff --git a/src/macos.m b/src/macos.m index bbbaaa19..6f833e12 100644 --- a/src/macos.m +++ b/src/macos.m | |||
@@ -28,38 +28,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
28 | 28 | ||
29 | #import <AppKit/AppKit.h> | 29 | #import <AppKit/AppKit.h> |
30 | 30 | ||
31 | #if 0 | 31 | static NSTouchBarItemIdentifier goBack_TouchId_ = @"fi.skyjake.Lagrange.back"; |
32 | static NSTouchBarItemIdentifier play_TouchId_ = @"fi.skyjake.BitwiseHarmony.play"; | 32 | static NSTouchBarItemIdentifier goForward_TouchId_ = @"fi.skyjake.Lagrange.forward"; |
33 | static NSTouchBarItemIdentifier restart_TouchId_ = @"fi.skyjake.BitwiseHarmony.restart"; | 33 | static NSTouchBarItemIdentifier find_TouchId_ = @"fi.skyjake.Lagrange.find"; |
34 | 34 | static NSTouchBarItemIdentifier newTab_TouchId_ = @"fi.skyjake.Lagrange.tabs.new"; | |
35 | static NSTouchBarItemIdentifier seqMoveUp_TouchId_ = @"fi.skyjake.BitwiseHarmony.sequence.move.up"; | ||
36 | static NSTouchBarItemIdentifier seqMoveDown_TouchId_ = @"fi.skyjake.BitwiseHarmony.sequence.move.down"; | ||
37 | |||
38 | static NSTouchBarItemIdentifier goto_TouchId_ = @"fi.skyjake.BitwiseHarmony.goto"; | ||
39 | static NSTouchBarItemIdentifier mute_TouchId_ = @"fi.skyjake.BitwiseHarmony.mute"; | ||
40 | static NSTouchBarItemIdentifier solo_TouchId_ = @"fi.skyjake.BitwiseHarmony.solo"; | ||
41 | static NSTouchBarItemIdentifier color_TouchId_ = @"fi.skyjake.BitwiseHarmony.color"; | ||
42 | static NSTouchBarItemIdentifier event_TouchId_ = @"fi.skyjake.BitwiseHarmony.event"; | ||
43 | |||
44 | static NSTouchBarItemIdentifier eventList_TouchId_ = @"fi.skyjake.BitwiseHarmony.eventlist"; | ||
45 | static NSTouchBarItemIdentifier masterGainEvent_TouchId_ = @"fi.skyjake.BitwiseHarmony.event.mastergain"; | ||
46 | static NSTouchBarItemIdentifier resetEvent_TouchId_ = @"fi.skyjake.BitwiseHarmony.event.reset"; | ||
47 | static NSTouchBarItemIdentifier voiceEvent_TouchId_ = @"fi.skyjake.BitwiseHarmony.event.voice"; | ||
48 | static NSTouchBarItemIdentifier panEvent_TouchId_ = @"fi.skyjake.BitwiseHarmony.event.pan"; | ||
49 | static NSTouchBarItemIdentifier gainEvent_TouchId_ = @"fi.skyjake.BitwiseHarmony.event.gain"; | ||
50 | static NSTouchBarItemIdentifier fadeEvent_TouchId_ = @"fi.skyjake.BitwiseHarmony.event.fade"; | ||
51 | static NSTouchBarItemIdentifier pitchSpeedEvent_TouchId_ = @"fi.skyjake.BitwiseHarmony.event.pitchspeed"; | ||
52 | static NSTouchBarItemIdentifier pitchBendUpEvent_TouchId_ = @"fi.skyjake.BitwiseHarmony.event.pitchbendup"; | ||
53 | static NSTouchBarItemIdentifier pitchBendDownEvent_TouchId_ = @"fi.skyjake.BitwiseHarmony.event.pitchbenddown"; | ||
54 | static NSTouchBarItemIdentifier tremoloEvent_TouchId_ = @"fi.skyjake.BitwiseHarmony.event.tremolo"; | ||
55 | #endif | ||
56 | 35 | ||
57 | enum iTouchBarVariant { | 36 | enum iTouchBarVariant { |
58 | default_TouchBarVariant, | 37 | default_TouchBarVariant, |
59 | }; | 38 | }; |
60 | 39 | ||
61 | #if 0 | 40 | /*----------------------------------------------------------------------------------------------*/ |
62 | @interface CommandButton : NSButtonTouchBarItem { | 41 | |
42 | @interface CommandButton : NSCustomTouchBarItem { | ||
63 | NSString *command; | 43 | NSString *command; |
64 | iWidget *widget; | 44 | iWidget *widget; |
65 | } | 45 | } |
@@ -70,6 +50,10 @@ enum iTouchBarVariant { | |||
70 | title:(NSString *)title | 50 | title:(NSString *)title |
71 | widget:(iWidget *)widget | 51 | widget:(iWidget *)widget |
72 | command:(NSString *)cmd; | 52 | command:(NSString *)cmd; |
53 | - (id)initWithIdentifier:(NSTouchBarItemIdentifier)identifier | ||
54 | image:(NSImage *)image | ||
55 | widget:(iWidget *)widget | ||
56 | command:(NSString *)cmd; | ||
73 | - (void)dealloc; | 57 | - (void)dealloc; |
74 | @end | 58 | @end |
75 | 59 | ||
@@ -79,9 +63,17 @@ enum iTouchBarVariant { | |||
79 | title:(NSString *)title | 63 | title:(NSString *)title |
80 | command:(NSString *)cmd { | 64 | command:(NSString *)cmd { |
81 | [super initWithIdentifier:identifier]; | 65 | [super initWithIdentifier:identifier]; |
82 | self.title = title; | 66 | self.view = [NSButton buttonWithTitle:title target:self action:@selector(buttonPressed)]; |
83 | self.target = self; | 67 | command = cmd; |
84 | self.action = @selector(buttonPressed); | 68 | return self; |
69 | } | ||
70 | |||
71 | - (id)initWithIdentifier:(NSTouchBarItemIdentifier)identifier | ||
72 | image:(NSImage *)image | ||
73 | widget:(iWidget *)widget | ||
74 | command:(NSString *)cmd { | ||
75 | [super initWithIdentifier:identifier]; | ||
76 | self.view = [NSButton buttonWithImage:image target:self action:@selector(buttonPressed)]; | ||
85 | command = cmd; | 77 | command = cmd; |
86 | return self; | 78 | return self; |
87 | } | 79 | } |
@@ -111,7 +103,8 @@ enum iTouchBarVariant { | |||
111 | } | 103 | } |
112 | 104 | ||
113 | @end | 105 | @end |
114 | #endif | 106 | |
107 | /*----------------------------------------------------------------------------------------------*/ | ||
115 | 108 | ||
116 | @interface MyDelegate : NSResponder<NSApplicationDelegate, NSTouchBarDelegate> { | 109 | @interface MyDelegate : NSResponder<NSApplicationDelegate, NSTouchBarDelegate> { |
117 | enum iTouchBarVariant touchBarVariant; | 110 | enum iTouchBarVariant touchBarVariant; |
@@ -120,7 +113,7 @@ enum iTouchBarVariant { | |||
120 | NSMutableDictionary<NSString *, NSString*> *menuCommands; | 113 | NSMutableDictionary<NSString *, NSString*> *menuCommands; |
121 | } | 114 | } |
122 | - (id)initWithSDLDelegate:(NSObject<NSApplicationDelegate> *)sdl; | 115 | - (id)initWithSDLDelegate:(NSObject<NSApplicationDelegate> *)sdl; |
123 | //- (NSTouchBar *)makeTouchBar; | 116 | - (NSTouchBar *)makeTouchBar; |
124 | - (BOOL)application:(NSApplication *)app openFile:(NSString *)filename; | 117 | - (BOOL)application:(NSApplication *)app openFile:(NSString *)filename; |
125 | - (void)application:(NSApplication *)app openFiles:(NSArray<NSString *> *)filenames; | 118 | - (void)application:(NSApplication *)app openFiles:(NSArray<NSString *> *)filenames; |
126 | - (void)application:(NSApplication *)app openURLs:(NSArray<NSURL *> *)urls; | 119 | - (void)application:(NSApplication *)app openURLs:(NSArray<NSURL *> *)urls; |
@@ -153,8 +146,6 @@ static void appearanceChanged_MacOS_(NSString *name) { | |||
153 | const iBool isDark = [name containsString:@"Dark"]; | 146 | const iBool isDark = [name containsString:@"Dark"]; |
154 | const iBool isHighContrast = [name containsString:@"HighContrast"]; | 147 | const iBool isHighContrast = [name containsString:@"HighContrast"]; |
155 | postCommandf_App("~os.theme.changed dark:%d contrast:%d", isDark ? 1 : 0, isHighContrast ? 1 : 0); | 148 | postCommandf_App("~os.theme.changed dark:%d contrast:%d", isDark ? 1 : 0, isHighContrast ? 1 : 0); |
156 | // printf("Effective appearance changed: %s\n", [name cStringUsingEncoding:NSUTF8StringEncoding]); | ||
157 | // fflush(stdout); | ||
158 | } | 149 | } |
159 | 150 | ||
160 | - (void)setAppearance:(NSString *)name { | 151 | - (void)setAppearance:(NSString *)name { |
@@ -204,42 +195,17 @@ static void appearanceChanged_MacOS_(NSString *name) { | |||
204 | } | 195 | } |
205 | } | 196 | } |
206 | 197 | ||
207 | #if 0 | 198 | #if 1 |
208 | - (NSTouchBar *)makeTouchBar { | 199 | - (NSTouchBar *)makeTouchBar { |
209 | NSTouchBar *bar = [[NSTouchBar alloc] init]; | 200 | NSTouchBar *bar = [[NSTouchBar alloc] init]; |
210 | bar.delegate = self; | 201 | bar.delegate = self; |
211 | switch (touchBarVariant) { | 202 | switch (touchBarVariant) { |
212 | case default_TouchBarVariant: | 203 | case default_TouchBarVariant: |
213 | bar.defaultItemIdentifiers = @[ play_TouchId_, restart_TouchId_, | 204 | bar.defaultItemIdentifiers = @[ goBack_TouchId_, goForward_TouchId_, |
214 | NSTouchBarItemIdentifierFixedSpaceSmall, | 205 | NSTouchBarItemIdentifierFixedSpaceSmall, |
215 | NSTouchBarItemIdentifierOtherItemsProxy ]; | 206 | find_TouchId_, |
216 | break; | ||
217 | case sequence_TouchBarVariant: | ||
218 | bar.defaultItemIdentifiers = @[ play_TouchId_, restart_TouchId_, | ||
219 | NSTouchBarItemIdentifierFlexibleSpace, | ||
220 | seqMoveUp_TouchId_, seqMoveDown_TouchId_, | ||
221 | NSTouchBarItemIdentifierFlexibleSpace, | ||
222 | NSTouchBarItemIdentifierOtherItemsProxy]; | ||
223 | break; | ||
224 | case tracker_TouchBarVariant: | ||
225 | bar.defaultItemIdentifiers = @[ play_TouchId_, restart_TouchId_, | ||
226 | NSTouchBarItemIdentifierFlexibleSpace, | ||
227 | goto_TouchId_, | ||
228 | event_TouchId_, | ||
229 | NSTouchBarItemIdentifierFlexibleSpace, | ||
230 | solo_TouchId_, mute_TouchId_, color_TouchId_, | ||
231 | NSTouchBarItemIdentifierFlexibleSpace, | ||
232 | NSTouchBarItemIdentifierOtherItemsProxy ]; | ||
233 | break; | ||
234 | case wide_TouchBarVariant: | ||
235 | bar.defaultItemIdentifiers = @[ play_TouchId_, restart_TouchId_, | ||
236 | NSTouchBarItemIdentifierFlexibleSpace, | ||
237 | event_TouchId_, | ||
238 | NSTouchBarItemIdentifierFlexibleSpace, | ||
239 | solo_TouchId_, mute_TouchId_, color_TouchId_, | ||
240 | NSTouchBarItemIdentifierFlexibleSpace, | ||
241 | seqMoveUp_TouchId_, seqMoveDown_TouchId_, | ||
242 | NSTouchBarItemIdentifierFlexibleSpace, | 207 | NSTouchBarItemIdentifierFlexibleSpace, |
208 | newTab_TouchId_, | ||
243 | NSTouchBarItemIdentifierOtherItemsProxy ]; | 209 | NSTouchBarItemIdentifierOtherItemsProxy ]; |
244 | break; | 210 | break; |
245 | } | 211 | } |
@@ -265,6 +231,30 @@ static void appearanceChanged_MacOS_(NSString *name) { | |||
265 | - (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar | 231 | - (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar |
266 | makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { | 232 | makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { |
267 | iUnused(touchBar); | 233 | iUnused(touchBar); |
234 | if ([identifier isEqualToString:goBack_TouchId_]) { | ||
235 | return [[CommandButton alloc] initWithIdentifier:identifier | ||
236 | image:[NSImage imageNamed:NSImageNameTouchBarGoBackTemplate] | ||
237 | widget:nil | ||
238 | command:@"navigate.back"]; | ||
239 | } | ||
240 | else if ([identifier isEqualToString:goForward_TouchId_]) { | ||
241 | return [[CommandButton alloc] initWithIdentifier:identifier | ||
242 | image:[NSImage imageNamed:NSImageNameTouchBarGoForwardTemplate] | ||
243 | widget:nil | ||
244 | command:@"navigate.forward"]; | ||
245 | } | ||
246 | else if ([identifier isEqualToString:find_TouchId_]) { | ||
247 | return [[CommandButton alloc] initWithIdentifier:identifier | ||
248 | image:[NSImage imageNamed:NSImageNameTouchBarSearchTemplate] | ||
249 | widget:nil | ||
250 | command:@"focus.set id:find.input"]; | ||
251 | } | ||
252 | else if ([identifier isEqualToString:newTab_TouchId_]) { | ||
253 | return [[CommandButton alloc] initWithIdentifier:identifier | ||
254 | image:[NSImage imageNamed:NSImageNameTouchBarAddTemplate] | ||
255 | widget:nil | ||
256 | command:@"tabs.new"]; | ||
257 | } | ||
268 | #if 0 | 258 | #if 0 |
269 | if ([identifier isEqualToString:play_TouchId_]) { | 259 | if ([identifier isEqualToString:play_TouchId_]) { |
270 | return [NSButtonTouchBarItem | 260 | return [NSButtonTouchBarItem |
@@ -524,18 +514,7 @@ void handleCommand_MacOS(const char *cmd) { | |||
524 | if (equal_Command(cmd, "tabs.changed")) { | 514 | if (equal_Command(cmd, "tabs.changed")) { |
525 | MyDelegate *myDel = (MyDelegate *) [[NSApplication sharedApplication] delegate]; | 515 | MyDelegate *myDel = (MyDelegate *) [[NSApplication sharedApplication] delegate]; |
526 | const char *tabId = suffixPtr_Command(cmd, "id"); | 516 | const char *tabId = suffixPtr_Command(cmd, "id"); |
527 | if (equal_CStr(tabId, "tracker")) { | 517 | [myDel setTouchBarVariant:default_TouchBarVariant]; |
528 | [myDel setTouchBarVariant:tracker_TouchBarVariant]; | ||
529 | } | ||
530 | else if (equal_CStr(tabId, "sequence")) { | ||
531 | [myDel setTouchBarVariant:sequence_TouchBarVariant]; | ||
532 | } | ||
533 | else if (equal_CStr(tabId, "trackertab")) { | ||
534 | [myDel setTouchBarVariant:wide_TouchBarVariant]; | ||
535 | } | ||
536 | else { | ||
537 | [myDel setTouchBarVariant:default_TouchBarVariant]; | ||
538 | } | ||
539 | } | 518 | } |
540 | #endif | 519 | #endif |
541 | } | 520 | } |