Lazarus

Programming => Widgetset => GTK => Topic started by: megatron on June 30, 2020, 08:43:30 pm

Title: Problem with gtk3 when compile empty app
Post by: megatron on June 30, 2020, 08:43:30 pm
Problem with gtk3 when compile empty app
Title: Re: Problem with gtk3 when compile empty app
Post by: marcov on June 30, 2020, 11:32:38 pm
On Windows, afaik IUNknown is stdcall. So this probably never has been used on windows.
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on July 01, 2020, 02:22:47 am
Are you cross compiling or  trying to build a gtk3 windows app ?

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: PascalDragon on July 01, 2020, 09:20:10 am
On Windows, afaik IUNknown is stdcall. So this probably never has been used on windows.

It would be enough to remove the calling conventions from the implementation. It's correct in the interface part of TGtk3Widget. Probably using Code Completion let to the addition of only the cdecl in the implementation.
Title: Re: Problem with gtk3 when compile empty app
Post by: megatron on July 01, 2020, 12:40:13 pm
Are you cross compiling or  trying to build a gtk3 windows app ?

Davo


trying build a gtk 3 window app only

i work with gtk2 without any problem

but i am try to build app with gtk3
Title: Re: Problem with gtk3 when compile empty app
Post by: m.abudrais on July 01, 2020, 02:38:06 pm
why do you need gtk in windows?
Title: Re: Problem with gtk3 when compile empty app
Post by: Thaddy on July 01, 2020, 02:52:07 pm
why do you need gtk in windows?
Whereas it it usually recommended to use the default look for the OS, it can be the case that one wants to have the same look across all platforms. (E.g. games, sometimes corporate, etc)
This is not uncommon.
Title: Re: Problem with gtk3 when compile empty app
Post by: marcov on July 01, 2020, 02:59:12 pm
why do you need gtk in windows?
Whereas it it usually recommended to use the default look for the OS, it can be the case that one wants to have the same look across all platforms. (E.g. games, sometimes corporate, etc)
This is not uncommon.

Apparently it is, if this is the first time it is compiled on Windows :-) The GTK3 port is half a decade old.
Title: Re: Problem with gtk3 when compile empty app
Post by: Thaddy on July 01, 2020, 03:00:09 pm
It would be enough to remove the calling conventions from the implementation. It's correct in the interface part of TGtk3Widget. Probably using Code Completion let to the addition of only the cdecl in the implementation.
One could use winapi instead of a specific convention, since that chooses the right calling convention for a platform and works not just on windows. Assumes 3.2.0 or higher.
Title: Re: Problem with gtk3 when compile empty app
Post by: Thaddy on July 01, 2020, 03:04:12 pm
Apparently it is, if this is the first time it is compiled on Windows :-) The GTK3 port is half a decade old.
I never used GTK3, but there are many GTK2 applications available on Windows for the reasons I mentioned.
(isn't Blender one of those? and how about the mingw interface? Just to name two)

The point I try to make is not related to GTK3, but to any portable widgetset.
 
Title: Re: Problem with gtk3 when compile empty app
Post by: PascalDragon on July 01, 2020, 09:59:53 pm
It would be enough to remove the calling conventions from the implementation. It's correct in the interface part of TGtk3Widget. Probably using Code Completion let to the addition of only the cdecl in the implementation.
One could use winapi instead of a specific convention, since that chooses the right calling convention for a platform and works not just on windows. Assumes 3.2.0 or higher.

The code is older than 3.2.0 and Lazarus supports the last two releases. Also the IInterface methods are declared the same way and one likely will simply copy these to implement them.
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on July 02, 2020, 03:17:36 am
But seriously, why use GTK3 on Windows ?

GTK3 on Linux has a long way to go, my guess is its far worse on Windows ?  megatron, perhaps you are not aware of the usual way to make cross platform apps ?   if you leave the default setting in place, Lazarus will use the local default widgetset, so, on Linux it will use GTK2 (which is pretty good, stable, widely supported) and on Windows will use the Win32 widgetset, again, just what you want on Windows.

If you want to help track down the GTK3 issues (and more power to your strong right arm) then you would find Linux a much friendly place to do so.

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: marcov on July 02, 2020, 11:14:26 am
Apparently it is, if this is the first time it is compiled on Windows :-) The GTK3 port is half a decade old.
I never used GTK3, but there are many GTK2 applications available on Windows for the reasons I mentioned.

