Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The most elegant way of creating a fullscreen overlay on Mac OS X (Lion)?

I'm searching for the "best" way of creating a fullscreen overlay under Mac OS X. I want to create a transparent or semi-transparent overlay, which cares about mouse events and shows other input/output elements.

This overlay should be above every other GUI items (like the CMD-Tab overlay).

Do you know how to do it effectively? At the moment I'm playing around with this kind of code:

int windowLevel = CGShieldingWindowLevel();
NSRect windowRect = [[NSScreen mainScreen] frame];
NSWindow *overlayWindow = [[NSWindow alloc] initWithContentRect:windowRect
                                          styleMask:NSBorderlessWindowMask
                                            backing:NSBackingStoreBuffered
                                              defer:NO
                                             screen:[NSScreen mainScreen]];

[overlayWindow setReleasedWhenClosed:YES];
[overlayWindow setLevel:windowLevel];
[overlayWindow setBackgroundColor:[NSColor colorWithCalibratedRed:0.0
                                                          green:0.0
                                                           blue:0.0
                                                          alpha:0.5]];
[overlayWindow setAlphaValue:1.0];
[overlayWindow setOpaque:NO];
[overlayWindow setIgnoresMouseEvents:NO];
[overlayWindow makeKeyAndOrderFront:nil];

…and it works fine but I've got no options to initiate any kind of animations like slowly increasing the transparency (slowly dimming the screen) etc.

Although I'm not understanding how to put this window in the background, without releasing it and let it pop up time to time.

So is there a better or "standard" way to do it?

like image 893
tamasgal Avatar asked Nov 25 '11 17:11

tamasgal


People also ask

How do you fullscreen full screen on a Mac?

It's quite simple to activate full-screen mode for any app on a Mac, and there are three ways you can do this: Click the green button at the left of its toolbar, Press Command-Control-F, or. Choose View > Enter Full Screen.

What is the shortcut to full screen on a Mac?

There's also a keyboard shortcut: In macOS Big Sur and earlier, press Ctrl+Command+F to enter full-screen mode. In macOS Monterey or later, press Fn+F (Function+F).

How do you tab out of full screen on a Mac?

Go to the in-game tab and click on the overlay shortcut keys and press f5. Restart whatever game you are playing and press f5 to tab out and there you go.

How do I make Chrome open in full screen Mac?

For Chrome on macOS, in the upper-left corner of Chrome, select the green circle to go to full-screen mode, and select it again to return to the full-size screen. There are two other options to activate full-screen mode: From the menu bar, select View > Enter Full Screen.


1 Answers

You can use NSViewAnimation. Yes, it works on windows, too.

Your animation's target should be the window, and its effect should be fade-in or fade-out, depending on whether you're showing or hiding it. Leave out the frame keys, since you probably don't want to move or resize the window.

Of course, you should leave out the makeKeyAndOrderFront: message, since you'll be ordering it front with the fade-in effect.

like image 130
Peter Hosey Avatar answered Oct 01 '22 18:10

Peter Hosey