Bug 563001 - Changing system GTK theme doesn't reinit system colors
Summary: Changing system GTK theme doesn't reinit system colors
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.16   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.18 M1   Edit
Assignee: Amit Mendapara CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 563736
Blocks: 563684
  Show dependency tree
 
Reported: 2020-05-09 14:05 EDT by Anton Keks CLA
Modified: 2020-11-13 04:03 EST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Keks CLA 2020-05-09 14:05:13 EDT
There is code in Display.signalProc() that tries to re-initialize system colors if system theme changes. However, it doesn't get called when theme actually changes, resulting in some controls updating their colors, but many backgrounds staying with the old color from theme loaded at startup.

Seems to be broken for many SWT releases already.

This is especially prevalent when changing between Light/Dark themes in Gnome/Ubuntu 20.04.

I am using SWT for my own app (without JFace): https://angryip.org
Comment 1 Alexander Kurtakov CLA 2020-05-12 16:10:26 EDT
This has never been implemented. I agree it's good idea to reset the colors. Do you want to try providing a patch ?
Comment 2 Amit Mendapara CLA 2020-05-29 03:28:36 EDT
This is required to have proper dark theme support on Linux. See the Bug 563684.
Comment 3 Lars Vogel CLA 2020-05-29 03:33:05 EDT
(In reply to Amit Mendapara from comment #2)
> This is required to have proper dark theme support on Linux. See the Bug
> 563684.

Amit, can you provide a Gerrit?
Comment 4 Amit Mendapara CLA 2020-05-29 03:38:28 EDT
(In reply to Lars Vogel from comment #3)
> (In reply to Amit Mendapara from comment #2)
> > This is required to have proper dark theme support on Linux. See the Bug
> > 563684.
> 
> Amit, can you provide a Gerrit?

I worked on a GTK specific solution by listening to "notify::gtk-application-prefer-dark-theme" signal on GtkSettings with Display.signalProc() as callback.

What could be the proper way to do it for all supported platforms?
Comment 5 Amit Mendapara CLA 2020-05-29 03:49:01 EDT
As it's Linux/GTK specific, it should be acceptable. I will provide gerrit soon.
Comment 6 Eclipse Genie CLA 2020-05-29 03:57:16 EDT
New Gerrit change created: https://git.eclipse.org/r/163821
Comment 7 Lars Vogel CLA 2020-05-29 04:21:58 EDT
Gtk specific solution should be fine here. As we are in the 4.16 freeze this may have to wait 2 weeks.
Comment 8 Amit Mendapara CLA 2020-05-29 10:52:13 EDT
(In reply to Eclipse Genie from comment #6)
> New Gerrit change created: https://git.eclipse.org/r/163821

This change can lead to following error:

org.eclipse.swt.SWTException: Graphic is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4723)
	at org.eclipse.swt.SWT.error(SWT.java:4638)
	at org.eclipse.swt.SWT.error(SWT.java:4609)
	at org.eclipse.swt.graphics.Color.getRGB(Color.java:323)
	at org.eclipse.ui.themes.ColorUtil.getSystemColor(ColorUtil.java:137)
	at org.eclipse.ui.themes.ColorUtil.process(ColorUtil.java:48)
	at org.eclipse.ui.themes.ColorUtil.getColorValue(ColorUtil.java:156)
	at org.eclipse.ui.internal.themes.ColorDefinition.getValue(ColorDefinition.java:111)
	at org.eclipse.ui.internal.themes.ThemeElementHelper.installColor(ThemeElementHelper.java:287)
	at org.eclipse.ui.internal.themes.ThemeElementHelper.populateRegistry(ThemeElementHelper.java:184)
	at org.eclipse.ui.internal.themes.WorkbenchThemeManager.updateThemes(WorkbenchThemeManager.java:176)
	at org.eclipse.ui.internal.themes.WorkbenchThemeManager.lambda$1(WorkbenchThemeManager.java:147)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5686)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:5678)
	at org.eclipse.swt.widgets.Display.runSettings(Display.java:5008)


The code in question "WorkbenchThemeManager.updateThemes" seems too old and related to Windows. We can omit "sendEvent" from "Display.runSettings" but I don't know the purpose of emitting that event.
Comment 9 Amit Mendapara CLA 2020-05-29 11:42:32 EDT
The code in question is very old fix for the Bug 19229 and looks like Windows specific.
Comment 10 Soraphol (Paul) Damrongpiriyapong CLA 2020-07-28 09:45:34 EDT
Hello, I have tried testing the patch on Linux and haven't found a difference in behavior when I change the system theme through gnome-tweaks. I set a breakpoint at the callback function as well to see if the signal was emitted and found that it is not. 

Am I testing this correctly, if so please give me some help. Thanks!
Comment 11 Amit Mendapara CLA 2020-07-28 16:28:41 EDT
(In reply to Soraphol (Paul) Damrongpiriyapong from comment #10)
> Hello, I have tried testing the patch on Linux and haven't found a
> difference in behavior when I change the system theme through gnome-tweaks.
> I set a breakpoint at the callback function as well to see if the signal was
> emitted and found that it is not. 
I am not sure whether we can listen to system sent signal.
 
> Am I testing this correctly, if so please give me some help. Thanks!
Need to test with the changes of bug 563684. Apply the gerrit https://git.eclipse.org/r/163800 to eclipse.platform.ui and test it along with eclipse.platform.swt.
Comment 12 Lars Vogel CLA 2020-08-13 06:31:02 EDT
Any update on your testing, Paul?
Comment 13 Soraphol (Paul) Damrongpiriyapong CLA 2020-08-13 12:37:51 EDT
Hello, I have just gotten around to looking at this again. I have done what Amit asked me to do. (apply the patch from platform as well). Nothing has changed from my previous comment.  

My question is what is supposed to happen when I apply this patch? When I change the system theme in GNOME-tweaks, the signalProc function is not called as suggested by 

OS.g_signal_connect(GTK.gtk_settings_get_default (), OS.notify_theme_change, signalProc, STYLE_UPDATED);
Comment 14 Amit Mendapara CLA 2020-08-14 08:27:36 EDT
(In reply to Soraphol (Paul) Damrongpiriyapong from comment #13)
> Hello, I have just gotten around to looking at this again. I have done what
> Amit asked me to do. (apply the patch from platform as well). Nothing has
> changed from my previous comment.  
> 
> My question is what is supposed to happen when I apply this patch? When I
> change the system theme in GNOME-tweaks, the signalProc function is not
> called as suggested by 
> 
> OS.g_signal_connect(GTK.gtk_settings_get_default (), OS.notify_theme_change,
> signalProc, STYLE_UPDATED);

I don't know if this api can be used to trap system sent signals.

The signal is called on eclipse startup (soon after display is created) or when we change eclipse theme. This patch is required to re-initialize system colors when running eclipse with dark theme under light system (gnome) theme or vice versa.

To see the effect, apply https://git.eclipse.org/r/163800 patch and run eclipse as I mentioned in previous comment. If you run the eclipse with only https://git.eclipse.org/r/163800 patch and not this one, you will see wrong colors.
Comment 16 Niraj Modi CLA 2020-11-13 03:54:40 EST
Can this bug be closed ? otherwise please re-target.
Comment 17 Amit Mendapara CLA 2020-11-13 04:03:32 EST
Yes, it can be closed. Working fine with the fix.