Screen (display info)
Display enumeration and change events, flat on window.Electron (no namespace). Source: src/main/screen.ts, channel prefix screen:*. Always on, no config needed. Listeners are attached inside app.whenReady() — Electron's screen module isn't usable before that.
Methods
| Method | Returns | Notes |
|---|---|---|
getAllDisplays() |
Promise<ElectronDisplay[]> |
|
getPrimaryDisplay() |
Promise<ElectronDisplay> |
|
getCursorScreenPoint() |
Promise<{ x: number; y: number }> |
|
getCursorDisplay() |
Promise<ElectronDisplay> |
The display nearest the current cursor position. |
onScreenEvent(callback: (data: ScreenEventPayload) => void) |
() => void (unsubscribe) |
Not part of .safe (event subscription, never throws). |
ElectronDisplay
{ id, label, bounds: Rect, workArea: Rect, size, workAreaSize, scaleFactor, rotation, internal, touchSupport, accelerometerSupport, colorDepth, colorSpace, depthPerComponent, displayFrequency, detected, monochrome } — mirrors Electron's own Display object.
ScreenEventPayload
{ type: 'display-added' | 'display-removed' | 'display-metrics-changed', data } — data is an ElectronDisplay for display-added/display-removed, or { display, changedMetrics: string[] } for display-metrics-changed.
Example
const displays = await window.Electron.getAllDisplays();
const unsubscribe = window.Electron.onScreenEvent(({ type, data }) => {
if (type === 'display-metrics-changed') console.log('metrics changed:', data);
});
.safe
getAllDisplays, getPrimaryDisplay, getCursorScreenPoint, getCursorDisplay are fully mirrored at window.Electron.safe.*. onScreenEvent has no .safe counterpart — it's a pure event subscription.