mirror of
https://github.com/godotengine/godot.git
synced 2025-04-07 00:44:24 +08:00
Merge pull request #103857 from bruvzg/macos_trans_b
[macOS] Enable transparency for windows with decorations.
This commit is contained in:
commit
89a2f3634c
@ -265,9 +265,15 @@ void DisplayServerMacOS::set_window_per_pixel_transparency_enabled(bool p_enable
|
||||
return;
|
||||
}
|
||||
if (p_enabled) {
|
||||
[wd.window_object setBackgroundColor:[NSColor clearColor]];
|
||||
[wd.window_object setOpaque:NO];
|
||||
[wd.window_object setHasShadow:NO];
|
||||
if (wd.borderless) {
|
||||
[wd.window_object setBackgroundColor:[NSColor clearColor]];
|
||||
[wd.window_object setHasShadow:NO];
|
||||
} else {
|
||||
// Note: transparent and not borderless - set alpha to non-zero value to ensure window shadow is rendered correctly.
|
||||
[wd.window_object setBackgroundColor:[NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:0.004f]];
|
||||
[wd.window_object setHasShadow:YES];
|
||||
}
|
||||
CALayer *layer = [(NSView *)wd.window_view layer];
|
||||
if (layer) {
|
||||
[layer setBackgroundColor:[NSColor clearColor].CGColor];
|
||||
@ -286,7 +292,9 @@ void DisplayServerMacOS::set_window_per_pixel_transparency_enabled(bool p_enable
|
||||
}
|
||||
[wd.window_object setBackgroundColor:bg_color];
|
||||
[wd.window_object setOpaque:YES];
|
||||
[wd.window_object setHasShadow:YES];
|
||||
if (!wd.borderless) {
|
||||
[wd.window_object setHasShadow:YES];
|
||||
}
|
||||
CALayer *layer = [(NSView *)wd.window_view layer];
|
||||
if (layer) {
|
||||
[layer setBackgroundColor:bg_color.CGColor];
|
||||
@ -2622,12 +2630,17 @@ void DisplayServerMacOS::window_set_flag(WindowFlags p_flag, bool p_enabled, Win
|
||||
wd.borderless = p_enabled;
|
||||
if (p_enabled) {
|
||||
[wd.window_object setStyleMask:NSWindowStyleMaskBorderless];
|
||||
} else {
|
||||
[wd.window_object setHasShadow:NO];
|
||||
if (wd.layered_window) {
|
||||
wd.layered_window = false;
|
||||
set_window_per_pixel_transparency_enabled(false, p_window);
|
||||
[wd.window_object setBackgroundColor:[NSColor clearColor]];
|
||||
}
|
||||
} else {
|
||||
[wd.window_object setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | (wd.extend_to_title ? NSWindowStyleMaskFullSizeContentView : 0) | (wd.resize_disabled ? 0 : NSWindowStyleMaskResizable)];
|
||||
[wd.window_object setHasShadow:YES];
|
||||
if (wd.layered_window) {
|
||||
// Note: transparent and not borderless - set alpha to non-zero value to ensure window shadow is rendered correctly.
|
||||
[wd.window_object setBackgroundColor:[NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:0.004f]];
|
||||
}
|
||||
// Force update of the window styles.
|
||||
NSRect frameRect = [wd.window_object frame];
|
||||
[wd.window_object setFrame:NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width + 1, frameRect.size.height) display:NO];
|
||||
@ -2659,11 +2672,6 @@ void DisplayServerMacOS::window_set_flag(WindowFlags p_flag, bool p_enabled, Win
|
||||
if (wd.fullscreen) {
|
||||
return;
|
||||
}
|
||||
if (p_enabled) {
|
||||
[wd.window_object setStyleMask:NSWindowStyleMaskBorderless]; // Force borderless.
|
||||
} else if (!wd.borderless) {
|
||||
[wd.window_object setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | (wd.extend_to_title ? NSWindowStyleMaskFullSizeContentView : 0) | (wd.resize_disabled ? 0 : NSWindowStyleMaskResizable)];
|
||||
}
|
||||
wd.layered_window = p_enabled;
|
||||
set_window_per_pixel_transparency_enabled(p_enabled, p_window);
|
||||
// Force update of the window styles.
|
||||
|
@ -184,10 +184,12 @@
|
||||
}
|
||||
|
||||
// Restore borderless, transparent and resizability state.
|
||||
if (wd.borderless || wd.layered_window) {
|
||||
if (wd.borderless) {
|
||||
[wd.window_object setStyleMask:NSWindowStyleMaskBorderless];
|
||||
[wd.window_object setHasShadow:NO];
|
||||
} else {
|
||||
[wd.window_object setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | (wd.extend_to_title ? NSWindowStyleMaskFullSizeContentView : 0) | (wd.resize_disabled ? 0 : NSWindowStyleMaskResizable)];
|
||||
[wd.window_object setHasShadow:YES];
|
||||
}
|
||||
if (wd.layered_window) {
|
||||
ds->set_window_per_pixel_transparency_enabled(true, window_id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user