Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_SystemCocoa.mm
| Show First 20 Lines • Show All 490 Lines • ▼ Show 20 Lines | GHOST_SystemCocoa::GHOST_SystemCocoa() | ||||
| m_modifierMask = 0; | m_modifierMask = 0; | ||||
| m_outsideLoopEventProcessed = false; | m_outsideLoopEventProcessed = false; | ||||
| m_needDelayedApplicationBecomeActiveEventProcessing = false; | m_needDelayedApplicationBecomeActiveEventProcessing = false; | ||||
| m_displayManager = new GHOST_DisplayManagerCocoa(); | m_displayManager = new GHOST_DisplayManagerCocoa(); | ||||
| GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n"); | GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n"); | ||||
| m_displayManager->initialize(); | m_displayManager->initialize(); | ||||
| m_windowMouseCaptured = nil; | |||||
| // NSEvent timeStamp is given in system uptime, state start date is boot time | // NSEvent timeStamp is given in system uptime, state start date is boot time | ||||
| mib[0] = CTL_KERN; | mib[0] = CTL_KERN; | ||||
| mib[1] = KERN_BOOTTIME; | mib[1] = KERN_BOOTTIME; | ||||
| len = sizeof(struct timeval); | len = sizeof(struct timeval); | ||||
| sysctl(mib, 2, &boottime, &len, NULL, 0); | sysctl(mib, 2, &boottime, &len, NULL, 0); | ||||
| m_start_time = ((boottime.tv_sec * 1000) + (boottime.tv_usec / 1000)); | m_start_time = ((boottime.tv_sec * 1000) + (boottime.tv_usec / 1000)); | ||||
| ▲ Show 20 Lines • Show All 425 Lines • ▼ Show 20 Lines | @autoreleasepool { | ||||
| // There is on special exception for ctrl+(shift)+tab. We do not | // There is on special exception for ctrl+(shift)+tab. We do not | ||||
| // get keyDown events delivered to the view because they are | // get keyDown events delivered to the view because they are | ||||
| // special hotkeys to switch between views, so override directly | // special hotkeys to switch between views, so override directly | ||||
| if ([event type] == NSEventTypeKeyDown && [event keyCode] == kVK_Tab && | if ([event type] == NSEventTypeKeyDown && [event keyCode] == kVK_Tab && | ||||
| ([event modifierFlags] & NSEventModifierFlagControl)) { | ([event modifierFlags] & NSEventModifierFlagControl)) { | ||||
| handleKeyEvent(event); | handleKeyEvent(event); | ||||
| continue; | |||||
| } | } | ||||
| else { | |||||
| if (([event type] == NSEventTypeLeftMouseDown || [event type] == NSEventTypeLeftMouseUp) | |||||
| && m_windowMouseCaptured) { | |||||
| NSWindow *cocoawindow = (NSWindow *)m_windowMouseCaptured->getCocoaWindow(); | |||||
| if (cocoawindow != [event window]) { | |||||
| // Simulate mouse event capture by recreating an event with the | |||||
| // window that "captures" the event. | |||||
| NSPoint mousePos_scr = [[event window] convertPointToScreen:[event locationInWindow]]; | |||||
| event = [[NSEvent mouseEventWithType] | |||||
| type:[event type] | |||||
| location:[cocoawindow convertPointFromScreen:mousePos_scr] | |||||
| modifierFlags:[event modifierFlags] | |||||
| timestamp:[event timestamp] | |||||
| windowNumber:[cocoawindow windowNumber] | |||||
| context:nil | |||||
| eventNumber:[event eventNumber] | |||||
| clickCount:[event clickCount] | |||||
| pressure:[event pressure]]; | |||||
| // For some reason NSApp does not accept these events, so handle | |||||
| // these events directly. | |||||
| handleMouseEvent(event); | |||||
| continue; | |||||
| } | |||||
| } | |||||
| // For some reason NSApp is swallowing the key up events when modifier | // For some reason NSApp is swallowing the key up events when modifier | ||||
| // key is pressed, even if there seems to be no apparent reason to do | // key is pressed, even if there seems to be no apparent reason to do | ||||
| // so, as a workaround we always handle these up events. | // so, as a workaround we always handle these up events. | ||||
| if ([event type] == NSEventTypeKeyUp && | if ([event type] == NSEventTypeKeyUp && | ||||
| ([event modifierFlags] & (NSEventModifierFlagCommand | NSEventModifierFlagOption))) | ([event modifierFlags] & (NSEventModifierFlagCommand | NSEventModifierFlagOption))) { | ||||
| handleKeyEvent(event); | handleKeyEvent(event); | ||||
| } | |||||
| [NSApp sendEvent:event]; | [NSApp sendEvent:event]; | ||||
| } | } | ||||
| } | |||||
| } while (event != nil); | } while (event != nil); | ||||
| #if 0 | #if 0 | ||||
| } while (waitForEvent && !anyProcessed); // Needed only for timer implementation | } while (waitForEvent && !anyProcessed); // Needed only for timer implementation | ||||
| #endif | #endif | ||||
| if (m_needDelayedApplicationBecomeActiveEventProcessing) | if (m_needDelayedApplicationBecomeActiveEventProcessing) | ||||
| handleApplicationBecomeActiveEvent(); | handleApplicationBecomeActiveEvent(); | ||||
| ▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | switch (eventType) { | ||||
| case GHOST_kEventWindowActivate: | case GHOST_kEventWindowActivate: | ||||
| m_windowManager->setActiveWindow(window); | m_windowManager->setActiveWindow(window); | ||||
| window->loadCursor(window->getCursorVisibility(), window->getCursorShape()); | window->loadCursor(window->getCursorVisibility(), window->getCursorShape()); | ||||
| pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window)); | pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowActivate, window)); | ||||
| break; | break; | ||||
| case GHOST_kEventWindowDeactivate: | case GHOST_kEventWindowDeactivate: | ||||
| m_windowManager->setWindowInactive(window); | m_windowManager->setWindowInactive(window); | ||||
| pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowDeactivate, window)); | pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowDeactivate, window)); | ||||
| window->lostMouseCapture(); | |||||
| break; | break; | ||||
| case GHOST_kEventWindowUpdate: | case GHOST_kEventWindowUpdate: | ||||
| if (m_nativePixel) { | if (m_nativePixel) { | ||||
| window->setNativePixelSize(); | window->setNativePixelSize(); | ||||
| pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventNativeResolutionChange, window)); | pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventNativeResolutionChange, window)); | ||||
| } | } | ||||
| pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowUpdate, window)); | pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowUpdate, window)); | ||||
| break; | break; | ||||
| case GHOST_kEventWindowMove: | case GHOST_kEventWindowMove: | ||||
| pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowMove, window)); | pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowMove, window)); | ||||
| break; | break; | ||||
| case GHOST_kEventWindowSize: | case GHOST_kEventWindowSize: | ||||
| if (!m_ignoreWindowSizedMessages) { | if (!m_ignoreWindowSizedMessages) { | ||||
| // Enforce only one resize message per event loop | // Enforce only one resize message per event loop | ||||
| // (coalescing all the live resize messages) | // (coalescing all the live resize messages) | ||||
| window->updateDrawingContext(); | window->updateDrawingContext(); | ||||
| pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window)); | pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window)); | ||||
| // Mouse up event is trapped by the resizing event loop, | // Mouse up event is trapped by the resizing event loop, | ||||
| // so send it anyway to the window manager. | // so send it anyway to the window manager. | ||||
| pushEvent(new GHOST_EventButton(getMilliSeconds(), | pushEvent(new GHOST_EventButton(getMilliSeconds(), | ||||
| GHOST_kEventButtonUp, | GHOST_kEventButtonUp, | ||||
| window, | window, | ||||
| GHOST_kButtonMaskLeft, | GHOST_kButtonMaskLeft, | ||||
| GHOST_TABLET_DATA_NONE)); | GHOST_TABLET_DATA_NONE)); | ||||
| window->updateMouseCapture(MouseReleased); | |||||
| // m_ignoreWindowSizedMessages = true; | // m_ignoreWindowSizedMessages = true; | ||||
| } | } | ||||
| break; | break; | ||||
| case GHOST_kEventNativeResolutionChange: | case GHOST_kEventNativeResolutionChange: | ||||
| if (m_nativePixel) { | if (m_nativePixel) { | ||||
| window->setNativePixelSize(); | window->setNativePixelSize(); | ||||
| pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventNativeResolutionChange, window)); | pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventNativeResolutionChange, window)); | ||||
| ▲ Show 20 Lines • Show All 871 Lines • Show Last 20 Lines | |||||