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

Bug 549451

Summary: [MAC][API]Query the current system setting for dark mode
Product: [Eclipse Project] Platform Reporter: Lakshmi P Shanmugam <lshanmug>
Component: SWTAssignee: Lakshmi P Shanmugam <lshanmug>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: ericwill, lshanmug, niraj.modi
Version: 4.12   
Target Milestone: 4.13 M3   
Hardware: PC   
OS: Mac OS X   
See Also: https://git.eclipse.org/r/146543
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=ef55fab390e3fdd8fba59a3541336ac5c7f8ac1f
https://git.eclipse.org/r/147532
https://git.eclipse.org/c/www.eclipse.org/eclipse/news.git/commit/?id=6659a2b2ce1804d8eee97139cc1771290ebaf1c9
Whiteboard:
Bug Depends on:    
Bug Blocks: 547038    

Description Lakshmi P Shanmugam CLA 2019-07-22 02:06:45 EDT
Bug 546859 captures the discussion for the complete set of APIs to get and set the Theme for SWT applications. 

This bug tracks the implementation of the API to detect if the current system setting is dark.

This API is required by Bug 547038 - when eclipse is starting up, detect if the System is in dark theme and then set Eclipse to dark theme automatically by applying the required css styling.
Comment 1 Eclipse Genie CLA 2019-07-24 02:54:23 EDT
New Gerrit change created: https://git.eclipse.org/r/146543
Comment 2 Lakshmi P Shanmugam CLA 2019-08-01 01:15:38 EDT
@Niraj, can you please provide the Windows implementation for the API?

For Windows, we could read the registry entry as specified in https://stackoverflow.com/questions/51334674/how-to-detect-windows-10-light-dark-mode-in-win32-application
Comment 3 Lakshmi P Shanmugam CLA 2019-08-01 01:30:12 EDT
@Eric,
Can you please check if you can implement this API on GTK? If this API works on GTK, we could have Eclipse on GTK too start in dark theme when system theme is dark (Bug 547038)

I did a quick google search on how to detect the Dark theme, but didn't find anything useful other than this - https://lzone.de/blog/Detecting%20a%20Dark%20Theme%20in%20GTK

The API is currently made static and that works fine for Mac & Windows. Will having it as static work for GTK too?
Comment 4 Niraj Modi CLA 2019-08-01 07:49:45 EDT
(In reply to Lakshmi Shanmugam from comment #2)
> @Niraj, can you please provide the Windows implementation for the API?
> 
> For Windows, we could read the registry entry as specified in
> https://stackoverflow.com/questions/51334674/how-to-detect-windows-10-light-
> dark-mode-in-win32-application

Created bug 549713
Comment 5 Eric Williams CLA 2019-08-01 08:55:10 EDT
(In reply to Lakshmi Shanmugam from comment #3)
> @Eric,
> Can you please check if you can implement this API on GTK? If this API works
> on GTK, we could have Eclipse on GTK too start in dark theme when system
> theme is dark (Bug 547038)
> 
> I did a quick google search on how to detect the Dark theme, but didn't find
> anything useful other than this -
> https://lzone.de/blog/Detecting%20a%20Dark%20Theme%20in%20GTK
> 
> The API is currently made static and that works fine for Mac & Windows. Will
> having it as static work for GTK too?

I'll take a look, should be doable by M3.
Comment 6 Eric Williams CLA 2019-08-01 15:28:50 EDT
(In reply to Eric Williams from comment #5)
> (In reply to Lakshmi Shanmugam from comment #3)
> > @Eric,
> > Can you please check if you can implement this API on GTK? If this API works
> > on GTK, we could have Eclipse on GTK too start in dark theme when system
> > theme is dark (Bug 547038)
> > 
> > I did a quick google search on how to detect the Dark theme, but didn't find
> > anything useful other than this -
> > https://lzone.de/blog/Detecting%20a%20Dark%20Theme%20in%20GTK
> > 
> > The API is currently made static and that works fine for Mac & Windows. Will
> > having it as static work for GTK too?
> 
> I'll take a look, should be doable by M3.

Turns out we already have an internal flag in GTK to look for ":dark" variant themes, so this is pretty straightforward. I've uploaded a patch for bug 549733, you can go ahead and merge this one and I'll rebase after you've done so.
Comment 7 Lakshmi P Shanmugam CLA 2019-08-05 06:20:17 EDT
(In reply to Eric Williams from comment #6)
> (In reply to Eric Williams from comment #5)
> > (In reply to Lakshmi Shanmugam from comment #3)
> > > @Eric,
> > > Can you please check if you can implement this API on GTK? If this API works
> > > on GTK, we could have Eclipse on GTK too start in dark theme when system
> > > theme is dark (Bug 547038)
> > > 
> > > I did a quick google search on how to detect the Dark theme, but didn't find
> > > anything useful other than this -
> > > https://lzone.de/blog/Detecting%20a%20Dark%20Theme%20in%20GTK
> > > 
> > > The API is currently made static and that works fine for Mac & Windows. Will
> > > having it as static work for GTK too?
> > 
> > I'll take a look, should be doable by M3.
> 
> Turns out we already have an internal flag in GTK to look for ":dark"
> variant themes, so this is pretty straightforward. I've uploaded a patch for
> bug 549733, you can go ahead and merge this one and I'll rebase after you've
> done so.

Thanks, that's great!
To clarify:
The API will return true only if :dark is specified in the dark theme name, and will return false for dark themes that don't follow this naming convention, right? Should we mention this as a note in the javadoc?
Comment 9 Eric Williams CLA 2019-08-05 14:45:00 EDT
(In reply to Lakshmi Shanmugam from comment #7)
> Thanks, that's great!
> To clarify:
> The API will return true only if :dark is specified in the dark theme name,
> and will return false for dark themes that don't follow this naming
> convention, right? Should we mention this as a note in the javadoc?

Correct. This will work for the official GTK theme (which is the only thing SWT-GTK supports), and most "sane" 3rd party themes -- I don't think a Javadoc comment is needed.
Comment 10 Lakshmi P Shanmugam CLA 2019-08-07 06:52:58 EDT
Resolving.
Comment 11 Eclipse Genie CLA 2019-08-12 04:10:43 EDT
New Gerrit change created: https://git.eclipse.org/r/147532
Comment 13 Lakshmi P Shanmugam CLA 2019-08-20 06:54:03 EDT
Verified in I20190819-2355.