Recent

Author Topic: Problem with TForm.ShowModal on Linux  (Read 2749 times)

cerrato

  • New member
  • *
  • Posts: 10
Problem with TForm.ShowModal on Linux
« on: February 25, 2019, 12:18:29 am »
This is my first message on this forum, so, first of all, I'd like to say 'hello' to all of you  :)

Recently I've come across some strange behavior of LCL and I can't say if it is a bug or feature ;) My application consists of two forms - main one with size equal to screen size, BorderStyle set to bsNone and FormStyle set to fsSystemStayOnTop (in other words - it's full-screen window always staying on the foreground). The second one is created dynamically and showed with ShowModal. On Windows everything works just fine, but problem/unwanted behavior occurs on Linux.

When I try to display the second form by ShowModal, the new window goes behind the main window, which becomes disabled. I am not able to show the second form on top of the main window, even Alt+Tab can't bring it to the foreground, Form2.BringToFront also fails. Everything works OK when I use Form2.Show instead of ShowModal.

I've noticed, that this happens only when the main form has no border. When I leave BorderStyle set to bsNormal, I can ShowModal the second form and everything works like I expect: new form is shown on the foreground, the main form in the background is disabled and I can't switch to the main form as long, as Form2 is opened.

Please - check if you can you reproduce this situation and let me know about results. Firstly I'd like to find out, what is the reason of such application behavior, is it my mistake (and if it is - how can I fix it?) or is it something about the way LCL is implemented on Linux. I am using Linux Mint 19.1 MATE and Lazarus 1.8.4.
« Last Edit: March 09, 2019, 09:31:59 pm by cerrato »
That game of life is hard to play
I'm gonna lose it anyway
The losing card I'll someday lay
So this is all I have to say

jamie

  • Hero Member
  • *****
  • Posts: 1540
Re: Problem with TForm.ShowModal on Linux
« Reply #1 on: February 25, 2019, 12:44:44 am »
Try upgrading to the latest laz.

If that does not work create a small example and present it to the bug page, it sounds like a widget issue...

cerrato

  • New member
  • *
  • Posts: 10
Re: Problem with TForm.ShowModal on Linux
« Reply #2 on: February 25, 2019, 01:08:44 am »
I also think this may be a bug, but that is why I wanted you to try to reproduce this by yourselves. If people would be able to get the same behavior, it would suggest that it's not my mistake, but some issue with LCL.

For now I don't want to show you my code, because I don't want to mislead anyone and make them repeat my mistakes (in case that it's not problem with Lazarus, but caused by me).
That game of life is hard to play
I'm gonna lose it anyway
The losing card I'll someday lay
So this is all I have to say

dbannon

  • Hero Member
  • *****
  • Posts: 570
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Problem with TForm.ShowModal on Linux
« Reply #3 on: February 25, 2019, 01:48:40 am »
In Lazarus 2.0.0 it works as expected for me.

Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.     Form2.Showmodal;
  4. end;
  5.  
  6. procedure TForm1.FormCreate(Sender: TObject);
  7. begin
  8.     BorderStyle := bsNone;
  9.     FormStyle := fsSystemStayOnTop;
  10.     width := 1900;
  11.     height := 1000;
  12. end;
  13.  
  14. procedure TForm1.Button2Click(Sender: TObject);
  15. begin
  16.     close;
  17. end;          
  18.  

I did not bother to set width and height to exactly what it should be but thats not (IMHO) likely to be a factor.

Davo
Lazarus 1.8, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

cerrato

  • New member
  • *
  • Posts: 10
Re: Problem with TForm.ShowModal on Linux
« Reply #4 on: February 25, 2019, 09:08:26 am »
@dbannon - you didn't tell which OS you are using. As I wrote in my first message, on Windows everything works fine, problem occurs only on Linux (or at least on my distro - Mint 19 MATE).

In the evening I'll be home, so I'll try to upgrade my Lazarus to current version (2.0.0) and check if problem still appears.
That game of life is hard to play
I'm gonna lose it anyway
The losing card I'll someday lay
So this is all I have to say

Thaddy

  • Hero Member
  • *****
  • Posts: 7975
Re: Problem with TForm.ShowModal on Linux
« Reply #5 on: February 25, 2019, 09:27:47 am »
I believe it is fixed but it happened to me too with laz 1.8.0.
I " fixed" it like this I believe (I haven't a 1.8.x anymore, so can't test: the code any more or if my memory serves me right.
Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.     Form2.Showmodal;
  4.     Form2.BringToFront;
  5.     Application.ProcessMessages;
  6. end;

Side note:
This was on a Raspberry Pi 2 and with Rasbian - I guess at the time - Jessie if I remember well.
This particular Pi is now running headless w/o graphical UI installed. And yes, it's the one I wanted to give away and nobody wanted/reacted... Too late, it's now my PiHole server. (recommended)
« Last Edit: February 25, 2019, 09:31:32 am by Thaddy »
Hamlet 1.4 (nothing wrong with the Danish, btw)

zeljko

  • Hero Member
  • *****
  • Posts: 1044
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Problem with TForm.ShowModal on Linux
« Reply #6 on: February 25, 2019, 09:44:46 am »
It's about window manager. Try to set fsStayOnTop for modal form too. My wild guess is that it's gtk2 widgetset with metacity as wm below.

cerrato

  • New member
  • *
  • Posts: 10
Re: Problem with TForm.ShowModal on Linux
« Reply #7 on: February 25, 2019, 10:19:11 am »
@thaddy - I've tried many things, as I wrote in my first message " Form2.BringToFront also fails.".

@zeljko - I've played with fsStayOnTop and fsSystemStayOnTop on both main and popup window, but without any success. It seems that ShowModal on Linux in some circumstances is broken... In the evening I'll do some more tests and I will post here info about what I'll find out.
« Last Edit: February 25, 2019, 11:08:52 am by cerrato »
That game of life is hard to play
I'm gonna lose it anyway
The losing card I'll someday lay
So this is all I have to say

zeljko

  • Hero Member
  • *****
  • Posts: 1044
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Problem with TForm.ShowModal on Linux
« Reply #8 on: February 25, 2019, 11:16:14 am »
@cerrato, X11 doesn't know anything about borderless windows - such windows are handled by toolkit eg gtk2/qt etc so that's main problem. AFAIR I've fixed such scenario with qt and qt5 inside lclqt(5).

Thaddy

  • Hero Member
  • *****
  • Posts: 7975
Re: Problem with TForm.ShowModal on Linux
« Reply #9 on: February 25, 2019, 11:19:49 am »
@thaddy - I've tried many things, as I wrote in my first message " Form2.BringToFront also fails.".
It is the application.processmessages, I believe. Sorry can't test 1.8.X anymore but something along these lines got it working... I think I am very close to what I did, maybe even a mainform.sendtoback - first - too?
I got just as frustrated as you, btw. But I did not need any low-level hacks or something to get it working.
« Last Edit: February 25, 2019, 11:24:33 am by Thaddy »
Hamlet 1.4 (nothing wrong with the Danish, btw)

cerrato

  • New member
  • *
  • Posts: 10
Re: Problem with TForm.ShowModal on Linux
« Reply #10 on: February 25, 2019, 01:14:06 pm »
I hope that upgrading to latest version would fix this issue, so there will be no reason to search for workarounds ;)
That game of life is hard to play
I'm gonna lose it anyway
The losing card I'll someday lay
So this is all I have to say

Zoran

  • Hero Member
  • *****
  • Posts: 1389
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Problem with TForm.ShowModal on Linux
« Reply #11 on: February 25, 2019, 02:44:45 pm »
Probably related to bug 33806.

cerrato

  • New member
  • *
  • Posts: 10
Re: Problem with TForm.ShowModal on Linux
« Reply #12 on: February 25, 2019, 03:19:19 pm »
It is very likely that my problem is related to that bug.

Although bug #33806 behaves different from my problem, cause of both of them may be the same. And if so, there are two things about this that make me a little sad: first that problem occurs due to Linux window manager, so it would be hard to fix by Lazarus developers, and second - bug you have showed is (as for now) not fixed in current version :(
« Last Edit: February 25, 2019, 03:54:03 pm by cerrato »
That game of life is hard to play
I'm gonna lose it anyway
The losing card I'll someday lay
So this is all I have to say

dbannon

  • Hero Member
  • *****
  • Posts: 570
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Problem with TForm.ShowModal on Linux
« Reply #13 on: February 25, 2019, 11:31:06 pm »
@dbannon - you didn't tell which OS you are using.
....

Ubuntu 18.04, using Marco, the default windows manager. I don't have metacity installed, but I do have several others. If you already have alternative wm available, perhaps try another and see if it helps.

Davo
Lazarus 1.8, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

cerrato

  • New member
  • *
  • Posts: 10
Re: Problem with TForm.ShowModal on Linux
« Reply #14 on: March 09, 2019, 09:25:03 pm »
Sorry for delayed answer, but I couldn't find time to focus on this problem hard enough :( Before we go any further, I'd like @dbannon to check one thing. The code you gave works almost OK, but on my OS taskbar stays visible. To hide taskbar, I added
Code: Pascal  [Select]
  1. Form1.Left:= 0;
  2. Form1.Top:= 0;
With this modification, the main window was really displayed on the full screen (with no taskbar), but there was also a drawback - ShowModal stopped working properly. So I am asking you to do the same modification. Please - check this and let me/us know, what results you would get.
« Last Edit: March 09, 2019, 09:30:32 pm by cerrato »
That game of life is hard to play
I'm gonna lose it anyway
The losing card I'll someday lay
So this is all I have to say