Recent

Author Topic: Have form to stay on top of the app  (Read 536 times)

d4eva

  • New Member
  • *
  • Posts: 16
Have form to stay on top of the app
« 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.

dje

  • Full Member
  • ***
  • Posts: 124
Re: Have form to stay on top of the app
« Reply #1 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;  
   

MarkMLl

  • Hero Member
  • *****
  • Posts: 5564
Re: Have form to stay on top of the app
« Reply #2 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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

d4eva

  • New Member
  • *
  • Posts: 16
Re: Have form to stay on top of the app
« Reply #3 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