xgo

package module
v0.0.0-...-7e1b477 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: AGPL-3.0 Imports: 17 Imported by: 0

README

This is a wrapper for github.com/jezek/xgb, which is a patched fork of github.com/BurntSushi/xgb.

The purpose of this package is to make window creation and window handling easier and adds keyboard typing and mouse moving abilities using X11 testing module.

Dependencies

Konwn issues

  • Keyboard writing doesn't write not mapped characters, if audacious's Global Hotkeys plugin is enabled.

Documentation

Index

Constants

View Source
const (
	IsUnmapped   = xproto.MapStateUnmapped
	IsUnviewable = xproto.MapStateUnviewable
	IsViewable   = xproto.MapStateViewable
)
View Source
const (
	SizeReqestMax                = (1 << 16) * 4
	SizeRequestPutImageFixedPart = 24
)

Variables

View Source
var (
	DEBUG bool = os.Getenv("XGO_DEBUG") != ""
)

Functions

func TextExtents

func TextExtents(text string, f Fontable) (*xproto.QueryTextExtentsReply, error)

TODO? return non xproto result?

Types

type Display

type Display struct {
	*xgb.Conn
	// contains filtered or unexported fields
}

Display instance.

func OpenDisplay

func OpenDisplay(d string) (*Display, error)

Creates a new Display instance.

Parameter d contains display name, such as ":0". If empty, it uses the environment variable DISPLAY.

returns nil on failure

func (*Display) ActiveWindow

func (d *Display) ActiveWindow() *Window

func (*Display) Atom

func (d *Display) Atom(aid xproto.Atom) string

func (*Display) DefaultScreen

func (d *Display) DefaultScreen() *Screen

func (*Display) FindWindow

func (d *Display) FindWindow(wid uint32) (*Window, error)

func (*Display) FontOpen

func (d *Display) FontOpen(pattern string) (*Font, error)

func (*Display) Name

func (d *Display) Name() string

func (*Display) NewGraphicsContext

func (d *Display) NewGraphicsContext(components ...GraphicsContextComponent) (*GraphicsContext, error)

Creates GraphicsContext on default screen. Calls Display.Screen().NewGraphicsContext.

func (*Display) NewWindow

func (d *Display) NewWindow(operations ...WindowOperation) (*Window, error)

Calls NewWindow on default screen

func (*Display) NumberOfDesktops

func (d *Display) NumberOfDesktops() uint32

func (*Display) NumberOfScreens

func (d *Display) NumberOfScreens() int

func (*Display) Pointer

func (d *Display) Pointer() *DisplayPointer

func (*Display) Screens

func (d *Display) Screens() []*Screen

func (*Display) Setup

func (d *Display) Setup() *Setup

type DisplayPointer

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

func (*DisplayPointer) Status

func (p *DisplayPointer) Status() (PointerStatus, error)

type Drawable

type Drawable interface {
	Drawable() xproto.Drawable
}

type Font

type Font struct {
	xproto.Font
	// contains filtered or unexported fields
}

Font allocated on display

func OpenFontOnDisplay

func OpenFontOnDisplay(d *Display, pattern string) (*Font, error)

Opens font with pattern on provided display. If you don't want to use the font anymore, use Close method on it. On any error, the error is returned

func (*Font) Close

func (f *Font) Close() error

Closes font allocation in X. Font has not be used anymore after close.

func (*Font) Display

func (f *Font) Display() *Display

func (*Font) Fontable

func (f *Font) Fontable() xproto.Fontable

func (*Font) Info

func (f *Font) Info() (*FontInfo, error)

func (*Font) TextExtents

func (f *Font) TextExtents(text string) (*xproto.QueryTextExtentsReply, error)

type FontInfo

type FontInfo struct {
	*xproto.QueryFontReply
	// contains filtered or unexported fields
}

TODO timestamps for all X replies

func FontQuery

func FontQuery(f Fontable) (*FontInfo, error)

Returns font information for Fontable structures, or error if some troubles. Current Fontables are: *Font, *GraphicsContext

func (*FontInfo) Display

func (fi *FontInfo) Display() *Display

func (*FontInfo) Fontable

func (fi *FontInfo) Fontable() Fontable

func (*FontInfo) Properties

func (fi *FontInfo) Properties() map[string]string

type Fontable

type Fontable interface {
	Fontable() xproto.Fontable
	Display() *Display
}

type GraphicsContext

type GraphicsContext struct {
	xproto.Gcontext
	// contains filtered or unexported fields
}

func NewGraphicsContextOnDisplay

