Why isn't Liquid Glass effect applied when using pyobjc?

I can compile this

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (strong) NSWindow *window;
@property (strong) NSSlider *slider;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
    // Window size
    NSRect frame = NSMakeRect(0, 0, 400, 300);
    NSUInteger style = NSWindowStyleMaskTitled |
                       NSWindowStyleMaskClosable |
                       NSWindowStyleMaskResizable;

    self.window = [[NSWindow alloc] initWithContentRect:frame
                                              styleMask:style
                                                backing:NSBackingStoreBuffered
                                                  defer:NO];
    [self.window setTitle:@"Centered Slider Example"];
    [self.window makeKeyAndOrderFront:nil];

    // Slider size
    CGFloat sliderWidth = 200;
    CGFloat sliderHeight = 32;
    CGFloat windowWidth = self.window.frame.size.width;
    CGFloat windowHeight = self.window.frame.size.height;

    CGFloat sliderX = (windowWidth - sliderWidth) / 2;
    CGFloat sliderY = (windowHeight - sliderHeight) / 2;

    self.slider = [[NSSlider alloc] initWithFrame:NSMakeRect(sliderX, sliderY, sliderWidth, sliderHeight)];
    [self.slider setMinValue:0];
    [self.slider setMaxValue:100];
    [self.slider setDoubleValue:50];

    [self.window.contentView addSubview:self.slider];
}

@end

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSApplication *app = [NSApplication sharedApplication];
        AppDelegate *delegate = [[AppDelegate alloc] init];
        [app setDelegate:delegate];
        [app run];
    }
    return 0;
}

with

(base) johnzhou@Johns-MacBook-Pro liquidglasstest % clang -framework Foundation -framework AppKit testobjc.m

and get this neat liquid glass effect:

https://github.com/user-attachments/assets/4199493b-6011-4ad0-9c9f-25db8585e547

However if I use pyobjc to make an equivalent

import sys
from Cocoa import (
    NSApplication, NSApp, NSWindow, NSSlider, NSMakeRect,
    NSWindowStyleMaskTitled, NSWindowStyleMaskClosable,
    NSWindowStyleMaskResizable, NSBackingStoreBuffered,
    NSObject
)

class AppDelegate(NSObject):
    def applicationDidFinishLaunching_(self, notification):
        # Create the main window
        window_size = NSMakeRect(0, 0, 400, 300)
        style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable

        self.window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
            window_size, style, NSBackingStoreBuffered, False
        )
        self.window.setTitle_("Centered Slider Example")
        self.window.makeKeyAndOrderFront_(None)

        # Slider size and positioning
        slider_width = 200
        slider_height = 32
        window_width = self.window.frame().size.width
        window_height = self.window.frame().size.height

        slider_x = (window_width - slider_width) / 2
        slider_y = (window_height - slider_height) / 2

        self.slider = NSSlider.alloc().initWithFrame_(NSMakeRect(slider_x, slider_y, slider_width, slider_height))
        self.slider.setMinValue_(0)
        self.slider.setMaxValue_(100)
        self.slider.setDoubleValue_(50)

        self.window.contentView().addSubview_(self.slider)


if __name__ == "__main__":
    app = NSApplication.sharedApplication()
    delegate = AppDelegate.alloc().init()
    app.setDelegate_(delegate)
    app.run()

I get a result shown at

https://github.com/user-attachments/assets/7da022bc-122b-491d-9e08-030dcb9337c3

which does not have the new liquid glass effect.

Why is this? Is this perhaps related to the requirement that you must compile on latest Xcode as indicated in the docs? Why, is the compiler doing some magic?

Answered by galad87 in 859994022

There is no magic, macOS just checks which version of the SDK was used when compiling the app, if the SDK version is 26 or higher, it will make it go through the new UI path, if not it will get the previous UI.

I don't know how the Python bridge works, but it clearly needs to be updated or recompiled with the new SDK.

FWIW and for SEO: pyobjc is a Python bridge with Objective-C, making it possible to write apps in pyobjc that are completely native for macOS.

Accepted Answer

There is no magic, macOS just checks which version of the SDK was used when compiling the app, if the SDK version is 26 or higher, it will make it go through the new UI path, if not it will get the previous UI.

I don't know how the Python bridge works, but it clearly needs to be updated or recompiled with the new SDK.

For posterity: the main process matters so if you have a stub app that links libpython<whatever>.dylib the stub app needs to get compiled with latest sdk, not nessacarily the libpython.

Why isn't Liquid Glass effect applied when using pyobjc?
 
 
Q