-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
X11: Program does not terminate when the window closes #829
Comments
On macOS the application doesn't terminate when the last window is closed, just the menu will continue running. A lot of macOS apps work like this, but not all. It would probably be good to make this configurable. On Windows the application doesn't terminate either, but this is a bug. It's being tackled in #763 In general the solution here should be to add the capability to shut down the loop in druid-shell, but the decision to shut it down should be made in druid, so that it can be configurable and not all druid-shell users might want this behavior. Also, crucially, even though we've been using this term too, the program should 100% not terminate. Druid should instead give control back to its caller, i.e. break druid's run loop. Because the caller might want to do some final cleanup - or just go to sleep waiting for some event. |
How Electron recommends to termination on different systems is opt in, basically. https://www.electronjs.org/docs/tutorial/first-app. The user has to write the code to handle application lifecycle clean-up, and explicitly make the decision to end the process or not. // Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
}) |
Supporting handling such an event can be useful, as can other no-windows-exist events. However right now there's no way to supply a general app event handler to druid. This is probably something that's going to be needed eventually, especially for macOS. |
@xStrom Isn't that what |
I'm not sure, I haven't looked into It might make sense to extend I really need to look more closely into this to have a more concrete understanding. |
yes I'm on the fence about (The important distinction being that AppHandler is a |
Although #900 does indeed allow for closing the application when the last window closes (and does so on Windows), all the druid examples still don't quit on MacOS when the last window is closed. This feels awkward, because for simple applications quitting is still the default behaviour. And I would propose having all the druid example do so, unless specifically unwanted (such as I added this functionality to the For reference, this is the extra code added: #[derive(Clone, Default, Data)]
struct AppState {
window_count: usize,
}
struct Delegate;
impl AppDelegate<AppState> for Delegate {
fn window_added(
&mut self,
_id: druid::WindowId,
data: &mut AppState,
_env: &druid::Env,
_ctx: &mut druid::DelegateCtx,
) {
data.window_count += 1;
}
fn window_removed(
&mut self,
_id: druid::WindowId,
data: &mut AppState,
_env: &druid::Env,
_ctx: &mut druid::DelegateCtx,
) {
data.window_count -= 1;
if data.window_count == 0 {
Application::global().quit();
}
}
} and AppLauncher::with_window(WindowDesc::new(build_ui))
.delegate(Delegate)
.launch(AppState::default())?; |
One of the things I didn't get to when I wrote #599, and one of the bullet points being tracked in #475.
I'm not sure if this is a Druid-related issue or an XCB-related one (or both?).
Problem
When you run a Druid program (say with
cargo run --example calc --features=x11
) and then close the Druid window, the program will still be running. The user must Ctrl+C (SIGINT) the program to get it to exit.Expected functionality
Instead, when you close the window, the program should terminate (as do Windows, Mac, and GTK backends).
The text was updated successfully, but these errors were encountered: