[Lazarus] Gtk 1.2 fixes (again)

Kostas Michalopoulos badsectoracula at gmail.com
Sat Feb 12 18:25:18 CET 2022

Sending this mail again since it didn't arrive last time (can't even see 
it in the archives).

This is actually my third attempt, using my gmail account now (i tried 
my own email - not sure if it didn't pass through because the other one 
wasn't subscribed or due to some configuration issue... the mailing list 
page mentions that i only need to be subscribed to receive messages, not 
to send them too so i assumed it'd work - in the former case, i wonder 
how many of my replies were ignored since i switched to my own domain's 


Hi all,

I submitted some fixes for the Gtk 1.2 LCL backend here that should 
bring it in working state (as it is right now it doesn't build due to 
some procs being moved to other units and even after adding those it 
barely works, windows get moved to 0,0, changing desktops or shading 
windows is broken, opening various dialogs crashes the program and other 
nice stuff :-P).


With the patch applied the IDE seems to work fine for the most part. 
There are some glitches (e.g. the main window doesn't get the proper 
height at first try but shading/unshading it or changing desktop and 
coming back or even just changing active tab in the component palette - 
basically anything that causes it to recalculate the height after it has 
been visible for a bit - fixes it so it is more of an annoyance than a 
blocker) but it works. Similarly it seems to use the wrong mouse cursor 
in some cases.

I've also tried a bunch of examples as well as some of my own projects 
and anything that didn't need functionality that wouldn't exist in Gtk 
1.2 anyway seemed to work fine.

I might check those at some point but for now i wanted to fix the more 
broken things, like windows not being positioned correctly, the IDE 
getting minimized when switching desktops and crashing when trying to 
open some forms like the console output or the Lazarus build 
configuration. Especially that last one since i spend the whole day 
trying to track it down (and turned out to be a bug in Gtk 1.2 that is 
only triggered in specific creation order for notebook pages - which i 
had to work around).

There are a couple of hacks in there that might have been done better 
(but still beats the current state of not working at all :-P):

1. The Gtk 1.2 LCL backend treats the unmapping as if it was a minimize 
event but that isn't strictly correct since unmapping can also happen 
when a window is shaded or when the current desktop changes. In either 
case you do not want all application windows to be minimized (which is 
what normally happens for a minimize event). There was some code to 
check for the desktop change case but there is a race condition which 
triggers with modern fast desktops (i guess it was written a long time 
ago) where the unmap event happens before the window manager switches 
desktops. I added a check for the shaded state and... a hacky Sleep for 
100ms (happens only once even with multiple unmapped windows) to avoid 
the race condition :-P. Even at 10ms seemed to work but i put it at 
100ms which seem safe.

2. The ScrollWindowEx function was not implemented at all and some 
controls, like the tree widget seem to rely on it for visual updates 
when scrolling, which in practice means that nothing scrolls when you 
use the scrollbar or the mouse wheel over the control. With my patch it 
still doesn't work, but i made it invalidate the control that requested 
the scroll which causes it to fully draw itself (and adds the ironic 
twist where the control uses ScrollWindowEx to optimize draws but ends 
up doing more work instead :-P). The call still returns False (ie. it 
failed) so it shouldn't break anything as the invalidation could 
theoretically come from anything - ie. some overzealous window manager 
or something. In theory some control could rely on scrolling to display 
partial animations but that control would have been broken in Gtk 1.2 

I have also tried the OpenGL control but it doesn't seem to build. I've 
spent very little time on it though but i'll try to fix it in a separate 

Note that the link above also contains a link to the Gtk 1.2 libraries 
(source code) that the LCL backend relies on that should compile with 
current Linux OSes (though there will be some warnings). Gtk and glib 
are from Slackware and with its patches applied with some minor mod and 
Gdk_pixbuf (which Slackware doesn't seem to carry - or at least not the 
version needed by the Gtk 1.2 backend since there is the Gtk 2.x verson) 
is from an old Red Hat source distribution (might not be the latest 
version but LCL doesn't seem to use it much - it might be possible to 
remove the current dependency so that things work in Slackware out of 
the box as it seems to be one of the very few distributions that still 
ship with Gtk 1.2) that i have fixed to build and install without (much) 
problem. So if you want to test it you can find the sources there (make 
sure to read the README).


More information about the lazarus mailing list