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}), and any later x/y you y = 0 is the bottom of the screen, and y increases upward. This matches hs.ui.window. But element content positioned inside a canvas -- every frame, center, and y = 0 is the top of the canvas, and y increases downward. These two coordinate senses are independent of each other and easy to conflate, especially when a script computes an element's position from the same screen geometry it used for the window's own placement. If a shape appears vertically mirrored from where you expect, this mismatch is the first thing to check.

    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()

    Variables

    compositeTypes
    windowBehaviors
    windowLevels

    Functions

    create