Lazarus

Programming => LCL => Topic started by: cerrato on February 25, 2019, 12:18:29 am

Title: Problem with TForm.ShowModal on Linux
Post by: cerrato 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.
Title: Re: Problem with TForm.ShowModal on Linux
Post by: jamie 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...
Title: Re: Problem with TForm.ShowModal on Linux
Post by: cerrato 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).
Title: Re: Problem with TForm.ShowModal on Linux
Post by: dbannon 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
Title: Re: Problem with TForm.ShowModal on Linux
Post by: cerrato 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.
Title: Re: Problem with TForm.ShowModal on Linux
Post by: Thaddy 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)
Title: Re: Problem with TForm.ShowModal on Linux
Post by: zeljko 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.
Title: Re: Problem with TForm.ShowModal on Linux
Post by: cerrato 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.
Title: Re: Problem with TForm.ShowModal on Linux
Post by: zeljko 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).
Title: Re: Problem with TForm.ShowModal on Linux
Post by: Thaddy 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.
Title: Re: Problem with TForm.ShowModal on Linux
Post by: cerrato 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 ;)
Title: Re: Problem with TForm.ShowModal on Linux
Post by: Zoran on February 25, 2019, 02:44:45 pm
Probably related to bug 33806 (https://bugs.freepascal.org/view.php?id=33806).
Title: Re: Problem with TForm.ShowModal on Linux
Post by: cerrato 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 :(
Title: Re: Problem with TForm.ShowModal on Linux
Post by: dbannon 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
Title: Re: Problem with TForm.ShowModal on Linux
Post by: cerrato 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.
Title: Re: Problem with TForm.ShowModal on Linux
Post by: dbannon on March 09, 2019, 11:46:51 pm
Cerrato,
I did as you requested and, again, it works for me as expected.

Note that in my OS, Ubuntu Mate, the task is not hidden, my taskbar is across the top, from memory on LUbunto its across the bottom. (You are referring to OS taskbar ?)

Now, I am also still not setting my with and height so that it exactly fills the screen. Are you doing that using your own know screen size ? Thats not a great approach, very unportable. But maybe the other things you are doing, like hiding taskbar by forcing it to be covered are also a bit dodgy ? By that I mean its depending on undocumented behaviours, results will vary depending on OS ....

Davo

Title: Re: Problem with TForm.ShowModal on Linux
Post by: cerrato on March 10, 2019, 09:27:02 pm
Thanks for your help. What you wrote proves to me, that it's probably not a problem with Lazarus/LCL, but with window manager (or something else, but still related to OS, not IDE).

Your tips about width and height of form were obvoius to me, but in this application they really don't matter because code you and I were posting in this thread is sort of PoC, just to show strange and unexpected behavioiur of ShowModal. In real life applications I check resolution of screen and adjust my window size to it (for example by using "width:=screen.width"). As for now, one thing is important - it doesnt't matter, whether size of the window is hard-coded or adjusted to size of the screen. As long as I don't play with Top and Left, ShowModal works fine.

Look at this code - it's final version of my tests. As you can see, I've changed width and height to fit screen size, but as I wrote above, it doesn't change anything.
Code: Pascal  [Select][+][-]
  1.     BorderStyle := bsNone;
  2.     FormStyle := fsSystemStayOnTop;
  3.     Left := 0;
  4.     Top := 0;
  5.     Width := Screen.Width;
  6.     Height := Screen.Height;
When lines 3 and 4 are commented out, ShowModal works properly, but taskbar is still visible on bottom of the screen. And when I uncomment lines setting Top and Left to zero, window is really shown on full screen. but ShowModal stops working - second window is displayed behind main window and I'm not able to bring it to front.

You can see on screenshot attached to this post how application looks, when I don't set Left and Top to 0. The bar at the bottom of screen is OS taskbar. In your last post, you weren't certain to which bar I was referring to ;)
Title: Re: Problem with TForm.ShowModal on Linux
Post by: lucamar on March 10, 2019, 09:50:48 pm
About ShowModal behaviour, does it change if you set Form2's PopupParent to Form1 and Form2's PopupMode to pmExplicit?
Title: Re: Problem with TForm.ShowModal on Linux
Post by: cerrato on March 10, 2019, 10:21:09 pm
@lucamar - I've tried many options, but none of them worked. As far as I remember, playing with  PopupMode and PopupParent gave no result. You can put here some code that works for you, and I'll check it, but I'm afraid that your suggestions won't succeed :(
Title: Re: Problem with TForm.ShowModal on Linux
Post by: wittbo on March 10, 2019, 10:45:12 pm
Hallo to all,
I don't have any experience with Lazarus on Linux, but actually I'm getting dubious problems with a very simple dialog form and showmodal on MacOS. Under some conditions it works as expected, others -reproducable- the program hangs with showmodal, third situation there was a setfocus error with a complete separate form.
I will try to make a reduced application to provide for analysis.
And, replacing ShowModal by Show none of these problems appear...
Title: Re: Problem with TForm.ShowModal on Linux
Post by: lucamar on March 11, 2019, 01:26:28 am
As far as I remember, playing with  PopupMode and PopupParent gave no result. [...] I'm afraid that your suggestions won't succeed :(

It was just an idea. While reading this thread I remembered having seen recently another similar thread about ShowModal in which the solution rested on the proper use of PopupMode and PopupParent. If that doesn't work for you, sorry. Bad luck. :(


@wittbo,

ShowModal is tricky in that, quite logically, the form/dialog shown modally gets all the application's focus, leaving any other form ... let's say "in limbo". :)  If some problem arises and the modal form isn't correctly closed (or opened!) that may hung your application or cause other problems, but that is a very rare, unusual situation.

Difficult to say more without seeing your code; I'll wait for it.
Title: Re: Problem with TForm.ShowModal on Linux
Post by: wittbo on March 11, 2019, 04:05:52 pm
@lucamar. Thank you for your answer.
meanwhile I stripped down my program to the essential functions. It contains three forms:
main, frmDialog, frmTermine.
1.  Click button "Button1"; frmDialog appears correctly; press OK to close.
2.  Click the button with the table symbol; then press OK to close; repeat step 1; errormessage (see attachment)

If I would...
- open frmTermin with ShowModal too, no error    or
- open frmDialog only with Show, no error.
- remove btnOK.SetFocus in frmTermine.FormActivate, no error

It seems, that different opening (Show, ShowModal) of different forms in one application won't work. BTW this is only the case in my MacOS environment, with Windows 10 no problem...
Title: Re: Problem with TForm.ShowModal on Linux
Post by: dbannon on March 12, 2019, 05:34:06 am
OK wittbo, I have tried your demo making both Carbon and Cocoa apps using both Lazarus 2.0.0 and Fixes (2.0.1) and it works fine for me, all four times.

So, what are we doing differently ?

I am using Sierra and building with a 32bit Carbon version of Lazarus in all cases. Both my Lazarus installs are built from source rather than downloaded dmg.

Davo
Title: Re: Problem with TForm.ShowModal on Linux
Post by: wittbo on March 12, 2019, 06:23:59 am
Thanks, Davo, for testing.
It's a real question, what are the differences?
I'm using 2.0.0, not the 2.0.1 fixes.
I will check it this evening (in Germany). I'm not skilled in finding and installing fixes between the regular releases, but I will try it and report afterwards.
Title: Re: Problem with TForm.ShowModal on Linux
Post by: dbannon on March 12, 2019, 08:04:47 am
wittbo, I'd encourage you to try fixes but I don't think it will solve your issue. I did not see your problem on 2.0.0 either !

What release of OSX are you using ?  (Obviously a pretty high res screen from your button locations :-)   )

Davo

PS - install fixes ?

You need svn (and, obviously FPC but you have that)
Code: [Select]
svn checkout http://svn.freepascal.org/svn/lazarus/branches/fixes_2_0
cd fixes_2_0
make CPU_TARGET=i386 LCL_PLATFORM=carbon bigide
open startlazarus.app --args "--pcp=~/.fixes_2_0"

Note the --pcp stuff, thats to keep the fixes install from messing with your existing 2.0.0 install.

svn
Title: Re: Problem with TForm.ShowModal on Linux
Post by: wittbo on March 12, 2019, 09:03:34 pm
Hallo Dave,

i tried the following combinations (OS version + compiler options):

10.14.3 Mojave
Cocoa      Default   Default   Error
Cocoa      Darwin   X86_64   Error
Cocoa      Darwin   i386      Error
Carbon      Default   Default   No Error   
Carbon      Darwin   X86_64   No Error
Carbon      Darwin   i386      No Error


10.13.6 High Sierra
Cocoa      Default   Default   Error
Cocoa      Darwin   X86_64   Error
Cocoa      Darwin   i386      Error
Carbon      Default   Default   No Error   
Carbon      Darwin   X86_64   No Error
Carbon      Darwin   i386      No Error

So the problem as described can be reproduced with cocoa only; carbon is OK.
In the last minutes i experienced with the svn fixes, I did it the first time, easy install with your tips!
Even with this new version 2.0.1 the problem appears with Cocoa. Perhaps it would be good to report it to bugtracker.
Title: Re: Problem with TForm.ShowModal on Linux
Post by: dbannon on March 12, 2019, 11:44:08 pm
...... Perhaps it would be good to report it to bugtracker.

Yep, I agree. Would be nice if we could have a (eg) High Sierra user confirm it but does look like its related to OS. Mention in the bug report you have tried fixes.

Thanks

Davo
Title: Re: Problem with TForm.ShowModal on Linux
Post by: cerrato on March 22, 2019, 09:32:20 pm
Funny thing - after upgrading Lazarus to version 2.0.0 everything seems to work OK, ShowModal on Linux does exactly what it is supposed to do. I don't know if it is coincidence or maybe something in LCL has been fixed... anyway, for now my problem seems to be gone.

Thanks you all for your help :)
TinyPortal © 2005-2018