A low-level, absolutely-positioned drawing surface
hs.canvas mirrors v1 Hammerspoon's hs.canvas module: elements are plain JS
objects (mirroring v1's Lua tables) describing shapes (rectangle, circle,
oval, text) with a fill/stroke/strokeAndFill/clip/build/skip action
pipeline. This is a different tool from hs.ui, which is a SwiftUI stack/layout
builder for app-like interfaces -- reach for hs.canvas when you need absolute
positioning, clipped/composited shapes, or direct window-level/Spaces control.
Coordinates
A canvas's window position (create({x, y, w, h}), frame(), setFrame(),
topLeft()) uses the same screen coordinates as hs.screen, hs.window and
hs.ui.window: y = 0 is the top of the primary screen, and y increases downward.
You can pass a window's or screen's frame straight to create() or setFrame().
Element content positioned inside a canvas -- every frame, center, and
coordinates value you pass to appendElements() and friends -- is relative to the
canvas: {x: 0, y: 0} is the canvas's top-left corner, and y increases downward.
hs.canvas
A low-level, absolutely-positioned drawing surface
hs.canvasmirrors v1 Hammerspoon'shs.canvasmodule: elements are plain JS objects (mirroring v1's Lua tables) describing shapes (rectangle,circle,oval,text) with afill/stroke/strokeAndFill/clip/build/skipaction pipeline. This is a different tool fromhs.ui, which is a SwiftUI stack/layout builder for app-like interfaces -- reach forhs.canvaswhen you need absolute positioning, clipped/composited shapes, or direct window-level/Spaces control.Coordinates
A canvas's window position (
create({x, y, w, h}),frame(),setFrame(),topLeft()) uses the same screen coordinates ashs.screen,hs.windowandhs.ui.window:y = 0is the top of the primary screen, andyincreases downward. You can pass a window's or screen'sframestraight tocreate()orsetFrame().Element content positioned inside a canvas -- every
frame,center, andcoordinatesvalue you pass toappendElements()and friends -- is relative to the canvas:{x: 0, y: 0}is the canvas's top-left corner, andyincreases downward.Example: a rounded screen corner overlay