hammerspoon2-docs
    Preparing search index...

    Namespace canvas

    hs.canvas

    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.

    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.

    const radius = 12
    const corner = hs.canvas.create({x: 0, y: 0, w: radius, h: radius})
    corner.appendElements([
    { action: "build", type: "rectangle" },
    { action: "clip", type: "circle", center: {x: radius, y: radius}, radius: radius, reversePath: true },
    { action: "fill", type: "rectangle", fillColor: { alpha: 1 } },
    { type: "resetClip" }
    ])
    corner.levelValue(hs.canvas.windowLevels.screenSaver + 1)
    corner.behavior("canJoinAllSpaces")
    corner.show()
    compositeTypes
    windowBehaviors
    windowLevels
    animate
    create