My program mostly runs in the background. But if some event is detected, it shall:
a) display a Form with a message and
b) display this Form over all other windows of all other programs and
c) receive the focus (so that e.g. keystrokes are noticed by my program).
What I have is this:
if event_detected then
begin
Form1.Show; {calls Form1.BringToFront}
Form1.FormStyle:=fsStayOnTop;
Form1.SetFocus; {does not work}
Form1.Label1.Caption:='This is my message';
end;
This code has 3 disadvantages:
1) If my Form had been hidden by a Button via "Form1.Hide" and then the next message shall be displayed, my Form gets visible, but does not receive the focus.
2) If my Form had been minimized and then the next message shall be displayed, my Form also gets visible, but does not receive the focus.
3) If my Form had been moved manually half behind another window and then the next message shall be displayed, my Form stays half behind the other window (does not come to front).
What I do not need (and not want) is, that after my Form has come in front, that it "stays" in front permanently, even if another window is moved over it.
I use Lazarus 2.0.10 with FPC 3.2.0 on Linux Ubuntu 22.04. Same results with Lazarus 2.2.4 and FPC 3.2.2. How can I solve the 3 disadvantages? Thanks in advance.
EDIT:Meanwhile I tested my program on Windows and there everything is fine. So the problem is only on Linux.