func NewGraphicsContextOnDisplay(d *Display, drawable Drawable, components ...GraphicsContextComponent) (resultGc *GraphicsContext, resultErr error)

Create and allocate graphics context on display with drawable root and depth using provided components Returned graphical context can be used with any destination drawable having the same root and depthe. Use with other drawables results in a BadMatch error.

func (*GraphicsContext) Display

func (gc *GraphicsContext) Display() *Display

func (*GraphicsContext) FontInfo

func (gc *GraphicsContext) FontInfo() (*FontInfo, error)

func (*GraphicsContext) Fontable

func (gc *GraphicsContext) Fontable() xproto.Fontable

func (*GraphicsContext) Free

func (gc *GraphicsContext) Free() error

func (*GraphicsContext) TextExtents

func (gc *GraphicsContext) TextExtents(text string) (*xproto.QueryTextExtentsReply, error)

type GraphicsContextComponent

type GraphicsContextComponent func(gc *GraphicsContext) (map[uint32]uint32, error)

type GraphicsContextComponents

type GraphicsContextComponents struct{}

func (GraphicsContextComponents) BackgroundPixel

func (GraphicsContextComponents) Font

func (GraphicsContextComponents) ForegroundPixel

func (GraphicsContextComponents) NewFont

Opens first font matching pattern an assigns to graphics context, if used in graphics context creation or editing. Font is closed upon graphics context freeing, or graphics contexts font beeing updated (eg. with this component again).

func (GraphicsContextComponents) NewFontIfMatch

func (_ GraphicsContextComponents) NewFontIfMatch(pattern string) GraphicsContextComponent

Opens first font matching pattern, if there is any and assigns it to graphics context, If font does not exist, previous is kept, or if there is no previous, default is used. if used in graphics context creation or editing. Font is closed upon graphics context freeing, or graphics contexts font beeing updated (eg. with this component again).

type Keyboard

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

func (*Keyboard) Control

func (k *Keyboard) Control() *KeyboardControll

func (*Keyboard) Display

func (k *Keyboard) Display() *Display

func (*Keyboard) MappingAll

func (k *Keyboard) MappingAll() *xproto.GetKeyboardMappingReply

func (*Keyboard) Screen

func (k *Keyboard) Screen() *Screen

func (*Keyboard) String

func (k *Keyboard) String() string

func (*Keyboard) Window

func (k *Keyboard) Window() *Window

type KeyboardControll

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

func (*KeyboardControll) Display

func (c *KeyboardControll) Display() *Display

func (*KeyboardControll) Screen

func (c *KeyboardControll) Screen() *Screen

func (*KeyboardControll) String

func (c *KeyboardControll) String() string

func (*KeyboardControll) Write

func (c *KeyboardControll) Write(s string) error

type Pixmap

type Pixmap struct {
	xproto.Pixmap

	Size  image.Point
	Depth byte
	// contains filtered or unexported fields
}

func NewPixmapFromImageOnScreen

func NewPixmapFromImageOnScreen(scr *Screen, img image.Image, operations ...PixmapOperation) (*Pixmap, error)

Allocate new pixmap in X on screen, with screen default depth and size of the image Then draws the image to pixmap and applies all pixmap operations. If there is an error along somewhere, pixmap is destroyed and the first occuring error is returned This is an shortcut for: NewPixmapOnScreen(

scr,
image.Pt(img.Bounds().Dx(),img.Bounds().Dy()),
PixmapOperations{}.DrawImage(img),
options...,
)

func NewPixmapOnScreen

func NewPixmapOnScreen(s *Screen, size image.Point, operations ...PixmapOperation) (*Pixmap, error)

Allocate new pixmap in X on screen, with screen default depth and provided size Then applies all pixmap operations. If there is an error along somewhere, pixmap is destroyed and the first occuring error is returned

func (*Pixmap) Destroy

func (p *Pixmap) Destroy() error

func (*Pixmap) Display

func (p *Pixmap) Display() *Display

func (*Pixmap) Draw

func (p *Pixmap) Draw(drawers ...PixmapDrawer) error

TODO implement all xproto draw functions TODO theese draw operations shoul be not only for pixmap, but all drawable objects (which are they???)

	if err := xproto.PolyLineChecked(
		d.Conn,
		xproto.CoordModeOrigin,
		xproto.Drawable(pixmapId),
		gc,
		[]xproto.Point{xproto.Point{0, 0}, xproto.Point{100, 100}, xproto.Point{0, 100}},
	).Check(); err != nil {
		fmt.Printf("Unable draw line: %v\n", err)
		return
	}
	fmt.Println("line draw")

}

