Bug 1232

Summary: NEWT Translucent [decorated] Windows Not Working On Windows >= 8 (Lack of Aero / Blur)
Product: [JogAmp] Newt Reporter: Sven Gothel <sgothel>
Component: windowsAssignee: Sven Gothel <sgothel>
Status: RESOLVED FIXED    
Severity: enhancement CC: alan.zgb, kdropucic
Priority: ---    
Version: 2.3.2   
Hardware: All   
OS: windows   
Type: FEATURE SCM Refs:
b3ecc88efca2a2f969e1e5a375086148821ee3c5 a9b3f6d13b45284e81b91a1e1e31b35c31dd3670 f60bc2eb827a89d5d26d7348761da268306c0623
Workaround: ---
Bug Depends on: 517    
Bug Blocks:    

Description Sven Gothel 2015-09-26 07:11:18 CEST
Alan Sambol reported in Bug 517 Comment 5:

"It seems translucency doesn't work on Windows 8 nor Windows 10 (they removed Aero effect in Windows 8 AFAIK). Tried with NEWT."
Comment 1 Sven Gothel 2015-09-26 08:06:55 CEST
<https://msdn.microsoft.com/en-us/library/windows/desktop/aa969538%28v=vs.85%29.aspx>

"Note  As of Windows 8, the information in this section is no longer valid. DWM can no longer be programmatically disabled, nor is it disabled when an application attempts to draw to the primary display surface. The following information applies to only Windows 7 and earlier systems."

+++

DwmIsCompositionEnabled:
<https://msdn.microsoft.com/en-us/library/windows/desktop/aa969518%28v=vs.85%29.aspx>
"Note  As of Windows 8, DWM composition is always enabled. If an app declares Windows 8 compatibility in their manifest, this function will receive a value of TRUE through pfEnabled. If no such manifest entry is found, Windows 8 compatibility is not assumed and this function receives a value of FALSE through pfEnabled. This is done so that older programs that interpret a value of TRUE to imply that high contrast mode is off can continue to make the correct decisions about rendering their images. (Note that this is a bad practice—you should use the SystemParametersInfo function with the SPI_GETHIGHCONTRAST flag to determine the state of high contrast mode.)"

Looks like we shall wrap this method
and always return true if >= 8!

+++

We use 'DwmEnableBlurBehindWindow()'
<https://msdn.microsoft.com/en-us/library/windows/desktop/aa969537%28v=vs.85%29.aspx>

Should work as expected!
...
Comment 2 Sven Gothel 2015-09-26 08:17:30 CEST
Also see Version Number <https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832%28v=vs.85%29.aspx>.

Example:
  - Windows 10, Java8_u60:
    - OS Version 10.0
    - NEWT Applet w/ translucent window works.
Comment 3 Sven Gothel 2015-09-26 08:51:19 CEST
Commandline:
  - OS Version 10.0 .. Java8_u60

What I have experienced is:
  - Window Decoration Off: Translucency works
  - Window Decoration On: Translucency does not work
Comment 4 Sven Gothel 2015-09-26 09:56:47 CEST
commit b3ecc88efca2a2f969e1e5a375086148821ee3c5:

    - Wrap GDI::DwmIsCompositionEnabled() in GDIUtil,
      so it always returns true if Windows >= 8 (even if not manifested)
    
    - Nothing we seem to be able to do about the lack of Aero,
      i.e. blur effect of decorated windows
    
    - Undecorated windows work well though ..
Comment 5 Sven Gothel 2015-09-26 09:58:12 CEST
if you know a way to add Aero / Blur programmatically or otherwise,
pls add this info here, thx!

I close this bug now. At least the little API change could be addressed.
Comment 6 Alan Sambol 2015-09-28 11:17:29 CEST
Tested in Windows 10 with RawGL2ES2demo (both decorated and undecorated window) and still no transparency. On Linux the same source works.

Used gluegen-b896-896 and jogl-b1452-1452 jars (latest I found, checked their src and it contains the changes from commit b3ecc88efca2a2f969e1e5a375086148821ee3c5):
jogl-all.jar
jogl-all-natives-windows-amd64.jar
gluegen-rt.jar
gluegen-rt-natives-windows-amd64.jar

Am i missing something in Windows settings, maybe some option to enable transparent windows?

Thanks for your quick responses!
Comment 7 Sven Gothel 2015-09-30 16:45:10 CEST
Seems Windows 10 has a new undocumented API for translucency ..

'SetWindowCompositionAttribute'

- <https://github.com/riverar/sample-win10-aeroglass/blob/master/MainWindow.xaml.cs>

- <http://undoc.airesoft.co.uk/user32.dll/SetWindowCompositionAttribute.php>
- <http://undoc.airesoft.co.uk/user32.dll/GetWindowCompositionAttribute.php>

It is proposed to use 'SetWindowCompositionAttribute'
instead of 'DwmEnableBlurBehindWindow',
maybe even abandon 'DwmExtendFrameIntoClientArea'.

See <http://withinrafael.com/adding-the-aero-glass-blur-to-your-windows-10-apps/>.
Comment 8 Sven Gothel 2015-09-30 16:46:12 CEST
Fix for Bug 1205 comment 3, 
see JOGL commit f607c0148736fa198fb91b60123824e53366022e,
also seems to break translucency on Windows 10.

But have to validate w/ 'SetWindowCompositionAttribute'
comment 7.
Comment 9 Sven Gothel 2015-10-02 00:02:51 CEST
commit a9b3f6d13b45284e81b91a1e1e31b35c31dd3670

Adopting new undocumented user32.dll Windows >= 8 API:
  - SetWindowCompositionAttribute / AccentState

See:
  - <https://github.com/riverar/sample-win10-aeroglass/blob/master/MainWindow.xaml.cs>
  - <http://withinrafael.com/adding-the-aero-glass-blur-to-your-windows-10-apps/>
  - <http://undoc.airesoft.co.uk/user32.dll/SetWindowCompositionAttribute.php>
  - <http://undoc.airesoft.co.uk/user32.dll/GetWindowCompositionAttribute.php>

+++

Cleaning up WindowsDWM.h, use on header file (in stub_includes)
for GlueGen and implementation.

+++

Merge java implementation within GDIUtil.DwmSetupTranslucency(..),
to be utilized by NEWT and JOGL.

NEWT issues GDIUtil.DwmSetupTranslucency(..) at creation
and when toggling decoration.

Toggling decoration on Win >= 8 leads to lost of translucency
when returning to decorated window.
On Win 7, this may work .. but is also buggy.

+++

Followup patch is needed for NEWT to _not_ clear the background!
Comment 10 Sven Gothel 2015-10-02 00:03:26 CEST
commit f60bc2eb827a89d5d26d7348761da268306c0623

Revert clear background to support fix for Bug 1232: 
NEWT Translucency Windows >= 8
    
Reverting 'clear backrgound' portion of commit f607c0148736fa198fb91b60123824e53366022e.
It has been identified, that Windows does initialize 
onscreen windows (i.e. w/ white/DESKTOP color).
    
This is also required for allowing translucent windows,
since clearing the background intefers on Windows >= 8 (undecorated windows).
Comment 11 Alan Sambol 2015-10-02 12:22:55 CEST
Tested build jogl-b1456-1456 on Windows 10 and translucency works only for decorated windows.

Is there a way to avoid Aero Blur translucency and have full transparency, like on Linux? Our goal is to achieve a "non-rectangular", undecorated window.