sqweek / dialog

Simple cross-platform dialog API for go-lang
ISC License
493 stars 76 forks source link

AlwaysOnTop options #7

Open juliardi opened 6 years ago

juliardi commented 6 years ago

Can we have an options to make the message dialog appear always on top? I have a little program that works like an alarm. At a fixed time, I want it to show a message dialog. The message dialog appears, but it's burried under another application window. So it will be nice to have a dialog that will appear always on top of other application window.

sqweek commented 6 years ago

I'm presuming the little program doesn't have any other windows?

AFAIK there's no cross-platform way to do this, since OSX's focus model prevents "background" applications from popping up windows in front of the "foreground" application.

In linux such behaviour depends on the window manager in use and how it is configured -- you might find the "focus stealing" policy is preventing the dialog from appearing on top. You'll also probably find there's another mechanism for generating such alerts eg. via system tray balloon messages or similar.

But a best effort feature should be feasible. Preliminary research suggests:

win32: add MB_TOPMOST style https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx osx: [window setLevel:NSFloatingWindowLevel]; https://stackoverflow.com/questions/3278208/how-do-i-to-make-a-windowosx-always-hover-on-top-of-screen/3278262#3278262 gtk: gtk_window_set_keep_above(GTK_WINDOW(win), true) or use GTK_WINDOW_POPUP https://stackoverflow.com/questions/10331394/how-to-keep-transient-window-on-top-in-gtk

(just keeping notes here for now)

samschurter commented 4 years ago

I tried MB_TOPMOST, MB_SYSTEMMODAL, MB_TASKMODAL, and MB_SETFOREGROUND, the only one that brought the alert box all the way to the top was MB_SYSTEMMODAL.

I added the MB_SYSTEMMODAL flag to https://github.com/TheTitanrain/w32 to keep things consistent, added a bool member to the MsgBuilder struct and a method to set it true if the dialog should be on top.

The Windows code will add the MB_SYSTEMMODAL flag if the Top flag is true, but Linux and OSX will just ignore it. I don't have experience with or access to those systems to see what works.

The file and directory dialogs don't have the same options available, looks like they will be harder to set as topmost.

sqweek commented 3 years ago

Sorry for not acknowledging this sooner. I started replying months ago but never finished the comment :S

I don't love the solution because MB_SYSTEMMODAL is also the most anti-social ux possible, but also based on your testing (thank you!) it doesn't seem like there's much alternative. I think I would like to better understand the circumstances in which a new dialog appears behind other windows though, in case there is a way to avoid that without adding another option to the API.