Uses all draw functions in order. Stops on first encountered error and returns it.

func (*Pixmap) Screen

func (p *Pixmap) Screen() *Screen

type PixmapDrawer

type PixmapDrawer func(*Pixmap) error

TODO use Drawable instead of pixmap

type PixmapDrawers

type PixmapDrawers struct{}

func (PixmapDrawers) Image

func (pd PixmapDrawers) Image(img image.Image) PixmapDrawer

Draws image "img" to pixmap, so top-left corner of image "img.Bounds().Min" is at point [0,0].

func (PixmapDrawers) ImageAt

func (_ PixmapDrawers) ImageAt(img image.Image, pt image.Point) PixmapDrawer

Draws image "img" to pixmap, so top-left corner of image "img.Bounds().Min" is at point "pt".

func (PixmapDrawers) Text

func (_ PixmapDrawers) Text(text string, position image.Point, gc *GraphicsContext) PixmapDrawer

type PixmapOperation

type PixmapOperation func(*Pixmap) error

type PixmapOperations

type PixmapOperations struct{}

func (PixmapOperations) Draw

func (_ PixmapOperations) Draw(drawers ...PixmapDrawer) PixmapOperation

type Pointer

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

func (*Pointer) Control

func (p *Pointer) Control() *PointerControll

func (*Pointer) Display

func (p *Pointer) Display() *Display

func (*Pointer) MotionNotify

func (p *Pointer) MotionNotify(stop <-chan struct{}) <-chan xproto.MotionNotifyEvent

func (*Pointer) Screen

func (p *Pointer) Screen() *Screen

func (*Pointer) Status

func (p *Pointer) Status() (PointerStatus, error)

func (*Pointer) String

func (p *Pointer) String() string

func (*Pointer) Window

func (p *Pointer) Window() *Window

type PointerControll

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

func (*PointerControll) ClickLeft

func (c *PointerControll) ClickLeft() error

func (*PointerControll) ClickRight

func (c *PointerControll) ClickRight() error

func (*PointerControll) Display

func (c *PointerControll) Display() *Display

func (*PointerControll) DownLeft

func (c *PointerControll) DownLeft() error

func (*PointerControll) DownRight

func (c *PointerControll) DownRight() error

func (*PointerControll) Move

func (c *PointerControll) Move(x, y int) error

func (*PointerControll) MoveRelative

func (c *PointerControll) MoveRelative(x, y int) error

func (*PointerControll) Screen

func (c *PointerControll) Screen() *Screen

func (*PointerControll) ScrollDown

func (c *PointerControll) ScrollDown() error

func (*PointerControll) ScrollUp

func (c *PointerControll) ScrollUp() error

func (*PointerControll) UpLeft

func (c *PointerControll) UpLeft() error

func (*PointerControll) UpRight

func (c *PointerControll) UpRight() error

type PointerStatus

type PointerStatus struct {
	*xproto.QueryPointerReply
	Pointer *Pointer
	Root    *Window
	Child   *Window
	Button  [6]bool
}

type Screen

type Screen struct {
	*xproto.ScreenInfo
	// contains filtered or unexported fields
}

Screen instance

func (*Screen) Default

func (s *Screen) Default() bool

func (*Screen) Display

func (s *Screen) Display() *Display

func (*Screen) Id

func (s *Screen) Id() int

func (*Screen) NewGraphicsContext

func (s *Screen) NewGraphicsContext(components ...GraphicsContextComponent) (*GraphicsContext, error)

Creates GraphicsContext with this creens root window depth.

func (*Screen) NewPixmap

func (s *Screen) NewPixmap(size image.Point, operations ...PixmapOperation) (*Pixmap, error)

Calls NewPixmapOnScreen on current screen

func (*Screen) NewPixmapFromImage

func (s *Screen) NewPixmapFromImage(image image.Image, operations ...PixmapOperation) (*Pixmap, error)

Calls NewPixmapFromImageOnScreen on current screen

func (*Screen) NewWindow

func (s *Screen) NewWindow(operations ...WindowOperation) (*Window, error)

func (*Screen) Window

func (s *Screen) Window() *Window

type Setup

type Setup struct {
	*xproto.SetupInfo
	// contains filtered or unexported fields
}

Setup instance

type Window

type Window struct {
	xproto.Window //required
	// contains filtered or unexported fields
}

func NewWindowOnScreen

func NewWindowOnScreen(s *Screen, operations ...WindowOperation) (*Window, error)

