index

X Nonrectangular Window

Shape Extension Protocol

Version 1.0X Consortium Standard X Version 11, Release 6.4

Keith Packard MIT X Consortium

Copyright (C) 1989 X Consortium Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of the X Consortium shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the X Consortium.

-- --

1. Overview

This extension provides arbitrary window and border shapes within the X11 protocol. The restriction of rectangular windows within the X protocol is a significant limitation in the implementa-tion of many styles of user interface. For example, many transient windows would like to display a "drop shadow" to giv e the illusion of 3 dimensions. As another example, some user interface style guides call forbuttons with rounded corners; the full simulation of a nonrectangular shape, particularly with respect to event distribution and cursor shape, is not possible within the core X protocol. As a final example, roundclocks and nonrectangular icons are desirable visual addition to the desktop.

This extension provides mechanisms for changing the visible shape of a window to an arbitrary, possiblydisjoint, nonrectangular form. The intent of the extension is to supplement the existing semantics, not replace them. In particular, it is desirable for clients that are unaware of the extension to still be able tocope reasonably with shaped windows. For example, window managers should still be able to negotiate screen real estate in rectangular pieces. To ward this end, any shape specified for a window is clipped by thebounding rectangle for the window as specified by the window's geometry in the core protocol. An expected convention would be that client programs expand their shape to fill the area offered by the windowmanager.

2. Description

Each window (even with no shapes specified) is defined by two regions: the bounding region and the clip region. The bounding region is the area of the parent window that the window will occupy (including border). The clip region is the subset of the bounding region that is available for subwindows and graphics.

The area between the bounding region and the clip region is defined to be the border of the window. A nonshaped window will have a bounding region that is a rectangle spanning the window, including itsborder; the clip region will be a rectangle filling the inside dimensions (not including the border). In this document, these areas are referred to as the default bounding region and the default clip region. For a win-dow with inside size of width by height and border width bwidth, the default bounding and clip regions are the rectangles (relative to the window origin):

bounding.x = -bwidthbounding.y = -

bwidthbounding.width =

width + 2 * bwidthbounding.height =

height + 2 * bwidth

clip.x = 0clip.y = 0 clip.width = widthclip.height =

height

This extension allows a client to modify either or both of the bounding or clip regions by specifying newregions that combine with the default regions. These new regions are called the client bounding region andthe client clip region. They are specified relative to the origin of the window and are always defined by off-sets relative to the window origin (that is, region adjustments are not required when the window is moved).

Three mechanisms for specifying regions are provided: a list of rectangles, a bitmap, and an existing bounding or clip region from a window. This is modeled on the specification of regions in graphics contexts in the core protocol and allows a variety of different uses of the extension. When using an existing window shape as an operand in specifying a new shape, the client region is used,unless none has been set, in which case the default region is used instead.

The effective bounding region of a window is defined to be the intersection of the client bounding regionwith the default bounding region. Any portion of the client bounding region that is not included in the default bounding region will not be included in the effective bounding region on the screen. This meansthat window managers (or other geometry managers) used to dealing with rectangular client windows will be able to constrain the client to a rectangular area of the screen. Construction of the effective bounding region is dynamic; the client bounding region is not mutated toobtain the effective bounding region. If a client bounding region is specified that extends beyond the current default bounding region, and the window is later enlarged, the effective bounding region will been larged to include more of the client bounding region.

The effective clip region of a window is defined to be the intersection of the client clip region with both thedefault clip region and the client bounding region. Any portion of the client clip region that is not included in both the default clip region and the client bounding region will not be included in the effective clipregion on the screen.

Construction of the effective clip region is dynamic; the client clip region is not mutated to obtain the effec-tive clip region. If a client clip region is specified that extends beyond the current default clip region and the window or its bounding region is later enlarged, the effective clip region will be enlarged to includemore of the client clip region if it is included in the effective bounding region.