Gtk3widgets is in the lcl\interfaces\gtk3 dir. We are talking about the Lazarus GTK3 interface here, not about a hypothetical GTK3-only application.

And there is not much reason  to use that on Windows, since a proper Lazarus win32 interface is available, which is evident since it doesn't even compile.

Quote
The point I try to make is not related to GTK3, but to any portable widgetset.

Most of those applications have gtk on Windows because they are hardcoded to GTK and thus are condemned to it. It is not a choice but a result of the lack of choice.
Title: Re: Problem with gtk3 when compile empty app
Post by: Thaddy on July 02, 2020, 01:04:03 pm
Most of those applications have gtk on Windows because they are hardcoded to GTK and thus are condemned to it. It is not a choice but a result of the lack of choice.
So we agree?  ;D
Title: Re: Problem with gtk3 when compile empty app
Post by: prof7bit on September 25, 2021, 01:49:22 pm
Apparently it is, if this is the first time it is compiled on Windows :-) The GTK3 port is half a decade old.
I never used GTK3, but there are many GTK2 applications available on Windows for the reasons I mentioned.
(isn't Blender one of those? and how about the mingw interface? Just to name two)

The only reason for these applications to use GTK on Windows is because they have originally been developed on *ix against one particular GUI framework (GTK2 in that case) and only later been ported to Windows. At this point the developers realized that it was a mistake to develop directly against GTK instead of using one of the available abstractions like LCL for Pascal programmmers (or wxWidgets if they are using C++) and then they were forced to ship their application along with a complete copy of GTK.

The approach of Lazarus/LCL (and other similar abstraction layers) is to always use the native Widgetset on the target-OS and abstract away the differences for the programmer. So you don't have to ship an entire GUI framework with your app and your app will have native look and feel.

If you plan to be cross platform from the beginning on you should use LCL (if you are using ObjectPascal) or wxWidgets if you are using C++ and let the abstraction do its magic. With some experience you can work around those few corner cases where the native platform behavior is still shining through and causing subtle differences, you will still need some testing and tweaking on all target platforms but it is manageable and 99% will just work out of the box.

And Blender isn't really using GTK, they have their very own completely customdrawn widgetset running directly on top of OpenGL. A customdrawn widgetset is another approach you can use if you really want it to look and behave exactly the same everywhere and want to have full control over the appearance, like it is the case in Blender where all their tiny widgets and special gizmos in the UI don't even exist in any of the large GUI frameworks and are all handcrafted anyways.
Title: Re: Problem with gtk3 when compile empty app
Post by: Akira1364 on January 16, 2022, 03:51:21 am
FWIW, though I'm well aware of general attitudes towards CodeTyphon here, this kind of thing is one area where they're noticeably ahead of base Lazarus. Which is to say, their current revision of the GTK3 widgetset just transparently compiles (and works properly) on Windows 10 (and presumably all other platforms.) They also already have a GTK4 version of the LCL well underway, seemingly.

I would go as far as to suggest there would be no downside to simply copying and pasting the entire CodeTyphon version of the GTK3 LCL into mainline Lazarus, considering that the Lazarus version doesn't even yet include the basic cross-platform defines that the CodeTyphon one has such as the following, anywhere:

Code: Pascal  [Select][+][-]
  1. {$IF DEFINED(WINDOWS)}
  2.   Gtk3_library = 'libgtk-3-0.dll';
  3. {$ELSEIF DEFINED(DARWIN)}
  4.   Gtk3_library = 'libgtk-3.dynlib';
  5. {$ELSE}
  6.   Gtk3_library = 'libgtk-3.so.0';
  7. {$ENDIF}
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 16, 2022, 04:25:13 am
I put that in the same category as "wow, someone is going to ride a push bike across the Simpson Desert" !  It may be possible but why on earth would you do it ?

If the folks at CT are so hot with GTK3, I cannot but think their efforts would be more useful focusing on Unix platforms where GTK is a lot more comfortable !

(Honestly, I thought Gnome had given up with its 'portable' model with GTK2, but here it is, how to setup GTK3 on Windows, gee !

https://www.gtk.org/docs/installations/windows/

The page even has a real Windows look and feel. )

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: Akira1364 on January 16, 2022, 04:35:55 am
I put that in the same category as "wow, someone is going to ride a push bike across the Simpson Desert" !  It may be possible but why on earth would you do it ?

If the folks at CT are so hot with GTK3, I cannot but think their efforts would be more useful focusing on Unix platforms where GTK is a lot more comfortable !

(Honestly, I thought Gnome had given up with its 'portable' model with GTK2, but here it is, how to setup GTK3 on Windows, gee !

https://www.gtk.org/docs/installations/windows/

The page even has a real Windows look and feel. )

Davo

I'm not trying to be rude but like, what are you even talking about? My point was that:

A) CodeTyphon's GTK3 widgetset is not in any way an "alpha", on any platform, as Lazarus's is
B) Beyond completing it on non-Windows platforms, they also made it work properly (as it should) on Windows.

