< KWin
Revision as of 21:43, 25 January 2011 by Mgraesslin (talk | contribs) (Idea for new shadows)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

KWin Shadows

The ideas for a new shadow system originated from the disadvantages of the old system. The old code shows serious bugs in conjunction with blur effect, slows down the system, is mostly obsoleted by the decoration shadows and not consistent with the overall look'n'feel. The widget style has no influence in the shadow.

Giving control to the Widget Style

The new system should give the control to the widget style. A shadow is part of the overall light model. The compositor does not know about the light model or about things like the Oxygen glow.

Nevertheless the decoration shadows should be kept and the new shadow system should only be used if the decoration does not provide shadows. The new system is therefore mostly meant for unmanaged windows such as menus, tooltips, dropdown menus, etc. but can also be used for "normal" windows with a legacy decoration. In future we could think about allowing an ARGB deco to not use the decoration shadows any more, but the new system. For decorations like Aurorae we will still need the decoration shadows.

The shadow elements

The shadow elements are inspired by Plasma's FrameSvg borders. There will be eight pixmaps defining the shadow:

* top-left
* top
* top-right
* right
* bottom-right
* bottom
* bottom-left
* left

The center element is not required as we do not want to have shadows behind the window. The shadow pixmaps are specified on the root window with the following new properties:

* _KDE_NET_WM_SHADOW_TOPLEFT
* ...
* _KDE_NET_WM_SHADOW_LEFT

An additional property is required to define whether the border elements (without the corners) need to be stretched or tiled:

* _KDE_NET_WM_SHADOW_TILE_BORDER with 0 for stretch and 1 for tile

The compositor announces support for the shadows through _KDE_NET_WM_SHADOW

Requesting Shadow for a Window

To set a shadow for a window the toolkit/widget style should set the property _KDE_NET_WM_SHADOW. The structure of the property is the padding in the various directions starting from top in clockwise direction. For border elements only one element is required, for corner elements x and y padding is required, that is 12 elements:

* padding in y-pixels for TOP
* padding in x-pixels for TOP-RIGHT
* padding in y-pixels for TOP-RIGHT
* padding in x-pixels for RIGHT
* ...
* padding in x-pixels for TOP-LEFT
* padding in y-pixels for TOP-LEFT

An example for a shadow of 10 pixels in all directions and 20 pixels on the bottom would look like the following: _KDE_NET_WM_SHADOW=10, 10, 10, 10, 10, 20, 20, 10, 20, 10, 10, 10

The pixmaps start from the offset and are painted in there complete size. For the borders the pixmaps are either tiled or stretched in the respective direction, the other size is fixed.

Implementation in KWin

Shadows are moved directly into the compositor following the approach of the decoration shadows. Window quads for each of the shadow areas are added and rendered before the window (if it is RGB) or rendered together with the window in case of RGBA (for Oxygen the latter case will always be the case).

Moving the shadows directly into the compositor and not in an effect should provide the required performance and should not show the visual bugs seen before with e.g. blur effect. The shadow belongs to the window, so even wobbly shadows should work better ;-)

Ideas for Future Improvements

The toolkit should be allowed to set several shadows. E.g. one for active windows, one for inactive, one for unmanaged and so on. The toolkit should be allowed to define animation transitions from one of the shadow states to another (goodbye Oxygen pixmap cache problems with NVIDIA blob). It should be possible to set shadow pixmaps on a per-window level (though global shadows on the root window should be preferred for performance reasons).


Content is available under Creative Commons License SA 4.0 unless otherwise noted.