Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 519576

Summary: [GTK3] Use GTK CSS for background/foreground colors on GTK3.14 and below
Product: [Eclipse Project] Platform Reporter: Eric Williams <ericwill>
Component: SWTAssignee: Eric Williams <ericwill>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: loskutov
Version: 4.8Keywords: triaged
Target Milestone: 4.8 M7   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/101291
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=96f0522cddf7d1c748b48ed1d89b9374b0298000
https://git.eclipse.org/r/101588
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=a41ace50d2855d495d0fcf97bc5e59092a213f13
https://git.eclipse.org/r/101653
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=511aa0454b2843c23c65b83a67b3012babdde383
https://git.eclipse.org/r/102262
https://git.eclipse.org/r/102266
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=5b627dee1b88bd7a659b33fa7c94d1c23506bb75
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=b69831d4025b9c00cf4f5f43b3a78aafa674e76d
Whiteboard:

Description Eric Williams CLA 2017-07-12 15:00:27 EDT
Now that SWT has support for transparent colors, there are some notable issues with the SWT background/foreground machinery that need to be fixed on GTK3.14 and below.

For example, consider the following code:

GdkRGBA rgba = new GdkRGBA();
long /*int*/ context = OS.gtk_widget_get_style_context (handle);
if (OS.GTK_VERSION < OS.VERSION(3, 18, 0)) {
    OS.gtk_style_context_get_background_color (context, OS.GTK_STATE_FLAG_NORMAL, rgba);
} else {
    OS.gtk_style_context_get_background_color (context, OS.gtk_widget_get_state_flags(handle), rgba);
}
draw = rgba.alpha == 0;


This code is now problematic because rgba.alpha could be 0 because a transparent color was set. In the past this was used to check if the rgba returned was NULL, based on the assumption that all colors are opaque. This code is in the windowProc() callback which determines if a Control draws its background.

Instead we should use GTK CSS, which supports background and foreground colors out of the box as of GTK 3.0.[1] This would bring background/foreground colors into line with the current approach on GTK3.16+, which makes for better flowing code and easier debugging.

1: https://thegnomejournal.wordpress.com/2011/03/15/styling-gtk-with-css/
Comment 1 Eclipse Genie CLA 2017-07-14 11:47:31 EDT
New Gerrit change created: https://git.eclipse.org/r/101291
Comment 2 Eric Williams CLA 2017-07-14 11:53:16 EDT
(In reply to Eclipse Genie from comment #1)
> New Gerrit change created: https://git.eclipse.org/r/101291

This patch moves back the threshold for GTK CSS from 3.16+ to 3.14+. 3.14 and below still uses GtkStyleContext machinery, since CSS working on GTK3.10 and below requires more investigation.

I am planning on doing this incrementally to prevent big breakages where possible.
Comment 4 Eric Williams CLA 2017-07-18 13:04:32 EDT
(In reply to Eclipse Genie from comment #3)
> Gerrit change https://git.eclipse.org/r/101291 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=96f0522cddf7d1c748b48ed1d89b9374b0298000

This is an incremental patch which brings GTK CSS for backgrounds and foregrounds to GTK 3.14. GTK3.10 and below still use GtkStyleContext machinery (for now).
Comment 5 Eclipse Genie CLA 2017-07-19 15:18:13 EDT
New Gerrit change created: https://git.eclipse.org/r/101588
Comment 7 Eric Williams CLA 2017-07-19 16:02:19 EDT
(In reply to Eclipse Genie from comment #6)
> Gerrit change https://git.eclipse.org/r/101588 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=a41ace50d2855d495d0fcf97bc5e59092a213f13

This was just a simple fix for Tree/Table/List selection colours. GTK3.20+ uses the old style selector for selection backgrounds.
Comment 9 Eclipse Genie CLA 2017-07-20 10:55:28 EDT
New Gerrit change created: https://git.eclipse.org/r/101653
Comment 11 Eric Williams CLA 2017-07-20 11:07:19 EDT
(In reply to Eclipse Genie from comment #10)
> Gerrit change https://git.eclipse.org/r/101653 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=511aa0454b2843c23c65b83a67b3012babdde383

Test fixes are merged. Just reverted some of the Table/Tree fixes from earlier. Nothing new in this patch.
Comment 12 Eclipse Genie CLA 2017-07-31 13:34:14 EDT
New Gerrit change created: https://git.eclipse.org/r/102262
Comment 13 Eclipse Genie CLA 2017-07-31 15:10:16 EDT
New Gerrit change created: https://git.eclipse.org/r/102266
Comment 15 Eric Williams CLA 2017-07-31 15:52:13 EDT
(In reply to Eclipse Genie from comment #14)
> Gerrit change https://git.eclipse.org/r/102262 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=5b627dee1b88bd7a659b33fa7c94d1c23506bb75

This fixes the failing Platform UI test case: 

http://download.eclipse.org/eclipse/downloads/drops4/I20170728-2000/testresults/html/org.eclipse.e4.ui.tests.css.swt_ep48I-unit-cen64-gtk3_linux.gtk.x86_64_8.0.html
Comment 17 Eric Williams CLA 2017-08-08 11:22:05 EDT
(In reply to Eclipse Genie from comment #16)
> Gerrit change https://git.eclipse.org/r/102266 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=b69831d4025b9c00cf4f5f43b3a78aafa674e76d

Test cases for SWT to prevent a similar bug from happening in the future.
Comment 18 Eric Williams CLA 2018-03-28 11:25:02 EDT
I'm going to close this one as it's really no longer worth it to spend time getting GTK3.14- to work properly. 3.14+ using GTK CSS for colors is sufficient IMO.
Comment 19 Eric Williams CLA 2018-05-08 10:24:50 EDT
Verified in I20180507-2205.