diff --git a/github-electron/github-electron-main-tests.ts b/github-electron/github-electron-main-tests.ts index 4ab87bea9..efaadcffe 100644 --- a/github-electron/github-electron-main-tests.ts +++ b/github-electron/github-electron-main-tests.ts @@ -608,6 +608,18 @@ app.on('ready', () => { y: externalDisplay.bounds.y + 50, }); } + + screen.on('display-added', (event, display) => { + console.log('display-added', display); + }); + + screen.on('display-removed', (event, display) => { + console.log('display-removed', display); + }); + + screen.on('display-metrics-changed', (event, display, changes) => { + console.log('display-metrics-changed', display, changes); + }); }); // shell diff --git a/github-electron/github-electron.screen.d.ts b/github-electron/github-electron.screen.d.ts index 5aa3d1c7c..93c854229 100644 --- a/github-electron/github-electron.screen.d.ts +++ b/github-electron/github-electron.screen.d.ts @@ -6,16 +6,28 @@ /// declare namespace Electron { - + /** + * The Display object represents a physical display connected to the system. + * A fake Display may exist on a headless system, or a Display may correspond to a remote, virtual display. + */ interface Display { + /** + * Unique identifier associated with the display. + */ id: number; bounds: Bounds; workArea: Bounds; size: Dimension; workAreaSize: Dimension; + /** + * Output device’s pixel scale factor. + */ scaleFactor: number; + /** + * Can be 0, 1, 2, 3, each represents screen rotation in clock-wise degrees of 0, 90, 180, 270. + */ rotation: number; - touchSupport: string; + touchSupport: 'available' | 'unavailable' | 'unknown'; } interface Bounds { @@ -35,7 +47,26 @@ declare namespace Electron { y: number; } + type DisplayMetrics = 'bounds' | 'workArea' | 'scaleFactor' | 'rotation'; + + /** + * The screen module retrieves information about screen size, displays, cursor position, etc. + * You should not use this module until the ready event of the app module is emitted. + */ class Screen extends EventEmitter { + /** + * Emitted when newDisplay has been added. + */ + on(event: 'display-added', listener: (event: Event, newDisplay: Display) => void): this; + /** + * Emitted when oldDisplay has been removed. + */ + on(event: 'display-removed', listener: (event: Event, oldDisplay: Display) => void): this; + /** + * Emitted when one or more metrics change in a display. + */ + on(event: 'display-metrics-changed', listener: (event: Event, display: Display, changedMetrics: DisplayMetrics[]) => void): this; + on(event: string, listener: Function): this; /** * @returns The current absolute position of the mouse pointer. */