The border of a window is defined to be the difference between the effective bounding region and the effec-tive clip region. If this region is empty, no border is displayed. If this region is nonempty, the border is filled using the border-tile or border-pixel of the window as specified in the core protocol. Note that a win-dow with a nonzero border width will never be able to draw beyond the default clip region of the window. Also note that a zero border width does not prevent a window from having a border, since the clip shapecan still be made smaller than the bounding shape.

All output to the window and visible regions of any subwindows will be clipped to the effective clip region.The server must not retain window contents beyond the effective bounding region with backing store. The window's origin (for graphics operations, background tiling, and subwindow placement) is not affected bythe existence of a bounding region or clip region.

Areas that are inside the default bounding region but outside the effective bounding region are not part ofthe window; these areas of the screen will be occupied by other windows. Input ev ents that occur within the default bounding region but outside the effective bounding region will be delivered as if the windowwas not occluding the event position. Events that occur in a nonrectangular border of a window will be delivered to that window, just as for events that occur in a normal rectangular border. An InputOnly window can have its bounding region set, but it is a Match error to attempt to set a clipregion on an InputOnly window or to specify its clip region as a source to a request in this extension.

The server must accept changes to the clip region of a root window, but the server is permitted to ignorerequested changes to the bounding region of a root window. If the server accepts bounding region changes, the contents of the screen outside the bounding region are implementation dependent.

3. Types

The following types are used in the request and event definitions in subsequent sections.

SHAPE_KIND: {Bounding, Clip}

SHAPE_OP: {Set, Union, Intersect, Subtract, Invert}

Set indicates that the region specified as an explicit source in the request is stored unaltered as the new des-tination client region. Union indicates that the source and destination regions are unioned together to produce the new destination client region. Intersect indicates that the source and destination regions are inter-sected together to produce the new destination client region. Subtract indicates that the source region is subtracted from the destination region to produce the new destination region. Invert indicates that the des-tination region is subtracted from the source region to produce the new destination region.

4. Requests

ShapeQueryVersion

major Version: CARD16 minor Version: CARD16

This request can be used to ensure that the server version of the SHAPE extension is usable by the client.This document defines major version one (1), minor version zero (0).

ShapeRectangles

dest: WINDOW destKind: SHAPE_KIND op: SHAPE_OP xOff, yOff: INT16 rectangles: LISTofRECTANGLES ordering: {UnSorted, YSorted, YXSorted, YXBanded}

Errors: Window, Length, Match, Value

This request specifies an array of rectangles, relative to the origin of the window plus the specified offset(xOff and yOff) that together define a region. This region is combined (as specified by the operator op) with the existing client region (specified by destKind) of the destination window, and the result is stored as the specified client region of the destination window. Note that the list of rectangles can be empty, specifying an empty region; this is not the same as passing None to ShapeMask. If known by the client, ordering relations on the rectangles can be specified with the ordering argument.This may provide faster operation by the server. The meanings of the ordering values are the same as in the core protocol SetClipRectangles request. If an incorrect ordering is specified, the server may generate aMatch error, but it is not required to do so. If no error is generated, the graphics results are undefined. Except for UnSorted, the rectangles should be nonintersecting, or the resulting region will be undefined.UnSorted means that the rectangles are in arbitrary order. YSorted means that the rectangles are nondecreasing in their Y origin. YXSorted additionally constrains YSorted order in that all rectangles with anequal Y origin are nondecreasing in their X origin. YXBanded additionally constrains YXSorted by requiring that, for every possible Y scanline, all rectangles that include that scanline have identical Y ori-gins and Y extents.

ShapeMask

dest: WINDOW destKind: SHAPE_KIND op: SHAPE_OP xOff, yOff: INT16 source: PIXMAP or None

Errors: Window, Pixmap, Match, Value

