Different background color on Windows and Linux

43 views
Skip to first unread message

Michele Alessandrini

unread,
Apr 22, 2026, 4:36:41 AM (13 days ago) Apr 22
to fltk.general
Hi, sometimes (not always) the background color of a window is lighter on Windows than on Linux. I'm attaching screnshots from one of the official examples where no color or theme is changed (happens in FLTK 1.4.4 and 1.5).
That's strange because the bg color is always 49, I checked the actual map and the color is #C0C0C0 in both cases.

win.png

linux.png

Michele Alessandrini

unread,
Apr 22, 2026, 5:52:07 AM (13 days ago) Apr 22
to fltk.general
Ok I digged a little bit more and found the function get_system_colors() that's OS-specific and changes some of the colors. It's called in Fl_Window::show(), so I was checking the color's value too early in the main(). Now I see that on Windows it's changed to #F0F0F0 (that may depends on my Windows configuration maybe).
How was #C0C0C0 chosen as a default on X11? I find it a little bit too dark... What if I call Fl::background() and change it to something else? When shoud I call it to not being changed back from get_system_colors()?
Thank you in advance
Michele

Manolo

unread,
Apr 22, 2026, 6:35:21 AM (13 days ago) Apr 22
to fltk.general
If you show your 1st window with win->show(argc, argv) or call Fl::args() the value of FL_BACKGROUND_COLOR
is given distinct values under each platform, which produces the color differences you report here.

To avoid that, you may refrain from transmitting (argc, argv), but this would prevent your program from
using any arguments, which is probably not the best choice.
You can also call Fl::background(r, g, b) to set the desired r,g,b for default widget backgrounds.
That call can be made after of before calling win->show(argc, argv) with no difference because
FLTK refrains from changing the background color during show(argc, argv) if the background
was set before. 

The Linux grey is (192,192,192). The default Windows grey is (240,240, 240) which is quite lighter.

Albrecht Schlosser

unread,
Apr 22, 2026, 8:33:30 AM (13 days ago) Apr 22
to fltkg...@googlegroups.com
On 4/22/26 11:44 Michele Alessandrini wrote:
> Ok I digged a little bit more and found the function
> get_system_colors() that's OS-specific and changes some of the colors.
> It's called in Fl_Window::show(), so I was checking the color's value
> too early in the main(). Now I see that on Windows it's changed to
> #F0F0F0 (that may depends on my Windows configuration maybe).
> How was #C0C0C0 chosen as a default on X11? I find it a little bit too
> dark...

I can't tell why this particular value was chosen, but I see that this
value has been in the code at least since 2003, maybe even earlier. It's
likely that this was a typical background color on Unix (or maybe
already on Linux) systems. Many features (colors, themes) were based on
SGI systems, AFAICT.

> What if I call Fl::background() and change it to something else? When
> should I call it to not being changed back from get_system_colors()?

Please see Manolo's reply on this.

I'd like to add that you can use the commandline switch " -bg
'#rrggbb00' " on Linux to test the background color (r/g/b) you like
best w/o having to change the source code - i.e. before you finalize
your code. Note the single quotes and the trailing 00, but remove the
double quotes.

In my opinion, however, it's not good practice to hardcode things like
the background color. Users should have the option to set the color
themselves (e.g., via preferences).

Michele Alessandrini

unread,
Apr 23, 2026, 5:18:23 AM (12 days ago) Apr 23
to fltk.general
Thanks to everyone!
Reply all
Reply to author
Forward
0 new messages