Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make my app stay on top of fullscreen apps

I have an app which must always stay on top of other applications. I'm currently using the setLevel property for the main window to keep it on top of other desktop applications.

I'm trying to fix my app so it can also stay on top of full-screen apps in Lion. Any ideas on how this can be done?

The Application delegate looks like this:

#import "alwaysOnTopAppDelegate.h"

@implementation alwaysOnTopAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [window setLevel:NSFloatingWindowLevel];
}

@end
like image 979
Pétur Ingi Egilsson Avatar asked Sep 28 '11 09:09

Pétur Ingi Egilsson


People also ask

How do I get my apps to stay on top?

To make the active window always on top, press Ctrl + Spacebar (or the keyboard shortcut you assigned). Press the keyboard shortcut again to disable “always on top” for the active window. For script options, right-click on the AutoHotkey icon in the system tray.

How do I pin a window always on top?

In order to pin a window, right-click on the icon in your tray again and enter Pin Mode. Your cursor will change to a pin – click on the title bar of the window you want to always keep on top, and a pin will appear on that bar. It'll be the color you set in the options menu earlier.

How do I keep apps on top in Windows 10?

Just press CTRL + SPACE on whatever window you want to stay on top.

How do I keep apps on top in Windows 11?

Select the window you want to keep on top and press “Ctrl + Space” simultaneously.


2 Answers

Found the answer: The app delegate should look like this:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [window setLevel:kCGMainMenuWindowLevel-1];
    [window setCollectionBehavior:NSWindowCollectionBehaviorStationary|NSWindowCollectionBehaviorCanJoinAllSpaces|NSWindowCollectionBehaviorFullScreenAuxiliary];
}
like image 50
Pétur Ingi Egilsson Avatar answered Sep 27 '22 16:09

Pétur Ingi Egilsson


The way that Yoink works is simple: Just set "Application is Agent (UIElement)" to YES in the Info.plist for your application. It will mean it doesn't show in the dock etc. but that's probably fine for an auxiliary window (well, it was for me!). It probably makes sense to provide a menu bar item in this case so the user can stop the application easily.

like image 35
Alan Avatar answered Sep 27 '22 16:09

Alan