Porting an FPC / Lazarus application from Windows to Linux

Reactions to  ....... or  .........  You have to type this. No cut&paste.

In short:
A program developed with Free Pascal and the Lazarus IDE on a Windows platform generally compiles and runs well on Linux.
But: I encountered several problems, most of cosmetic nature. Quite often cosmetics are important for a neat GUI.
You may download the whole GUI project here. View / Compile with the (latest) Free-Pascal / Lazarus IDE (freeware)

The case:
The application concerned is a Touch-screen GUI for a CNC milling machine. It was developed in early 2014 on a WXP platform with Lazarus 1.0.14 and FPC 2.6.2. For communication with the hardware controller (Arduino Mega with ETH shield) the Lnet605 library was installed in Lazarus.
The target platform was Ubuntu 12.4 LTS on a 32 bit i386 motherboard with an SSD. (In the future I'd like to port it to a Raspberry Pi. Produces less heat)

Below a screenshot of the -fttb- final ported version on WXP. I will not go into the functionality here.


Problems: (not in the order I found or resolved them)

Colors of controls:
It appeared that several colors were different in the Linux version. The reason was that I used some colors from the "system" palette, such as clScrollBar which easily differs from platform to platform, probably also from version to version.
The Message: Use only absolute colors, or -better- define the colors to use in hexadecimal form.

Positioning of controls in a GroupBox behaves different in WXP and Linux:
It appeared that the controls in a GroupBox were placed somewhat lower on the screen in the Linux version. Closer examination learned me that in Windows the Top property of the controls is measured w.r.t. the upper left of the box, while in linux it is w.r.t. the botton of the title font.
If you increase the title font all controls shift a bit down in Linux. Also, all controls are cut-off at the font-bottomline, over the full width of the box.
The workaround I used was a clause in the FormCreate procedure like: 
{$IFDEF linux}
        // The linux version appears to position the controls in a GroupBox
        // according to the Fontsize of the GroupBox title.
        // In windows the positions are relative to the box's outline.
        ShiftControlsInGroupBoxes := -10; // so we need to shift them in Linux
        ButtKoelMode.top := ButtKoelmode.top + ShiftControlsInGroupBoxes;
And: don't make the controls to high.

Wingdings 3 font:
On a few controls I used characters from the Windows font Wingdings3. (example: the right rotating arrow in the "Spindel" groupbox.
Althoug I installed Wingdings3 in Linux and although it showed perfectly in LibreOffice, and even in the Lazarus IDE while selecting a font, it did NOT show on the controls. Only a single-pixel-dot appeared.
The workaround I used was the following: Take screenshots from the WXP version, carefully cut them at the right size with a suitable picture editor and save them as a .bmp file. Then at FormCreate place these images on the controls you want to have them.
For this to succeed I had to change the type of these controls to Timage.

Touchscreen Double Click:
At first I had the expectation that it would take a lot of efford to get the touchscreen working under Linux. But that turned out to be the easy part. In ubuntu 12 most touchscreen stuff is already there. I have an ELO E271-2210 controller with serial interface.
Sufficient were the following entries:
In /etc/rc.local add a line /usr/bin/inputattach --daemon --elotouch /dev/ttyS0
To calibrate the touchscreen I used   (apt-get install) xinput-calibrator, but ignore the instructions for where to put the result. That dir/file is not there(*)
In stead edit  /usr/share/X11/xorg.conf.d/10-evdev.conf  and add in the section with  Identifier = "evdev touchscreen catchall"  the line
   Option  "Calibration" "3593 453 500 3445"  or whatever the calibration result was. This will let the calibration survive a reboot.

(*) Later, in trying to make an eGalax schreen work on another Linuxbox I found that creating that dir/file did work and that the 10-evdev.conf modification did not. So try both methods.

Now the Double Click problem:
Although several linux applications reacted properly to a doubleclick on the touchscreen (e.g. the desktop changer requires a double click to select the new desktop),  the FPC application did not. To get a doubleclick recognized I had to click almost impossibly fast and so the result was unreliable.
The ubuntu settings for mouse-doubleclick-time had no effect on the touchscreen. 

The workaround I used was the following, yes very specific for that application:
I added a button "DblClk" (the dark green one)  which sets a boolean "DblClk" and then turns red. There is a timer which after 1.5 seconds resets this boolean and the color. 
For controls which need to respond to a doubleclick I enabled both single- and doubleclick events. In the singeclick-event the boolean "DblClk" is inspected and if set, the doubleclick event is called.
This way it reacts in the normal way with mouse-doubleclicks (which worked from the beginning on) and also with the touchscreen, if you first hit the DblClk button.

The application uses some sounds to audibly mark the activation of a control or to report that you try to do something impossible or forbidden.
In the WXP version I used the MulitMedia control, but that is not available in Linux. The sound files were "click.wav" and "ding.wav" from the WXP system.
I have quite some experience with the Bass audio library in M$ Visual Basic 6, but I could not get it to work on the Linux box. There was a .dll problem which I could not fix.
So I went out, tried a few other things, an finally ended up with the UOS Audio Library which did what I wanted.    Or not completely?
At first I could not get it to work with .WAV files which I used in the old MM version. So I converted my sounds to mp3, which worked fine in WXP and in Linux. Or not?  When I ran the application in Linux as root or in the Lazarus IDE it worked fine, but as a normal user the "click.mp3"  file did play only at random, and mostly not. The "ding.mp3" played always.
The workaround was to use a somewhat larger file with a click sound, which played well on every ocasion.

Positioning of windows:
Probably this is not a FPC/Lazarus problem, but I had to explicitely put some things in the source code.
The WXP version was just full-screen 1024 x 768, the maximum resolution the available monitor could handle. That was not a problem.
For the Linux port I decided
not to use the full screen but to leave room for the dash and the top bar. This required me to scale down the size of the whole GUI and all of the controls, which took me a few hours or so. In the main form I had to explicitely set the Top and Left properties and to experiment with the correct values.