Skip to content

Commit

Permalink
Support all apple os variants, silence materialx GL warnings.
Browse files Browse the repository at this point in the history
* We do this by shifting usage away from target specific apple
  platforms such as TARGET_OS_VISION, TARGET_OS_IOS by
  using the catch-all TARGET_OS_IPHONE which encompasses
  every apple platform except macOS and DriverKit.
  • Loading branch information
furby-tm committed Jan 15, 2024
1 parent ef91f14 commit f54b635
Show file tree
Hide file tree
Showing 26 changed files with 506 additions and 501 deletions.
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,10 @@ let package = Package(
Arch.OS.python(),
],
exclude: getConfig(for: .materialx).exclude,
publicHeadersPath: "include"
publicHeadersPath: "include",
cxxSettings: [
.define("GL_SILENCE_DEPRECATION", to: "1"),
]
),

.executableTarget(
Expand Down
120 changes: 60 additions & 60 deletions Sources/GLFW/cocoa_init.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void createMenuBar(void)
appName = @"GLFW Application";
}

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
NSMenu* bar = [[NSMenu alloc] init];
[NSApp setMainMenu:bar];

Expand All @@ -129,7 +129,7 @@ static void createMenuBar(void)
action:NULL
keyEquivalent:@""] setSubmenu:servicesMenu];

#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
NSSet *scenes = [[UIApplication sharedApplication] connectedScenes];

UIView *menuView = nil;
Expand Down Expand Up @@ -191,13 +191,13 @@ static void createMenuBar(void)

[builder insertSiblingMenu:servicesMenu
beforeMenuForIdentifier:UIMenuServices];
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

#if !__has_feature(objc_arc)
[servicesMenu release];
#endif

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
[appMenu addItem:[NSMenuItem separatorItem]];
[appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", appName]
action:@selector(hide:)
Expand Down Expand Up @@ -244,10 +244,10 @@ static void createMenuBar(void)
// to get the application menu working properly.
SEL setAppleMenuSelector = NSSelectorFromString(@"setAppleMenu:");
[NSApp performSelector:setAppleMenuSelector withObject:appMenu];
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
}

#if TARGET_OS_VISION
#if TARGET_OS_IPHONE
static void didTap(UIGestureRecognizer *recognizer,
UIEditMenuInteraction *appMenuInteraction)
{
Expand All @@ -261,7 +261,7 @@ static void didTap(UIGestureRecognizer *recognizer,
[appMenuInteraction presentEditMenuWithConfiguration:config];
}
}
#endif /* TARGET_OS_VISION */
#endif /* TARGET_OS_IPHONE */

// Create key code translation tables
//
Expand Down Expand Up @@ -399,7 +399,7 @@ static void createKeyTables(void)
//
static GLFWbool updateUnicodeDataNS(void)
{
#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
if (_glfw.ns.inputSource)
{
CFRelease(_glfw.ns.inputSource);
Expand All @@ -424,17 +424,17 @@ static GLFWbool updateUnicodeDataNS(void)
"Cocoa: Failed to retrieve keyboard layout Unicode data");
return GLFW_FALSE;
}
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
return GLFW_FALSE;
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
return GLFW_TRUE;
}

// Load HIToolbox.framework and the TIS symbols we need from it
//
static GLFWbool initializeTIS(void)
{
#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
// This works only because Cocoa has already loaded it properly
_glfw.ns.tis.bundle =
CFBundleGetBundleWithIdentifier(CFSTR("com.apple.HIToolbox"));
Expand Down Expand Up @@ -471,9 +471,9 @@ static GLFWbool initializeTIS(void)
_glfw.ns.tis.kPropertyUnicodeKeyLayoutData =
*kPropertyUnicodeKeyLayoutData;

#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
return GLFW_FALSE;
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
return updateUnicodeDataNS();
}

Expand All @@ -493,32 +493,32 @@ - (void)doNothing:(id)object

@end // GLFWHelper

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
@interface GLFWApplicationDelegate : NSObject <NSApplicationDelegate>
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
@interface GLFWApplicationDelegate : NSObject <UIApplicationDelegate>
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
@end

