Open a window on a given monitor with keep it always in front?

Hi there,

I am using OpenFl to target Windows and I need my application to be always in front (because it’s a public application in a Museum)…I used to do this with nativeWindow.alwaysInFront = true in Adobe Air…is there any equivalent in OpenFL ?

More over, I create sometimes multi-screens applications…is there any way to open a window on a given monitor, like in Adobe Air ?

Thanks for your help !

Multi-window support is not heavily used, but you should be able to use <window id="1" width="800" height="600" /> to define a second window (there are some runtime ways to do it too)

The <window /> has a display attribute that is also not often used, but I’d be happy to hear feedback – it should request a window on the display index used, rather than the default

SDL is our native C library we use for window creation on the desktop, it has SDL_WINDOW_ALWAYS_ON_TOP it looks like (https://wiki.libsdl.org/SDL_WindowFlags) but I’m not sure we have that exposed. I’m sure this would not be too hard to expose, or patch into the source manually

Hi singmajesty and thanks for your response!

I will have a look at the windows id and display attribute soon…

My priority is the ALWAYS_ON_TOP feature.

As I am new to OpenFL, I tried to patch manually the source but with no success…I do not really know where to start…

I tried to edit lime._backend.native.NativeWindow

adding

var WINDOW_FLAG_ALWAYS_ON_TOP = 0x00008000;

in the WindowFlags

and

if (Reflect.hasField (parent.config, "alwaysontop") && parent.config.alwaysontop) flags |= cast WindowFlags.WINDOW_FLAG_ALWAYS_ON_TOP;

in the create function

then lime.app.Config with

@:optional var alwaysontop:Bool;

and then I added

<window alwaysontop="true" />

in my project.xml

But yes I know I am far away to find the way to do such a thing!
Can you tell me what other files are concerned?

Thanks again.

Megametrope.

It sounds like this might be the missing part:

You could even hardcode it in here, temporarily, by adding

sdlFlags |= SDL_WINDOW_ALWAYS_ON_TOP;

Here’s instructions for building Lime from source: https://github.com/openfl/lime#building-from-source :slight_smile:

Thanks for all singmajesty,

I am not familiar with github tools and environnment and I tried to rebuild in vain… :frowning:

Any chance this will be exposed in the next release ?

Best.

I have it working here:

https://github.com/openfl/lime/tree/feature/always-on-top

This required some improvements to SDL2, SDL_WINDOW_ALWAYS_ON_TOP was implemented for X11 (Linux) but not Windows, but I was able to add support in my own copy. I’m seeing if we can get this contributed back to SDL official.

Yep, if it’s stable it will go out in a future release of Lime :smile:

Very nice, i’ve been struggling with finding a good solution to this myself. Does it stay on top in fullscreen mode also?

The code was forcing on top if full screen and input focused, but I suppose that it would have allowed it to fall behind if the full screen window did not have focus.

The changes I made should override that if “always on top” is set. The only problem is that you cannot toggle it on/off at runtime currently, or maybe there’s a way

1 Like

Good to hear this can be part of the next release!
Thank you singmajesty!

Hm, i’m testing this with Lime 4.1.0 and OpenFL 5.0 but im not getting the expected results.
I see no change from Lime 4.9.2 ; the window is not staying on top at all… Im using Win10.
Tested both windowed mode and fullscreen.

And the property is not accessible from code, just from the project.xml right?

Try it with dashes:

<window always-on-top="true" />

You’re right, I guess it’s not available at runtime yet

Hm, It doesnt seem to make a difference. Still not staying on top.

I’ve been doing it using the win cpp way

untyped __cpp__(' SetWindowPos(hwnd, HWND_TOPMOST, winposx, winposy, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SW_SHOW) ');

Unfortunately it doesnt really work with fullscreen mode. So having a true always-on-top function would be very welcome :slight_smile:

Fixed, my test was a Lime project, OpenFL was missing a line in the entry point template:

Thanks for the fix!
Now it works, in window mode and while fullscreen mode has focus.

I did some work a while ago trying to find a good always-on-top solution for fullscreen.
When the app focus is lost, the application minimizes and doesnt stay on top. Pressing the win key, opening task manager or simply clicking on another window on a different screen will make the fullscreen app minimize.

I couldn’t find a good solution to this, except running in non-fullscreen mode just creating a chromeless window at the size of the screen. But this is not a great solution, and there are some framerate issues when running in non-fullscreen mode sometimes.

Any ideas to work around this?

I’m not sure, the OS might be designed to allow focus to be removed from a fullscreen window by design. When implementing this feature, I did notice the difference between “the current thread has to have priority” in order to execute certain commands (or something along those lines)

My gaming keyboard has a mode to disable the Windows start button for a reason :slight_smile:

Hm. Could be. But infact, the AIR runtime stays infront all the time, and doesnt minimize when it looses focus. (but will show the windows menu).

I wonder how they do it…

I think the AIR runtime has little bits written in plain GDI for win32, which allows them to process Windows messages - specifically the one dealing with focus lost. If the focus is lost, they probably just veto the event, or reset the focus (and topmost window) to be their hosted view.

There’s probably a way to patch it into your codebase using the untyped(c++) macros, but it’s slow going and may cost you too much time. A good first step is to set your window like so:

SetWindowPos(hwnd, NULL, 0, 0, 320, 240, HWND_TOPMOST);