cursor

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cursor reads the host's system cursor: whether it shows, whether an app holds the mouse, and where it is.

Index

Constants

View Source
const MaxSide = 256

MaxSide bounds a Shape's width and height: a larger cursor is scaled down to fit.

Variables

View Source
var ErrUnsupported = errors.New("cursor: not supported on this platform")

ErrUnsupported is what Read returns where the platform cannot tell.

Functions

func Normalize

func Normalize(x, y int, display Rect) (nx, ny uint16, ok bool)

Normalize maps a desktop point onto 0..65535 across display, as absolute pointer moves address it; ok is false off the display.

Types

type Rect

type Rect struct{ X, Y, W, H int }

Rect is a rectangle of the desktop, in pixels.

type Shape

type Shape struct {
	W, H       int
	HotX, HotY int
	// DPI is the display's the cursor was sized for; 96 is 100%.
	DPI int
	// RGBA is the image, not premultiplied, rows top down.
	RGBA []byte
}

Shape is the image of the system cursor.

func Fit

func Fit(s Shape, side int) Shape

Fit scales a shape larger than side down to fit, nearest pixel, and its DPI with it, each pixel the one at its centre, so that it keeps its size on the client.

func ReadShape

func ReadShape(s State) (Shape, error)

ReadShape reads the image of the cursor s reports, s.Handle.

func (Shape) Hash

func (s Shape) Hash() uint64

Hash names the shape by its size, hotspot, DPI and pixels.

type State

type State struct {
	Visible bool
	// Captured is set while an app confines the cursor to less than the
	// whole desktop, as a game holding the mouse does. A hidden cursor
	// alone is not captured: a page's cursor: none, a video player and
	// Windows hiding the pointer while typing all hide it.
	Captured bool
	// X and Y are the cursor's place on the desktop, in physical pixels.
	X, Y int
	// Handle is the system's handle of the cursor's image, which changes
	// as the cursor changes shape; 0 while none shows.
	Handle uintptr
}

State is the system cursor.

func Read

func Read() (State, error)

Read reports the system cursor now.

Jump to

Keyboard shortcuts

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