make window transparent

This commit is contained in:
Jesús A. Álvarez 2019-10-25 23:11:36 +02:00
parent 8e9fa50385
commit 36195df44a
2 changed files with 39 additions and 0 deletions

View File

@ -52,6 +52,40 @@ void disable_SDL2_macosx_menu_bar_keyboard_shortcuts() {
}
}
void make_window_transparent(SDL_Window * window)
{
if (!window) {
return;
}
SDL_SysWMinfo wmInfo;
SDL_VERSION(&wmInfo.version);
if (!SDL_GetWindowWMInfo(window, &wmInfo)) {
return;
}
CGColorRef clearColor = [NSColor clearColor].CGColor;
NSWindow *cocoaWindow = wmInfo.info.cocoa.window;
NSView *sdlView = cocoaWindow.contentView;
sdlView.layer.backgroundColor = [NSColor clearColor].CGColor;
cocoaWindow.backgroundColor = [NSColor clearColor];
cocoaWindow.hasShadow = NO;
cocoaWindow.opaque = NO;
// make metal layer transparent
for (NSView *view in sdlView.subviews) {
if ([view.className isEqualToString:@"SDL_cocoametalview"]) {
view.layer.opaque = NO;
view.layer.backgroundColor = clearColor;
return;
}
}
// make OpenGL surface transparent
GLint zero = 0;
[[NSOpenGLContext currentContext] setValues:&zero forParameter:NSOpenGLCPSurfaceOpacity];
}
bool is_fullscreen_osx(SDL_Window * window)
{
if (!window) {

View File

@ -751,6 +751,11 @@ static SDL_Surface * init_sdl_video(int width, int height, int bpp, Uint32 flags
}
if (flags & SDL_WINDOW_FULLSCREEN) SDL_SetWindowGrab(sdl_window, SDL_TRUE);
#ifdef __MACOSX__
extern void make_window_transparent(SDL_Window * window);
make_window_transparent(sdl_window);
#endif
// Some SDL events (regarding some native-window events), need processing
// as they are generated. SDL2 has a facility, SDL_AddEventWatch(), which
// allows events to be processed as they are generated.