23# pragma clang diagnostic ignored "-Wdeprecated-declarations"
26#ifdef WITH_METAL_BACKEND
30#ifdef WITH_VULKAN_BACKEND
38#include "AssertMacros.h"
40#import <Cocoa/Cocoa.h>
43#include <Carbon/Carbon.h>
45#include <sys/sysctl.h>
49#include <mach/mach_time.h>
139 case kVK_ANSI_Keypad0:
141 case kVK_ANSI_Keypad1:
143 case kVK_ANSI_Keypad2:
145 case kVK_ANSI_Keypad3:
147 case kVK_ANSI_Keypad4:
149 case kVK_ANSI_Keypad5:
151 case kVK_ANSI_Keypad6:
153 case kVK_ANSI_Keypad7:
155 case kVK_ANSI_Keypad8:
157 case kVK_ANSI_Keypad9:
159 case kVK_ANSI_KeypadDecimal:
161 case kVK_ANSI_KeypadEnter:
163 case kVK_ANSI_KeypadPlus:
165 case kVK_ANSI_KeypadMinus:
167 case kVK_ANSI_KeypadMultiply:
169 case kVK_ANSI_KeypadDivide:
171 case kVK_ANSI_KeypadClear:
228 case kVK_ForwardDelete:
269 if ((recvChar >=
'A') && (recvChar <=
'Z')) {
273 if ((recvChar >=
'a') && (recvChar <=
'z')) {
278 const TISInputSourceRef kbdTISHandle = TISCopyCurrentKeyboardLayoutInputSource();
280 const CFDataRef uchrHandle =
static_cast<CFDataRef
>(
281 TISGetInputSourceProperty(kbdTISHandle, kTISPropertyUnicodeKeyLayoutData));
282 CFRelease(kbdTISHandle);
288 UInt32 deadKeyState = 0;
289 UniCharCount actualStrLength = 0;
291 UCKeyTranslate((UCKeyboardLayout *)CFDataGetBytePtr(uchrHandle),
296 kUCKeyTranslateNoDeadKeysMask,
342#define FIRSTFILEBUFLG 512
372- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
373- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename;
374- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
375- (void)applicationWillTerminate:(NSNotification *)aNotification;
376- (void)applicationWillBecomeActive:(NSNotification *)aNotification;
377- (void)toggleFullScreen:(NSNotification *)notification;
378- (void)windowWillClose:(NSNotification *)notification;
380- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app;
393 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
394 [center addObserver:self
395 selector:@selector(windowWillClose:)
396 name:NSWindowWillCloseNotification
407 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
408 [center removeObserver:self name:NSWindowWillCloseNotification object:nil];
413- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
415 if (m_systemCocoa->m_windowFocus) {
420 [NSApp activateIgnoringOtherApps:YES];
423 [NSEvent setMouseCoalescingEnabled:NO];
426- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
428 return m_systemCocoa->handleOpenDocumentRequest(filename);
431- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
436 m_systemCocoa->handleQuitRequest();
437 return NSTerminateCancel;
443- (void)applicationWillTerminate:(NSNotification *)aNotification
450- (void)applicationWillBecomeActive:(NSNotification *)aNotification
452 m_systemCocoa->handleApplicationBecomeActiveEvent();
455- (void)toggleFullScreen:(NSNotification *)notification
476- (void)windowWillClose:(NSNotification *)notification
479 NSWindow *closing_window = (NSWindow *)[notification
object];
481 if (![closing_window isKeyWindow]) {
492 const NSInteger index = [[NSApp orderedWindows] indexOfObject:closing_window];
493 if (index != NSNotFound) {
497 for (NSWindow *current_window in [NSApp orderedWindows]) {
498 if (current_window == closing_window) {
501 if (current_window.isOnActiveSpace && current_window.canBecomeKeyWindow) {
502 [current_window makeKeyAndOrderFront:nil];
507 for (NSNumber *window_number in [NSWindow windowNumbersWithOptions:0]) {
508 NSWindow *current_window = [NSApp windowWithWindowNumber:[window_number integerValue]];
509 if (current_window == closing_window) {
512 if ([current_window canBecomeKeyWindow]) {
513 [current_window makeKeyAndOrderFront:nil];
528- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
542 m_outsideLoopEventProcessed =
false;
543 m_needDelayedApplicationBecomeActiveEventProcessing =
false;
545 GHOST_ASSERT(m_displayManager,
"GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n");
546 m_displayManager->initialize();
548 m_ignoreWindowSizedMessages =
false;
549 m_ignoreMomentumScroll =
false;
550 m_multiTouchScroll =
false;
551 m_last_warp_timestamp = 0;
564 [NSApp setDelegate:nil];
565 [appDelegate release];
575#ifdef WITH_INPUT_NDOF
583 if (!GetCurrentProcess(&psn)) {
584 TransformProcessType(&psn, kProcessTransformToForegroundApplication);
585 SetFrontProcess(&psn);
590 [NSApplication sharedApplication];
592 if ([NSApp mainMenu] == nil) {
593 NSMenu *mainMenubar = [[NSMenu alloc] init];
594 NSMenuItem *menuItem;
599 appMenu = [[NSMenu alloc] initWithTitle:@"Blender"];
601 [appMenu addItemWithTitle:@"About Blender"
602 action:@selector(orderFrontStandardAboutPanel:)
604 [appMenu addItem:[NSMenuItem separatorItem]];
606 menuItem = [appMenu addItemWithTitle:@"Hide Blender"
607 action:@selector(hide:)
609 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
611 menuItem = [appMenu addItemWithTitle:@"Hide Others"
612 action:@selector(hideOtherApplications:)
614 menuItem.keyEquivalentModifierMask = (NSEventModifierFlagOption |
615 NSEventModifierFlagCommand);
617 [appMenu addItemWithTitle:@"Show All"
618 action:@selector(unhideAllApplications:)
621 menuItem = [appMenu addItemWithTitle:@"Quit Blender"
622 action:@selector(terminate:)
624 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
626 menuItem = [[NSMenuItem alloc] init];
627 menuItem.submenu = appMenu;
629 [mainMenubar addItem:menuItem];
634 windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
636 menuItem = [windowMenu addItemWithTitle:@"Minimize"
637 action:@selector(performMiniaturize:)
639 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
641 [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
643 menuItem = [windowMenu addItemWithTitle:@"Enter Full Screen"
644 action:@selector(toggleFullScreen:)
646 menuItem.keyEquivalentModifierMask = NSEventModifierFlagControl |
647 NSEventModifierFlagCommand;
649 menuItem = [windowMenu addItemWithTitle:@"Close"
650 action:@selector(performClose:)
652 menuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand;
654 menuItem = [[NSMenuItem alloc] init];
655 menuItem.submenu = windowMenu;
657 [mainMenubar addItem:menuItem];
660 [NSApp setMainMenu:mainMenubar];
661 [NSApp setWindowsMenu:windowMenu];
662 [windowMenu release];
665 if ([NSApp delegate] == nil) {
667 [NSApp setDelegate:appDelegate];
673 NSWindow.allowsAutomaticWindowTabbing = NO;
675 [NSApp finishLaunching];
688 return (
uint64_t)([[NSProcessInfo processInfo] systemUptime] * 1000);
696 return NSScreen.screens.count;
704 const NSRect frame = [[NSScreen mainScreen] visibleFrame];
707 const NSRect contentRect = [NSWindow
708 contentRectForFrameRect:frame
709 styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
710 NSWindowStyleMaskMiniaturizable)];
712 width = contentRect.size.width;
713 height = contentRect.size.height;
720 getMainDisplayDimensions(width, height);
731 const bool is_dialog,
737 const NSRect frame = [[NSScreen mainScreen] visibleFrame];
738 const NSRect contentRect = [NSWindow
739 contentRectForFrameRect:frame
740 styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
741 NSWindowStyleMaskMiniaturizable)];
743 int32_t bottom = (contentRect.size.height - 1) - height - top;
746 left = left > contentRect.origin.x ?
left : contentRect.origin.x;
748 bottom = bottom > contentRect.origin.y ? bottom + contentRect.origin.y : contentRect.origin.y;
766 GHOST_ASSERT(m_windowManager,
"m_windowManager not initialized");
767 m_windowManager->addWindow(window);
768 m_windowManager->setActiveWindow(window);
775 GHOST_PRINT(
"GHOST_SystemCocoa::createWindow(): window invalid\n");
793#ifdef WITH_VULKAN_BACKEND
794 case GHOST_kDrawingContextTypeVulkan: {
797 if (context->initializeDrawingContext()) {
805#ifdef WITH_METAL_BACKEND
806 case GHOST_kDrawingContextTypeMetal: {
809 if (context->initializeDrawingContext()) {
837 const NSPoint scr_co = NSMakePoint(x, y);
840 const int windowNumberAtPoint = [NSWindow windowNumberAtPoint:scr_co
841 belowWindowWithWindowNumber:0];
842 NSWindow *nswindow = [NSApp windowWithWindowNumber:windowNumberAtPoint];
844 if (nswindow == nil) {
848 return m_windowManager->getWindowAssociatedWithOSWindow((
const void *)nswindow);
857 const NSPoint mouseLoc = [NSEvent mouseLocation];
877 CGAssociateMouseAndMouseCursorPosition(
false);
878 setMouseCursorPosition(x, y);
879 CGAssociateMouseAndMouseCursorPosition(
true);
884 m_outsideLoopEventProcessed =
true;
908 if (!CGPreflightScreenCaptureAccess()) {
909 CGRequestScreenCaptureAccess();
913 const CGEventRef
event = CGEventCreate(nil);
917 const CGPoint mouseLocation = CGEventGetLocation(event);
920 const CGRect rect = CGRectMake(mouseLocation.x, mouseLocation.y, 1, 1);
921 const CGImageRef image = CGWindowListCreateImage(
922 rect, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);
926 NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc] initWithCGImage:image] autorelease];
927 CGImageRelease(image);
929 NSColor *color = [bitmap colorAtX:0 y:0];
933 NSColor *srgbColor = [color colorUsingColorSpace:[NSColorSpace sRGBColorSpace]];
938 CGFloat
red = 0.0, green = 0.0, blue = 0.0;
939 [color getRed:&red green:&green blue:&blue alpha:nil];
956 NSScreen *windowScreen = window->
getScreen();
957 const NSRect screenRect = windowScreen.frame;
960 xf -= screenRect.origin.x;
961 yf -= screenRect.origin.y;
964 yf = screenRect.size.height - yf;
966 CGDisplayMoveCursorToPoint((CGDirectDisplayID)[[[windowScreen deviceDescription]
967 objectForKey:
@"NSScreenNumber"] unsignedIntValue],
968 CGPointMake(xf, yf));
975 CGAssociateMouseAndMouseCursorPosition(
true);
985 (m_modifierMask & NSEventModifierFlagShift) ?
true :
false);
987 (m_modifierMask & NSEventModifierFlagControl) ?
true :
false);
994 const UInt32 button_state = GetCurrentEventButtonState();
1022 bool anyProcessed =
false;
1035 timeOut = kEventDurationForever;
1038 timeOut = (
double)(
next - getMilliSeconds())/1000.0;
1043 ::ReceiveNextEvent(0,
nullptr, timeOut,
false, &event);
1046 if (timerMgr->
fireTimers(getMilliSeconds())) {
1047 anyProcessed =
true;
1052 event = [NSApp nextEventMatchingMask:NSEventMaskAny
1053 untilDate:[NSDate distantPast]
1054 inMode:NSDefaultRunLoopMode
1060 anyProcessed =
true;
1070 if (event.type == NSEventTypeKeyDown && event.keyCode == kVK_Tab &&
1071 (event.modifierFlags & NSEventModifierFlagControl))
1073 handleKeyEvent(event);
1079 if (event.type == NSEventTypeKeyUp &&
1080 (event.modifierFlags & (NSEventModifierFlagCommand | NSEventModifierFlagOption)))
1082 handleKeyEvent(event);
1085 [NSApp sendEvent:event];
1088 }
while (event != nil);
1090 }
while (waitForEvent && !anyProcessed);
1093 if (m_needDelayedApplicationBecomeActiveEventProcessing) {
1094 handleApplicationBecomeActiveEvent();
1097 if (m_outsideLoopEventProcessed) {
1098 m_outsideLoopEventProcessed =
false;
1102 m_ignoreWindowSizedMessages =
false;
1104 return anyProcessed;
1111 for (
GHOST_IWindow *iwindow : m_windowManager->getWindows()) {
1114 [window->getViewWindow() makeKeyAndOrderFront:nil];
1123 m_needDelayedApplicationBecomeActiveEventProcessing =
true;
1127 m_needDelayedApplicationBecomeActiveEventProcessing =
false;
1129 const unsigned int modifiers = [[[NSApplication sharedApplication] currentEvent]
1132 if ((modifiers & NSEventModifierFlagShift) != (m_modifierMask & NSEventModifierFlagShift)) {
1140 if ((modifiers & NSEventModifierFlagControl) != (m_modifierMask & NSEventModifierFlagControl))
1149 if ((modifiers & NSEventModifierFlagOption) != (m_modifierMask & NSEventModifierFlagOption)) {
1157 if ((modifiers & NSEventModifierFlagCommand) != (m_modifierMask & NSEventModifierFlagCommand))
1167 m_modifierMask = modifiers;
1169 m_outsideLoopEventProcessed =
true;
1176 for (
GHOST_IWindow *iwindow : m_windowManager->getWindows()) {
1187 m_outsideLoopEventProcessed =
true;
1194 if (!validWindow(window)) {
1197 switch (eventType) {
1202 m_windowManager->setActiveWindow(window);
1207 m_windowManager->setWindowInactive(window);
1211 if (m_nativePixel) {
1221 if (!m_ignoreWindowSizedMessages) {
1238 if (m_nativePixel) {
1248 m_outsideLoopEventProcessed =
true;
1261 NSImageRep *imageRepresentation = [[image representations] firstObject];
1262 return NSMakeSize(imageRepresentation.pixelsWide, imageRepresentation.pixelsHigh);
1281 NSBitmapImageRep *bitmapImage = nil;
1282 for (NSImageRep *representation in [image representations]) {
1283 if ([representation isKindOfClass:[NSBitmapImageRep class]]) {
1284 bitmapImage = (NSBitmapImageRep *)representation;
1289 if (bitmapImage == nil || bitmapImage.bitsPerPixel != 32 || bitmapImage.isPlanar ||
1290 bitmapImage.bitmapFormat & (NSBitmapFormatAlphaFirst | NSBitmapFormatFloatingPointSamples))
1299 for (
int y = 0; y < imageSize.height; y++) {
1300 const int row_byte_count = 4 * imageSize.width;
1301 const int ibuf_off = (imageSize.height - y - 1) * row_byte_count;
1302 const int bmp_off = y * row_byte_count;
1303 memcpy(ibuf_data + ibuf_off, bmp_data + bmp_off, row_byte_count);
1318 if (!validWindow(window)) {
1321 switch (eventType) {
1327 getMilliSeconds(), eventType, draggedObjectType, window, mouseX, mouseY,
nullptr));
1337 switch (draggedObjectType) {
1339 NSArray *droppedArray = (NSArray *)data;
1347 strArray->
count = droppedArray.count;
1348 if (strArray->
count == 0) {
1355 for (
int i = 0; i < strArray->
count; i++) {
1356 NSString *droppedStr = [droppedArray objectAtIndex:i];
1357 const size_t pastedTextSize = [droppedStr
1358 lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1362 strArray->
count = i;
1367 [droppedStr cStringUsingEncoding:NSUTF8StringEncoding],
1369 temp_buff[pastedTextSize] =
'\0';
1371 strArray->
strings[i] = temp_buff;
1378 NSString *droppedStr = (NSString *)data;
1379 const size_t pastedTextSize = [droppedStr
1380 lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1383 if (temp_buff ==
nullptr) {
1388 temp_buff, [droppedStr cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize);
1389 temp_buff[pastedTextSize] =
'\0';
1395 NSImage *droppedImg =
static_cast<NSImage *
>(
data);
1400 [droppedImg release];
1411 getMilliSeconds(), eventType, draggedObjectType, window, mouseX, mouseY, eventData));
1418 m_outsideLoopEventProcessed =
true;
1433 m_outsideLoopEventProcessed =
true;
1438 NSString *filepath = (NSString *)filepathStr;
1444 NSArray *windowsList = [NSApp orderedWindows];
1445 if ([windowsList
count]) {
1446 [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
1449 GHOST_Window *window = m_windowManager->getWindows().empty() ?
1463 const size_t filenameTextSize = [filepath lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
1464 char *temp_buff = (
char *)malloc(filenameTextSize + 1);
1466 if (temp_buff ==
nullptr) {
1470 memcpy(temp_buff, [filepath cStringUsingEncoding:NSUTF8StringEncoding], filenameTextSize);
1471 temp_buff[filenameTextSize] =
'\0';
1483 NSEvent *
event = (NSEvent *)eventPtr;
1485 GHOST_IWindow *window = m_windowManager->getWindowAssociatedWithOSWindow(
1486 (
const void *)
event.window);
1494 switch (eventType) {
1495 case NSEventTypeTabletPoint:
1504 ct.
Xtilt =
event.tilt.x;
1505 ct.
Ytilt =
event.tilt.y;
1508 case NSEventTypeTabletProximity:
1511 if (event.isEnteringProximity) {
1513 switch (event.pointingDeviceType) {
1514 case NSPointingDeviceTypePen:
1517 case NSPointingDeviceTypeEraser:
1520 case NSPointingDeviceTypeCursor:
1521 case NSPointingDeviceTypeUnknown:
1529 GHOST_ASSERT(
FALSE,
"GHOST_SystemCocoa::handleTabletEvent : unknown event received");
1538 NSEvent *
event = (NSEvent *)eventPtr;
1540 switch (event.subtype) {
1541 case NSEventSubtypeTabletPoint:
1542 handleTabletEvent(eventPtr, NSEventTypeTabletPoint);
1544 case NSEventSubtypeTabletProximity:
1545 handleTabletEvent(eventPtr, NSEventTypeTabletProximity);
1555 NSEvent *
event = (NSEvent *)eventPtr;
1561 ->getWindowAssociatedWithOSWindow((
const void *)
event.window);
1570 switch (event.type) {
1571 case NSEventTypeLeftMouseDown:
1572 handleTabletEvent(event);
1579 case NSEventTypeRightMouseDown:
1580 handleTabletEvent(event);
1587 case NSEventTypeOtherMouseDown:
1588 handleTabletEvent(event);
1595 case NSEventTypeLeftMouseUp:
1596 handleTabletEvent(event);
1603 case NSEventTypeRightMouseUp:
1604 handleTabletEvent(event);
1611 case NSEventTypeOtherMouseUp:
1612 handleTabletEvent(event);
1619 case NSEventTypeLeftMouseDragged:
1620 case NSEventTypeRightMouseDragged:
1621 case NSEventTypeOtherMouseDragged:
1622 handleTabletEvent(event);
1624 case NSEventTypeMouseMoved: {
1628 bool is_tablet =
false;
1634 switch (grab_mode) {
1637 int32_t x_warp, y_warp, x_accum, y_accum,
x,
y;
1644 x_accum +=
event.deltaX;
1645 y_accum += -
event.deltaY;
1659 const NSTimeInterval timestamp =
event.timestamp;
1660 if (timestamp < m_last_warp_timestamp) {
1678 correctedBounds.
m_b = (windowBounds.
m_b - windowBounds.
m_t) - correctedBounds.
m_b;
1679 correctedBounds.
m_t = (windowBounds.
m_b - windowBounds.
m_t) - correctedBounds.
m_t;
1685 const NSPoint mousePos =
event.locationInWindow;
1687 const int32_t x_mouse = mousePos.x;
1688 const int32_t y_mouse = mousePos.y;
1691 int32_t warped_x_mouse = x_mouse;
1692 int32_t warped_y_mouse = y_mouse;
1697 if (x_mouse != warped_x_mouse || y_mouse != warped_y_mouse) {
1700 setMouseCursorPosition(warped_x, warped_y);
1702 y_accum + (y_mouse - warped_y_mouse));
1705 m_last_warp_timestamp = [[NSProcessInfo processInfo] systemUptime];
1721 const NSPoint mousePos =
event.locationInWindow;
1736 case NSEventTypeScrollWheel: {
1737 const NSEventPhase momentumPhase =
event.momentumPhase;
1738 const NSEventPhase phase =
event.phase;
1744 if (momentumPhase) {
1745 if (m_ignoreMomentumScroll) {
1750 m_ignoreMomentumScroll =
false;
1756 if (phase == NSEventPhaseBegan && m_multitouchGestures) {
1757 m_multiTouchScroll =
true;
1759 else if (phase == NSEventPhaseEnded) {
1760 m_multiTouchScroll =
false;
1765 if (!m_multiTouchScroll && momentumPhase == NSEventPhaseNone) {
1766 double deltaF =
event.deltaY;
1768 if (deltaF == 0.0) {
1769 deltaF =
event.deltaX;
1771 if (deltaF == 0.0) {
1775 const int32_t delta = deltaF > 0.0 ? 1 : -1;
1779 const NSPoint mousePos =
event.locationInWindow;
1782 double dx =
event.scrollingDeltaX;
1783 double dy =
event.scrollingDeltaY;
1787 if (phase == NSEventPhaseNone && momentumPhase == NSEventPhaseNone) {
1798 const NSPoint delta = [[view_window contentView]
1799 convertPointToBacking:NSMakePoint(dx, dy)];
1807 event.isDirectionInvertedFromDevice));
1812 case NSEventTypeMagnify: {
1813 const NSPoint mousePos =
event.locationInWindow;
1821 event.magnification * 125.0 + 0.1,
1826 case NSEventTypeSmartMagnify: {
1827 const NSPoint mousePos =
event.locationInWindow;
1834 case NSEventTypeRotate: {
1835 const NSPoint mousePos =
event.locationInWindow;
1843 event.rotation * -5.0,
1856 NSEvent *
event = (NSEvent *)eventPtr;
1857 GHOST_IWindow *window = m_windowManager->getWindowAssociatedWithOSWindow(
1858 (
const void *)
event.window);
1865 switch (event.type) {
1866 case NSEventTypeKeyDown:
1867 case NSEventTypeKeyUp: {
1870 char utf8_buf[6] = {
'\0'};
1873 NSString *charsIgnoringModifiers =
event.charactersIgnoringModifiers;
1874 if (charsIgnoringModifiers.length > 0) {
1875 keyCode =
convertKey(event.keyCode, [charsIgnoringModifiers characterAtIndex:0]);
1881 NSString *characters =
event.characters;
1882 if ([characters length] > 0) {
1883 NSData *convertedCharacters = [characters dataUsingEncoding:NSUTF8StringEncoding];
1885 for (
int x = 0; x < convertedCharacters.length; x++) {
1886 utf8_buf[x] = ((
char *)convertedCharacters.bytes)[x];
1902 if (m_modifierMask & NSEventModifierFlagCommand) {
1906 if ((keyCode ==
GHOST_kKeyQ) && (m_modifierMask & NSEventModifierFlagCommand)) {
1910 if (event.type == NSEventTypeKeyDown) {
1918 printf(
"Key down rawCode=0x%x charsIgnoringModifiers=%c keyCode=%u utf8=%s\n",
1920 charsIgnoringModifiers.length > 0 ? [charsIgnoringModifiers characterAtIndex:0] :
1930 printf(
"Key up rawCode=0x%x charsIgnoringModifiers=%c keyCode=%u utf8=%s\n",
1932 charsIgnoringModifiers.length > 0 ? [charsIgnoringModifiers characterAtIndex:0] :
1938 m_ignoreMomentumScroll =
true;
1941 case NSEventTypeFlagsChanged: {
1942 const unsigned int modifiers =
event.modifierFlags;
1944 if ((modifiers & NSEventModifierFlagShift) != (m_modifierMask & NSEventModifierFlagShift)) {
1952 if ((modifiers & NSEventModifierFlagControl) !=
1953 (m_modifierMask & NSEventModifierFlagControl))
1956 event.timestamp * 1000,
1962 if ((modifiers & NSEventModifierFlagOption) != (m_modifierMask & NSEventModifierFlagOption))
1965 event.timestamp * 1000,
1971 if ((modifiers & NSEventModifierFlagCommand) !=
1972 (m_modifierMask & NSEventModifierFlagCommand))
1975 event.timestamp * 1000,
1982 m_modifierMask = modifiers;
1983 m_ignoreMomentumScroll =
true;
2001 NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
2002 NSString *textPasted = [pasteBoard stringForType:NSPasteboardTypeString];
2004 if (textPasted == nil) {
2008 const size_t pastedTextSize = [textPasted lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
2010 char *temp_buff = (
char *)malloc(pastedTextSize + 1);
2012 if (temp_buff ==
nullptr) {
2016 memcpy(temp_buff, [textPasted cStringUsingEncoding:NSUTF8StringEncoding], pastedTextSize);
2017 temp_buff[pastedTextSize] =
'\0';
2033 NSPasteboard *pasteBoard = NSPasteboard.generalPasteboard;
2034 [pasteBoard declareTypes:@[ NSPasteboardTypeString ] owner:nil];
2036 NSString *textToCopy = [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
2037 [pasteBoard setString:textToCopy forType:NSPasteboardTypeString];
2043 NSURL *pasteboardImageFile = Nil;
2046 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
2047 NSDictionary *pasteboardFilteringOptions = @{
2048 NSPasteboardURLReadingFileURLsOnlyKey : @YES,
2049 NSPasteboardURLReadingContentsConformToTypesKey : [NSImage imageTypes]
2052 NSArray *pasteboardMatches = [pasteboard readObjectsForClasses:@[ [NSURL class] ]
2053 options:pasteboardFilteringOptions];
2055 if (!pasteboardMatches || !pasteboardMatches.count) {
2059 pasteboardImageFile = [[pasteboardMatches firstObject] copy];
2062 return [pasteboardImageFile autorelease];
2068 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
2069 NSArray *supportedTypes = [NSArray
2070 arrayWithObjects:NSPasteboardTypeFileURL, NSPasteboardTypeTIFF, NSPasteboardTypePNG, nil];
2072 NSPasteboardType availableType = [pasteboard availableTypeFromArray:supportedTypes];
2074 if (!availableType) {
2079 if ([pasteboard availableTypeFromArray:@[ NSPasteboardTypeFileURL ]] &&
2091 if (!hasClipboardImage()) {
2096 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
2098 NSImage *clipboardImage = Nil;
2101 clipboardImage = [[[NSImage alloc] initWithContentsOfURL:pasteboardImageFile] autorelease];
2105 clipboardImage = [[[NSImage alloc] initWithPasteboard:pasteboard] autorelease];
2108 if (!clipboardImage) {
2116 const size_t byteCount = clipboardImageSize.width * clipboardImageSize.height * 4;
2117 uint *rgba = (
uint *)malloc(byteCount);
2127 *r_width = clipboardImageSize.width;
2128 *r_height = clipboardImageSize.height;
2140 const size_t rowByteCount = width * 4;
2142 NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc]
2143 initWithBitmapDataPlanes:nil
2150 colorSpaceName:NSDeviceRGBColorSpace
2151 bytesPerRow:rowByteCount
2156 uint8_t *dstBuffer =
static_cast<uint8_t *
>([imageRep bitmapData]);
2158 for (
int y = 0; y < height; y++) {
2159 const int dstOff = (height - y - 1) * rowByteCount;
2160 const int srcOff = y * rowByteCount;
2161 memcpy(dstBuffer + dstOff, srcBuffer + srcOff, rowByteCount);
2164 NSImage *image = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)] autorelease];
2165 [image addRepresentation:imageRep];
2167 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
2168 [pasteboard clearContents];
2170 BOOL pasteSuccess = [pasteboard writeObjects:@[ image ]];
2172 if (!pasteSuccess) {
2180 const char *message,
2181 const char *help_label,
2182 const char *continue_label,
2187 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
2188 alert.accessoryView = [[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 500, 0)] autorelease];
2190 NSString *titleString = [NSString stringWithCString:title];
2191 NSString *messageString = [NSString stringWithCString:message];
2192 NSString *continueString = [NSString stringWithCString:continue_label];
2193 NSString *helpString = [NSString stringWithCString:help_label];
2196 alert.alertStyle = NSAlertStyleCritical;
2199 alert.alertStyle = NSAlertStyleWarning;
2202 alert.alertStyle = NSAlertStyleInformational;
2205 alert.messageText = titleString;
2206 alert.informativeText = messageString;
2208 [alert addButtonWithTitle:continueString];
2209 if (link && strlen(link)) {
2210 [alert addButtonWithTitle:helpString];
2213 const NSModalResponse response = [alert runModal];
2214 if (response == NSAlertSecondButtonReturn) {
2215 NSString *linkString = [NSString stringWithCString:link];
2216 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:linkString]];
void BLI_kdtree_nd_ free(KDTree *tree)
typedef double(DMatrix)[4][4]
#define GHOST_ASSERT(x, info)
static GHOST_TKey convertKey(int rawCode, unichar recvChar)
static ImBuf * NSImageToImBuf(NSImage *image)
int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG])
static char g_firstFileBuf[FIRSTFILEBUFLG]
static NSSize getNSImagePixelSize(NSImage *image)
static bool g_hasFirstFile
static GHOST_TButton convertButton(int button)
static NSURL * NSPasteboardGetImageFile()
@ GHOST_kTrackpadEventMagnify
@ GHOST_kTrackpadEventSmartMagnify
@ GHOST_kTrackpadEventRotate
@ GHOST_kTrackpadEventScroll
@ GHOST_kEventWindowClose
@ GHOST_kEventDraggingDropDone
@ GHOST_kEventDraggingExited
@ GHOST_kEventNativeResolutionChange
@ GHOST_kEventDraggingUpdated
@ GHOST_kEventOpenMainFile
@ GHOST_kEventDraggingEntered
@ GHOST_kEventWindowActivate
@ GHOST_kEventWindowUpdate
@ GHOST_kEventWindowDeactivate
@ GHOST_kEventQuitRequest
static const GHOST_TabletData GHOST_TABLET_DATA_NONE
@ GHOST_kTabletModeEraser
@ GHOST_kTabletModeStylus
@ GHOST_kCapabilityPrimaryClipboard
void * GHOST_TDragnDropDataPtr
#define GHOST_CAPABILITY_FLAG_ALL
@ GHOST_kKeyNumpadAsterisk
const void * GHOST_TEventDataPtr
@ GHOST_kModifierKeyLeftControl
@ GHOST_kModifierKeyLeftAlt
@ GHOST_kModifierKeyLeftShift
@ GHOST_kModifierKeyLeftOS
@ GHOST_kDragnDropTypeFilenames
@ GHOST_kDragnDropTypeBitmap
@ GHOST_kDragnDropTypeString
@ GHOST_kButtonMaskButton4
@ GHOST_kButtonMaskButton7
@ GHOST_kButtonMaskButton6
@ GHOST_kButtonMaskButton5
@ GHOST_kButtonMaskMiddle
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its red
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a producing a negative Combine Generate a color from its green
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
virtual bool getValid() const =0
virtual void wrapPoint(int32_t &x, int32_t &y, int32_t ofs, GHOST_TAxisFlag axis)
bool processEvents(bool waitForEvent) override
uint * getClipboardImage(int *r_width, int *r_height) const override
GHOST_TSuccess disposeContext(GHOST_IContext *context) override
void getAllDisplayDimensions(uint32_t &width, uint32_t &height) const override
GHOST_TSuccess getCursorPosition(int32_t &x, int32_t &y) const override
GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa *window)
GHOST_TSuccess handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType, GHOST_WindowCocoa *window, int mouseX, int mouseY, void *data)
GHOST_TSuccess handleApplicationBecomeActiveEvent()
GHOST_TSuccess hasClipboardImage() const override
GHOST_TSuccess handleMouseEvent(void *eventPtr)
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &keys) const override
GHOST_IWindow * createWindow(const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_GPUSettings gpuSettings, const bool exclusive=false, const bool is_dialog=false, const GHOST_IWindow *parentWindow=nullptr) override
void notifyExternalEventProcessed()
GHOST_TSuccess handleKeyEvent(void *eventPtr)
~GHOST_SystemCocoa() override
GHOST_TSuccess init() override
GHOST_TSuccess getPixelAtCursor(float r_color[3]) const override
uint64_t getMilliSeconds() const override
GHOST_TCapabilityFlag getCapabilities() const override
GHOST_TSuccess showMessageBox(const char *title, const char *message, const char *help_label, const char *continue_label, const char *link, GHOST_DialogOptions dialog_options) const override
uint8_t getNumDisplays() const override
void getMainDisplayDimensions(uint32_t &width, uint32_t &height) const override
GHOST_TSuccess handleTabletEvent(void *eventPtr, short eventType)
bool handleOpenDocumentRequest(void *filepathStr)
GHOST_TSuccess setCursorPosition(int32_t x, int32_t y) override
char * getClipboard(bool selection) const override
GHOST_TSuccess setMouseCursorPosition(int32_t x, int32_t y)
void putClipboard(const char *buffer, bool selection) const override
GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const override
GHOST_IWindow * getWindowUnderCursor(int32_t x, int32_t y) override
GHOST_IContext * createOffscreenContext(GHOST_GPUSettings gpuSettings) override
GHOST_TSuccess putClipboardImage(uint *rgba, int width, int height) const override
virtual GHOST_TSuccess init()
bool fireTimers(uint64_t time)
bool isDialog() const override
void clientToScreenIntern(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const
void * getOSWindow() const override
GHOST_TabletData & GetCocoaTabletData()
void getClientBounds(GHOST_Rect &bounds) const override
void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override
void screenToClientIntern(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const
void setNativePixelSize()
void loadCursor(bool visible, GHOST_TStandardCursor cursor) const
GHOST_TSuccess getCursorGrabBounds(GHOST_Rect &bounds) const override
void setCursorGrabAccum(int32_t x, int32_t y)
void getCursorGrabInitPos(int32_t &x, int32_t &y) const
GHOST_TAxisFlag getCursorGrabAxis() const
GHOST_TStandardCursor getCursorShape() const override
bool getCursorVisibility() const override
GHOST_TGrabCursorMode getCursorGrabMode() const
GHOST_TSuccess updateDrawingContext()
bool getCursorGrabModeIsWarp() const
void getCursorGrabAccum(int32_t &x, int32_t &y) const
draw_view in_light_buf[] float
struct ImBuf * IMB_allocImBuf(unsigned int, unsigned int, unsigned char, unsigned int)
void IMB_freeImBuf(ImBuf *)
GHOST_SystemCocoa * systemCocoa
unsigned __int64 uint64_t
GHOST_TDrawingContextType context_type
GHOST_GPUDevice preferred_device
void set(GHOST_TModifierKey mask, bool down)
ImBufByteBuffer byte_buffer
void WM_exit(bContext *C, const int exit_code)