From 6b3eaba308b93cba97fb758dbc942716fcbec3e7 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Thu, 22 Jan 2026 20:43:30 +0100 Subject: [PATCH] Codechange: remove unneeded MacOSVersionIsAtLeast calls --- src/os/macosx/font_osx.cpp | 20 ++++---------------- src/os/macosx/macos.h | 19 ------------------- src/os/macosx/macos.mm | 4 +--- src/os/macosx/string_osx.cpp | 14 -------------- src/video/cocoa/cocoa_v.mm | 20 ++++++++------------ src/video/cocoa/cocoa_wnd.mm | 6 ++---- 6 files changed, 15 insertions(+), 68 deletions(-) diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp index 3cc86f6e26..6bc7682942 100644 --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -123,12 +123,7 @@ const Sprite *CoreTextFontCache::InternalGetGlyph(GlyphID key, bool use_aa) { /* Get glyph size. */ CGGlyph glyph = (CGGlyph)key; - CGRect bounds = CGRectNull; - if (MacOSVersionIsAtLeast(10, 8, 0)) { - bounds = CTFontGetOpticalBoundsForGlyphs(this->font.get(), &glyph, nullptr, 1, 0); - } else { - bounds = CTFontGetBoundingRectsForGlyphs(this->font.get(), kCTFontOrientationDefault, &glyph, nullptr, 1); - } + CGRect bounds = CTFontGetOpticalBoundsForGlyphs(this->font.get(), &glyph, nullptr, 1, 0); if (CGRectIsNull(bounds)) UserError("Unable to render font glyph"); uint bb_width = (uint)std::ceil(bounds.size.width) + 1; // Sometimes the glyph bounds are too tight and cut of the last pixel after rounding. @@ -218,15 +213,10 @@ public: std::string font = GetFontCacheFontName(fs); if (font.empty()) return nullptr; - CFAutoRelease font_ref; - - if (MacOSVersionIsAtLeast(10, 6, 0)) { - /* Might be a font file name, try load it. */ - font_ref.reset(LoadFontFromFile(font)); - if (!font_ref) ShowInfo("Unable to load file '{}' for {} font, using default OS font selection instead", font, FontSizeToName(fs)); - } - + /* Might be a font file name, try load it. */ + CFAutoRelease font_ref(LoadFontFromFile(font)); if (!font_ref) { + ShowInfo("Unable to load file '{}' for {} font, using default OS font selection instead", font, FontSizeToName(fs)); CFAutoRelease name(CFStringCreateWithCString(kCFAllocatorDefault, font.c_str(), kCFStringEncodingUTF8)); /* Simply creating the font using CTFontCreateWithNameAndSize will *always* return @@ -339,8 +329,6 @@ public: private: static CTFontDescriptorRef LoadFontFromFile(const std::string &font_name) { - if (!MacOSVersionIsAtLeast(10, 6, 0)) return nullptr; - /* Might be a font file name, try load it. Direct font loading is * only supported starting on OSX 10.6. */ CFAutoRelease path; diff --git a/src/os/macosx/macos.h b/src/os/macosx/macos.h index 5b471e43cc..48697e430e 100644 --- a/src/os/macosx/macos.h +++ b/src/os/macosx/macos.h @@ -15,25 +15,6 @@ void ShowMacDialog(std::string_view title, std::string_view message, std::string void GetMacOSVersion(int *return_major, int *return_minor, int *return_bugfix); -/** - * Check if we are at least running on the specified version of Mac OS. - * @param major major version of the os. This would be 10 in the case of 10.4.11. - * @param minor minor version of the os. This would be 4 in the case of 10.4.11. - * @param bugfix bugfix version of the os. This would be 11 in the case of 10.4.11. - * @return true if the running os is at least what we asked, false otherwise. - */ -inline bool MacOSVersionIsAtLeast(long major, long minor, long bugfix) -{ - int version_major, version_minor, version_bugfix; - GetMacOSVersion(&version_major, &version_minor, &version_bugfix); - - if (version_major < major) return false; - if (version_major == major && version_minor < minor) return false; - if (version_major == major && version_minor == minor && version_bugfix < bugfix) return false; - - return true; -} - bool IsMonospaceFont(CFStringRef name); void MacOSSetThreadName(const std::string &name); diff --git a/src/os/macosx/macos.mm b/src/os/macosx/macos.mm index ee209917b6..7e025aeb63 100644 --- a/src/os/macosx/macos.mm +++ b/src/os/macosx/macos.mm @@ -193,9 +193,7 @@ bool IsMonospaceFont(CFStringRef name) */ void MacOSSetThreadName(const std::string &name) { - if (MacOSVersionIsAtLeast(10, 6, 0)) { - pthread_setname_np(name.c_str()); - } + pthread_setname_np(name.c_str()); NSThread *cur = [ NSThread currentThread ]; if (cur != nil && [ cur respondsToSelector:@selector(setName:) ]) { diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp index ac9598ef17..28e67bbf5b 100644 --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -124,8 +124,6 @@ static const CTRunDelegateCallbacks _sprite_font_callback = { /* static */ std::unique_ptr CoreTextParagraphLayoutFactory::GetParagraphLayout(CharType *buff, CharType *buff_end, FontMap &font_mapping) { - if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr; - /* Can't layout an empty string. */ ptrdiff_t length = buff_end - buff; if (length == 0) return nullptr; @@ -276,8 +274,6 @@ void MacOSResetScriptCache(FontSize size) /** Register an external font file with the CoreText system. */ void MacOSRegisterExternalFont(std::string_view file_path) { - if (!MacOSVersionIsAtLeast(10, 6, 0)) return; - CFAutoRelease path(CFStringCreateWithBytes(kCFAllocatorDefault, reinterpret_cast(file_path.data()), file_path.size(), kCFStringEncodingUTF8, false)); CFAutoRelease url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path.get(), kCFURLPOSIXPathStyle, false)); @@ -287,8 +283,6 @@ void MacOSRegisterExternalFont(std::string_view file_path) /** Store current language locale as a CoreFoundation locale. */ void MacOSSetCurrentLocaleName(std::string_view iso_code) { - if (!MacOSVersionIsAtLeast(10, 5, 0)) return; - CFAutoRelease iso(CFStringCreateWithBytes(kCFAllocatorDefault, reinterpret_cast(iso_code.data()), iso_code.size(), kCFStringEncodingUTF8, false)); _osx_locale.reset(CFLocaleCreate(kCFAllocatorDefault, iso.get())); } @@ -302,9 +296,6 @@ void MacOSSetCurrentLocaleName(std::string_view iso_code) */ int MacOSStringCompare(std::string_view s1, std::string_view s2) { - static const bool supported = MacOSVersionIsAtLeast(10, 5, 0); - if (!supported) return 0; - CFStringCompareFlags flags = kCFCompareCaseInsensitive | kCFCompareNumerically | kCFCompareLocalized | kCFCompareWidthInsensitive | kCFCompareForcedOrdering; CFAutoRelease cf1(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)s1.data(), s1.size(), kCFStringEncodingUTF8, false)); @@ -326,9 +317,6 @@ int MacOSStringCompare(std::string_view s1, std::string_view s2) */ int MacOSStringContains(std::string_view str, std::string_view value, bool case_insensitive) { - static const bool supported = MacOSVersionIsAtLeast(10, 5, 0); - if (!supported) return -1; - CFStringCompareFlags flags = kCFCompareLocalized | kCFCompareWidthInsensitive; if (case_insensitive) flags |= kCFCompareCaseInsensitive; @@ -447,7 +435,5 @@ int MacOSStringContains(std::string_view str, std::string_view value, bool case_ /* static */ std::unique_ptr OSXStringIterator::Create() { - if (!MacOSVersionIsAtLeast(10, 5, 0)) return nullptr; - return std::make_unique(); } diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index bb9bb7f101..5392c67d6c 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -103,8 +103,6 @@ void VideoDriver_Cocoa::Stop() */ std::optional VideoDriver_Cocoa::Initialize() { - if (!MacOSVersionIsAtLeast(10, 7, 0)) return "The Cocoa video driver requires Mac OS X 10.7 or later."; - if (_cocoa_video_started) return "Already started"; _cocoa_video_started = true; @@ -237,18 +235,16 @@ std::vector VideoDriver_Cocoa::GetListOfMonitorRefreshRates() { std::vector rates{}; - if (MacOSVersionIsAtLeast(10, 6, 0)) { - std::array displays; + std::array displays; - uint32_t count = 0; - CGGetActiveDisplayList(displays.size(), displays.data(), &count); + uint32_t count = 0; + CGGetActiveDisplayList(displays.size(), displays.data(), &count); - for (uint32_t i = 0; i < count; i++) { - CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displays[i]); - int rate = (int)CGDisplayModeGetRefreshRate(mode); - if (rate > 0) rates.push_back(rate); - CGDisplayModeRelease(mode); - } + for (uint32_t i = 0; i < count; i++) { + CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displays[i]); + int rate = static_cast(CGDisplayModeGetRefreshRate(mode)); + if (rate > 0) rates.push_back(rate); + CGDisplayModeRelease(mode); } return rates; diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm index 5518e182cf..c5550b0d62 100644 --- a/src/video/cocoa/cocoa_wnd.mm +++ b/src/video/cocoa/cocoa_wnd.mm @@ -310,10 +310,8 @@ static void setupWindowMenu() [ menuItem setSubmenu:windowMenu ]; [ [ NSApp mainMenu ] addItem:menuItem ]; - if (MacOSVersionIsAtLeast(10, 7, 0)) { - /* The OS will change the name of this menu item automatically */ - [ windowMenu addItemWithTitle:@"Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"^f" ]; - } + /* The OS will change the name of this menu item automatically */ + [ windowMenu addItemWithTitle:@"Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"^f" ]; /* Tell the application object that this is now the window menu */ [ NSApp setWindowsMenu:windowMenu ];