Skip to content

Commit

Permalink
Cocoa: Implement GLFW_TRANSPARENT
Browse files Browse the repository at this point in the history
This is an extract of a commit, minimally edited to ensure it compiles.

Closes #663.
Related to #197.
  • Loading branch information
ckaran authored and elmindreda committed Sep 19, 2017
1 parent 3c5e34f commit 765cc1a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/cocoa_window.m
Expand Up @@ -413,7 +413,11 @@ - (void)dealloc

- (BOOL)isOpaque
{
return YES;
// Set to NO even if alphaMask is not used;
// The NSView/GLFWContentView does not need to be opaque anyway,
// and to avoid keeping track of alphaMask inside the NSView we
// just return NO here instead.
return NO;
}

- (BOOL)canBecomeKeyView
Expand Down Expand Up @@ -1081,6 +1085,12 @@ static GLFWbool createNativeWindow(_GLFWwindow* window,
if (wndconfig->ns.retina)
[window->ns.view setWantsBestResolutionOpenGLSurface:YES];

if (window->transparent)
{
[window->ns.object setOpaque:NO];
[window->ns.object setBackgroundColor:[NSColor clearColor]];
}

[window->ns.object setContentView:window->ns.view];
[window->ns.object makeFirstResponder:window->ns.view];
[window->ns.object setTitle:[NSString stringWithUTF8String:wndconfig->title]];
Expand Down
6 changes: 6 additions & 0 deletions src/nsgl_context.m
Expand Up @@ -296,6 +296,12 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
return GLFW_FALSE;
}

if (window->transparent)
{
GLint opaque = 0;
[window->context.nsgl.object setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
}

[window->context.nsgl.object setView:window->ns.view];

window->context.makeCurrent = makeContextCurrentNSGL;
Expand Down

0 comments on commit 765cc1a

Please sign in to comment.