Guides
Follow the page's title and fullscreen
Keep a window's title and fullscreen state in step with its page and hear when they change.
A window takes its page’s title and goes fullscreen with its page by itself. Two hooks tell your app when that happens so it can update its own controls.
Fix a window’s title
A window follows its page’s <title> unless its options fix one with WindowOptions::title:
use kurogane::{App, WindowOptions};
fn main() {
App::new("content")
.window(WindowOptions::new().title("Notes"))
.run_or_exit();
}
A popup always follows its page. The taskbar and the window switcher show the window’s title, a remote page’s included.
Hear title changes
App::on_title_change hears every title a page gives itself. That’s its <title> as it loads or document.title set by a script:
use kurogane::App;
fn main() {
App::new("content")
.on_title_change(|change, _app| {
println!("{:?} is now {:?}", change.window(), change.title());
})
.run_or_exit();
}
The hook hears every change whether the window follows the title or not. Popups and embedded browsers are reported too.
Title your own window
A browser embedded in your own window doesn’t title that window. Your app does. Send the title to your loop and set it there:
use std::sync::mpsc;
use kurogane::{App, RuntimeError};
fn main() -> Result<(), RuntimeError> {
let (titles, new_titles) = mpsc::channel::<String>();
let runtime = App::new("content")
.on_title_change(move |change, _app| {
let _ = titles.send(change.title().to_owned());
})
.start_embedded()?;
// In your loop, after each pump
while let Ok(title) = new_titles.try_recv() {
println!("set the host window's title to {title}");
}
runtime.shutdown();
Ok(())
}
TitleChange::window is None for an embedded browser. TitleChange::browser says which browser changed.
Hear fullscreen changes
A page enters fullscreen with requestFullscreen() and leaves it with exitFullscreen() or the user’s Escape. App::on_fullscreen_change hears both:
use kurogane::App;
fn main() {
App::new("content")
.on_fullscreen_change(|change, _app| {
println!("fullscreen: {}", change.is_fullscreen());
})
.run_or_exit();
}
Hide your app’s own controls there. A window of Kurogane’s goes fullscreen with its page by itself. Kurogane doesn’t resize a browser embedded in your own window. Your app sizes it, for example to fill a window it made fullscreen.
Open or keep a window fullscreen
WindowState::Fullscreen opens a window fullscreen:
use kurogane::{App, WindowOptions, WindowState};
fn main() {
App::new("content")
.window(WindowOptions::new().state(WindowState::Fullscreen))
.run_or_exit();
}
The user toggles fullscreen with F11 (Cmd+Ctrl+F on macOS). Refuse ChromeCommand::Fullscreen in App::on_chrome_command to turn that shortcut off. See Keyboard shortcuts.
Rules for the hooks
- Both hooks run on the UI thread and must not block.
- A hook that panics is logged.
- DevTools isn’t reported.
- A later call replaces an earlier hook.