Dynamically set alwaysOnTop

I want to set whether a lime.ui.Window can be always on top or not.
Digging through some lime documentations I found that lime.ui.WindowAttributes has the option awaysOnTop which sounds pretty much like what I want. Unfortunately WindowAttributes are for when windows are being created and I cannot access or change it’s value later on unless I wanted to destroy the window and recreate it.

Would there be a simple way to set this after the windows is created? Also would this work when using OpenFL as well?

Thanks in advance.

I’m not sure we can do this dynamically in SDL (which we use for native windowing), but there is a window.focus () method, which may bring the window forward and give it focus. This isn’t quite the same as always on top (where it is on top, with or without focus) but it still may be useful for certain use cases?

1 Like

Thanks for answering @singmajesty!

Unfortunately, calling focus is not a solution I can use. apps running in the background would not be able to be accessed this way because window.focus() would unfocus any other window. this prevents some items being clicked and text input in other applications.

Since it doesn’t appear to be possible to dynamically change alwaysOnTop I believe I can close that window with window.close() and create a new one with application.createWindow(/*set alwaysOnTop*/);. The next step would be to add OpenFL to that window. I can probably do application.addModule(new openfl.display.Stage(/*newly created window here*/)); to add OpenFL to the window. I’m going to assume for now that lime would remove the previous Stage of the no longer existent window.

Does this sound about right? It might be messy and I probably shouldn’t switch setting alwaysOnTop too often but this sounds like it should work out being done occasionally. would there also be anyway to recycle OpenFL stages and swap in a new window? I suspect not but if there is… no harm in asking and finding out :smile:!

When using OpenFL, the default Application instance is an openfl.display.Application, which attaches an OpenFL stage to each created window. Try app.createWindow and check to see if stage is already instantiated :slight_smile:

I’ve found this post https://discourse.libsdl.org/t/can-i-change-the-always-on-top-flag-somehow/24030 which might be helpful. I can give no further info though on if it works, or how to bake it into openfl.

1 Like

That’s helpful – it looks like the makings of the ability to create a patch to SDL that would properly expose a method for allowing changes to this at runtime

1 Like