The source in this request is a 1-bit deep pixmap, or None. If source is None, the specified client region isremoved from the window, causing the effective region to revert to the default region. The ShapeNotify ev ent generated by this request and subsequent ShapeQueryExtents will report that a client shape has notbeen specified. If a valid pixmap is specified, it is converted to a region, with bits set to one included in the region and bits set to zero excluded, and an offset from the window origin as specified by xOff and yOff.The resulting region is then combined (as specified by the operator op) with the existing client region (indicated by destKind) of the destination window, and the result is stored as the specified client region of thedestination window. The source pixmap and destination window must have been created on the same screen, or else a Match error results.

ShapeCombine

dest: WINDOW destKind: SHAPE_KIND op: SHAPE_OP xOff, yOff: INT16 source: WINDOW sourceKind: SHAPE_KIND

Errors: Window, Match, Value

The client region, indicated by sourceKind, of the source window is offset from the window origin by xOffand yOff and combined with the client region, indicated by destKind, of the destination window. The result is stored as the specified client region of the destination window. The source and destination windows mustbe on the same screen, or else a Match error results.

ShapeOffset

dest: WINDOW destKind: SHAPE_KIND xOff, yOff: INT16

Errors: Window, Match, Value

The client region, indicated by destKind, is moved relative to its current position by the amounts xOff andyOff.

ShapeQueryExtents

dest: WINDOW =>

boundingShaped: BOOLclipShaped: BOOL

xBoundingShape: INT16yBoundingShape: INT16 widthBoundingShape: CARD16heightBoundingShape: CARD16 xClipShape: INT16yClipShape: INT16 widthClipShape: CARD16heightClipShape: CARD16

Errors: Window The boundingShaped and clipShaped results are True if the corresponding client regions have been speci-fied, else they are False. The x, y, width, and height values define the extents of the client regions, when a client region has not been specified, the extents of the corresponding default region are reported.

ShapeSelectInput

window: WINDOW enable: BOOL

Errors: Window, Value

Specifying enable as True causes the server to send the requesting client a ShapeNotify ev ent whenever

4

-- --

X11 Nonrectangular Window Shape Extension Protocol the bounding or clip region of the specified window is altered by any client. Specifying enable as Falsecauses the server to stop sending such events.

ShapeInputSelected

window: WINDOW =>

enable: BOOL Errors: Window

If enable is True, then ShapeNotify ev ents for the window are generated for this client.

ShapeGetRectangles

window: WINDOW kind: SHAPE_KIND

=>

rectangles: LISTofRECTANGLEordering: {UnSorted, YSorted, YXSorted, YXBanded}

Errors: Window, Match A list of rectangles describing the region indicated by kind, and the ordering of those rectangles, isreturned. The meaning of the ordering values is the same as in the ShapeRectangles request.

5. Events

ShapeNotify

window: WINDOW kind: SHAPE_KIND shaped: BOOL x, y: INT16 width, height: CARD16 time: TIMESTAMP

Whenever the client bounding or clip shape of a window is modified, a ShapeNotify ev ent is sent to eachclient that has used ShapeSelectInput to request it. Kind indicates which client region (bounding or clip) has been modified; shaped is True when the windowhas a client shape of type kind, and is False when the window no longer has a client shape of this type. The x, y, width, and height indicate the extents of the current shape. When shaped is False these will indi-cate the extents of the default region. The timestamp indicates the server time when the shape was changed.

6. Encoding

Please refer to the X11 Protocol Encoding document as this document uses conventions established there. The name of this extension is "SHAPE".

6.1. New Types SHAPE_KIND0 Bounding

1 Clip

SHAPE_OP 0 Set

1 Union2 Intersect 3 Subtract4 Inv ert

6.2. Requests

ShapeQueryVersion

1 CARD8 opcode1 0 shape opcode

2 1 request length =>1 1 Reply

1 unused2 CARD16 sequence number 4 0 length2 CARD16 major version 2 CARD16 minor version20 unused

ShapeRectangles

1 CARD8 opcode1 1 shape opcode

2 4+2n request length1 SHAPE_OP operation 1 SHAPE_KIND destination kind1 ordering

0 UnSorted1 YSorted 2 YXSorted3 YXBanded 1 unused4 WINDOW destination window 2 INT16 x offset2 INT16 y offset 8n LISTofRECTANGLE rectangles

