本文整理汇总了Golang中github.com/BurntSushi/xgbutil/xrect.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateWindow
// When a cross is declared in its object literal form, it may not have the appropriate window.
// this function creates a new X11 window for the cross with the correct geometry depending
// on its Icon* parameters.
func (c *Cross) CreateWindow(X *xgbutil.XUtil, icons_per_direction int, bg_color uint32) (*xwindow.Window, error) {
// calculate the dimensions of the spars of our cross +
// width/height reflect the vertical-orientation rectangle
width := c.IconMargin*2 + c.IconSize
// padding between the icons, margin on the edges
height := c.IconSize*icons_per_direction + c.IconPadding*(icons_per_direction-1) + c.IconMargin*2
// intitialize a basic window for the cross
win, err := xwindow.Generate(X)
if err != nil {
return nil, err
}
win.Create(X.RootWin(), 0, 0, height, height,
xproto.CwBackPixel|xproto.CwOverrideRedirect, bg_color, 1)
// the rects we will be adding together to form the shape of the cross
vert := xrect.New(0, 0, width, height)
horiz := xrect.New(0, 0, height, width)
struts := []xrect.Rect{vert, horiz}
geom, err := win.Geometry()
if err != nil {
return nil, err
}
// center struts over window
x, y := util.CenterChild(vert, geom)
vert.XSet(x)
vert.YSet(y)
x, y = util.CenterChild(horiz, geom)
horiz.XSet(x)
horiz.YSet(y)
// build the cross shape from our friendly rectangles
err = ComposeShape(X, win.Id, struts)
if err != nil {
return nil, err
}
// add the window to our cross struct
c.Window = win
// create icons from our images
clr := RGB(bg_color)
if c.imagesToBecomeIcons != nil {
icons := make(map[string]*Icon, len(c.imagesToBecomeIcons))
for name, img := range c.imagesToBecomeIcons {
icon := NewIcon(X, img, win.Id)
icon.Background = clr
icons[name] = icon
}
c.Icons = icons
} else {
return nil, errors.New("Cross: you must create crosses using the NewCross function (this cross has now iconsToBecomeImage)")
}
return win, nil
}
示例2: newClientState
func (c *Client) newClientState() clientState {
s := clientState{
geom: xrect.New(xrect.Pieces(c.frame.Geom())),
headGeom: nil,
frame: c.frame,
maximized: c.maximized,
}
if c.workspace.IsVisible() {
s.headGeom = xrect.New(xrect.Pieces(c.workspace.HeadGeom()))
}
return s
}
示例3: maybeInitPlace
func (c *Client) maybeInitPlace(presumedWorkspace workspace.Workspacer) {
// This is a hack. Before a client gets sucked into some layout, we
// always want to have some floating state to fall back on to. However,
// by the time we're "allowed" to save the client's state, it will have
// already been placed in the hands of some layout---which may or may
// not be floating. So we inject our own state forcefully here.
defer func() {
wrk := presumedWorkspace
if wrk.IsVisible() {
c.states["last-floating"] = clientState{
geom: xrect.New(xrect.Pieces(c.frame.Geom())),
headGeom: xrect.New(xrect.Pieces(wrk.HeadGeom())),
frame: c.frame,
maximized: c.maximized,
}
}
}()
// Any client that isn't normal doesn't get placed.
// Let it do what it do, baby.
if c.PrimaryType() != TypeNormal {
return
}
// If it's sticky, let it do what it do.
if _, ok := presumedWorkspace.(*workspace.Sticky); ok {
return
}
// Transients never get placed.
if c.transientFor != nil {
return
}
// If a user/program position is specified, do not place.
if c.nhints.Flags&icccm.SizeHintUSPosition > 0 ||
c.nhints.Flags&icccm.SizeHintPPosition > 0 {
return
}
// We're good, do a placement unless we're already mapped or on a
// hidden workspace..
if !presumedWorkspace.IsVisible() || !c.isAttrsUnmapped() {
return
}
w := presumedWorkspace.(*workspace.Workspace)
w.LayoutFloater().InitialPlacement(c)
}
示例4: PhysicalHeads
// PhyiscalHeads returns the list of heads in a physical ordering.
// Namely, left to right then top to bottom. (Defined by (X, Y).)
// Xinerama must have been initialized, otherwise the xinerama.QueryScreens
// request will panic.
// PhysicalHeads also checks to make sure each rectangle has a unique (x, y)
// tuple, so as not to return the geometry of cloned displays.
// (At present moment, xgbutil initializes Xinerama automatically during
// initial connection.)
func PhysicalHeads(xu *xgbutil.XUtil) (Heads, error) {
xinfo, err := xinerama.QueryScreens(xu.Conn()).Reply()
if err != nil {
return nil, err
}
hds := make(Heads, 0)
for _, info := range xinfo.ScreenInfo {
head := xrect.New(int(info.XOrg), int(info.YOrg),
int(info.Width), int(info.Height))
// Maybe Xinerama is enabled, but we have cloned displays...
unique := true
for _, h := range hds {
if h.X() == head.X() && h.Y() == head.Y() {
unique = false
break
}
}
if unique {
hds = append(hds, head)
}
}
sort.Sort(hds)
return hds, nil
}
示例5: query
func query(X *xgbutil.XUtil) xinerama.Heads {
if X.ExtInitialized("XINERAMA") {
heads, err := xinerama.PhysicalHeads(X)
if err != nil || len(heads) == 0 {
if err == nil {
logger.Warning.Printf("Could not find any physical heads " +
"with the Xinerama extension.")
} else {
logger.Warning.Printf("Could not load physical heads via "+
"Xinerama: %s", err)
}
logger.Warning.Printf("Assuming one head with size equivalent " +
"to the root window.")
} else {
return heads
}
}
// If we're here, then something went wrong or the Xinerama extension
// isn't available. So query the root window for its geometry and use that.
rgeom := xwindow.RootGeometry(X)
return xinerama.Heads{
xrect.New(rgeom.X(), rgeom.Y(), rgeom.Width(), rgeom.Height()),
}
}
示例6: ApplyStruts
func (hds *Heads) ApplyStruts(clients Clients) {
hds.workarea = make(xinerama.Heads, len(hds.geom))
for i, hd := range hds.geom {
hds.workarea[i] = xrect.New(hd.X(), hd.Y(), hd.Width(), hd.Height())
}
rgeom := xwindow.RootGeometry(hds.X)
for i := 0; i < clients.Len(); i++ {
c := clients.Get(i)
strut, _ := ewmh.WmStrutPartialGet(hds.X, c.Id())
if strut == nil {
continue
}
xrect.ApplyStrut(hds.workarea, rgeom.Width(), rgeom.Height(),
strut.Left, strut.Right, strut.Top, strut.Bottom,
strut.LeftStartY, strut.LeftEndY,
strut.RightStartY, strut.RightEndY,
strut.TopStartX, strut.TopEndX,
strut.BottomStartX, strut.BottomEndX)
}
for _, wrk := range hds.workspaces.Wrks {
wrk.Place()
}
}
示例7: Run
func (cmd Focus) Run() gribble.Value {
return syncRun(func() gribble.Value {
return withClient(cmd.Client, func(c *xclient.Client) {
if c == nil {
focus.Root()
// Use the mouse coordinates to find which workspace it was
// clicked in. If a workspace can be found (i.e., no clicks in
// dead areas), then activate it.
xc, rw := wm.X.Conn(), wm.X.RootWin()
qp, err := xproto.QueryPointer(xc, rw).Reply()
if err != nil {
logger.Warning.Printf("Could not query pointer: %s", err)
return
}
geom := xrect.New(int(qp.RootX), int(qp.RootY), 1, 1)
if wrk := wm.Heads.FindMostOverlap(geom); wrk != nil {
wm.SetWorkspace(wrk, false)
}
} else {
c.Focus()
xevent.ReplayPointer(wm.X)
}
})
})
}
示例8: New
// New creates a new window value from a window id and an XUtil type.
// Geom is initialized to zero values. Use Window.Geometry to load it.
// Note that the geometry is the size of this particular window and nothing
// else. If you want the geometry of a client window including decorations,
// please use Window.DecorGeometry.
func New(xu *xgbutil.XUtil, win xproto.Window) *Window {
return &Window{
X: xu,
Id: win,
Geom: xrect.New(0, 0, 1, 1),
Destroyed: false,
}
}
示例9: RawGeometry
// RawGeometry isn't smart. It just queries the window given for geometry.
func RawGeometry(xu *xgbutil.XUtil, win xproto.Drawable) (xrect.Rect, error) {
xgeom, err := xproto.GetGeometry(xu.Conn(), win).Reply()
if err != nil {
return nil, err
}
return xrect.New(int(xgeom.X), int(xgeom.Y),
int(xgeom.Width), int(xgeom.Height)), nil
}
示例10: main
func main() {
X, _ := xgbutil.NewConn()
heads, err := xinerama.PhysicalHeads(X)
if err != nil {
fmt.Printf("ERROR: %v\n", err)
}
// Test intersection
r1 := xrect.New(0, 0, 100, 100)
r2 := xrect.New(100, 100, 100, 100)
fmt.Println(xrect.IntersectArea(r1, r2))
// Test largest overlap
window := xrect.New(1800, 0, 300, 200)
fmt.Println(xrect.LargestOverlap(window, heads))
// Test ApplyStrut
rgeom, _ := xwindow.RawGeometry(X, xproto.Drawable(X.RootWin()))
fmt.Println("---------------------------")
for i, head := range heads {
fmt.Printf("%d - %v\n", i, head)
}
// Let's actually apply struts to the current environment
clients, _ := ewmh.ClientListGet(X)
for _, client := range clients {
strut, err := ewmh.WmStrutPartialGet(X, client)
if err == nil {
xrect.ApplyStrut(heads, rgeom.Width(), rgeom.Height(),
strut.Left, strut.Right, strut.Top, strut.Bottom,
strut.LeftStartY, strut.LeftEndY,
strut.RightStartY, strut.RightEndY,
strut.TopStartX, strut.TopEndX,
strut.BottomStartX, strut.BottomEndX)
}
}
fmt.Println("---------------------------")
fmt.Println("After applying struts...")
for i, head := range heads {
fmt.Printf("%d - %v\n", i, head)
}
}
示例11: Bound
// given a slice of rects, return a rect that covers all of them!
func Bound(rects []xrect.Rect) xrect.Rect {
min_x, min_y, max_x, max_y := coords(rects[0])
for _, rect := range rects[1:] {
x1, y1, x2, y2 := coords(rect)
min_x = min(x1, min_x)
min_y = min(y1, min_y)
max_x = max(x2, max_x)
max_y = max(y2, max_y)
}
return xrect.New(min_x, min_y, max_x-min_x, max_y-min_y)
}
示例12: DragMoveBegin
func (c *Client) DragMoveBegin(rx, ry, ex, ey int) {
f := c.frame
moving := f.MovingState()
moving.Moving = true
moving.RootX, moving.RootY = rx, ry
// call for side-effect; makes sure parent window has a valid geometry
f.Parent().Geometry()
// unmax!
c.EnsureUnmax()
c.dragGeom = xrect.New(xrect.Pieces(f.Geom()))
}
示例13: Convert
// Convert takes a source and a destination rect, along with a rect
// in the source's rectangle, and returns a new rect translated into the
// destination rect.
func Convert(rect, src, dest xrect.Rect) xrect.Rect {
nx, ny, nw, nh := xrect.Pieces(rect)
rectRatio := func(r xrect.Rect) float64 {
return float64(r.Width()) / float64(r.Height())
}
ratio := rectRatio(dest) / rectRatio(src)
nx = int(ratio*float64(nx-src.X())) + dest.X()
ny = int(ratio*float64(ny-src.Y())) + dest.Y()
// XXX: Allow window scaling as a config option.
return xrect.New(nx, ny, nw, nh)
}
示例14: handleMotionNotify
func handleMotionNotify(X *xgbutil.XUtil, ev xevent.MotionNotifyEvent) {
qp, err := xproto.QueryPointer(X.Conn(), X.RootWin()).Reply()
if err != nil {
logger.Warning.Printf("Could not query pointer: %s", err)
return
}
geom := xrect.New(int(qp.RootX), int(qp.RootY), 1, 1)
if wrk := wm.Heads.FindMostOverlap(geom); wrk != nil {
if wrk != wm.Workspace() {
wm.SetWorkspace(wrk, false)
wm.FocusFallback()
}
}
}
示例15: DragMoveBegin
func (c *Client) DragMoveBegin(rx, ry, ex, ey int) bool {
if c.IsMaximized() {
return false
}
f := c.frame
moving := f.MovingState()
moving.Moving = true
moving.RootX, moving.RootY = rx, ry
// call for side-effect; makes sure parent window has a valid geometry
f.Parent().Geometry()
c.dragGeom = xrect.New(xrect.Pieces(f.Geom()))
return true
}