Say what you will about Codetyphon but one thing they are extremely good at is taking existing code and really properly refining it / re-structuring it so that it consistently works well in as many scenarios as possible.

In particular, none of their packages have the super-annoying problem often encountered in Lazarus whenever you attempt to build a package written by someone who fails to understand that Lazarus is not Delphi, and that you simply cannot have "runtime packages" and "design time packages" with units that overlap and live in the same folders without encountering weird PPU incompatibility problems.

They separate everything in the only way that actually reliably works in the overall "Lazarus unit / package system", which is: no two packages contain ANY of the same units, ever, and no package includes the unit folders of ANY other in its search directory. So "design time" packages just depend on "runtime" packages as a whole, without actually directly re-compiling the "runtime" units.
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 16, 2022, 04:44:26 am
....
B) Beyond completing it on non-Windows platforms, they also made it work properly (as it should) on Windows.
...

OK, are you saying that CT has working GTK3 on, eg, Linux ?  Now, that would impress me, I missed your hint completely !

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: Akira1364 on January 16, 2022, 04:52:27 am
OK, are you saying that CT has working GTK3 on, eg, Linux ?  Now, that would impress me, I missed your hint completely !

As far as I can tell, yeah. I think they don't claim their IDE itself works completely flawlessly when built with it, but that user projects do. Testing several apps (on Windows) of mine, indeed everything does in fact work and look like any other GTK3 app out there, so I'd be surprised if it was somehow worse on Linux.
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 16, 2022, 05:11:27 am
Thats very interesting.

This -
https://www.pilotlogic.com/sitejoom/index.php/88-wiki/technical/400-what-is-platform.html

and this -
https://www.pilotlogic.com/sitejoom/index.php/forum/general-discussions/5402-gtk3.html
Quote
Sir
CodeTyphon has already GTK3 support for projects.
.....

Seems to be the only relevent mention of GTK3 on their entire website.

The first link is quite confusing, the second supports what you say in a very understated way. Further research is indicated !

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: Akira1364 on January 16, 2022, 05:13:15 am
Thats very interesting.

This -
https://www.pilotlogic.com/sitejoom/index.php/88-wiki/technical/400-what-is-platform.html

and this -
https://www.pilotlogic.com/sitejoom/index.php/forum/general-discussions/5402-gtk3.html
Quote
Sir
CodeTyphon has already GTK3 support for projects.
.....

Seems to be the only relevent mention of GTK3 on their entire website.

The first link is quite confusing, the second supports what you say in a very understated way. Further research is indicated !

Davo

I don't think they speak super proficient English TBH. I'm basing everything I'm saying off of just actually experimenting with CT in practice, to be clear (and also a few things that I've sort of interpreted from CT forum posts made by its developers).
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 16, 2022, 08:22:02 am
Yep, I have to agree, CT appears to be doing GTK3 better than Lazarus.  Someone has been very busy, what a pity they have not pushed those improvements back to Lazarus where they started from !

Seriously, it does look pretty good !

A full review ?  A pretty ordinary installer, have to download a gig over a slow link, seems to bring all sorts of things down, binaries for every OS under the sun so it needs to be big. Then run an install, as root that you have no idea about what is happening. You have to install into root space even though we all know both FPC and Lazarus are happier in user land.

I installed into a VM, yeah, I'm a coward.

But i does all run, looks a lot like Lazarus (because it is Lazarus) but a very hard to use button bar apparently trying to show every menu item, quite confusing. But its configurable and you should be able to trim it down to fighting weight.

Apart from the buttonbar, it soon feels quite familiar except that you can, in fact, build GTK3 apps.  I will, when I get some time, try and build a bit more complicated one !

And we still get heaps of GTK3 critical errors on stderror ....

