summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/macos.m249
-rw-r--r--src/ui/window.c2
2 files changed, 72 insertions, 179 deletions
diff --git a/src/macos.m b/src/macos.m
index cb5d76e2..c8793eac 100644
--- a/src/macos.m
+++ b/src/macos.m
@@ -22,9 +22,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
22 22
23#include "macos.h" 23#include "macos.h"
24#include "app.h" 24#include "app.h"
25#include "ui/color.h"
25#include "ui/command.h" 26#include "ui/command.h"
27#include "ui/keys.h"
26#include "ui/widget.h" 28#include "ui/widget.h"
27#include "ui/color.h"
28#include "ui/window.h" 29#include "ui/window.h"
29 30
30#include <SDL_timer.h> 31#include <SDL_timer.h>
@@ -246,6 +247,10 @@ static void appearanceChanged_MacOS_(NSString *name) {
246 postCommand_App("tabs.close"); 247 postCommand_App("tabs.close");
247} 248}
248 249
250- (NSString *)commandForItem:(NSMenuItem *)menuItem {
251 return [menuCommands objectForKey:[menuItem title]];
252}
253
249- (void)postMenuItemCommand:(id)sender { 254- (void)postMenuItemCommand:(id)sender {
250 NSString *command = [menuCommands objectForKey:[(NSMenuItem *)sender title]]; 255 NSString *command = [menuCommands objectForKey:[(NSMenuItem *)sender title]];
251 if (command) { 256 if (command) {
@@ -300,144 +305,6 @@ static void appearanceChanged_MacOS_(NSString *name) {
300 widget:nil 305 widget:nil
301 command:@"tabs.new"]; 306 command:@"tabs.new"];
302 } 307 }
303#if 0
304 if ([identifier isEqualToString:play_TouchId_]) {
305 return [NSButtonTouchBarItem
306 buttonTouchBarItemWithIdentifier:identifier
307 image:[NSImage imageNamed:NSImageNameTouchBarPlayPauseTemplate]
308 target:self
309 action:@selector(playPressed)];
310 }
311 else if ([identifier isEqualToString:restart_TouchId_]) {
312 return [NSButtonTouchBarItem
313 buttonTouchBarItemWithIdentifier:identifier
314 image:[NSImage imageNamed:NSImageNameTouchBarSkipToStartTemplate]
315 target:self
316 action:@selector(restartPressed)];
317 }
318 else if ([identifier isEqualToString:seqMoveUp_TouchId_]) {
319 return [[CommandButton alloc] initWithIdentifier:identifier
320 title:@"Seq\u2b06"
321 widget:findWidget_App("sequence")
322 command:@"sequence.swap arg:-1"];
323 }
324 else if ([identifier isEqualToString:seqMoveDown_TouchId_]) {
325 return [[CommandButton alloc] initWithIdentifier:identifier
326 title:@"Seq\u2b07"
327 widget:findWidget_App("sequence")
328 command:@"sequence.swap arg:1"];
329 }
330 else if ([identifier isEqualToString:goto_TouchId_]) {
331 return [[CommandButton alloc] initWithIdentifier:identifier
332 title:@"Go to…"
333 command:@"pattern.goto arg:-1"];
334 }
335 else if ([identifier isEqualToString:event_TouchId_]) {
336 NSTouchBar *events = [[NSTouchBar alloc] init];
337 events.delegate = self;
338 events.defaultItemIdentifiers = @[ eventList_TouchId_ ];
339 NSPopoverTouchBarItem *pop = [[NSPopoverTouchBarItem alloc] initWithIdentifier:identifier];
340 pop.collapsedRepresentationLabel = @"Event";
341 pop.popoverTouchBar = events;
342 [events release];
343 return pop;
344 }
345 else if ([identifier isEqualToString:eventList_TouchId_]) {
346 const struct {
347 NSTouchBarItemIdentifier id;
348 const char *title;
349 const char *command;
350 } buttonDefs_[] = {
351 { voiceEvent_TouchId_, "Voice", "tracker.setevent type:2" },
352 { panEvent_TouchId_, "Pan", "tracker.setevent type:3 arg:128" },
353 { gainEvent_TouchId_, "Gain", "tracker.setevent type:4 arg:128" },
354 { fadeEvent_TouchId_, "Fade", "tracker.setevent type:5" },
355 { tremoloEvent_TouchId_, "Trem", "tracker.setevent type:9" },
356 { pitchSpeedEvent_TouchId_, "P.Spd", "tracker.setevent type:6" },
357 { pitchBendUpEvent_TouchId_, "BnUp", "tracker.setevent type:7" },
358 { pitchBendDownEvent_TouchId_, "BnDn", "tracker.setevent type:8" },
359 { masterGainEvent_TouchId_, "M.Gain", "tracker.setevent type:10 arg:64" },
360 { resetEvent_TouchId_, "Reset", "tracker.setevent type:1" },
361 };
362 NSMutableArray *items = [[NSMutableArray alloc] init];
363 iForIndices(i, buttonDefs_) {
364 CommandButton *button = [[CommandButton alloc]
365 initWithIdentifier:buttonDefs_[i].id
366 title:[NSString stringWithUTF8String:buttonDefs_[i].title]
367 widget:findWidget_App("tracker")
368 command:[NSString stringWithUTF8String:buttonDefs_[i].command]
369 ];
370 [items addObject:button];
371 }
372 NSGroupTouchBarItem *group = [NSGroupTouchBarItem groupItemWithIdentifier:identifier
373 items:items];
374 [items release];
375 return group;
376 }
377 else if ([identifier isEqualToString:mute_TouchId_]) {
378 return [[CommandButton alloc] initWithIdentifier:identifier
379 title:@"Mute"
380 widget:findWidget_App("tracker")
381 command:@"tracker.mute"];
382 }
383 else if ([identifier isEqualToString:solo_TouchId_]) {
384 return [[CommandButton alloc] initWithIdentifier:identifier
385 title:@"Solo"
386 widget:findWidget_App("tracker")
387 command:@"tracker.solo"];
388 }
389 else if ([identifier isEqualToString:color_TouchId_]) {
390 NSTouchBar *colors = [[NSTouchBar alloc] init];
391 colors.delegate = self;
392 colors.defaultItemIdentifiers = @[ NSTouchBarItemIdentifierFlexibleSpace,
393 whiteColor_TouchId_,
394 yellowColor_TouchId_,
395 orangeColor_TouchId_,
396 redColor_TouchId_,
397 magentaColor_TouchId_,
398 blueColor_TouchId_,
399 cyanColor_TouchId_,
400 greenColor_TouchId_,
401 NSTouchBarItemIdentifierFlexibleSpace ];
402 NSPopoverTouchBarItem *pop = [[NSPopoverTouchBarItem alloc] initWithIdentifier:identifier];
403 pop.collapsedRepresentationImage = [NSImage imageNamed:NSImageNameTouchBarColorPickerFill];
404 pop.popoverTouchBar = colors;
405 [colors release];
406 return pop;
407 }
408 else if ([identifier isEqualToString:whiteColor_TouchId_]) {
409 return [[ColorButton alloc] initWithIdentifier:identifier
410 trackColor:white_TrackColor];
411 }
412 else if ([identifier isEqualToString:yellowColor_TouchId_]) {
413 return [[ColorButton alloc] initWithIdentifier:identifier
414 trackColor:yellow_TrackColor];
415 }
416 else if ([identifier isEqualToString:orangeColor_TouchId_]) {
417 return [[ColorButton alloc] initWithIdentifier:identifier
418 trackColor:orange_TrackColor];
419 }
420 else if ([identifier isEqualToString:redColor_TouchId_]) {
421 return [[ColorButton alloc] initWithIdentifier:identifier
422 trackColor:red_TrackColor];
423 }
424 else if ([identifier isEqualToString:magentaColor_TouchId_]) {
425 return [[ColorButton alloc] initWithIdentifier:identifier
426 trackColor:magenta_TrackColor];
427 }
428 else if ([identifier isEqualToString:blueColor_TouchId_]) {
429 return [[ColorButton alloc] initWithIdentifier:identifier
430 trackColor:blue_TrackColor];
431 }
432 else if ([identifier isEqualToString:cyanColor_TouchId_]) {
433 return [[ColorButton alloc] initWithIdentifier:identifier
434 trackColor:cyan_TrackColor];
435 }
436 else if ([identifier isEqualToString:greenColor_TouchId_]) {
437 return [[ColorButton alloc] initWithIdentifier:identifier
438 trackColor:green_TrackColor];
439 }
440#endif
441 return nil; 308 return nil;
442} 309}
443 310
@@ -500,6 +367,42 @@ void enableMenu_MacOS(const char *menuLabel, iBool enable) {
500 [label release]; 367 [label release];
501} 368}
502 369
370static void setShortcut_NSMenuItem_(NSMenuItem *item, int key, int kmods) {
371 iString str;
372 init_String(&str);
373 if (key == SDLK_LEFT) {
374 appendChar_String(&str, 0x2190);
375 }
376 else if (key == SDLK_RIGHT) {
377 appendChar_String(&str, 0x2192);
378 }
379 else if (key == SDLK_UP) {
380 appendChar_String(&str, 0x2191);
381 }
382 else if (key == SDLK_DOWN) {
383 appendChar_String(&str, 0x2193);
384 }
385 else if (key) {
386 appendChar_String(&str, key);
387 }
388 NSEventModifierFlags modMask = 0;
389 if (kmods & KMOD_GUI) {
390 modMask |= NSEventModifierFlagCommand;
391 }
392 if (kmods & KMOD_ALT) {
393 modMask |= NSEventModifierFlagOption;
394 }
395 if (kmods & KMOD_CTRL) {
396 modMask |= NSEventModifierFlagControl;
397 }
398 if (kmods & KMOD_SHIFT) {
399 modMask |= NSEventModifierFlagShift;
400 }
401 [item setKeyEquivalentModifierMask:modMask];
402 [item setKeyEquivalent:[NSString stringWithUTF8String:cstr_String(&str)]];
403 deinit_String(&str);
404}
405
503void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) { 406void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) {
504 NSApplication *app = [NSApplication sharedApplication]; 407 NSApplication *app = [NSApplication sharedApplication];
505 MyDelegate *myDel = (MyDelegate *) app.delegate; 408 MyDelegate *myDel = (MyDelegate *) app.delegate;
@@ -520,44 +423,21 @@ void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *
520 } 423 }
521 else { 424 else {
522 const iBool hasCommand = (items[i].command && items[i].command[0]); 425 const iBool hasCommand = (items[i].command && items[i].command[0]);
523 iString key;
524 init_String(&key);
525 if (items[i].key == SDLK_LEFT) {
526 appendChar_String(&key, 0x2190);
527 }
528 else if (items[i].key == SDLK_RIGHT) {
529 appendChar_String(&key, 0x2192);
530 }
531 else if (items[i].key == SDLK_UP) {
532 appendChar_String(&key, 0x2191);
533 }
534 else if (items[i].key == SDLK_DOWN) {
535 appendChar_String(&key, 0x2193);
536 }
537 else if (items[i].key) {
538 appendChar_String(&key, items[i].key);
539 }
540 NSMenuItem *item = [menu addItemWithTitle:[NSString stringWithUTF8String:label] 426 NSMenuItem *item = [menu addItemWithTitle:[NSString stringWithUTF8String:label]
541 action:(hasCommand ? @selector(postMenuItemCommand:) : nil) 427 action:(hasCommand ? @selector(postMenuItemCommand:) : nil)
542 keyEquivalent:[NSString stringWithUTF8String:cstr_String(&key)]]; 428 keyEquivalent:@""];
543 NSEventModifierFlags modMask = 0; 429 int key = items[i].key;
544 if (items[i].kmods & KMOD_GUI) { 430 int kmods = items[i].kmods;
545 modMask |= NSEventModifierFlagCommand;
546 }
547 if (items[i].kmods & KMOD_ALT) {
548 modMask |= NSEventModifierFlagOption;
549 }
550 if (items[i].kmods & KMOD_CTRL) {
551 modMask |= NSEventModifierFlagControl;
552 }
553 if (items[i].kmods & KMOD_SHIFT) {
554 modMask |= NSEventModifierFlagShift;
555 }
556 [item setKeyEquivalentModifierMask:modMask];
557 if (hasCommand) { 431 if (hasCommand) {
558 [myDel setCommand:[NSString stringWithUTF8String:items[i].command] forMenuItem:item]; 432 [myDel setCommand:[NSString stringWithUTF8String:items[i].command] forMenuItem:item];
433 /* Bindings may have a different key. */
434 const iBinding *bind = findCommand_Keys(items[i].command);
435 if (bind) {
436 key = bind->key;
437 kmods = bind->mods;
438 }
559 } 439 }
560 deinit_String(&key); 440 setShortcut_NSMenuItem_(item, key, kmods);
561 } 441 }
562 } 442 }
563 [mainItem setSubmenu:menu]; 443 [mainItem setSubmenu:menu];
@@ -570,13 +450,26 @@ void handleCommand_MacOS(const char *cmd) {
570 appearanceChanged_MacOS_(currentSystemAppearance_()); 450 appearanceChanged_MacOS_(currentSystemAppearance_());
571 } 451 }
572 } 452 }
573#if 0 453 else if (equal_Command(cmd, "bindings.changed")) {
574 if (equal_Command(cmd, "tabs.changed")) { 454 NSApplication *app = [NSApplication sharedApplication];
575 MyDelegate *myDel = (MyDelegate *) [[NSApplication sharedApplication] delegate]; 455 MyDelegate *myDel = (MyDelegate *) app.delegate;
576 const char *tabId = suffixPtr_Command(cmd, "id"); 456 NSMenu *appMenu = [app mainMenu];
577 [myDel setTouchBarVariant:default_TouchBarVariant]; 457 for (NSMenuItem *mainMenuItem in appMenu.itemArray) {
458 NSMenu *menu = mainMenuItem.submenu;
459 if (menu) {
460 for (NSMenuItem *menuItem in menu.itemArray) {
461 NSString *command = [myDel commandForItem:menuItem];
462 if (command) {
463 const iBinding *bind = findCommand_Keys(
464 [command cStringUsingEncoding:NSUTF8StringEncoding]);
465 if (bind) {
466 setShortcut_NSMenuItem_(menuItem, bind->key, bind->mods);
467 }
468 }
469 }
470 }
471 }
578 } 472 }
579#endif
580} 473}
581 474
582void log_MacOS(const char *msg) { 475void log_MacOS(const char *msg) {
diff --git a/src/ui/window.c b/src/ui/window.c
index 867f535d..6199c4e2 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -773,7 +773,7 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) {
773 /* Suspiciously close to when input focus was received. For example under openbox, 773 /* Suspiciously close to when input focus was received. For example under openbox,
774 closing xterm with Ctrl+D will cause the keydown event to "spill" over to us. 774 closing xterm with Ctrl+D will cause the keydown event to "spill" over to us.
775 As a workaround, ignore these events. */ 775 As a workaround, ignore these events. */
776 return iFalse; 776 return iTrue; /* won't go to bindings, either */
777 } 777 }
778 /* Map mouse pointer coordinate to our coordinate system. */ 778 /* Map mouse pointer coordinate to our coordinate system. */
779 if (event.type == SDL_MOUSEMOTION) { 779 if (event.type == SDL_MOUSEMOTION) {