ShapeMask

1 CARD8 opcode1 2 shape opcode

2 5 request length1 SHAPE_OP operation 1 SHAPE_KIND destination kind2 unused 4 WINDOW destination window2 INT16 x offset 2 INT16 y offset4 PIXMAP source bitmap

0 None

ShapeCombine

1 CARD8 opcode1 3 shape opcode

2 5 request length1 SHAPE_OP operation 1 SHAPE_KIND destination kind1 SHAPE_KIND source kind 1 unused4 WINDOW destination window 2 INT16 x offset2 INT16 y offset 4 WINDOW source window

ShapeOffset

1 CARD8 opcode1 4 shape opcode

2 4 request length1 SHAPE_KIND destination kind 3 unused4 WINDOW destination window 2 INT16 x offset2 INT16 y offset

ShapeQueryExtents

1 CARD8 opcode1 5 shape opcode

2 2 request length4 WINDOW destination window

=>1 1 Reply

1 unused2 CARD16 sequence number 4 0 reply length1 BOOL bounding shaped 1 BOOL clip shaped2 unused 2 INT16 bounding shape extents x2 INT16 bounding shape extents y 2 CARD16 bounding shape extents width2 CARD16 bounding shape extents height 2 INT16 clip shape extents x2 INT16 clip shape extents y 2 CARD16 clip shape extents width2 CARD16 clip shape extents height 4 unused

ShapeSelectInput

1 CARD8 opcode1 6 shape opcode

2 3 request length4 WINDOW destination window

1 BOOL enable3 unused

ShapeInputSelected

1 CARD8 opcode1 6 shape opcode

2 2 request length4 WINDOW destination window

=>1 1 Reply

1 BOOL enabled2 CARD16 sequence number 4 0 reply length24 unused

ShapeGetRectangles

1 CARD8 opcode1 7 shape opcode

2 3 request length4 WINDOW window 1 SHAPE_KIND source kind3 unused

=>1 1 Reply

1 ordering0 UnSorted

1 YSorted2 YXSorted 3 YXBanded2 CARD16 sequence number 4 2n reply length4 CARD32 nrects 20 unused8n LISTofRECTANGLE rectangles

6.3. Events

ShapeNotify

1 CARD8  type (0 + extension event base)
1 SHAPE_KIND  shape kind
2 CARD16  sequence number
4 WINDOW affected window
2 INT16  x value of extents
2 INT16  y value of extents
2 CARD16  width of extents
2 CARD16  height of extents
4 TIMESTAMP  server time
1 BOOL  shaped
11  unused

7. Glossary

bounding region
The area of the parent window that this window will occupy. This area is divided into two parts: the border and the interior.
clip region
The interior of the window, as a subset of the bounding region. This region describes the area thatwill be painted with the window background when the window is cleared, will contain all graphics output to the window, and will clip any subwindows.
default bounding region
The rectangular area, as described by the core protocol window size, that covers the interior of thewindow and its border.
default clip region
The rectangular area, as described by the core protocol window size, that covers the interior of thewindow and excludes the border.
client bounding region
The region associated with a window that is directly modified via this extension when specified by ShapeBounding. This region is used in conjunction with the default bounding region to produce the effective bounding region.
client clip region
The region associated with a window that is directly modified via this extension when specified byShapeClip. This region is used in conjunction with the default clip region and the client bounding region to produce the effective clip region.
effective bounding region
The actual shape of the window on the screen, including border and interior (but excluding the effectsof overlapping windows). When a window has a client bounding region, the effective bounding region is the intersection of the default bounding region and the client bounding region. Otherwise, theeffective bounding region is the same as the default bounding region.
effective clip region
The actual shape of the interior of the window on the screen (excluding the effects of overlappingwindows). When a window has a client clip region or a client bounding region, the effective clip region is the intersection of the default clip region, the client clip region (if any) and the client bound-ing region (if any). Otherwise, the effective clip region is the same as the default clip region.