xrect

package
v0.0.0-...-e2e9464 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2024 License: BSD-3-Clause Imports: 1 Imported by: 5

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

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

func IntersectArea(r1 Rect, r2 Rect) int

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

func LargestOverlap(needle Rect, haystack []Rect) int

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 Pieces

func Pieces(xr Rect) (int, int, int, int)

func RectPieces

func RectPieces(xr Rect) (int, int, int, int)

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

func Valid

func Valid(r Rect) bool

Valid returns whether a rectangle is valid or not. i.e., a width AND height not equal to zero.

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

func Subtract(r1 Rect, r2 Rect) []Rect

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.

type XRect

type XRect struct {
	// contains filtered or unexported fields
}

Provide a simple implementation of a rect. Maybe this will be all we need?

func New

func New(x, y, w, h int) *XRect

Provide the ability to construct an XRect.

func (*XRect) Height

func (r *XRect) Height() int

func (*XRect) HeightSet

func (r *XRect) HeightSet(height int)

func (*XRect) Pieces

func (r *XRect) Pieces() (int, int, int, int)

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

func (*XRect) String

func (r *XRect) String() string

func (*XRect) Width

func (r *XRect) Width() int

func (*XRect) WidthSet

func (r *XRect) WidthSet(width int)

func (*XRect) X

func (r *XRect) X() int

Satisfy the Rect interface

func (*XRect) XSet

func (r *XRect) XSet(x int)

func (*XRect) Y

func (r *XRect) Y() int

func (*XRect) YSet

func (r *XRect) YSet(y int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL