diff --git a/Makefile b/Makefile index cea23d81..c4a645ab 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ CFLAGS := -arch $(ARCH) -mmacosx-version-min=$(MIN_VER) $(AVAIL) \ LDFLAGS := -arch $(ARCH) -mmacosx-version-min=$(MIN_VER) \ -dynamiclib -install_name @rpath/notproton.dylib -FRAMEWORKS := -framework CoreFoundation -framework CoreGraphics +FRAMEWORKS := -framework AppKit -framework CoreFoundation -framework CoreGraphics -framework QuartzCore DOBBY_DIR := build/dobby DOBBY_LIBS := $(DOBBY_DIR)/libdobby.a \ @@ -69,7 +69,7 @@ ARM64_DYLIB := $(OUT_DIR)/notproton.arm64.dylib X86_STUB := $(OUT_DIR)/notproton.x86_64.dylib TARGET := $(OUT_DIR)/notproton.dylib -OBJS := $(patsubst %.c,$(OUT_DIR)/%.o,$(SRCS)) +OBJS := $(patsubst %.c,$(OUT_DIR)/%.o,$(SRCS)) $(OUT_DIR)/dylib/feats/rounded_windows.o DEPS := $(OBJS:.o=.d) .PHONY: all clean rebuild dobby deploy dylib dylib-install sigcheck fonts fonts-install app-payload app app-zip \ @@ -545,6 +545,10 @@ $(OUT_DIR)/%.o: %.c @mkdir -p $(dir $@) $(CC) $(CFLAGS) -c $< -o $@ +$(OUT_DIR)/%.o: %.m + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -fobjc-arc -c $< -o $@ + $(RUN_SCRIPT_H): dylib/feats/compat_run.sh dylib/embed_script.py @mkdir -p $(GENERATED_DIR) python3 dylib/embed_script.py $< $@ RUN_SCRIPT diff --git a/app/Sources/NotProtonApp/Resources/Localization/Localizable.xcstrings b/app/Sources/NotProtonApp/Resources/Localization/Localizable.xcstrings index 96beeaf1..d2c6c68e 100644 --- a/app/Sources/NotProtonApp/Resources/Localization/Localizable.xcstrings +++ b/app/Sources/NotProtonApp/Resources/Localization/Localizable.xcstrings @@ -9398,6 +9398,34 @@ } } }, + "Restart Steam to apply this setting." : { + "localizations" : { + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "Starte Steam neu, um diese Einstellung anzuwenden." + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Redémarrez Steam pour appliquer ce réglage." + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "Riavvia Steam per applicare questa impostazione." + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "重启 Steam 后应用此设置。" + } + } + } + }, "Restart Steam to update its list of compatibility tools." : { "localizations" : { "de" : { @@ -9594,6 +9622,34 @@ } } }, + "Round Steam windows" : { + "localizations" : { + "de" : { + "stringUnit" : { + "state" : "translated", + "value" : "Abgerundete Steam-Fenster" + } + }, + "fr" : { + "stringUnit" : { + "state" : "translated", + "value" : "Arrondir les fenêtres Steam" + } + }, + "it" : { + "stringUnit" : { + "state" : "translated", + "value" : "Arrotonda gli angoli delle finestre di Steam" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "Steam 窗口圆角" + } + } + } + }, "Run" : { "localizations" : { "de" : { diff --git a/app/Sources/NotProtonApp/Views/StatusView.swift b/app/Sources/NotProtonApp/Views/StatusView.swift index 79819198..fda652a6 100644 --- a/app/Sources/NotProtonApp/Views/StatusView.swift +++ b/app/Sources/NotProtonApp/Views/StatusView.swift @@ -160,6 +160,7 @@ struct StatusRow: View { struct StatusView: View { @Environment(SystemStatus.self) private var status + @AppStorage("roundSteamWindows") private var roundSteamWindows = false private static let updateBlockPrompt = String(localized: "Steam client updates may break NotProton. If you don't want to wait for NotProton to be updated to be compatible with future Steam versions at the cost of not getting updates to the Steam client, you can stop the Steam client from updating itself.") @@ -331,6 +332,11 @@ struct StatusView: View { ) } updateBlockRow(snapshot.updateBlocked) + StatusRow( + title: String(localized: "Round Steam windows"), + value: String(localized: "Restart Steam to apply this setting."), + toggle: $roundSteamWindows + ) StatusRow( title: String(localized: "Controller permission"), value: String(localized: "Clear Steam's controller permission so macOS asks for it again."), diff --git a/dylib/core/loader.c b/dylib/core/loader.c index a21ec34b..54f092f2 100644 --- a/dylib/core/loader.c +++ b/dylib/core/loader.c @@ -9,6 +9,7 @@ #include "../feats/ceg.h" #include "../feats/compat.h" #include "../feats/input_access.h" +#include "../feats/rounded_windows.h" #include "dobby.h" #include @@ -337,6 +338,7 @@ static void np_init(void) { if (is_main_helper(pn)) { np_log_attach(); np_hooks_spawn_install(); + np_rounded_windows_install(); return; } if (strcmp(pn, "steam_osx") != 0) diff --git a/dylib/feats/rounded_windows.h b/dylib/feats/rounded_windows.h new file mode 100644 index 00000000..e1ceb12e --- /dev/null +++ b/dylib/feats/rounded_windows.h @@ -0,0 +1,3 @@ +#pragma once + +void np_rounded_windows_install(void); diff --git a/dylib/feats/rounded_windows.m b/dylib/feats/rounded_windows.m new file mode 100644 index 00000000..5b2a8845 --- /dev/null +++ b/dylib/feats/rounded_windows.m @@ -0,0 +1,135 @@ +#import +#import +#import +#include +#include + +#include "rounded_windows.h" + +// Use the SDL3 already loaded by Steam Helper. +typedef struct SDL_Window SDL_Window; +enum { + SDL_FULLSCREEN = 0x1, + SDL_MODAL = 0x1000, + SDL_ALWAYS_ON_TOP = 0x10000, + SDL_UTILITY = 0x20000, + SDL_TOOLTIP = 0x40000, + SDL_POPUP_MENU = 0x80000, +}; +static struct { + SDL_Window **(*windows)(int *); + uint32_t (*properties)(SDL_Window *); + void *(*pointer)(uint32_t, const char *, void *); + uint64_t (*flags)(SDL_Window *); + void (*free)(void *); +} sdl; + +static BOOL load_sdl(void) { + sdl.windows = dlsym(RTLD_DEFAULT, "SDL_GetWindows"); + sdl.properties = dlsym(RTLD_DEFAULT, "SDL_GetWindowProperties"); + sdl.pointer = dlsym(RTLD_DEFAULT, "SDL_GetPointerProperty"); + sdl.flags = dlsym(RTLD_DEFAULT, "SDL_GetWindowFlags"); + sdl.free = dlsym(RTLD_DEFAULT, "SDL_free"); + return sdl.windows && sdl.properties && sdl.pointer && sdl.flags && sdl.free; +} + +static BOOL is_desktop_sdl_window(NSWindow *window) { + const uint64_t excluded = SDL_FULLSCREEN | SDL_MODAL | SDL_ALWAYS_ON_TOP | + SDL_UTILITY | SDL_TOOLTIP | SDL_POPUP_MENU; + int count = 0; + SDL_Window **windows = sdl.windows(&count); + if (!windows) + return NO; + + BOOL eligible = NO; + for (int i = 0; i < count; ++i) { + uint32_t properties = sdl.properties(windows[i]); + if (properties && + sdl.pointer(properties, "SDL.window.cocoa.window", NULL) == (__bridge void *)window) { + eligible = (sdl.flags(windows[i]) & excluded) == 0; + break; + } + } + sdl.free(windows); + return eligible; +} + +static BOOL can_round(NSWindow *window) { + const NSWindowStyleMask excluded = NSWindowStyleMaskTitled | NSWindowStyleMaskFullScreen | + NSWindowStyleMaskUtilityWindow | NSWindowStyleMaskDocModalWindow | NSWindowStyleMaskNonactivatingPanel; + return !(window.styleMask & excluded) && window.level == NSNormalWindowLevel && + window.isVisible && !window.isMiniaturized && !window.parentWindow && !window.isSheet && + ![window isKindOfClass:NSPanel.class] && window.contentView != nil; +} + +static char restore_corners_key; + +static void update_corners(NSWindow *window) { + dispatch_block_t restore = objc_getAssociatedObject(window, &restore_corners_key); + BOOL round = can_round(window) && is_desktop_sdl_window(window); + if (round == (restore != nil)) + return; + + CALayer *layer = window.contentView.layer; + if (round && (!layer || layer.mask || layer.cornerRadius != 0)) + return; + + [CATransaction begin]; + [CATransaction setDisableActions:YES]; + if (restore) { + restore(); + objc_setAssociatedObject(window, &restore_corners_key, nil, OBJC_ASSOCIATION_COPY_NONATOMIC); + } else { + __weak NSWindow *weak_window = window; + NSColor *background = window.backgroundColor; + BOOL window_opaque = window.opaque; + BOOL layer_opaque = layer.opaque; + BOOL clips = layer.masksToBounds; + CALayerCornerCurve curve = layer.cornerCurve; + objc_setAssociatedObject(window, &restore_corners_key, ^{ + weak_window.backgroundColor = background; + weak_window.opaque = window_opaque; + layer.opaque = layer_opaque; + layer.masksToBounds = clips; + layer.cornerCurve = curve; + layer.cornerRadius = 0; + }, OBJC_ASSOCIATION_COPY_NONATOMIC); + + // Keep SDL's borderless window and clip only its composited content. + window.opaque = NO; + window.backgroundColor = NSColor.clearColor; + layer.opaque = NO; + layer.cornerCurve = kCACornerCurveContinuous; + CGFloat radius = 11; + // The macOS 26 window design has larger corners. + if (@available(macOS 26.0, *)) + radius = 17; + layer.cornerRadius = radius; + layer.masksToBounds = YES; + } + [CATransaction commit]; + [window invalidateShadow]; +} + +void np_rounded_windows_install(void) { + if (!CFPreferencesGetAppBooleanValue(CFSTR("roundSteamWindows"), CFSTR("com.notproton.NotProton"), NULL)) + return; + + dispatch_async(dispatch_get_main_queue(), ^{ + if (!load_sdl()) + return; + + NSNotificationCenter *center = NSNotificationCenter.defaultCenter; + for (NSNotificationName name in @[NSWindowDidBecomeKeyNotification, NSWindowDidResizeNotification, + NSWindowDidEnterFullScreenNotification, NSWindowDidExitFullScreenNotification]) { + [center addObserverForName:name object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) { + NSWindow *window = note.object; + if (!window.inLiveResize) + dispatch_async(dispatch_get_main_queue(), ^{ update_corners(window); }); + }]; + } + + for (NSWindow *window in NSApp.windows) + update_corners(window); + }); +}