macos: Set transparent background for toplevel window

Toplevel window background is almost transparent.
For fully transparent windows the (macOS) shadow calculatation
becomes really slow.
This commit is contained in:
Arjan Molenaar 2024-08-25 12:00:02 +02:00
parent ffeca06bd6
commit d23833285e
2 changed files with 8 additions and 15 deletions

View File

@ -692,24 +692,9 @@ typedef NSString *CALayerContentsGravity;
-(void)setStyleMask:(NSWindowStyleMask)styleMask -(void)setStyleMask:(NSWindowStyleMask)styleMask
{ {
gboolean was_opaque;
gboolean is_opaque;
was_opaque = (([self styleMask] & NSWindowStyleMaskTitled) != 0);
[super setStyleMask:styleMask]; [super setStyleMask:styleMask];
is_opaque = (([self styleMask] & NSWindowStyleMaskTitled) != 0);
_gdk_macos_surface_update_fullscreen_state (gdk_surface); _gdk_macos_surface_update_fullscreen_state (gdk_surface);
if (was_opaque != is_opaque)
{
[self setOpaque:is_opaque];
if (!is_opaque)
[self setBackgroundColor:[NSColor clearColor]];
}
} }
-(NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen -(NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen

View File

@ -617,6 +617,14 @@ _gdk_macos_toplevel_surface_constructed (GObject *object)
_gdk_macos_surface_set_native (GDK_MACOS_SURFACE (self), window); _gdk_macos_surface_set_native (GDK_MACOS_SURFACE (self), window);
[window setOpaque:NO];
/* Workaround: if we use full transparency, window rendering becomes slow,
* because macOS tries to dynamically calculate the shadow.
* Instead provide a tiny bit of alpha, so shadows are drawn around the window.
*/
[window setBackgroundColor:[[NSColor blackColor] colorWithAlphaComponent:0.00001]];
/* Allow NSWindow to go fullscreen */ /* Allow NSWindow to go fullscreen */
[window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];