Lazarus

Programming => Widgetset => Cocoa => Topic started by: d4eva on June 05, 2022, 10:57:02 pm

Title: Have form to stay on top of the app
Post by: d4eva on June 05, 2022, 10:57:02 pm
Is there way to have the form to be on top of the application only, and not the system?
If I set FormStyle to  fsStayOnTop, the form stays on top of the app, but it also stays on top of other windows, if I they are moved on the app.
It works fine on Windows, i.e. the form is only kept on top of the app, but no the whole OS.

I'm using Lazarus 2.2.2. MacOS Monterey 12.0.1 (also tried on Mac Mini M1).
I attached the image on how it looks. I'd prefer the form2 to be below the Finder but still on top of the app.
Title: Re: Have form to stay on top of the app
Post by: dje on June 06, 2022, 02:14:57 am
Same thing happens on the Raspberry Pi (GTK).

But, there is a comment in the CocoaWSForms unit (Near the array FormStyleToHideOnDeactivate)
Quote
Window levels make the form always stay on top, so if it is supposed to stay on top of the app only, then a workaround is to hide it while the app is deactivated

The GTK implementation seems to treat fsStayOnTop and fsSystemStayOnTop as the same, and uses the function gtk_window_set_keep_above().

Code: Pascal  [Select][+][-]
  1. fsAllStayOnTop = [fsStayOnTop, fsSystemStayOnTop];
  2. gtk_window_set_keep_above({%H-}PGtkWindow(AForm.Handle),
  3.       GBoolean(AFormStyle in fsAllStayOnTop))

If you google gtk_window_set_keep_above, it seems that the function is to be removed (?)

https://discourse.gnome.org/t/gtk-4-how-to-replace-gtk-window-set-keep-above-and-gtk-window-set-keep-below/3550

Anyway, I tried using TApplicationProperties and this code, which kinda seems to work. It may work for you, but I'd do a _lot_ of testing.

Code: Pascal  [Select][+][-]
  1. procedure TFormMain.ApplicationPropertiesActivate(Sender: TObject);
  2. begin
  3.   FormLog.FormStyle := fsStayOnTop;
  4. end;
  5.  
  6. procedure TFormMain.ApplicationPropertiesDeactivate(Sender: TObject);
  7. begin
  8.   FormLog.FormStyle := fsNormal;
  9. end;  
   
Title: Re: Have form to stay on top of the app
Post by: MarkMLl on June 06, 2022, 11:22:25 am
With the caveat that I'm not a Mac user, but I think that this is very much dependant on the "Window Manager" part of the OS's GUI which in modern parlance is roughly equivalent to "desktop environment".

As such, the behaviour might vary depending on which desktop has been selected on a platform- e.g. the RPi or most systems based on X11- which allows it to be selected at login.

It might possibly be worth investigating the various dockable extensions, which might be safer than relying on OS facilities ** being portable and consistent.

** Hints passed from the Window Manager to the widget set (e.g. GTK) affecting the app's visual presentation, and requests from the widget set that the Window Manager handle the content of a window in a particular way.

MarkMLl
Title: Re: Have form to stay on top of the app
Post by: d4eva on June 06, 2022, 12:46:02 pm
Code: Pascal  [Select][+][-]
  1. procedure TFormMain.ApplicationPropertiesActivate(Sender: TObject);
  2. begin
  3.   FormLog.FormStyle := fsStayOnTop;
  4. end;
  5.  
  6. procedure TFormMain.ApplicationPropertiesDeactivate(Sender: TObject);
  7. begin
  8.   FormLog.FormStyle := fsNormal;
  9. end;  
   

Thanks. This kinda worked. I also added OnActivate/Deactivate handlers to the Form2.
TinyPortal © 2005-2018