By default, all windows passed to App.config({ windows }) are constructed
immediately at startup. For shells with many windows (launchers, dashboards,
settings panels) this adds to startup time even when those windows are never
opened.
The lazyWindows config field lets you register a factory function
instead. The window is only constructed the first time it is opened via
App.openWindow() or App.toggleWindow().
App.config({
windows: [
Bar(), // constructed immediately
],
lazyWindows: {
// Only constructed when you run: App.openWindow('launcher')
"launcher": () => Launcher(),
"dashboard": () => Dashboard(),
},
});
Each key is the window name (must match the name property of the window
returned by the factory). The value is a zero-argument function that returns a
Gtk.Window.
| Action | Unconstructed lazy window | Already constructed |
|---|---|---|
App.openWindow(name) |
Calls factory, registers window, shows it | Shows it |
App.toggleWindow(name) |
Calls factory, registers window, shows it | Toggles visibility |
App.closeWindow(name) |
No-op (nothing to hide) | Hides it |
App.getWindow(name) |
Returns undefined (no error logged) |
Returns the window |
After the factory runs once, the window behaves identically to an eagerly-constructed window. The factory is deleted after use and will not be called again.
Lazy windows work transparently with ags --toggle-window:
ags --toggle-window launcher
On first invocation this constructs the window and shows it. Subsequent invocations toggle visibility normally.
If a name appears in both windows and lazyWindows, an error is logged and
the lazy entry is skipped. The eagerly-constructed window takes precedence.
// BAD: 'bar' is registered twice
App.config({
windows: [
Widget.Window({ name: 'bar', ... }),
],
lazyWindows: {
'bar': () => Widget.Window({ name: 'bar', ... }),
// ^ Will throw an error: a window with that name already exists
},
})
Use lazyWindows for windows that:
Keep using windows for windows that must be visible at startup (bars,
notification popups).