Introduction
Many of the API classes represent global objects in the script’s context — methods that are marked as static can be accessed through these global objects. All other functions are instance methods. Instance objects can be accessed through the global objects or constructed with the relevant constructors.
For example, to bind a key to a function, you construct a Key
object. Notice that you must keep a reference to the handler, otherwise your callback will not get called, because the handler will be released from memory.
const handler = new Key('q', ['control', 'shift'], () => {});
To move the focused window to a new coordinate, you can call the setTopLeft
method for a Window
instance. To get a Window
instance, you can for example get the focused window with the focused
method for the global Window
object.
Window.focused().setTopLeft({ x: 0, y: 0 });
To combine, bind a key to move the focused window.
const handler = new Key('q', ['control', 'shift'], () => {
Window.focused().setTopLeft({ x: 0, y: 0 });
});
As an other example, to bind an event to a function, you construct an Event
object. Again notice that you must keep a reference to the handler, otherwise your callback will not get called. The callback will get triggered when the event with the specified name occurs.
const handler = new Event('screensDidChange', () => {});
You most likely do not want to handle the references manually. Therefore Phoenix supports “Managed Handlers”. This way you can let Phoenix take care of the state management for you.
Key.on('q', ['control', 'shift'], () => {});
Supported APIs
See below for an overview of the supported APIs. To read more, check the respective API documentation pages.
API | Description |
---|---|
Keys | Lists all the available keys for binding callbacks to |
Events | Lists all the available events for binding callbacks to |
Preferences | Configure the behaviour of Phoenix |
Require | Separate your configuration into multiple files |
Phoenix | Access global APIs and actions |
Storage | Use Storage to store values across reloads and reboots as JSON |
Point | A simple point object for 2D coordinates |
Size | A simple 2D size object |
Rectangle | A 2D rectangle representation of a Point and Size |
Identifiable | Objects that implement Identifiable can be identified and compared |
Iterable | Objects that implement Iterable can be traversed relatively to the current object |
Key | Use Key to construct keys, bind callbacks, access their properties, and enable or disable them |
Event | Use Event to construct events, bind callbacks, access their properties or disable them |
Timer | Use Timer to construct and control timers |
Task | Use Task to construct external tasks (such as running scripts), access their properties or terminate them |
Image | Use Image to load images from the file system |
Modal | Use Modal to display content as modal windows (in front of all other windows). Modals can be used to display icons and/or text for visual cues. |
Screen | Use Screen to access frame sizes and other screens on a multi-screen setup |
Space | Use the Space to control spaces |
Mouse | Use the Mouse to control the cursor |
App | Use App to control apps |
Window | Use Window to control app windows |