@implementation GLFWApplicationDelegate

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
- (void)applicationWillTerminate:(UIApplication *)application
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
{
_GLFWwindow* window;

for (window = _glfw.windowListHead; window; window = window->next)
_glfwInputWindowCloseRequest(window);

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
return NSTerminateCancel;
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
}

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
- (void)applicationDidChangeScreenParameters:(NSNotification *) notification
{
_GLFWwindow* window;
Expand Down Expand Up @@ -553,29 +553,29 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification
createMenuBar();
}
}
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
- (void)applicationDidFinishLaunching:(NSNotification *)notification
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)launchOptions;
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
{
_glfw.ns.finishedLaunching = GLFW_TRUE;
_glfwPlatformPostEmptyEvent();
#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
[NSApp stop:nil];
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
return true;
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
}

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
- (void)applicationDidHide:(NSNotification *)notification
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
- (void)applicationDidEnterBackground:(UIApplication *)application;
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
{
int i;

Expand Down Expand Up @@ -625,15 +625,15 @@ int _glfwPlatformInit(void)
[NSThread detachNewThreadSelector:@selector(doNothing:)
toTarget:_glfw.ns.helper
withObject:nil];
#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
if (NSApp)
_glfw.ns.finishedLaunching = GLFW_TRUE;
[NSApplication sharedApplication];
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
if (UIApplication.sharedApplication)
_glfw.ns.finishedLaunching = GLFW_TRUE;
[UIApplication sharedApplication];
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

_glfw.ns.delegate = [[GLFWApplicationDelegate alloc] init];
if (_glfw.ns.delegate == nil)
Expand All @@ -643,7 +643,7 @@ int _glfwPlatformInit(void)
return GLFW_FALSE;
}

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
[NSApp setDelegate:_glfw.ns.delegate];

NSEvent* (^block)(NSEvent*) = ^ NSEvent* (NSEvent* event)
Expand All @@ -653,7 +653,7 @@ int _glfwPlatformInit(void)

return event;
};
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
[[UIApplication sharedApplication] setDelegate:_glfw.ns.delegate];

UIEvent* (^block)(UIEvent*) = ^ UIEvent* (UIEvent* event)
Expand All @@ -677,13 +677,13 @@ int _glfwPlatformInit(void)

return event;
};
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
_glfw.ns.keyUpMonitor =
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyUp
handler:block];
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

if (_glfw.hints.init.ns.chdir)
changeToResourcesDirectory();
Expand All @@ -695,25 +695,25 @@ int _glfwPlatformInit(void)
[[NSNotificationCenter defaultCenter]
addObserver:_glfw.ns.helper
selector:@selector(selectedKeyboardInputSourceChanged:)
#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
name:NSTextInputContextKeyboardSelectionDidChangeNotification
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
name:UITextInputCurrentInputModeDidChangeNotification
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
object:nil];

createKeyTables();

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
_glfw.ns.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
if (!_glfw.ns.eventSource)
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
return GLFW_FALSE;
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
CGEventSourceSetLocalEventsSuppressionInterval(_glfw.ns.eventSource, 0.0);
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

if (!initializeTIS())
return GLFW_FALSE;
Expand All @@ -731,30 +731,30 @@ void _glfwPlatformTerminate(void)
{
@autoreleasepool {

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
if (_glfw.ns.inputSource)
{
CFRelease(_glfw.ns.inputSource);
_glfw.ns.inputSource = NULL;
_glfw.ns.unicodeData = nil;
}
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
if (_glfw.ns.eventSource)
{
CFRelease(_glfw.ns.eventSource);
_glfw.ns.eventSource = NULL;
}
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

if (_glfw.ns.delegate)
{
#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
[NSApp setDelegate:nil];
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
[[UIApplication sharedApplication] setDelegate:nil];
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
#if !__has_feature(objc_arc)
[_glfw.ns.delegate release];
#endif
Expand All @@ -765,11 +765,11 @@ void _glfwPlatformTerminate(void)
{
[[NSNotificationCenter defaultCenter]
removeObserver:_glfw.ns.helper
#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
name:NSTextInputContextKeyboardSelectionDidChangeNotification
#else /* TARGET_OS_VISION */
#else /* TARGET_OS_IPHONE */
name:UITextInputCurrentInputModeDidChangeNotification
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
object:nil];
[[NSNotificationCenter defaultCenter]
removeObserver:_glfw.ns.helper];
Expand All @@ -779,10 +779,10 @@ void _glfwPlatformTerminate(void)
_glfw.ns.helper = nil;
}

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
if (_glfw.ns.keyUpMonitor)
[NSEvent removeMonitor:_glfw.ns.keyUpMonitor];
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

free(_glfw.ns.clipboardString);

Expand Down
8 changes: 4 additions & 4 deletions Sources/GLFW/cocoa_joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

#include <IOKit/IOKitLib.h>

#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
#include <IOKit/IOCFPlugIn.h>
#include <IOKit/hid/IOHIDLib.h>
#include <IOKit/hid/IOHIDKeys.h>
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */

#define _GLFW_PLATFORM_JOYSTICK_STATE _GLFWjoystickNS ns
#define _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE struct { int dummyJoystick; }
Expand All @@ -45,9 +45,9 @@
//
typedef struct _GLFWjoystickNS
{
#if !TARGET_OS_VISION
#if !TARGET_OS_IPHONE
IOHIDDeviceRef device;
#endif /* !TARGET_OS_VISION */
#endif /* !TARGET_OS_IPHONE */
CFMutableArrayRef axes;
CFMutableArrayRef buttons;
CFMutableArrayRef hats;
Expand Down
Loading

0 comments on commit f54b635

Please sign in to comment.