Skip to content

The window

yassinezerguine08 edited this page Nov 3, 2026 · 2 revisions

The window

BrowserWindow is a frame with Chromium inside. The frame has no title bar or border of its own: the page draws them, so the whole window looks the way the application wants.

Describing the application

final Application application = new Application(
	AppId.of("hello"),                 // the id Oriel names things after
	"Hello",                           // the title, and the name in messages
	WindowIcon.images(Hello.class, "icons/hello-%d.png"),   // the icons; List.of() leaves the desktop's own
	new Dimension(800, 600),           // the size it opens at
	new Dimension(480, 360)            // the size it cannot be made smaller than
);

Nothing has a default. The opening size cannot be smaller than the minimum.

The id is lowercase letters, digits and -, starting with a letter. It ends up in folder names, a property and a cookie:

Name Built from the id For hello
Downloaded engine ~/.<id>/jcef ~/.hello/jcef
Browser data, also for an installed application ~/.<id>/browser/cef ~/.hello/browser/cef
Property naming a bundled engine <id>.jcef -Dhello.jcef=…
Session cookie <id>-session hello-session

Icons are drawn ahead of time at each size, because a large image scaled down at run time leaves the small sizes blurred. Keep one file per size next to a class of your own and name them with a pattern:

WindowIcon.images(Hello.class, "icons/hello-%d.png")   // reads hello-16.png … hello-256.png, next to Hello.class

The sizes are 16, 24, 32, 48, 64, 128 and 256.

Opening it

final BrowserWindow window = new BrowserWindow(application, options.windowSystem());
// give window.control() to Routes.create(…), then:
window.open(uri.resolve("/?" + SessionToken.PARAMETER + "=" + token.value()));

The window opens at the application's size, centred in the screen's work area. On a screen with less room, it shrinks to fit, so a small or scaled display still shows all of it. It has rounded corners while it floats and square ones while it is maximised, where the desktop allows it.

The title bar and the edges

/oriel/window.js turns markup into window controls:

Markup What it does
data-drag on the title bar Dragging it moves the window; double-clicking it maximises or restores
data-window="minimise", "maximise", "close" on a button Minimises, maximises or restores, or closes the window
data-resize="left", "right", "bottom", "bottom-right" on an element along the edge Dragging it resizes the window from that edge. The top is left to the title bar
data-theme-toggle on a button Switches data-theme on <html> between light and dark, and remembers the choice in localStorage

A title bar and edges, as a page draws them:

<header class="titlebar" data-drag>
	<span class="titlebar__title">Hello</span>
	<button class="titlebar__button" type="button" data-theme-toggle aria-label="Switch theme">&#9680;</button>
	<button class="titlebar__button" type="button" data-window="minimise" aria-label="Minimise">&#8211;</button>
	<button class="titlebar__button" type="button" data-window="maximise" aria-label="Maximise">&#9633;</button>
	<button class="titlebar__button titlebar__button--close" type="button" data-window="close"
		aria-label="Close">&#10005;</button>
</header>

<div class="resize resize--left" data-resize="left"></div>
<div class="resize resize--right" data-resize="right"></div>
<div class="resize resize--bottom" data-resize="bottom"></div>
<div class="resize resize--corner" data-resize="bottom-right"></div>

The edges need CSS of the application's own to give them a place and a cursor. To show the stored theme before the first paint, set it in <head>:

<script>document.documentElement.dataset.theme = localStorage.getItem("theme") || "dark";</script>

File dialogs

A page can be handed a file's contents but never its place on disk, so the window's own dialog is asked instead. The path it returns goes to an action:

<button type="button" data-choose-file="Open a note" hx-post="/action/open"
	hx-trigger="file-chosen" hx-vals="js:{path: event.detail.path}" hx-target="#note"
	hx-swap="outerHTML">Open…</button>

<button type="button" data-save-file="Save the note" data-file-name="note.txt"
	hx-post="/action/save" hx-trigger="file-chosen" hx-vals="js:{path: event.detail.path}"
	hx-target="#note" hx-swap="outerHTML">Save as…</button>
  • data-choose-file opens a dialog for picking a file. Its value is the dialog's title.
  • data-save-file opens a dialog for saving one, suggesting the name in data-file-name.
  • When the person picks a file, the button gets a file-chosen event with the path in event.detail.path. If the dialog is dismissed, nothing happens.
  • The page is inert while the dialog is open.

The action reads the path from its form:

@Action("open")
public NoteView onOpenChosen(final Form form) {
	final Path file = Path.of(form.get("path"));
	…
}

X11 and Wayland

On a Linux desktop the frame is an X11 window, even on Wayland, where it runs through Xwayland. Chromium can only be embedded in it from X11. On Wayland it would draw the page in a window of its own, and under GNOME it would load GTK 4, which freezes the GTK 3 file dialog. So Oriel uses X11 by default.

LaunchOptions takes Oriel's one command-line option and leaves the rest to the application:

final LaunchOptions options = LaunchOptions.of(args);
// options.windowSystem(): X11 unless --window-system=wayland or --window-system=auto was given
// options.remaining():    every other argument, untouched and in order
  • It accepts --window-system=x11|wayland|auto or --window-system x11, in any case.
  • It refuses a missing, unknown or repeated value with an IllegalArgumentException. What happens then is the application's to decide.
  • Everything after -- is the application's, even what looks like Oriel's.
  • LaunchOptions.help() gives a line for the application's own help, but only on Linux, where there is a choice.

Outside Linux the option is still read and checked, so one way of starting works everywhere, but it changes nothing.

The browser engine

Chromium is a native download of more than 100 MB, so it is not in the jar. Where it is:

  • An installed application carries it in its own folder, and its launcher names that folder with -D<id>.jcef=…. Oriel then uses it as it is and never downloads anything. A damaged engine there fails to start rather than being replaced.
  • Without that property, as in development, the engine is downloaded into ~/.<id>/jcef on the first start and reused afterwards. Each stage is logged as Preparing the browser engine: ….

Each application keeps its own engine, so one moving to another version leaves the others alone.

If the engine cannot start, StartFailure gives a message to show the person, naming the folder and the reason:

StartFailure.message(application, new CefLocation(application.id()).directory(), cause)
// "Hello could not start its browser engine from … Install Hello again to restore it."

Debugging

Starting with -Doriel.remote-debugging-port=9222 opens Chromium's DevTools on that port, so http://localhost:9222 in Chrome inspects the page. Nothing listens unless the property is set.

Closing

Closing the window hides it and shuts the browser engine down, which ends the process. If the engine has not finished within ten seconds, which happens now and then on macOS, the process ends anyway.

Clone this wiki locally