Holding the window at the top when switching spaces

I created a window using - [NSWindow setCollectionBehavior: NSWindowCollectionBehaviorCanJoinAllSpaces]. This does only half of what I want, but: when I switch the spaces, the window also switches the spaces (as expected), but my window moves back behind all the other windows in this space. This is especially bad because my application is active, but its window is below all windows of other applications. I tried changing the level to NSFloatingWindowLevel, and it really keeps it on top, but then it loses the key status (focus) when switching spaces.

I tried NSWindowCollectionBehaviorMoveToActiveSpace for collection behavior, but this is definitely not what I'm looking for.

Is there any hope? I know that there are almost no other APIs that apply to Spaces.

+5
source share
2 answers

Space is a pain. My solution was to register for a change notification as follows:

    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(activeSpaceDidChange:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil];

Then in my class WindowController:

- (void) activeSpaceDidChange:(NSNotification *)aNotification {
    if ([NSApp isActive]) [[self window] orderFront:self];
}
+2
source

For borderless windows (created using NSBorderlessWindowMask), I hit my head until I came up with the following modification for Francis:

- (void) activeSpaceDidChange:(NSNotification *)aNotification {

    if ([NSApp isActive]) 
    {
        NSRect windowRect = [[self window] frame];
        [[self window] setStyleMask:NSTitledWindowMask];
        [[self window] setStyleMask:NSBorderlessWindowMask];
        [[self window] setFrame:windowRect display:YES];
        [[NSApplication sharedApplication] activateIgnoringOtherApps : YES];
    }
}

, , , , . "Titled", "activateIgnoringOtherApps", " ", , , . , , , , . , - , , .

0

All Articles