So, as   Akira1364 said, a full import anyone ?   :-[  :-[

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: del on January 16, 2022, 04:11:08 pm
My 2 cents - I'm just a hobbyist. I ran into some problems with GTK2 and didn't like the QT alternative. So I've kinda put Lazarus on "pause" while I continue my hobby activity with wxWidgets / C++. It is encouraging that there is interest and activity in the area of getting some form of object Pascal to "talk" to GTK3.

EDIT: In fairness I really didn't understand qt5ct and the need for clDefault enough to get my apps to have a decent dark gtk theme. But things look a lot more nice and "gtk" now that I set all my widget colors to "clDefault" and qt5ct style to "gtk2".
Title: Re: Problem with gtk3 when compile empty app
Post by: JuhaManninen on January 16, 2022, 10:24:41 pm
So, as   Akira1364 said, a full import anyone ?   :-[  :-[
How big diff does it make? IIRC CodeTyphon has no public revision control system. If the diff is very big, it must be split into manageable and testable pieces.
Title: Re: Problem with gtk3 when compile empty app
Post by: AlexTP on January 16, 2022, 10:32:46 pm
Quote
I would go as far as to suggest there would be no downside to simply copying and pasting the entire CodeTyphon version of the GTK3 LCL

We had changes in LCL GTK3 regarding MsgBoxes issues (Application.MessageBox, LCLIntf.MessageBox, MessageDialog, InputDialog....). Not sure Typhoon guys have our fixes. I will test again if needed.
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 17, 2022, 12:13:10 am
Well, assuming they have left the structure pretty much the same, we could graft back method by method. A couple of sdiff runs in order...

And, also assuming there are no licensing complications. Thats a given but better check I suppose.

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: El Salvador on January 17, 2022, 12:19:27 pm
Yep, I have to agree, CT appears to be doing GTK3 better than Lazarus.  Someone has been very busy, what a pity they have not pushed those improvements back to Lazarus where they started from !
I see it pretty tough, given the attitude of the codetyphon developers.
Title: Re: Problem with gtk3 when compile empty app
Post by: JuhaManninen on January 20, 2022, 06:53:04 pm
I copied their LCL-GTK3 sources on top of ours and looked at the diff. It is not much.
Some of the changes did not compile. A boolean was tested against a number for example.
They must have changed the binding code under their components/ca_libGTKv3. Lazarus has similar files under lcl/interfaces/gtk3/gtk3bindings. I did not copy or compare those files exactly. Could somebody else please do it?

The actual LCL-GTK3 code is in lcl/interfaces/gtk3.
The changes I saw there were WriteLn changed to DebugLn, some typecasts etc. minor tweaking which cannot explain big improvements at runtime.
I cleaned the DebugLns more, added license headers etc. and committed.

Yep, I have to agree, CT appears to be doing GTK3 better than Lazarus.
Please give an example where the CT version works better. I didn't test CT now much. Actually I was not able to install it as normal user. Installing as root caused some hassle later.
I followed instructions and added my user name to sudoers, yet the installer complained I don't have sudo rights.
Some years ago I was able to install with normal user if I remember right.
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 21, 2022, 12:11:03 am
Juha, I just tried my GTK3 test projects against a week or so old trunk and again, more works than I expected.

But Radio buttons in a Radio Group box do not, strangly in a Group they are OK ???

Seems to be a lot of anchoring problems.

And a crash at exit, I traced down the guilting component behind that crash but don't remember whar I found  :(  but I will chase up some notes when I get some free time.

Do I understand you as saying you have committed the CT code to real Lazarus ?  I could test it against Main ?

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 21, 2022, 04:43:48 am
Juha, running my tomboy-ng under trunk lazarus GTK3, I am surprised, very surprised how close it is to working. I get a crash as my main form is show, a focus issue. There is nothing fancy about the main form itself but I do fiddle around with its visibility so possibly my problem. Seems some alignment problems and some updates are slow, probably because of the amount of debugging info being written.

My test app, which is supposed to be a small subset of tomboy-ng is much more unstable, thats what I have been looking at and perhaps, unfairly.

My app to manage the Lazarus Examples, https://gitlab.com/dbannon/laz_examples/-/tree/main/Utility/ExScanner appears just about userable as a GTK3 app !  Again a few sizing issues really, not bad. Sometimes a crash at exit, but I am wondering if thats debugger related.

Now, this is all with trunk, sorry, Main, from a few weeks ago. I should try the same thing on my CT install.

And yes, demanding to be installed as root is enough for me to say No Thanks !

Davo

Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 22, 2022, 01:27:18 am
OK, I have done a few test between a week old Lazarus, a day old Lazarus and Lazarus 2.2.0 and, of course CT.

First of all, you are not going to be pleased to hear this, some things work better in Lazarus 2.2.0 that all the rest, specifically the bitmaps that appear in Speedbuttons, its correct in 2.2.0, rubbish is all the rest.

I do not see any improvements delivered by your merge (but I am testing on Linux so getting rid of the writeln's is obviously a good thing for Windows).

In all cases, Radio Buttons do not work in RadioGroupbox (but do work as expected in a plain GroupBox ??).

In all cases, I cannot alter the height of a Panel programmatically, this code is ignored, works fine in all other widgetsets -

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.     if Panel1.Height > 10 then
  4.         Panel1.Height := 1
  5.     else Panel1.Height := 50;
  6. end;


I had to rewrite the very basic test app used to determine the above, I could not import lazarus project into CT - now, thats rude !

I also had to discard my existing GTK3 test apps, they were based around forms from my real app but have been fiddled endlessly and have problems that do not show up when I run the real app under GTK3. Corruption somewhere. That I am afraid explains my impression that Lazarus GTK3 was a lot worse that it really is.

And the writeln statements would explain Akira1364 better experience with CT on Windows.

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: JuhaManninen on January 24, 2022, 05:01:36 pm
Sorry for the delay in my reply.

OK, I have done a few test between a week old Lazarus, a day old Lazarus and Lazarus 2.2.0 and, of course CT.
First of all, you are not going to be pleased to hear this, some things work better in Lazarus 2.2.0 that all the rest, specifically the bitmaps that appear in Speedbuttons, its correct in 2.2.0, rubbish is all the rest.
Oh, if LCL-GTK3 is worse in the development branch "main", then we must find which revision caused it.
2.2 was branched some time ago, I am not sure how many commits affect LCL-GTK3.
If you can bisect the guilty revision with your tests, it would be helpful.

Quote
I do not see any improvements delivered by your merge (but I am testing on Linux so getting rid of the writeln's is obviously a good thing for Windows).
Yes, the commit was 02115d373b794b3, "LCL-GTK3: Turn WriteLn into DebugLn. Make sure they compile. Cleanup."
Most changes seem irrelevant. CT also did change Writeln to Debugln which is a good choice.
I included only a subset of their changes. Many of them did not compile which is weird. Like Integer - Boolean comparison and such. How can they compile their code?
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 25, 2022, 01:09:17 pm
OK, will do. As time permits....

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 27, 2022, 12:59:16 pm
Juha, the problem does appear to be in  02115d373b794b3, "LCL-GTK3: Turn WriteLn into DebugLn. Make sure they compile. Cleanup.", specifically in gtk3lclintf.inc

Around line 306 the function TGtk3WidgetSet.RawImage_DescriptionFromBitmap() pops some values into an array that is defined in gtk3bindings/lazcairo1.pas.  However, in the version committed in 02115d3 they appear to be in the wrong order compared to the bindings file. Looks like CT uncommented a few extra formats but they where in the wrong place ? It needs to be -

Code: Pascal  [Select][+][-]
  1. function TGtk3WidgetSet.RawImage_DescriptionFromBitmap(ABitmap: HBITMAP; out ADesc: TRawImageDescription): boolean;
  2. // var
  3. //  GDIObject: PGDIObject absolute ABitmap;
  4. const
  5.   CairoImageFormatToDepth: array[cairo_format_t] of integer =
  6.   (
  7.     {CAIRO_FORMAT_INVALID}   -1,
  8.     {CAIRO_FORMAT_ARGB32}    32,
  9.     {CAIRO_FORMAT_RGB24}     24,
  10.     {CAIRO_FORMAT_A8}         8,
  11.     {CAIRO_FORMAT_A1}         1,
  12.     {CAIRO_FORMAT_RGB16_565} 16,
  13.     {CAIRO_FORMAT_RGB30}     15
  14.   );  
                         

Now, doing that on my system certainly fixes the problem. The test is easy, blank form, add a speed button, assign it a bit map and test. On GTK3 without the fix, image is unrecognizable.

Do you want patch, pull request, bug report ?  Its an easy fix ....

Davo
Title: Re: Problem with gtk3 when compile empty app
Post by: dbannon on January 29, 2022, 11:49:44 am

I have posted a bug report.

https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39614

Davo
TinyPortal © 2005-2018