diff --git a/bypy/macos.conf b/bypy/macos.conf index ab2b19717..b366d2da2 100644 --- a/bypy/macos.conf +++ b/bypy/macos.conf @@ -5,4 +5,4 @@ vm_name 'macos-kitty' root '/Users/Shared/kitty-build' python '/Library/Frameworks/Python.framework/Versions/Current/bin/python3' universal 'true' -deploy_target '12.0' +deploy_target '14.0' diff --git a/glfw/cocoa_displaylink.m b/glfw/cocoa_displaylink.m index 43386e48e..1b15af695 100644 --- a/glfw/cocoa_displaylink.m +++ b/glfw/cocoa_displaylink.m @@ -5,74 +5,31 @@ * Distributed under terms of the GPL3 license. */ -// On macOS 14 and newer CADisplayLink, obtained via [NSScreen displayLinkWithTarget:selector:] -// is used. It fires on the main thread run loop. CVDisplayLink is deprecated -// and is used only as a fallback on older macOS versions. Remove it once base -// macOS version is 14. -#pragma clang diagnostic ignored "-Wdeprecated-declarations" +// Render frames are paced using CADisplayLink, obtained via +// [NSScreen displayLinkWithTarget:selector:]. It fires on the main thread run +// loop, as do all the functions in this file, so no locking is needed. #include "internal.h" -#include #include -#include #define DISPLAY_LINK_SHUTDOWN_CHECK_INTERVAL s_to_monotonic_t(30ll) #define MAX_NUM_OF_DISPLAYS 256 typedef struct _GLFWDisplayLinkNS { - // Either a CADisplayLink or a CVDisplayLinkRef depending on use_ca_display_link() - CFTypeRef displayLink; + CADisplayLink *displayLink; CGDirectDisplayID displayID; monotonic_t lastRenderFrameRequestedAt, first_unserviced_render_frame_request_at; - bool pending_dispatch; } _GLFWDisplayLinkNS; static struct { _GLFWDisplayLinkNS entries[MAX_NUM_OF_DISPLAYS]; - os_unfair_lock locks[MAX_NUM_OF_DISPLAYS]; - bool locks_initialized[MAX_NUM_OF_DISPLAYS]; size_t count; } displayLinks = {0}; -static inline size_t -index_for_entry(_GLFWDisplayLinkNS *entry) { - return (size_t)(entry - displayLinks.entries); -} - -static inline os_unfair_lock * -lock_for_entry(_GLFWDisplayLinkNS *entry) { - return &displayLinks.locks[index_for_entry(entry)]; -} - -static bool -use_ca_display_link(void) { - static int ans = -1; - if (ans < 0) { - if (@available(macOS 14.0, *)) ans = 1; - else ans = 0; - } - return ans == 1; -} - -static void _glfwDispatchRenderFrame(void *); - -static void -on_display_link_fired(_GLFWDisplayLinkNS *entry, bool on_main_thread) { - os_unfair_lock *lock = lock_for_entry(entry); - os_unfair_lock_lock(lock); - const bool should_dispatch = entry->first_unserviced_render_frame_request_at && !entry->pending_dispatch; - CGDirectDisplayID displayID = entry->displayID; - if (should_dispatch) entry->pending_dispatch = true; - os_unfair_lock_unlock(lock); - if (should_dispatch) { - if (on_main_thread) _glfwDispatchRenderFrame((void *)(uintptr_t)displayID); - else dispatch_async_f(dispatch_get_main_queue(), (void *)(uintptr_t)displayID, _glfwDispatchRenderFrame); - } -} +static void _glfwDispatchRenderFrame(CGDirectDisplayID displayID); // CADisplayLink retains its target, so use a separate target object that // holds no references to anything that needs releasing. -API_AVAILABLE(macos(14.0)) @interface GLFWDisplayLinkTarget : NSObject { _GLFWDisplayLinkNS *entry; } @@ -89,23 +46,10 @@ API_AVAILABLE(macos(14.0)) - (void)displayLinkFired:(CADisplayLink *)sender { (void)sender; - on_display_link_fired(entry, true); + if (entry->first_unserviced_render_frame_request_at) _glfwDispatchRenderFrame(entry->displayID); } @end -static CVReturn -displayLinkCallback( - CVDisplayLinkRef displayLink UNUSED, - const CVTimeStamp *now UNUSED, - const CVTimeStamp *outputTime UNUSED, - CVOptionFlags flagsIn UNUSED, - CVOptionFlags *flagsOut UNUSED, - void *userInfo) { - _GLFWDisplayLinkNS *entry = (_GLFWDisplayLinkNS *)userInfo; - if (entry) on_display_link_fired(entry, false); - return kCVReturnSuccess; -} - static NSScreen * screen_for_display_id(CGDirectDisplayID displayID) { for (NSScreen *screen in [NSScreen screens]) { @@ -115,72 +59,48 @@ screen_for_display_id(CGDirectDisplayID displayID) { return nil; } -// Must be called with the lock for entry held static void create_display_link(_GLFWDisplayLinkNS *entry) { - entry->displayLink = NULL; - if (use_ca_display_link()) { - if (@available(macOS 14.0, *)) { - @autoreleasepool { - NSScreen *screen = screen_for_display_id(entry->displayID); - if (!screen) return; - GLFWDisplayLinkTarget *target = [[GLFWDisplayLinkTarget alloc] initWithEntry:entry]; - CADisplayLink *link = [screen displayLinkWithTarget:target selector:@selector(displayLinkFired:)]; - [target release]; - if (!link) return; - link.paused = YES; - // Use common modes so that frames are delivered during live resize and modal loops - [link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; - entry->displayLink = (CFTypeRef)[link retain]; - } - } - } else { - CVDisplayLinkRef link = NULL; - CVDisplayLinkCreateWithCGDisplay(entry->displayID, &link); - if (link) { - CVDisplayLinkSetOutputCallback(link, &displayLinkCallback, entry); - entry->displayLink = link; - } + entry->displayLink = nil; + @autoreleasepool { + NSScreen *screen = screen_for_display_id(entry->displayID); + if (!screen) return; + GLFWDisplayLinkTarget *target = [[GLFWDisplayLinkTarget alloc] initWithEntry:entry]; + CADisplayLink *link = [screen displayLinkWithTarget:target selector:@selector(displayLinkFired:)]; + [target release]; + if (!link) return; + link.paused = YES; + // Use common modes so that frames are delivered during live resize and modal loops + [link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; + entry->displayLink = [link retain]; } } static void -link_start(CFTypeRef link) { - if (use_ca_display_link()) { - if (@available(macOS 14.0, *)) ((CADisplayLink *)link).paused = NO; - } else CVDisplayLinkStart((CVDisplayLinkRef)link); +link_start(CADisplayLink *link) { + link.paused = NO; } static void -link_stop(CFTypeRef link) { - if (use_ca_display_link()) { - if (@available(macOS 14.0, *)) ((CADisplayLink *)link).paused = YES; - } else CVDisplayLinkStop((CVDisplayLinkRef)link); +link_stop(CADisplayLink *link) { + link.paused = YES; } static bool -link_is_running(CFTypeRef link) { - if (use_ca_display_link()) { - if (@available(macOS 14.0, *)) return !((CADisplayLink *)link).paused; - return false; - } - return CVDisplayLinkIsRunning((CVDisplayLinkRef)link); +link_is_running(CADisplayLink *link) { + return !link.paused; } +// Remove the link from the run loop and release the reference owned by an entry static void -link_retain(CFTypeRef link) { CFRetain(link); } - -static void -link_release(CFTypeRef link) { CFRelease(link); } - -// Stop the link and release the reference owned by an entry -static void -link_destroy(CFTypeRef link) { - if (use_ca_display_link()) { +destroy_display_link(_GLFWDisplayLinkNS *entry) { + CADisplayLink *link = entry->displayLink; + entry->displayLink = nil; + if (link) { // invalidate removes the link from the run loop and releases its target - if (@available(macOS 14.0, *)) [(CADisplayLink *)link invalidate]; - } else CVDisplayLinkStop((CVDisplayLinkRef)link); - link_release(link); + [link invalidate]; + [link release]; + } } static CGDirectDisplayID @@ -196,16 +116,10 @@ void _glfwClearDisplayLinks(void) { for (size_t i = 0; i < displayLinks.count; i++) { _GLFWDisplayLinkNS *entry = &displayLinks.entries[i]; - os_unfair_lock *lock = &displayLinks.locks[i]; - os_unfair_lock_lock(lock); - CFTypeRef link = entry->displayLink; - entry->displayLink = NULL; + destroy_display_link(entry); entry->displayID = (CGDirectDisplayID)0; entry->lastRenderFrameRequestedAt = 0; entry->first_unserviced_render_frame_request_at = 0; - entry->pending_dispatch = false; - os_unfair_lock_unlock(lock); - if (link) link_destroy(link); } displayLinks.count = 0; } @@ -213,29 +127,17 @@ _glfwClearDisplayLinks(void) { unsigned _glfwCreateDisplayLink(CGDirectDisplayID displayID) { for (unsigned i = 0; i < displayLinks.count; i++) { - os_unfair_lock *existing_lock = &displayLinks.locks[i]; - os_unfair_lock_lock(existing_lock); - const bool already_created = displayLinks.entries[i].displayID == displayID; - os_unfair_lock_unlock(existing_lock); - if (already_created) return i; + if (displayLinks.entries[i].displayID == displayID) return i; } if (displayLinks.count >= MAX_NUM_OF_DISPLAYS) { _glfwInputError(GLFW_PLATFORM_ERROR, "Too many monitors cannot create display link"); return displayLinks.count; } - unsigned idx = displayLinks.count; + unsigned idx = displayLinks.count++; _GLFWDisplayLinkNS *entry = &displayLinks.entries[idx]; - if (!displayLinks.locks_initialized[idx]) { - displayLinks.locks[idx] = OS_UNFAIR_LOCK_INIT; - displayLinks.locks_initialized[idx] = true; - } - os_unfair_lock *lock = &displayLinks.locks[idx]; - os_unfair_lock_lock(lock); memset(entry, 0, sizeof(entry[0])); entry->displayID = displayID; - displayLinks.count++; create_display_link(entry); - os_unfair_lock_unlock(lock); return idx; } @@ -246,18 +148,9 @@ _glfwShutdownDisplayLinks(unsigned long long timer_id UNUSED, void *user_data UN display_link_shutdown_timer = 0; for (size_t i = 0; i < displayLinks.count; i++) { _GLFWDisplayLinkNS *dl = &displayLinks.entries[i]; - os_unfair_lock *lock = &displayLinks.locks[i]; - os_unfair_lock_lock(lock); - CFTypeRef link = dl->displayLink; - if (link) link_retain(link); dl->lastRenderFrameRequestedAt = 0; dl->first_unserviced_render_frame_request_at = 0; - dl->pending_dispatch = false; - os_unfair_lock_unlock(lock); - if (link) { - link_stop(link); - link_release(link); - } + if (dl->displayLink) link_stop(dl->displayLink); } } @@ -271,133 +164,74 @@ _glfwRequestRenderFrame(_GLFWwindow *w) { } monotonic_t now = glfwGetTime(); bool found_display_link = false; - _GLFWDisplayLinkNS *dl = NULL; for (size_t i = 0; i < displayLinks.count; i++) { - dl = &displayLinks.entries[i]; - bool need_start = false, need_stop = false, need_recreate = false; - bool retain_link = false; - CFTypeRef link = NULL; - CFTypeRef new_link = NULL; - bool new_link_retained = false; - os_unfair_lock *lock = &displayLinks.locks[i]; - os_unfair_lock_lock(lock); - if (dl->displayID == displayID && !dl->displayLink && use_ca_display_link()) { + _GLFWDisplayLinkNS *dl = &displayLinks.entries[i]; + if (dl->displayID == displayID) { + found_display_link = true; // NSScreen may not have been available when the link was first // created, for example, if AppKit had not yet caught up with a // display configuration change, so try again. - create_display_link(dl); - } - link = dl->displayLink; - if (dl->displayID == displayID) { - found_display_link = true; + if (!dl->displayLink) create_display_link(dl); monotonic_t first_unserviced = dl->first_unserviced_render_frame_request_at; dl->lastRenderFrameRequestedAt = now; if (!first_unserviced) { dl->first_unserviced_render_frame_request_at = now; first_unserviced = now; } - dl->pending_dispatch = false; - if (link) { - if (!link_is_running(link)) { - need_start = true; - retain_link = true; - } else if (now - first_unserviced > s_to_monotonic_t(1ll)) { - need_recreate = true; + if (dl->displayLink) { + if (!link_is_running(dl->displayLink)) link_start(dl->displayLink); + else if (now - first_unserviced > s_to_monotonic_t(1ll)) { dl->first_unserviced_render_frame_request_at = now; - dl->displayLink = NULL; + destroy_display_link(dl); + create_display_link(dl); + if (dl->displayLink) link_start(dl->displayLink); + _glfwInputError(GLFW_PLATFORM_ERROR, "Display link stuck possibly because of sleep/screensaver + Apple's incompetence, recreating."); } } - } else if (link && dl->lastRenderFrameRequestedAt && now - dl->lastRenderFrameRequestedAt >= DISPLAY_LINK_SHUTDOWN_CHECK_INTERVAL) { - need_stop = true; - retain_link = true; + } else if (dl->displayLink && dl->lastRenderFrameRequestedAt && now - dl->lastRenderFrameRequestedAt >= DISPLAY_LINK_SHUTDOWN_CHECK_INTERVAL) { dl->lastRenderFrameRequestedAt = 0; dl->first_unserviced_render_frame_request_at = 0; - dl->pending_dispatch = false; - } - if (retain_link && link) link_retain(link); - os_unfair_lock_unlock(lock); - if (need_recreate && link) { - link_destroy(link); - os_unfair_lock_lock(lock); - create_display_link(dl); - new_link = dl->displayLink; - if (new_link) { - link_retain(new_link); - new_link_retained = true; - } - dl->pending_dispatch = false; - os_unfair_lock_unlock(lock); - if (new_link) { - if (!link_is_running(new_link)) link_start(new_link); - if (new_link_retained) link_release(new_link); - } - _glfwInputError(GLFW_PLATFORM_ERROR, "Display link stuck possibly because of sleep/screensaver + Apple's incompetence, recreating."); - } else { - if (need_start && link) link_start(link); - else if (need_stop && link) link_stop(link); - if (retain_link && link) link_release(link); + link_stop(dl->displayLink); } } if (!found_display_link) { unsigned idx = _glfwCreateDisplayLink(displayID); if (idx < displayLinks.count) { - dl = &displayLinks.entries[idx]; - os_unfair_lock *lock = &displayLinks.locks[idx]; - os_unfair_lock_lock(lock); + _GLFWDisplayLinkNS *dl = &displayLinks.entries[idx]; dl->lastRenderFrameRequestedAt = now; dl->first_unserviced_render_frame_request_at = now; - dl->pending_dispatch = false; - CFTypeRef link = dl->displayLink; - if (link) link_retain(link); - os_unfair_lock_unlock(lock); - if (link) { - if (!link_is_running(link)) link_start(link); - link_release(link); - } + if (dl->displayLink && !link_is_running(dl->displayLink)) link_start(dl->displayLink); } } } +static bool +has_pending_render_frame_request(CGDirectDisplayID displayID) { + for (_GLFWwindow *w = _glfw.windowListHead; w; w = w->next) { + if (w->ns.renderFrameRequested && displayID == displayIDForWindow(w)) return true; + } + return false; +} + static void -_glfwDispatchRenderFrame(void *passed_in_data) { - CGDirectDisplayID displayID = (uintptr_t)passed_in_data; - _GLFWwindow *w = _glfw.windowListHead; - while (w) { +_glfwDispatchRenderFrame(CGDirectDisplayID displayID) { + // Reset before calling the callbacks so that any render frame requests + // they make are tracked as unserviced. + for (size_t i = 0; i < displayLinks.count; i++) { + if (displayLinks.entries[i].displayID == displayID) displayLinks.entries[i].first_unserviced_render_frame_request_at = 0; + } + for (_GLFWwindow *w = _glfw.windowListHead; w; w = w->next) { if (w->ns.renderFrameRequested && displayID == displayIDForWindow(w)) { w->ns.renderFrameRequested = false; w->ns.renderFrameCallback((GLFWwindow *)w); } - w = w->next; } for (size_t i = 0; i < displayLinks.count; i++) { _GLFWDisplayLinkNS *dl = &displayLinks.entries[i]; - bool need_stop = false; - CFTypeRef link = NULL; - os_unfair_lock *lock = &displayLinks.locks[i]; - os_unfair_lock_lock(lock); - if (dl->displayID == displayID) { - dl->first_unserviced_render_frame_request_at = 0; - dl->pending_dispatch = false; - bool any_pending_request = false; - _GLFWwindow *window = _glfw.windowListHead; - while (window) { - if (window->ns.renderFrameRequested && displayID == displayIDForWindow(window)) { - any_pending_request = true; - break; - } - window = window->next; - } - link = dl->displayLink; - if (!any_pending_request && link && link_is_running(link)) { - need_stop = true; - link_retain(link); - dl->lastRenderFrameRequestedAt = 0; - } - } - os_unfair_lock_unlock(lock); - if (need_stop && link) { - link_stop(link); - link_release(link); + if (dl->displayID != displayID) continue; + if (dl->displayLink && link_is_running(dl->displayLink) && !has_pending_render_frame_request(displayID)) { + link_stop(dl->displayLink); + dl->lastRenderFrameRequestedAt = 0; } } } diff --git a/glfw/cocoa_init.m b/glfw/cocoa_init.m index 0561e4f34..74be33917 100644 --- a/glfw/cocoa_init.m +++ b/glfw/cocoa_init.m @@ -326,34 +326,6 @@ static GLFWapplicationwillfinishlaunchingfun finish_launching_callback = NULL; if (finish_launching_callback) finish_launching_callback(false); } -- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename { - (void)sender; - if (!filename || !_glfw.ns.url_open_callback) return NO; - const char *url = NULL; - @try { - url = [[[NSURL fileURLWithPath:filename] absoluteString] UTF8String]; - } @catch (NSException *exc) { - NSLog(@"Converting openFile filename: %@ failed with error: %@", filename, exc.reason); - return NO; - } - if (!url) return NO; - return _glfw.ns.url_open_callback(url); -} - -- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames { - (void)sender; - if (!_glfw.ns.url_open_callback || !filenames) return; - for (id x in filenames) { - NSString *filename = x; - const char *url = NULL; - @try { - url = [[[NSURL fileURLWithPath:filename] absoluteString] UTF8String]; - } @catch (NSException *exc) { NSLog(@"Converting openFiles filename: %@ failed with error: %@", filename, exc.reason); } - if (url) _glfw.ns.url_open_callback(url); - } -} - -// Remove openFile and openFiles when the minimum supported macOS version is 10.13 - (void)application:(NSApplication *)sender openURLs:(NSArray *)urls { (void)sender; if (!_glfw.ns.url_open_callback || !urls) return; diff --git a/glfw/cocoa_monitor.m b/glfw/cocoa_monitor.m index eed836500..86c038f03 100644 --- a/glfw/cocoa_monitor.m +++ b/glfw/cocoa_monitor.m @@ -35,7 +35,6 @@ #include #include -#include #include @@ -43,14 +42,11 @@ // static char * getDisplayName(CGDirectDisplayID displayID, NSScreen *screen) { - // IOKit doesn't work on Apple Silicon anymore - // Luckily, 10.15 introduced -[NSScreen localizedName]. - // Use it if available, and fall back to IOKit otherwise. + // IOKit doesn't work on Apple Silicon anymore, so use + // -[NSScreen localizedName] and fall back to IOKit if there is no screen. if (screen) { - if ([screen respondsToSelector:@selector(localizedName)]) { - NSString *name = [screen valueForKey:@"localizedName"]; - if (name) { return _glfw_strdup([name UTF8String]); } - } + NSString *name = screen.localizedName; + if (name) { return _glfw_strdup([name UTF8String]); } } io_iterator_t it; io_service_t service; diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index b5c00f1b4..c0efb89f3 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -81,10 +81,8 @@ uti_to_mime(NSString *uti) { buf[j] = 0; return buf; } - if (@available(macOS 11.0, *)) { - UTType *t = [UTType typeWithIdentifier:uti]; // auto-released - if (t.preferredMIMEType != nil) return [t.preferredMIMEType UTF8String]; - } + UTType *t = [UTType typeWithIdentifier:uti]; // auto-released + if (t.preferredMIMEType != nil) return [t.preferredMIMEType UTF8String]; return ""; } @@ -2352,14 +2350,10 @@ _glfwPlatformUpdateIMEState(_GLFWwindow *w, const GLFWIMEUpdateEvent *ev) { return NO; } -#if (TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) - - (NSAccessibilityRole)accessibilityRole { return NSAccessibilityTextAreaRole; } -#endif - - (NSString *)accessibilitySelectedText { NSString *text = nil; if (_glfw.callbacks.get_current_selection) { @@ -3243,16 +3237,8 @@ _glfwPlatformHideWindow(_GLFWwindow *window) { if (_glfwPlatformWindowVisible(w)) num_visible++; } if (!num_visible) { - // yieldActivationToApplication was introduced in macOS 14 (Sonoma) - SEL selector = NSSelectorFromString(@"yieldActivationToApplication:"); - if ([NSApp respondsToSelector:selector]) { - [NSApp performSelector:selector withObject:app]; - [app activateWithOptions:0]; - } else { -#define NSApplicationActivateIgnoringOtherApps 2 - [app activateWithOptions:NSApplicationActivateIgnoringOtherApps]; -#undef NSApplicationActivateIgnoringOtherApps - } + [NSApp yieldActivationToApplication:app]; + [app activateWithOptions:0]; } } } @@ -3689,9 +3675,7 @@ bool _glfwPlatformIsFullscreen(_GLFWwindow *w, unsigned int flags) { NSWindow *window = w->ns.object; bool traditional = !(flags & 1); - if (traditional) { - if (@available(macOS 10.15.7, *)) return w->ns.in_traditional_fullscreen; - } + if (traditional) return w->ns.in_traditional_fullscreen; NSWindowStyleMask sm = [window styleMask]; return sm & NSWindowStyleMaskFullScreen; } @@ -3720,30 +3704,28 @@ _glfwUpdateNotchCover(_GLFWwindow *w) { w->ns.notch_cover_window = nil; } if (!w->ns.in_traditional_fullscreen) return; - if (@available(macOS 12.0, *)) { - CGFloat insetTop = window.screen.safeAreaInsets.top; - if (insetTop <= 0) return; - NSRect sf = [window.screen frame]; - NSWindow *bg_window = [[NSWindow alloc] initWithContentRect:sf styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]; - [bg_window setBackgroundColor:[NSColor clearColor]]; - [bg_window setHasShadow:NO]; - [bg_window setOpaque:NO]; - [bg_window setIgnoresMouseEvents:YES]; - [bg_window setReleasedWhenClosed:NO]; - [bg_window setColorSpace:[window colorSpace]]; - // Add a colored subview only in the notch strip area - NSView *notchView = [[NSView alloc] initWithFrame:NSMakeRect(0, sf.size.height - insetTop, sf.size.width, insetTop)]; - notchView.wantsLayer = YES; - unsigned int c = w->ns.notch_cover_color; - float a = w->ns.notch_cover_opacity; - notchView.layer.backgroundColor = - [NSColor colorWithSRGBRed:((c >> 16) & 0xFF) / 255.0 green:((c >> 8) & 0xFF) / 255.0 blue:(c & 0xFF) / 255.0 alpha:a].CGColor; - [bg_window.contentView addSubview:notchView]; - // must be above otherwise shadow of main window is rendered over bg_window - [window addChildWindow:bg_window ordered:NSWindowAbove]; - w->ns.notch_cover_window = bg_window; - [notchView release]; - } + CGFloat insetTop = window.screen.safeAreaInsets.top; + if (insetTop <= 0) return; + NSRect sf = [window.screen frame]; + NSWindow *bg_window = [[NSWindow alloc] initWithContentRect:sf styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:NO]; + [bg_window setBackgroundColor:[NSColor clearColor]]; + [bg_window setHasShadow:NO]; + [bg_window setOpaque:NO]; + [bg_window setIgnoresMouseEvents:YES]; + [bg_window setReleasedWhenClosed:NO]; + [bg_window setColorSpace:[window colorSpace]]; + // Add a colored subview only in the notch strip area + NSView *notchView = [[NSView alloc] initWithFrame:NSMakeRect(0, sf.size.height - insetTop, sf.size.width, insetTop)]; + notchView.wantsLayer = YES; + unsigned int c = w->ns.notch_cover_color; + float a = w->ns.notch_cover_opacity; + notchView.layer.backgroundColor = + [NSColor colorWithSRGBRed:((c >> 16) & 0xFF) / 255.0 green:((c >> 8) & 0xFF) / 255.0 blue:(c & 0xFF) / 255.0 alpha:a].CGColor; + [bg_window.contentView addSubview:notchView]; + // must be above otherwise shadow of main window is rendered over bg_window + [window addChildWindow:bg_window ordered:NSWindowAbove]; + w->ns.notch_cover_window = bg_window; + [notchView release]; } bool @@ -3754,60 +3736,43 @@ _glfwPlatformToggleFullscreen(_GLFWwindow *w, unsigned int flags) { bool ignore_safe_area_insets = flags & 2; NSWindowStyleMask sm = [window styleMask]; if (traditional) { - if (@available(macOS 10.15.7, *)) { - // As of Big Turd NSWindowStyleMaskFullScreen is no longer usable - // Also no longer compatible after a minor release of macOS 10.15.7 - if (!w->ns.in_traditional_fullscreen) { - // Apple throws NSGenericException if setStyleMask: clears - // NSWindowStyleMaskFullScreen outside a transition (see #9572). - // Split View sets this flag via the system, so fall back to - // Cocoa fullscreen toggle instead of the traditional path. - if (sm & NSWindowStyleMaskFullScreen) { - [window toggleFullScreen:nil]; - return false; - } - w->ns.pre_full_screen_style_mask = sm; - w->ns.pre_traditional_fullscreen_frame = [window frame]; - [window setStyleMask:NSWindowStyleMaskBorderless]; - [[NSApplication sharedApplication] setPresentationOptions:NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock]; - NSRect screenFrame = [window.screen frame]; - if (!ignore_safe_area_insets) { - if (@available(macOS 12.0, *)) { screenFrame.size.height -= window.screen.safeAreaInsets.top; } - } - [window setFrame:screenFrame display:YES]; - w->ns.in_traditional_fullscreen = true; - if (!ignore_safe_area_insets) _glfwUpdateNotchCover(w); - } else { - made_fullscreen = false; - if (sm & NSWindowStyleMaskFullScreen) { - // Split View added NSWindowStyleMaskFullScreen on top of our - // traditional fullscreen. We can't clear that flag directly - // (NSGenericException), so trigger a Cocoa exit and defer the - // traditional fullscreen cleanup to windowDidExitFullScreen: - // which fires after macOS finishes its async transition (#9572). - // Return true to prevent the caller from setting the window - // frame during the Cocoa exit animation. - [[NSApplication sharedApplication] setPresentationOptions:NSApplicationPresentationDefault]; - [window toggleFullScreen:nil]; - return true; - } else { - [window setStyleMask:w->ns.pre_full_screen_style_mask]; - [[NSApplication sharedApplication] setPresentationOptions:NSApplicationPresentationDefault]; - w->ns.in_traditional_fullscreen = false; - _glfwUpdateNotchCover(w); - } + if (!w->ns.in_traditional_fullscreen) { + // Apple throws NSGenericException if setStyleMask: clears + // NSWindowStyleMaskFullScreen outside a transition (see #9572). + // Split View sets this flag via the system, so fall back to + // Cocoa fullscreen toggle instead of the traditional path. + if (sm & NSWindowStyleMaskFullScreen) { + [window toggleFullScreen:nil]; + return false; } + w->ns.pre_full_screen_style_mask = sm; + w->ns.pre_traditional_fullscreen_frame = [window frame]; + [window setStyleMask:NSWindowStyleMaskBorderless]; + [[NSApplication sharedApplication] setPresentationOptions:NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock]; + NSRect screenFrame = [window.screen frame]; + if (!ignore_safe_area_insets) screenFrame.size.height -= window.screen.safeAreaInsets.top; + [window setFrame:screenFrame display:YES]; + w->ns.in_traditional_fullscreen = true; + if (!ignore_safe_area_insets) _glfwUpdateNotchCover(w); } else { - bool in_fullscreen = sm & NSWindowStyleMaskFullScreen; - if (!(in_fullscreen)) { - sm |= NSWindowStyleMaskBorderless | NSWindowStyleMaskFullScreen; - [[NSApplication sharedApplication] setPresentationOptions:NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock]; - } else { - made_fullscreen = false; - sm &= ~(NSWindowStyleMaskBorderless | NSWindowStyleMaskFullScreen); + made_fullscreen = false; + if (sm & NSWindowStyleMaskFullScreen) { + // Split View added NSWindowStyleMaskFullScreen on top of our + // traditional fullscreen. We can't clear that flag directly + // (NSGenericException), so trigger a Cocoa exit and defer the + // traditional fullscreen cleanup to windowDidExitFullScreen: + // which fires after macOS finishes its async transition (#9572). + // Return true to prevent the caller from setting the window + // frame during the Cocoa exit animation. [[NSApplication sharedApplication] setPresentationOptions:NSApplicationPresentationDefault]; + [window toggleFullScreen:nil]; + return true; + } else { + [window setStyleMask:w->ns.pre_full_screen_style_mask]; + [[NSApplication sharedApplication] setPresentationOptions:NSApplicationPresentationDefault]; + w->ns.in_traditional_fullscreen = false; + _glfwUpdateNotchCover(w); } - [window setStyleMask:sm]; } // Changing the style mask causes the first responder to be cleared [window makeFirstResponder:w->ns.view]; diff --git a/gpu/metal/surfaces.m b/gpu/metal/surfaces.m index bd05df1fc..0559564c6 100644 --- a/gpu/metal/surfaces.m +++ b/gpu/metal/surfaces.m @@ -95,7 +95,7 @@ surface_create(void *driver, const GPUNativeWindow *native, const GPUSurfaceConf [s->layer setOpaque:config->transparent ? NO : YES]; [s->layer setMaximumDrawableCount:3]; [s->layer setAllowsNextDrawableTimeout:YES]; - // kitty paces rendering itself, using CVDisplayLink, as with OpenGL, + // kitty paces rendering itself, using CADisplayLink, as with OpenGL, // where the swap interval is zero, see surface_set_swap_interval() [s->layer setDisplaySyncEnabled:NO]; configure_layer(s); diff --git a/gpu/metal/version.h b/gpu/metal/version.h index 536c533cf..1653e0a2f 100644 --- a/gpu/metal/version.h +++ b/gpu/metal/version.h @@ -8,6 +8,5 @@ #pragma once // The version of the Metal Shading Language shaders are compiled to, as -// major * 10 + minor. MSL 2.4 is supported from macOS 12, the minimum -// version of macOS supported by kitty. +// major * 10 + minor. MSL 2.4 is supported from macOS 12, kitty requires macOS 14. #define MSL_VERSION 24 diff --git a/gpu/opengl/nsgl.m b/gpu/opengl/nsgl.m index 87a70e253..d3da5c2e5 100644 --- a/gpu/opengl/nsgl.m +++ b/gpu/opengl/nsgl.m @@ -145,7 +145,7 @@ surface_create(const GPUNativeWindow *native, const GPUSurfaceConfig *config, ui GLint opaque = 0; [s->context setValues:&opaque forParameter:NSOpenGLContextParameterSurfaceOpacity]; } - // Swap intervals do not work as of Mojave, kitty uses CVDisplayLink instead + // Swap intervals do not work as of Mojave, kitty uses CADisplayLink instead GLint interval = 0; [s->context setValues:&interval forParameter:NSOpenGLContextParameterSwapInterval]; attach_to_view(s, s->context); @@ -168,7 +168,7 @@ present(GLSurface *s) { static void set_swap_interval(GLSurface *s, int interval) { - // As of Mojave this does not work so kitty uses CVDisplayLink instead + // As of Mojave this does not work so kitty uses CADisplayLink instead (void)s; (void)interval; } diff --git a/kitty/boss.py b/kitty/boss.py index b488b2c59..46fb6a62d 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -46,7 +46,6 @@ from .config import common_opts_as_dict, prepare_config_file_for_editing, store_ from .constants import ( RC_ENCRYPTION_PROTOCOL_VERSION, appname, - cache_dir, clear_handled_signals, config_dir, handled_signals, @@ -175,9 +174,7 @@ from .utils import ( is_ok_to_read_image_file, is_ok_to_read_image_path, is_path_in_temp_dir, - less_version, log_error, - macos_version, open_url, parse_address_spec, parse_os_window_state, @@ -2710,15 +2707,6 @@ class Boss: tab = self.active_tab if tab is not None: bdata = data.encode('utf-8') if isinstance(data, str) else data - if is_macos and cmd[0] == '/usr/bin/less' and macos_version()[:2] < (12, 3): - # the system less before macOS 12.3 barfs up OSC codes, so sanitize them ourselves - sentinel = os.path.join(cache_dir(), 'less-is-new-enough') - if not os.path.exists(sentinel): - if less_version(cmd[0]) >= 581: - open(sentinel, 'w').close() - else: - bdata = re.sub(rb'\x1b\].*?\x1b\\', b'', bdata) - return tab.new_special_window( SpecialWindow(cmd, bdata, title or _('History'), overlay_for=window.id, cwd=window.cwd_of_child), copy_colors_from=self.active_window ) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index 390d43f02..0689f81ab 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -437,8 +437,7 @@ do_notification_callback(const char *identifier, const char *event, const char * (void)(center); (void)notification; UNNotificationPresentationOptions options = UNNotificationPresentationOptionSound; - if (@available(macOS 11.0, *)) options |= UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner; - else options |= (1 << 2); // UNNotificationPresentationOptionAlert avoid deprecated warning + options |= UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner; completionHandler(options); } @@ -540,20 +539,11 @@ schedule_notification( if (appname) content.threadIdentifier = @(appname); if (category_id) content.categoryIdentifier = @(category_id); if (!muted) content.sound = [UNNotificationSound defaultSound]; -#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000 switch (urgency) { case 0: content.interruptionLevel = UNNotificationInterruptionLevelPassive; case 2: content.interruptionLevel = UNNotificationInterruptionLevelCritical; default: content.interruptionLevel = UNNotificationInterruptionLevelActive; } -#else - if ([content respondsToSelector:@selector(interruptionLevel)]) { - NSUInteger level = 1; - if (urgency == 0) level = 0; - else if (urgency == 2) level = 3; - [content setValue:@(level) forKey:@"interruptionLevel"]; - } -#endif if (image_path) { @try { NSError *error; @@ -1396,12 +1386,7 @@ bundle_image_as_png(PyObject *self UNUSED, PyObject *args, PyObject *kw) { } break; case 2: return render_emoji(@(b), image_size, output_path); default: - if (@available(macOS 11.0, *)) { - icon = [NSImage imageWithSystemSymbolName:@(b) accessibilityDescription:@""]; // autoreleased - } else { - PyErr_SetString(PyExc_ValueError, "Your version of macOS is too old to use symbol images, need >= 11.0"); - return NULL; - } + icon = [NSImage imageWithSystemSymbolName:@(b) accessibilityDescription:@""]; // autoreleased break; } if (!icon) { diff --git a/kitty/utils.py b/kitty/utils.py index 5826af919..1f4db9ab7 100644 --- a/kitty/utils.py +++ b/kitty/utils.py @@ -1032,29 +1032,6 @@ def path_from_osc7_url(url: str | bytes) -> str: return ans.replace('\0', '') -@run_once -def macos_version() -> tuple[int, ...]: - # platform.mac_ver does not work thanks to Apple's stupid "hardening", so just use sw_vers - import subprocess - - try: - o = subprocess.check_output(['sw_vers', '-productVersion'], stderr=subprocess.STDOUT).decode() - except Exception: - return 0, 0, 0 - return tuple(map(int, o.strip().split('.'))) - - -@lru_cache(maxsize=2) -def less_version(less_exe: str = 'less') -> int: - import subprocess - - o = subprocess.check_output([less_exe, '-V'], stderr=subprocess.STDOUT).decode() - m = re.match(r'less (\d+)', o) - if m is None: - raise ValueError(f'Invalid version string for less: {o}') - return int(m.group(1)) - - def is_pid_alive(pid: int) -> bool: try: os.kill(pid, 0) diff --git a/setup.py b/setup.py index dfcbe9256..75a4f0c5c 100755 --- a/setup.py +++ b/setup.py @@ -1247,7 +1247,7 @@ def glfw_init_env( elif module == 'cocoa': ans.cppflags.append('-DGL_SILENCE_DEPRECATION') - for f_ in 'Cocoa IOKit CoreFoundation CoreVideo QuartzCore UniformTypeIdentifiers'.split(): + for f_ in 'Cocoa IOKit CoreFoundation QuartzCore UniformTypeIdentifiers'.split(): ans.ldpaths.extend(('-framework', f_)) elif module == 'wayland': @@ -2129,7 +2129,7 @@ def macos_info_plist(for_quake: str = '') -> bytes: NSHumanReadableCopyright=time.strftime('Copyright %Y, Kovid Goyal'), CFBundleGetInfoString='kitty - The fast, feature-rich, GPU based terminal emulator. https://sw.kovidgoyal.net/kitty/', # Operating System Version - LSMinimumSystemVersion='12.0.0', + LSMinimumSystemVersion='14.0.0', # Categorization CFBundlePackageType='APPL', CFBundleSignature='????',