Creates an unmapped input/output window on default screen with no initialization. Window size is [1,1], position is [0,0], border 0, with screen root depth and none (default?) attributes. Then applies all window operations. If there is an error along somewhere, window is destroyed and the first occuring error is returned

func (*Window) AttributesChange

func (w *Window) AttributesChange(attributes ...WindowAttribute) error

Applies attributes to window. If duplicate attributes provided, error is produced. The attributes are not applied in provided order and are allways sorted by mask of the attribute. eg. if you use BackgroundPixelColor and BackgroundPixmap, it will not show the pixmap on background, because mask for BackgroundPixelColor has greater value than BackgroundPixmap and will com after. So every time the last background operation is BackgroundPixelColor. See WindowAttributes struct and underlying xproto.Cw... costants for mask value info TODO? or should I return error if background is set twice, or any other alike situations?

func (*Window) AttributesInfo

func (w *Window) AttributesInfo() (*WindowAttributesInfo, error)

func (*Window) Children

func (w *Window) Children() ([]*Window, error)

func (*Window) Clear

func (w *Window) Clear() error

Paints a rectangular area in the window with the window's background pixel or pixmap. If the window has a defined background tile, the rectangle clipped by any children is filled with this tile. If the window has background None, the contents of the window are not changed.

func (*Window) CloseNotify

func (w *Window) CloseNotify(stop <-chan struct{}) (<-chan struct{}, error)

func (*Window) Destroy

func (w *Window) Destroy() error

func (*Window) Display

func (w *Window) Display() *Display

func (*Window) Drawable

func (w *Window) Drawable() xproto.Drawable

func (*Window) IsRoot

func (w *Window) IsRoot() bool

func (*Window) IsVisible

func (w *Window) IsVisible() bool

func (*Window) Keyboard

func (w *Window) Keyboard() *Keyboard

func (*Window) Map

func (w *Window) Map() error

Maps window

func (*Window) MoveResize

func (w *Window) MoveResize(bounds image.Rectangle) error

Makes a ConfigRequest, to alter position and size. Returns error if something is wrong

func (*Window) Name

func (w *Window) Name() string

func (*Window) Operations

func (w *Window) Operations(operations ...WindowOperation) error

func (*Window) Parent

func (w *Window) Parent() (*Window, error)

func (*Window) Parents

func (w *Window) Parents() ([]*Window, error)

func (*Window) Pointer

func (w *Window) Pointer() *Pointer

func (*Window) Protocols

func (w *Window) Protocols() ([]string, error)

func (*Window) ProtocolsSet

func (w *Window) ProtocolsSet(protocols []string) error

func (*Window) Resize

func (w *Window) Resize(size image.Point) error

Makes a ConfigRequest, to alter size. Returns error if something is wrong

func (*Window) Screen

func (w *Window) Screen() *Screen

func (*Window) String

func (w *Window) String() string

type WindowAttribute

type WindowAttribute func() (mask uint32, value uint32)

type WindowAttributes

type WindowAttributes struct{}

func (WindowAttributes) BackgroundPixelColor

func (_ WindowAttributes) BackgroundPixelColor(col color.Color) WindowAttribute

TODO CwBorderPixmap, CwBorderPixel, CwBitGravity, CwWinGravity, CwBackingStore, CwBackingPlanes, CwBackingPixel, CwOverrideRedirect , CwSaveUnder, CwEventMask, CwDontPropagate, CwColormap, CwCursor

func (WindowAttributes) BackgroundPixmap

func (_ WindowAttributes) BackgroundPixmap(pixmap *Pixmap) WindowAttribute

type WindowAttributesInfo

type WindowAttributesInfo struct {
	*xproto.GetWindowAttributesReply
	// contains filtered or unexported fields
}

type WindowOperation

type WindowOperation func(*Window) error

type WindowOperations

type WindowOperations struct{}

func (WindowOperations) Attributes

func (_ WindowOperations) Attributes(attributes ...WindowAttribute) WindowOperation

func (WindowOperations) Clear

func (WindowOperations) Map

func (WindowOperations) Size

TODO ConfigWindowX, ConfigWindowY, ConfigWindowBorderWidth, ConfigWindowSibling, ConfigWindowStackMode,

Directories

Path Synopsis
examples
activeWindow
Prints active window's parents and children for default screeen.
Prints active window's parents and children for default screeen.
windowTree
Prints visible named window tree for all screens.
Prints visible named window tree for all screens.

Jump to

Keyboard shortcuts

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