Windows
Content draws in native windows made with new DesktopEngine.Window({ type }).
| type | For |
|---|---|
desktop | Wallpapers: the desktop level, below the desktop icons, on all Spaces, and it gets mouse moves |
widget | Widgets on the desktop: above the desktop icons, borderless with a clear background, can be dragged |
overlay | Above all windows: borderless with a clear background, on all Spaces and over full screen apps; for floating widgets and desktop pets |
panel | A floating panel with a title bar |
normal | A standard window |
Showing a desktop, widget or overlay window doesn't activate DesktopEngine, so it doesn't take the focus from the user's current app.
The content's type decides which windows it can create, and the runtime enforces it: wallpapers only desktop; widgets and desktop pets only widget and overlay (where the user put it: pass launchOptions.windowType). Any other type, including a standard window without type, makes new DesktopEngine.Window() throw. Content from desktopengine dev and the Develop menu is held to the same rules, so you find out before you ship; mini programs without a manifest aren't.
Windows are transparent and their styles have no corner radius: to round the corners, draw a rounded rectangle on a canvas (see the widget template). A window stays until you call destroy().
Mouse
- Pressing anywhere in a
widgetoroverlaywindow drags it (the system's own window dragging): a drag getsmousedown, the window'smove, andmouseupon release, with nomousemoveduring the drag; a click only getsclick, nomousedown/mouseup. - The window's
dragRegionlimits where a press drags the window; elsewhere presses and drags go to the components (mousedown,mousemovewhile the button is down,mouseup), for controls such as dials and sliders.null(the default) is the whole window,[]nowhere. - A window dropped on a screen edge keeps its size and stays where it was dropped, though macOS still shows where it would tile it. Set the window's
allowsTilingtotrueto let macOS tile it, e.g. to half the screen, and handleresize. - The window's
hitRegion(an array of rectangles in points from the window's top left corner) limits the mouse to those parts: clicks, drags and hovers elsewhere pass through to the windows below.null(the default) is the whole window. Transparent parts of a window still catch the mouse by default, so an irregularly shaped pet should update it as it draws (see the pet template). mouseenter,mousemoveandmouseleavefire even when the window isn't the key window.- Event callbacks get plain objects, and
thisis the object that fired the event; the double click event is nameddbclick.
Displays and scale
launchOptions.displayis the display the content is on:frameis the whole screen,visibleFrameleaves out the menu bar and the Dock.- A window's
devicePixelRatiois the scale of its display. When a widget or pet is dragged to a display with another scale (from a Retina screen to a 1x external display, say), or the user changes the display's resolution, it changes and the window firesdevicepixelratiochange: set the canvas'swidth/heightfor the new value and redraw. - Unlike in browsers, setting
width/heighthere doesn't reset the 2D context's state: set the scale withsetTransform(ratio, 0, 0, ratio, 0, 0)rather than adding anotherscale()(see the widget and pet templates).
See Window for all its properties and events.
