aerothemeplasma/Documentation/Software/KWin/Reflection.md

12 KiB
Executable File

REFLECTION EFFECT FOR KWIN

TABLE OF CONTENTS

  1. Detailed description
  2. List of excluded windows
  3. Reflection algorithm
  4. Colorization
  5. Configuration menu

Detailed description

This is a KWin effect forked from the internal blur effect. It provides the reflection and colorization effect from Windows Vista and 7. These two effects achieve a "tinted glass" effect which is applied to most transparent graphical effects. Despite being a fork of the internal blur effect from KWin, all of the blurring functionality has been stripped out, as this effect is designed to be used alongside the blur effect, rather than being a drop-in replacement.

Before the introduction of this effect, this project didn't have proper reflections and colorization was done in a rather inefficient way, having to directly edit SVG files and the Emerald theme config file in order to change the accent color across KDE. Furthermore, real time changes weren't possible through this method, instead having to reload the Plasma style and restart the compositor in order to apply the changes. AeroColorMixer did all of this under the hood, and would often break after subsequent updates.

AeroColorMixer as a standalone program is now deprecated and most of the underlying code has been removed, while the rest has been moved to this effect's settings menu. With this, the following changes have been made to simplify the process of applying accent colors:

  1. SVG files are no longer edited and elements that are supposed to be colorized are now completely transparent.
  2. Likewise, the Emerald theme is also no longer edited and elements that are supposed to be colorized are now completely transparent.
  3. Changes to the accent color and transparency are instant and rely on shared memory between the effect and the config menu.
  4. Everything is contained within the configuration of this effect. Because of this, ~/.config/.aerorc is no longer used.

The rendering priority relative to the blur effect, assuming no other active effects, goes like this:

  1. Blur
  2. Colorization
  3. Reflections
  4. Decorations

This ensures that reflections are always visible regardless of transparency options, which was a limitation of the previous approach to applying accent colors.

The user can provide their own reflection texture in the config menu for the effect, in a PNG format. A default reflection texture is already provided by the effect, which also acts as a fallback in case the provided texture file is invalid, doesn't exist or the path itself is invalid.

List of excluded windows

Reflections will not render on certain types of windows, even if they are normally allowed to have blur behind them. Here's the list of windows that are not affected by this effect, as defined by the method isWindowValid(KWin::EffectWindow*):

  • The desktop shell
  • Toolbars
  • Tooltips
  • Menus
  • Dropdown menus
  • Popup menus
  • Splash screens
  • Normal and critical notifications
  • OSDs
  • Combo boxes
  • Do not disturb icons
  • Windows specifically excluded by the user

The user can define a list of programs that should be excluded by this effect. The programs are identified by their X11 window class, separated by a semicolon (;) in the config menu.

The colorization effect can also be ignored for programs defined by the user in the same manner as above, however it should be noted that the colorization is applied to all server-side decorations regardless of the defined restrictions.

Reflection algorithm

As the reflection effect from Windows Vista and 7 is closed source, this is merely an effort to recreate the effect based on what can be deduced just by looking at what the effect does. At its core, the effect is very simple; it works as if the reflection texture is stretched across the monitor (or across multiple monitors) and transparent windows render the portion of the texture that they're "hovering above".

Of course, as the monitor configuration changes in any way (resolution, monitor placement), the texture is "stretched" again to cover all monitors. This may cause the texture to scale and distort out of proportion. Some examples of how the effect stretches the texture across different monitor configurations are shown below.

In the fragment shader, as the window draws the texture, the fragment coordinates are normalized relative to the screen geometry, and then used to sample the reflection texture. It should be noted that the sampling is done with a bilinear filter, and the alpha blending is done using glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_SRC_ALPHA).

There is also a secondary part of the reflection effect, which is a subtle horizontal offset that makes the reflection appear to move as the window is moved, creating a sort of parallax effect. This offset is calculated independently for every window by subtracing the horizontal midpoint of the screen with the horizontal midpoint of the window, and dividing that difference by some constant. Through some experimentation, a constant with the value of 10 gives acceptable results.

This additional parallax effect can be toggled in the config menu by the user.

Colorization

Colorization is the effect of rendering a color over the blurred background behind windows, causing a tinted appearance. The color can be either semi-transparent or opaque, and depending on the option set by the user, the accent color is altered in the following way:

  1. If transparency is enabled, the color is blended using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) as it's being rendered.
  2. If transparency is disabled, the color is mixed with a base color #e1e1e1 and the alpha component is treated as the percentage of mixing.

It should be noted that if transparency is disabled, this won't affect compositing, and it will also not guarantee that all graphical elements will be rendered with an opaque color due to user-defined exclusions of colorization. For example, Konsole can still render blur behind its custom blur region, if it is included in the exclusion list.

The accent color also changes depending on the window's focus state:

  1. If transparency is enabled, the alpha component of the accent color gets halved when the window is out of focus.
  2. If transparency is disabled, the saturation component (HSL) gets halved when the window is out of focus.

This only applies to regular windows (most windows with server-side decorations).

Configuration menu

The accent color can be edited in real time through the configuration menu. Internally, the color is stored in the RGB color model as that's what OpenGL expects during rendering. The color mixer window is designed to look and function like Windows 7's Personalization menu, and includes the accent colors found on Windows 7, which were directly pulled from the following registry key:

[ HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor ]

On Windows Vista, 7 and 8.1, this registry key holds the currently applied accent color, stored in the #AARRGGBB format. The predefined colors are:

Color Name Value
      Sky #6b74b8fc
      Twilight #a80046ad
      Sea #8032cdcd
      Leaf #6614a600
      Lime #6697d937
      Sun #54fadc0e
      Pumpkin #80ff9c00
      Ruby #a8ce0f0f
      Fuchsia #66ff0099
      Blush #70fcc7f8
      Violet #856e3ba1
      Lavander #528d5a94
      Taupe #6698844c
      Chocolate #a84f1b1b
      Slate #80555555
      Frost #54fcfcfc
      Sunset #89e61f8c

Sunset is a predefined color exclusive to AeroThemePlasma.

Windows Vista and 8.1 feature a unique selection of colors as well. Vista features significantly less colors than Windows 7, with a lot more straightforward color names:

Color Name Value
      Default #45409efe
      Graphite #a3000000
      Blue #a8004ade
      Teal #82008ca5
      Red #9cce0c0f
      Orange #a6ff7700
      Pink #49f93ee7
      Frost #cceff7f7

Windows 8.1 features a slightly more pastel variety of colors compared to Windows 7 and includes a new feature that can determine the accent color from the wallpaper by choosing its dominant color:

Color Value
      #c48f8f8f
      #c484c6ff
      #c4f276c9
      #c4f0c300
      #c492cb2a
      #c44ccdcd
      #c4ff981d
      #c4ff4040
      #c4ff57ab
      #c40abf46
      #c4c071ff
      #c454afff
      #c48c90ff
      #c4b09d8b
      #c4ffffff



While not very conclusive, here is a useful thread for more information on how accent colors work in Aero, focusing mainly on Windows 7.