## Documentation ¶

### Overview ¶

Package xrect defines a Rect interface and an XRect type implementing the Rect interface for working with X rectangles. Namely, X rectangles are specified by the 4-tuple (x, y, width, height) where the origin is the top-left corner and the width and height *must* be non-zero.

Some of the main features of this package include finding the area of intersection of two rectangles, finding the largest overlap between some rectangle and a set of rectangles, applying partial struts to rectangles representing all active heads, and a function to subtract two rectangles.

### Index ¶

- func ApplyStrut(rects []Rect, rootWidth, rootHeight uint, ...)
- func IntersectArea(r1 Rect, r2 Rect) int
- func LargestOverlap(needle Rect, haystack []Rect) int
- func Pieces(xr Rect) (int, int, int, int)
- func RectPieces(xr Rect) (int, int, int, int)
- func Valid(r Rect) bool
- type Rect
- type XRect
- func (r *XRect) Height() int
- func (r *XRect) HeightSet(height int)
- func (r *XRect) Pieces() (int, int, int, int)
- func (r *XRect) String() string
- func (r *XRect) Width() int
- func (r *XRect) WidthSet(width int)
- func (r *XRect) X() int
- func (r *XRect) XSet(x int)
- func (r *XRect) Y() int
- func (r *XRect) YSet(y int)

### Constants ¶

This section is empty.

### Variables ¶

This section is empty.

### Functions ¶

#### func ApplyStrut ¶

func ApplyStrut(rects []Rect, rootWidth, rootHeight uint, left, right, top, bottom, left_start_y, left_end_y, right_start_y, right_end_y, top_start_x, top_end_x, bottom_start_x, bottom_end_x uint)

ApplyStrut takes a list of Rects (typically the rectangles that represent each physical head in this case), the root window geometry, and a set of parameters representing a strut, and modifies the list of Rects to account for that strut. That is, it shrinks each rect. Note that if struts overlap, the *most restrictive* one is used. This seems like the most sensible response to a weird scenario. (If you don't have a partial strut, just use '0' for the extra fields.) See xgbutil/examples/workarea-struts for an example of how to use this to get accurate workarea for each physical head.

#### func IntersectArea ¶

IntersectArea takes two rectangles satisfying the Rect interface and returns the area of their intersection. If there is no intersection, return 0 area.

#### func LargestOverlap ¶

LargestOverlap returns the index of the rectangle in 'haystack' that has the largest overlap with the rectangle 'needle'. This is commonly used to find which monitor a window should belong on. (Since it can technically be partially displayed on more than one monitor at a time.) Be careful, the return value can be -1 if there is no overlap.

#### func RectPieces ¶

RectPieces just returns a four-tuple of x, y, width and height

### Types ¶

#### type Rect ¶

type Rect interface { X() int Y() int Width() int Height() int XSet(x int) YSet(y int) WidthSet(width int) HeightSet(height int) Pieces() (int, int, int, int) }

Define a base and simple Rect interface.

#### func Subtract ¶

Subtract subtracts r2 from r1 and returns the result as a new slice of Rects. Basically, rectangle subtraction works by cutting r2 out of r1, and returning the resulting rectangles. If r1 does not overlap r2, then only one rectangle is returned and is equivalent to r1. If r2 covers r1, then no rectangles are returned. If r1 covers r2, then four rectangles are returned. If r2 partially overlaps r1, then one, two or three rectangles are returned.