summaryrefslogtreecommitdiff
path: root/src/macos.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/macos.m')
-rw-r--r--src/macos.m51
1 files changed, 17 insertions, 34 deletions
diff --git a/src/macos.m b/src/macos.m
index 7b248c3b..5f376874 100644
--- a/src/macos.m
+++ b/src/macos.m
@@ -83,7 +83,9 @@ static void ignoreImmediateKeyDownEvents_(void) {
83 However, we shouldn't double-activate menu items when a shortcut key is used in our 83 However, we shouldn't double-activate menu items when a shortcut key is used in our
84 widgets. Quite a kludge: take advantage of Window's focus-acquisition threshold to 84 widgets. Quite a kludge: take advantage of Window's focus-acquisition threshold to
85 ignore the immediately following key down events. */ 85 ignore the immediately following key down events. */
86 get_Window()->focusGainedAt = SDL_GetTicks(); 86 iForEach(PtrArray, w, collect_PtrArray(listWindows_App())) {
87 as_Window(w.ptr)->focusGainedAt = SDL_GetTicks();
88 }
87} 89}
88 90
89/*----------------------------------------------------------------------------------------------*/ 91/*----------------------------------------------------------------------------------------------*/
@@ -435,9 +437,17 @@ static iBool processScrollWheelEvent_(NSEvent *event) {
435 const iBool isPerPixel = (event.hasPreciseScrollingDeltas != 0); 437 const iBool isPerPixel = (event.hasPreciseScrollingDeltas != 0);
436 const iBool isInertia = (event.momentumPhase & (NSEventPhaseBegan | NSEventPhaseChanged)) != 0; 438 const iBool isInertia = (event.momentumPhase & (NSEventPhaseBegan | NSEventPhaseChanged)) != 0;
437 const iBool isEnded = event.scrollingDeltaX == 0.0f && event.scrollingDeltaY == 0.0f && !isInertia; 439 const iBool isEnded = event.scrollingDeltaX == 0.0f && event.scrollingDeltaY == 0.0f && !isInertia;
438 const iWindow *win = &get_MainWindow()->base; 440 const iWindow *win = NULL; //&get_MainWindow()->base;
439 if (event.window != nsWindow_(win->win)) { 441 /* If this event belongs to one of the MainWindows, handle it and mark it for that window.
440 /* Not the main window. */ 442 If it's for an auxiliary window, let the system handle it. */
443 iConstForEach(PtrArray, i, mainWindows_App()) {
444 if (event.window == nsWindow_(as_Window(i.ptr)->win)) {
445 win = i.ptr;
446 break;
447 }
448 }
449 if (!win) { //event.window != nsWindow_(win->win)) {
450 /* Not a main window. */
441 return iFalse; 451 return iFalse;
442 } 452 }
443 if (isPerPixel) { 453 if (isPerPixel) {
@@ -478,16 +488,18 @@ static iBool processScrollWheelEvent_(NSEvent *event) {
478 else { 488 else {
479 SDL_MouseWheelEvent e = { .type = SDL_MOUSEWHEEL }; 489 SDL_MouseWheelEvent e = { .type = SDL_MOUSEWHEEL };
480 e.timestamp = SDL_GetTicks(); 490 e.timestamp = SDL_GetTicks();
491 e.windowID = id_Window(win);
481 e.which = 1; /* Distinction between trackpad and regular mouse. */ 492 e.which = 1; /* Distinction between trackpad and regular mouse. */
482 /* Disregard any wheel acceleration. */ 493 /* Disregard any wheel acceleration. */
483 e.x = event.scrollingDeltaX > 0 ? 1 : event.scrollingDeltaX < 0 ? -1 : 0; 494 e.x = event.scrollingDeltaX > 0 ? 1 : event.scrollingDeltaX < 0 ? -1 : 0;
484 e.y = event.scrollingDeltaY > 0 ? 1 : event.scrollingDeltaY < 0 ? -1 : 0; 495 e.y = event.scrollingDeltaY > 0 ? 1 : event.scrollingDeltaY < 0 ? -1 : 0;
485 SDL_PushEvent((SDL_Event *) &e); 496 SDL_PushEvent((SDL_Event *) &e);
486 return iTrue; 497 return iTrue;
487 } 498 }
488 /* Post corresponding MOUSEWHEEL events. */ 499 /* Post corresponding MOUSEWHEEL events. */
489 SDL_MouseWheelEvent e = { .type = SDL_MOUSEWHEEL }; 500 SDL_MouseWheelEvent e = { .type = SDL_MOUSEWHEEL };
490 e.timestamp = SDL_GetTicks(); 501 e.timestamp = SDL_GetTicks();
502 e.windowID = id_Window(win);
491 e.which = isPerPixel ? 0 : 1; /* Distinction between trackpad and regular mouse. */ 503 e.which = isPerPixel ? 0 : 1; /* Distinction between trackpad and regular mouse. */
492 setPerPixel_MouseWheelEvent(&e, isPerPixel); 504 setPerPixel_MouseWheelEvent(&e, isPerPixel);
493 if (isPerPixel) { 505 if (isPerPixel) {
@@ -517,28 +529,6 @@ static iBool processScrollWheelEvent_(NSEvent *event) {
517 // printf("#### [%d] dx:%d dy:%d phase:%ld inertia:%d end:%d\n", preventTapGlitch_, e.x, e.y, (long) event.momentumPhase, 529 // printf("#### [%d] dx:%d dy:%d phase:%ld inertia:%d end:%d\n", preventTapGlitch_, e.x, e.y, (long) event.momentumPhase,
518 // isInertia, isEnded); fflush(stdout); 530 // isInertia, isEnded); fflush(stdout);
519 SDL_PushEvent((SDL_Event *) &e); 531 SDL_PushEvent((SDL_Event *) &e);
520#if 0
521 /* On macOS, we handle both trackpad and mouse events. We expect SDL to identify
522 which device is sending the event. */
523 if (ev.wheel.which == 0) {
524 /* Trackpad with precise scrolling w/inertia (points). */
525 setPerPixel_MouseWheelEvent(&ev.wheel, iTrue);
526 ev.wheel.x *= -d->window->base.pixelRatio;
527 ev.wheel.y *= d->window->base.pixelRatio;
528 /* Only scroll on one axis at a time. */
529 if (iAbs(ev.wheel.x) > iAbs(ev.wheel.y)) {
530 ev.wheel.y = 0;
531 }
532 else {
533 ev.wheel.x = 0;
534 }
535 }
536 else {
537 /* Disregard wheel acceleration applied by the OS. */
538 ev.wheel.x = -ev.wheel.x;
539 ev.wheel.y = iSign(ev.wheel.y);
540 }
541#endif
542 return iTrue; 532 return iTrue;
543} 533}
544 534
@@ -565,13 +555,6 @@ void setupApplication_MacOS(void) {
565 windowCloseItem.action = @selector(closeTab); 555 windowCloseItem.action = @selector(closeTab);
566 [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskScrollWheel 556 [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskScrollWheel
567 handler:^NSEvent*(NSEvent *event){ 557 handler:^NSEvent*(NSEvent *event){
568// printf("event type: %lu\n", (unsigned long) event.type);
569// fflush(stdout);
570// if (event.type == NSEventTypeGesture) {
571// trackSwipe_(event);
572// printf("GESTURE phase:%lu\n", (unsigned long) event.phase);
573//fflush(stdout);
574// }
575 if (event.type == NSEventTypeScrollWheel && 558 if (event.type == NSEventTypeScrollWheel &&
576 processScrollWheelEvent_(event)) { 559 processScrollWheelEvent_(event)) {
577 return nil; /* was eaten */ 560 return nil; /* was eaten */