Keeping a Window on Top

  • I'm very new to all this, so apologies for any ignorance!!!

    I have looked around and am still struggling to get this to work
    properly - I would like my app window, which is an NSPanel (although
    could be something else) to stay on top of all windows of all
    applications - in the same way as the Force Quit window does.  I have
    tried using setLevel with various options, but nothing seems to work,
    as soon as another app is clicked, it sits on top of my window!?

    The best I have come up with is:
    - (void)applicationDidResignActive:(NSNotification *)n {
    [NSApp activateIgnoringOtherApps:YES];
    [theDialogWindow makeKeyAndOrderFront:nil];
    }

    Which works, but is not very nice as it completely prevents use of
    other applications, which I think for a "good experience" I should
    allow, so in the same way as the Force Quit Window, it can lose focus,
    but stays on top!

    Any points would be really great - thanks

    Ben.
  • > I have looked around and am still struggling to get this to work
    > properly - I would like my app window, which is an NSPanel (although
    > could be something else) to stay on top of all windows of all
    > applications - in the same way as the Force Quit window does.  I have
    > tried using setLevel with various options, but nothing seems to work,
    > as soon as another app is clicked, it sits on top of my window!?

      You might want to take a closer look at the NSWindow API reference.
    Particularly, -setLevel: (see the constants for the appropriate
    setting).

    --
    I.S.
  • Le 20 déc. 07 à 16:00, Ben Robinson a écrit :

    > I'm very new to all this, so apologies for any ignorance!!!
    >
    > I have looked around and am still struggling to get this to work
    > properly - I would like my app window, which is an NSPanel (although
    > could be something else) to stay on top of all windows of all
    > applications - in the same way as the Force Quit window does.  I
    > have tried using setLevel with various options, but nothing seems to
    > work, as soon as another app is clicked, it sits on top of my window!?
    >
    > The best I have come up with is:
    > - (void)applicationDidResignActive:(NSNotification *)n {
    > [NSApp activateIgnoringOtherApps:YES];
    > [theDialogWindow makeKeyAndOrderFront:nil];
    > }
    >
    > Which works, but is not very nice as it completely prevents use of
    > other applications, which I think for a "good experience" I should
    > allow, so in the same way as the Force Quit Window, it can lose
    > focus, but stays on top!
    >
    > Any points would be really great - thanks
    >
    >
    > Ben.

    All windows level are not exposed in NSWindow API:
    This can do what you want.

    [self setLevel:CGWindowLevelForKey(kCGOverlayWindowLevelKey)];
  • >> all windows of all applications

      Ack! I missed the "of all applications" part, my apologies.

    > All windows level are not exposed in NSWindow API:
    > This can do what you want.
    >
    > [self setLevel:CGWindowLevelForKey(kCGOverlayWindowLevelKey)];

      This is the correct answer, of course.

    --
    I.S.
  • >> I have looked around and am still struggling to get this to work
    >> properly - I would like my app window, which is an NSPanel (although
    >> could be something else) to stay on top of all windows of all
    >> applications - in the same way as the Force Quit window does.  I have
    >> tried using setLevel with various options, but nothing seems to work,
    >> as soon as another app is clicked, it sits on top of my window!?
    >
    > You might want to take a closer look at the NSWindow API reference.
    > Particularly, -setLevel: (see the constants for the appropriate
    > setting).
    >
    > --
    > I.S.

    Thanks for that - I had tried setLevel and it didn't work, but as you
    suggested it again I tried using setLevel in the
    applicationDidResignActive method instead of activateIgnoringOtherApps
    - and that solved the problem - works exactly as I want!!
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today