Documentation
¶
Overview ¶
Package screenshot is the screenshot host (crates/lys-shell/src/shell/screenshot) behind the dev.stubbe.lys.Screenshot1 D-Bus service: it resolves the capture target (opening the freeze-frame region overlay for region mode), captures a full-resolution image, saves a PNG, optionally copies it to the clipboard and fires a desktop notification, and replies with the path. It also hosts the color pick the portal's Screenshot.PickColor reuses: freeze every output, then the loupe.
Index ¶
- Constants
- Variables
- func DecodeQR(img image.Image) (string, error)
- func IsURL(s string) bool
- func OCRAvailable() bool
- func WritePNG(img image.Image, path string) error
- type Action
- type Client
- func (c *Client) Capture(ctx context.Context, caller portaldialogs.Caller, mode, target string) (string, error)
- func (c *Client) CapturePrivate(ctx context.Context, caller portaldialogs.Caller, mode, target string, ...) (string, error)
- func (c *Client) Dismiss(ctx context.Context, handle string) error
- func (c *Client) PickColor(ctx context.Context, caller portaldialogs.Caller) (color [3]float64, picked bool, err error)
- func (c *Client) PickColorText(ctx context.Context, caller portaldialogs.Caller, format config.ColorFormat, ...) (text string, picked bool, err error)
- func (c *Client) Read(ctx context.Context, caller portaldialogs.Caller, kind ReadKind) (string, error)
- type CompositorFocus
- type Daemon
- func (d *Daemon) Capture(c portaldialogs.Caller, mode, target string) (string, *dbus.Error)
- func (d *Daemon) CapturePrivate(c portaldialogs.Caller, mode, target string, pointer bool) (string, *dbus.Error)
- func (d *Daemon) Dismiss(handle string) *dbus.Error
- func (d *Daemon) Export(conn *dbus.Conn) (func(), error)
- func (d *Daemon) PickColor(c portaldialogs.Caller) (bool, float64, float64, float64, *dbus.Error)
- func (d *Daemon) PickColorText(c portaldialogs.Caller, format string, noLoupe, copyText bool) (bool, string, *dbus.Error)
- func (d *Daemon) Read(c portaldialogs.Caller, kind string) (string, *dbus.Error)
- type Focus
- type Host
- func (h *Host) Capture(c portaldialogs.Caller, mode, target string) (string, error)
- func (h *Host) CapturePrivate(c portaldialogs.Caller, mode, target string, pointer bool) (string, error)
- func (h *Host) Dismiss(handle string)
- func (h *Host) PickColor(caller portaldialogs.Caller) (color [3]float64, picked bool, err error)
- func (h *Host) PickColorText(caller portaldialogs.Caller, opts colorpicker.Options, copyText bool) (text string, picked bool, err error)
- func (h *Host) Read(c portaldialogs.Caller, kind ReadKind) (string, error)
- type Notice
- type ReadKind
- type Saved
Constants ¶
const ( ServiceName = "dev.stubbe.lys.Screenshot1" ServicePath = "/dev/stubbe/lys/Screenshot" )
D-Bus identity (wayle-ipc's screenshot proxy).
const ( ModeRegion = "region" ModeOutput = "output" ModeScreen = "screen" ModeWindow = "window" )
The capture modes of Capture: a drag-selected region, one output (the focused one without a target), the whole multi-monitor space composited, or the active window.
const Tesseract = "tesseract"
Tesseract is the OCR engine's binary.
Variables ¶
var ( // ErrNoTesseract answers a text reading on a system without tesseract. ErrNoTesseract = fmt.Errorf("%s is not installed, so text cannot be read from the screen: %w", Tesseract, exec.ErrNotFound) // ErrNoCode answers a QR reading of a region that holds no code. ErrNoCode = errors.New("no code found") // ErrNoText answers a text reading of a region tesseract found no text in. ErrNoText = errors.New("no text found") )
var ErrBusy = regionoverlay.ErrBusy
ErrBusy answers a capture or a color pick refused because another capture is in progress: nothing opened, nothing was captured, and what was running goes on untouched. It is neither a capture nor the user's cancel.
Functions ¶
func DecodeQR ¶ added in v0.3.15
DecodeQR is the payload of the QR code in img, ErrNoCode when it holds none.
func OCRAvailable ¶ added in v0.3.15
func OCRAvailable() bool
OCRAvailable reports whether tesseract is on PATH.
Types ¶
type Action ¶ added in v0.3.15
type Action string
Action is a button on the saved-capture notification.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the daemon: the `lys-shell screenshot` CLI, and the portal backend's Screenshot and PickColor.
func (*Client) Capture ¶
func (c *Client) Capture(ctx context.Context, caller portaldialogs.Caller, mode, target string) (string, error)
Capture asks the shell for a screenshot; see Daemon.Capture. A refused request is ErrBusy.
func (*Client) CapturePrivate ¶
func (c *Client) CapturePrivate(ctx context.Context, caller portaldialogs.Caller, mode, target string, pointer bool) (string, error)
CapturePrivate asks the shell for an app's screenshot; see Daemon.CapturePrivate. A refused request is ErrBusy.
func (*Client) PickColor ¶
func (c *Client) PickColor(ctx context.Context, caller portaldialogs.Caller) (color [3]float64, picked bool, err error)
PickColor asks the shell for an interactive color pick; picked is false for the user's cancel, and a refused request is ErrBusy.
func (*Client) PickColorText ¶ added in v0.3.15
func (c *Client) PickColorText(ctx context.Context, caller portaldialogs.Caller, format config.ColorFormat, noLoupe, copyText bool) (text string, picked bool, err error)
PickColorText asks the shell for an interactive color pick written in a format; see Daemon.PickColorText. An empty format starts in the one last used. picked is false for the user's cancel, and a refused request is ErrBusy.
type CompositorFocus ¶
type CompositorFocus struct {
Hyprland *hyprland.Connection
}
CompositorFocus asks Hyprland (when Hyprland is set), then lys-wm, then mango, then niri - the Rust host's order with lys-wm added. The focused output also comes from sway's and niri's focused workspace.
func (CompositorFocus) ActiveWindow ¶
func (f CompositorFocus) ActiveWindow() windowTarget
ActiveWindow implements Focus.
func (CompositorFocus) FocusedOutput ¶
func (f CompositorFocus) FocusedOutput() (string, bool)
FocusedOutput implements Focus.
func (CompositorFocus) Windows ¶
func (f CompositorFocus) Windows() []image.Rectangle
Windows is what the region overlay's click picks from: the visible windows' global logical rectangles, topmost first, from Hyprland, lys-wm or sway; none from niri and mango, which report no window geometry, so a click there picks the output.
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon exports a Host as dev.stubbe.lys.Screenshot1.
func (*Daemon) Capture ¶
Capture captures a screenshot and blocks until it is saved or cancelled. mode is region, output, screen, or window; target is an output connector name (output mode), a window's ext toplevel identifier (window mode; the active window when empty), or empty. Replies the saved PNG path, empty when a region selection was cancelled or dismissed; every mode fails with the Busy error while a capture overlay is open.
func (*Daemon) CapturePrivate ¶
func (d *Daemon) CapturePrivate(c portaldialogs.Caller, mode, target string, pointer bool) (string, *dbus.Error)
CapturePrivate captures a screenshot for an app as Capture does, to a private file and with none of the user's save, clipboard or notification settings; pointer composites the pointer in.
func (*Daemon) Dismiss ¶
Dismiss cancels the region selection or color pick showing for the request at handle.
func (*Daemon) Export ¶
Export exports the object and claims the well-known name; the returned release drops the name.
func (*Daemon) PickColor ¶
PickColor picks one screen color interactively, replying whether the user picked one and its sRGB (r, g, b) in [0, 1]; a failure is an error, the Busy error while a capture overlay is open.
func (*Daemon) PickColorText ¶ added in v0.3.15
func (d *Daemon) PickColorText(c portaldialogs.Caller, format string, noLoupe, copyText bool) (bool, string, *dbus.Error)
PickColorText picks one screen color interactively as PickColor does, replying whether the user picked one and the color written in the format the readout showed at the click. format names the readout's first format, empty for the last one used; noLoupe shows a crosshair instead of the magnifier; copyText puts the text on the clipboard.
type Focus ¶
type Focus interface {
// FocusedOutput is the focused output's connector name; false lets
// the capture fall back to the first output.
FocusedOutput() (string, bool)
// ActiveWindow identifies the focused window; the zero target
// matches nothing.
ActiveWindow() windowTarget
}
Focus resolves what the output and window modes capture: the focused output and the active window, from whichever compositor is running (screenshot/mod.rs's focused_output_name and active_window_target).
type Host ¶
type Host struct {
// Config is the [modules.screenshot] section in effect, read at
// each save so a reload applies to the next capture.
Config func() config.ScreenshotConfig
// Monitors lists the outputs' logical geometry, for scaling
// selections and compositing the whole screen.
Monitors func() []regionoverlay.Monitor
// Gate is the capture gate Region and Picker share: every capture of
// this host is admitted by it, so none runs while an overlay is open.
Gate *regionoverlay.Gate
// Region and Picker are the freeze-frame overlays.
Region interface {
Request(ctx context.Context, frames regionoverlay.Frames) (regionoverlay.Selection, bool, error)
}
Picker interface {
Request(ctx context.Context, frames regionoverlay.Frames, opts colorpicker.Options) (colorpicker.Pick, bool, error)
}
// Focus resolves the focused output and the active window.
Focus Focus
// Copy puts an image on the clipboard and returns what takes that
// copy back, nil when nothing can; nil disables the copy.
Copy func(image.Image) (retract func(), err error)
// CopyText puts text on the clipboard: a picked color, or text Read read.
CopyText func(string) error
// Notify announces a saved screenshot, and a failed copy with it;
// nil sends the desktop notification.
Notify func(Notice)
// Present shows the floating thumbnail of a saved capture; nil
// shows none.
Present func(Saved)
// Edit opens the markup editor on a saved capture, and OpenFolder
// the folder it was saved in: the notification's buttons.
Edit func(Saved)
OpenFolder func(dir string)
// Toast and OpenURL deliver what Read read: a line in a toast, a
// decoded link in the browser.
Toast func(text, icon string)
OpenURL func(string)
// Working shows that tesseract is reading, with a way for the user
// to cancel it; finished takes that down.
Working func(cancel func()) (finished func())
// Forget drops the GPU textures of the frozen frames with these
// identities, once the overlay that drew them has closed.
Forget func(ids []render.ImageID)
// contains filtered or unexported fields
}
Host performs captures. The capture half runs on the caller's goroutine (a D-Bus handler); the overlays marshal onto the lys-ui loop themselves.
func (*Host) Capture ¶
Capture takes a screenshot for the user and returns the saved PNG path, or "" when the user cancelled a region selection. It is saved where [modules.screenshot] says, then copied and announced as it says. Every mode answers ErrBusy while a capture overlay is open.
func (*Host) CapturePrivate ¶
func (h *Host) CapturePrivate(c portaldialogs.Caller, mode, target string, pointer bool) (string, error)
CapturePrivate takes a screenshot for an app: saved to a file of its own in lys-shell's cache, with none of the user's save, clipboard or notification settings applied, the pointer composited in when pointer is set. "" is a cancelled selection; every mode answers ErrBusy while a capture overlay is open.
func (*Host) Dismiss ¶
Dismiss cancels the overlay open for the request at handle; another request's stays.
func (*Host) PickColor ¶
PickColor freezes every output and lets the user pick one pixel with the loupe, returning sRGB channels in [0, 1]; picked is false when the user cancelled, ErrBusy answers while a capture overlay is open, and any other error is a failure.
func (*Host) PickColorText ¶ added in v0.3.15
func (h *Host) PickColorText(caller portaldialogs.Caller, opts colorpicker.Options, copyText bool) (text string, picked bool, err error)
PickColorText lets the user pick one pixel as PickColor does and returns it written in the format the readout showed at the click, which opts.Format starts it in; with copyText it is put on the clipboard too. picked is false when the user cancelled.
func (*Host) Read ¶ added in v0.3.15
Read lets the user drag a region and reads it: its text through tesseract, or the QR code in it. Nothing is saved. Text lands on the clipboard and in a toast; a code is announced with buttons to copy it or, for a URL, open it. "" is a cancelled selection. A text reading without tesseract fails with ErrNoTesseract before anything opens, and Dismiss with the caller's handle stops a running tesseract.
type Notice ¶ added in v0.2.0
Notice is the desktop notification announcing a saved screenshot. With Actions it carries those buttons, and Respond hears the one pressed.
type ReadKind ¶ added in v0.3.15
type ReadKind string
ReadKind is what Read looks for in a region of the screen.
func ParseReadKind ¶ added in v0.3.15
ParseReadKind is the kind a CLI or D-Bus argument names.