FloatingWindow hides when app loses the focus?

I have an app, it has lots of windows, one of which is a Floating Window, it shows continuously updated info about the status of content in a separate document window, which is always visible, though it may not be active.

When I click on another app, my app does not disappear, its windows stay visible (which is correct), but the floating window always hides! When I click back on my app, the floating window appears again. There is NO code anywhere in the app’s activate or deactivate events that tell the floating window to do this, and nothing in the floating window that looks at the app’s active status.

Can anyone explain this? Users are complaining because they want to see the content in all of my windows, even when they’re working in other apps.

This is on macOS.

this is by design on mcOS

Seems weird, no other windows behave this way. Is there a way around it? On Windows, I use the MBS call to keep the floating window on top all the time (because it doesn’t), but that call isn’t available on macOS.

Color pickers are much the same and will do this
Its a macOS thing to hide floating windows open by an app when the app isnt front most otherwise they float above other apps and obscure them

It’s pretty wild, but I guess I could have two identical windows - one a floating window for use when the app is active, and the other a regular document window that becomes visible when the app is inactive - both displaying the same info.

Maybe the users will just have to get over it :slight_smile:

Thanks for your help!

Each window level in macOS has associated behaviors. I would suggest experimenting with the window levels. Try using NSDockWindowLevel and see what happens. A little trick I learned was that you can go between window levels like NSFloatingWindowLevel + 1 or NSFloatingWindowLevel - 1. You just have to try it out to see if you get the behavior you want.

Global floating window will make the palette float above everything.

Or changing the floating window to be a regular document window.

This code on the Mac keeps always the window on top. So, all other apps remain behind it even if/when you are working with them (Preview, Safati etc.).
But maybe I’m missing your point.
BTW: it comes from MacOSLib but it can work on its own.
Public Sub AlwaysOnTop(extends w as Window, assigns Value as Boolean)
//# Sets the window’s window level to floating window level.

#if TargetMacOS
Const NSNormalWindowLevel = 0
Const NSFloatingWindowLevel = 3
Const NSModalPanelWindowLevel = 8
Const NSDockWindowLevel = 20
Const NSMainMenuWindowLevel = 24
Const NSPopUpMenuWindowLevel = 101
Const NSScreenSaverWindowLevel = 1001

declare sub NSWindowSetLevel lib "Cocoa" selector "setLevel:" (WindowRef as integer, Level as Integer)
if Value then
  NSWindowSetLevel w.Handle, NSFloatingWindowLevel
else
  NSWindowSetLevel w.Handle, NSNormalWindowLevel
end if

#else
Declare Function SetWindowPos Lib “User32.dll” (hWnd As Integer, hWndInsertAfter As Integer, X As Int32, Y As Int32, cx As Int32, cy As Int32, uFlags As UInt32) As Int32

Const HWND_BOTTOM = 1
Const HWND_NOTOPMOST = -2
Const HWND_TOP = 0
Const HWND_TOPMOST = -1

// the combination of those are the value of the last parameter of the argument.
'const SWP_NOSIZE = 1  // Retains the current size (ignores the cx and cy parameters).
'const SWP_NOMOVE = 2  // Retains the current position (ignores X and Y parameters).
'const SWP_NOZORDER = 4  // Retains the current Z order (ignores the hWndInsertAfter parameter).
'const SWP_NOREDRAW = 8  // Does not redraw changes. If this flag is set, no repainting of any kind occurs. (applies to the client area)
'const SWP_NOACTIVATE = 10  // Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter)
'const SWP_SHOWWINDOW = 40 // Displays the window.
'const SWP_HIDEWINDOW = 80  // Hides the window.
'const SWP_NOOWNERZORDER = 200  // Does not change the owner window's position in the Z order.

// in this example I used both SWP_NOSIZE + SWP_NOMOVE = 3

If Value Then
  Call SetWindowPos(w.Handle, HWND_TOPMOST, w.left, w.top, w.Width, w.Height, 0)//3)
Else
  Call SetWindowPos(w.Handle, HWND_NOTOPMOST, w.left, w.top, w.Width, w.Height,0)
End If

#endif
End Sub

2 Likes

This looks like it could do the trick, thank you @Carlo_Rubini!

1 Like

Or you could simply use NSWindow’s hidesOnDeactivate …No need to mess with WindowLevels. If you have MBS plugins, you can do: w.NSWindowMBS.hidesOnDeactivate = true

hidesOnDeactivate info:
https://developer.apple.com/documentation/appkit/nswindow/1419777-hidesondeactivate

…err I mean set it to false. derp!