From 8aa08e92d26513597234042bf14f59124b7b6149 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sat, 4 Jan 2025 21:55:15 -0700 Subject: [PATCH] Fix some macOS deprecation warnings --- examples/cocoa/CocoaAppDelegate.mm | 4 +--- src/SFML/Window/CMakeLists.txt | 4 ++++ src/SFML/Window/macOS/SFApplication.m | 8 +++----- src/SFML/Window/macOS/SFContext.mm | 4 ++-- .../Window/macOS/SFKeyboardModifiersHelper.mm | 18 ++++++++---------- src/SFML/Window/macOS/SFOpenGLView+keyboard.mm | 2 -- src/SFML/Window/macOS/SFOpenGLView+mouse.mm | 4 ++-- src/SFML/Window/macOS/SFOpenGLView.mm | 2 -- src/SFML/Window/macOS/SFWindowController.mm | 16 ++++++++-------- src/SFML/Window/macOS/WindowImplCocoa.hpp | 5 ----- .../Window/macOS/WindowImplDelegateProtocol.h | 5 ----- 11 files changed, 28 insertions(+), 44 deletions(-) diff --git a/examples/cocoa/CocoaAppDelegate.mm b/examples/cocoa/CocoaAppDelegate.mm index c2ab8d68e..227febfe7 100644 --- a/examples/cocoa/CocoaAppDelegate.mm +++ b/examples/cocoa/CocoaAppDelegate.mm @@ -34,8 +34,6 @@ #define GREEN @"Green" #define RED @"Red" -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - // Our PIMPL struct SFMLmainWindow { @@ -195,7 +193,7 @@ struct SFMLmainWindow - (IBAction)visibleChanged:(NSButton*)sender { if (self.initialized) - self.visible = [sender state] == NSOnState; + self.visible = [sender state] == NSControlStateValueOn; } - (IBAction)textChanged:(NSTextField*)sender diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index ae9d90ec8..5b6cdc246 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -335,6 +335,10 @@ elseif(SFML_OS_ANDROID) target_link_libraries(sfml-window PRIVATE android) endif() +if(SFML_OS_MACOS OR SFML_OS_IOS) + target_compile_definitions(sfml-window PRIVATE GL_SILENCE_DEPRECATION) +endif() + # on some platforms (e.g. Raspberry Pi 3 armhf), GCC requires linking libatomic to use features # that aren't supported by native CPU instructions (64-bit atomic operations on 32-bit architecture) if(SFML_COMPILER_GCC) diff --git a/src/SFML/Window/macOS/SFApplication.m b/src/SFML/Window/macOS/SFApplication.m index b8b679cfa..18be718cf 100644 --- a/src/SFML/Window/macOS/SFApplication.m +++ b/src/SFML/Window/macOS/SFApplication.m @@ -28,8 +28,6 @@ //////////////////////////////////////////////////////////// #import -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - //////////////////////////////////////////////////////////// @implementation SFApplication @@ -41,7 +39,7 @@ [SFApplication sharedApplication]; // Make sure NSApp exists NSEvent* event = nil; - while ((event = [NSApp nextEventMatchingMask:NSAnyEventMask + while ((event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES])) // Remove the event from the queue @@ -142,7 +140,7 @@ addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"]; - [hideOtherItem setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask)]; + [hideOtherItem setKeyEquivalentModifierMask:(NSEventModifierFlagOption | NSEventModifierFlagCommand)]; // SHOW ALL [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; @@ -253,7 +251,7 @@ // custom OpenGL view. See -[SFOpenGLView sfKeyUp:] for more details. id firstResponder = [[anEvent window] firstResponder]; - if (([anEvent type] != NSKeyUp) || (![firstResponder tryToPerform:@selector(sfKeyUp:) with:anEvent])) + if (([anEvent type] != NSEventTypeKeyUp) || (![firstResponder tryToPerform:@selector(sfKeyUp:) with:anEvent])) { // It's either not a key up event or no responder has a sfKeyUp // message implemented. diff --git a/src/SFML/Window/macOS/SFContext.mm b/src/SFML/Window/macOS/SFContext.mm index f382bbcc0..a7007ac59 100644 --- a/src/SFML/Window/macOS/SFContext.mm +++ b/src/SFML/Window/macOS/SFContext.mm @@ -77,7 +77,7 @@ SFContext::SFContext(SFContext* shared, const ContextSettings& settings, Vector2 // Create a dummy window/view pair (hidden) and assign it our context. m_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, size.x, size.y) - styleMask:NSBorderlessWindowMask + styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]; // Don't defer it! m_view = [[NSOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, size.x, size.y)]; @@ -148,7 +148,7 @@ void SFContext::setVerticalSyncEnabled(bool enabled) const AutoreleasePool pool; const GLint swapInterval = enabled; - [m_context setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; + [m_context setValues:&swapInterval forParameter:NSOpenGLContextParameterSwapInterval]; } diff --git a/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm b/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm index 8589947a7..cfb8057d3 100644 --- a/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm +++ b/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm @@ -29,8 +29,6 @@ #import #include -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - //////////////////////////////////////////////////////////// /// Here are define the mask value for the 'modifiers' @@ -163,10 +161,10 @@ sf::Event::KeyPressed keyPressedEventWithModifiers(NSUInteger modifiers, sf::Key sf::Event::KeyPressed event; event.code = key; event.scancode = code; - event.alt = modifiers & NSAlternateKeyMask; - event.control = modifiers & NSControlKeyMask; - event.shift = modifiers & NSShiftKeyMask; - event.system = modifiers & NSCommandKeyMask; + event.alt = modifiers & NSEventModifierFlagOption; + event.control = modifiers & NSEventModifierFlagControl; + event.shift = modifiers & NSEventModifierFlagShift; + event.system = modifiers & NSEventModifierFlagCommand; return event; } @@ -177,10 +175,10 @@ sf::Event::KeyReleased keyReleasedEventWithModifiers(NSUInteger modifiers, sf::K sf::Event::KeyReleased event; event.code = key; event.scancode = code; - event.alt = modifiers & NSAlternateKeyMask; - event.control = modifiers & NSControlKeyMask; - event.shift = modifiers & NSShiftKeyMask; - event.system = modifiers & NSCommandKeyMask; + event.alt = modifiers & NSEventModifierFlagOption; + event.control = modifiers & NSEventModifierFlagControl; + event.shift = modifiers & NSEventModifierFlagShift; + event.system = modifiers & NSEventModifierFlagCommand; return event; } diff --git a/src/SFML/Window/macOS/SFOpenGLView+keyboard.mm b/src/SFML/Window/macOS/SFOpenGLView+keyboard.mm index bd23188e6..778833eed 100644 --- a/src/SFML/Window/macOS/SFOpenGLView+keyboard.mm +++ b/src/SFML/Window/macOS/SFOpenGLView+keyboard.mm @@ -31,8 +31,6 @@ #import #include -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - //////////////////////////////////////////////////////////// /// In this file, we implement keyboard handling for SFOpenGLView /// diff --git a/src/SFML/Window/macOS/SFOpenGLView+mouse.mm b/src/SFML/Window/macOS/SFOpenGLView+mouse.mm index d462f0510..64a34d6f4 100644 --- a/src/SFML/Window/macOS/SFOpenGLView+mouse.mm +++ b/src/SFML/Window/macOS/SFOpenGLView+mouse.mm @@ -350,8 +350,8 @@ // is dissociated from its position. // Ignore any non-move related event - if (([eventOrNil type] == NSMouseMoved) || ([eventOrNil type] == NSLeftMouseDragged) || - ([eventOrNil type] == NSRightMouseDragged) || ([eventOrNil type] == NSOtherMouseDragged)) + if (([eventOrNil type] == NSEventTypeMouseMoved) || ([eventOrNil type] == NSEventTypeLeftMouseDragged) || + ([eventOrNil type] == NSEventTypeRightMouseDragged) || ([eventOrNil type] == NSEventTypeOtherMouseDragged)) { // Without this factor, the cursor flies around waaay too fast! // But I don't know if it because of retina display or because diff --git a/src/SFML/Window/macOS/SFOpenGLView.mm b/src/SFML/Window/macOS/SFOpenGLView.mm index deb2aaa2c..301c88806 100644 --- a/src/SFML/Window/macOS/SFOpenGLView.mm +++ b/src/SFML/Window/macOS/SFOpenGLView.mm @@ -33,8 +33,6 @@ #include -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - //////////////////////////////////////////////////////////// /// SFOpenGLView class: Privates Methods Declaration diff --git a/src/SFML/Window/macOS/SFWindowController.mm b/src/SFML/Window/macOS/SFWindowController.mm index 2f28d6f62..feef3b0dd 100644 --- a/src/SFML/Window/macOS/SFWindowController.mm +++ b/src/SFML/Window/macOS/SFWindowController.mm @@ -177,7 +177,7 @@ NSRect windowRect = NSMakeRect(0, 0, desktop.size.x, desktop.size.y); m_window = [[SFWindow alloc] initWithContentRect:windowRect - styleMask:NSBorderlessWindowMask + styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]; @@ -243,13 +243,13 @@ NSRect rect = NSMakeRect(0, 0, mode.size.x, mode.size.y); // Convert the SFML window style to Cocoa window style. - unsigned int nsStyle = NSBorderlessWindowMask; + unsigned int nsStyle = NSWindowStyleMaskBorderless; if (style & sf::Style::Titlebar) - nsStyle |= NSTitledWindowMask | NSMiniaturizableWindowMask; + nsStyle |= NSWindowStyleMaskTitled | NSWindowStyleMaskMiniaturizable; if (style & sf::Style::Resize) - nsStyle |= NSResizableWindowMask; + nsStyle |= NSWindowStyleMaskResizable; if (style & sf::Style::Close) - nsStyle |= NSClosableWindowMask; + nsStyle |= NSWindowStyleMaskClosable; // Create the window. m_window = [[SFWindow alloc] @@ -352,17 +352,17 @@ - (void)setCursorGrabbed:(BOOL)grabbed { // Remove or restore resizeable style if needed - BOOL resizeable = (([m_window styleMask] & NSResizableWindowMask) != 0) ? YES : NO; + BOOL resizeable = (([m_window styleMask] & NSWindowStyleMaskResizable) != 0) ? YES : NO; if (grabbed && resizeable) { m_restoreResize = YES; - NSUInteger newStyle = [m_window styleMask] & ~NSResizableWindowMask; + NSUInteger newStyle = [m_window styleMask] & ~NSWindowStyleMaskResizable; [m_window setStyleMask:newStyle]; } else if (!grabbed && m_restoreResize) { m_restoreResize = NO; - NSUInteger newStyle = [m_window styleMask] | NSResizableWindowMask; + NSUInteger newStyle = [m_window styleMask] | NSWindowStyleMaskResizable; [m_window setStyleMask:newStyle]; } diff --git a/src/SFML/Window/macOS/WindowImplCocoa.hpp b/src/SFML/Window/macOS/WindowImplCocoa.hpp index 7adf6f1b0..3b6f9fa73 100644 --- a/src/SFML/Window/macOS/WindowImplCocoa.hpp +++ b/src/SFML/Window/macOS/WindowImplCocoa.hpp @@ -32,9 +32,6 @@ #include #include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - //////////////////////////////////////////////////////////// /// Predefine OBJ-C classes //////////////////////////////////////////////////////////// @@ -387,5 +384,3 @@ private: } // namespace priv } // namespace sf - -#pragma GCC diagnostic pop diff --git a/src/SFML/Window/macOS/WindowImplDelegateProtocol.h b/src/SFML/Window/macOS/WindowImplDelegateProtocol.h index a35efc0d7..d0940fff3 100644 --- a/src/SFML/Window/macOS/WindowImplDelegateProtocol.h +++ b/src/SFML/Window/macOS/WindowImplDelegateProtocol.h @@ -36,9 +36,6 @@ #include -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - namespace sf::priv { class WindowImplCocoa; @@ -252,5 +249,3 @@ class WindowImplCocoa; - (void)applyContext:(NSOpenGLContext*)context; @end - -#pragma GCC diagnostic pop