app: add close request events - #182
Conversation
|
I didn't look at the implementation because I'm not sure this is a good idea. We've had similar discussions before, but basically my question is: when would you ever block the user from closing a window? This is outright impossible on some platforms (mobile, web), but seems misguided in all cases. If there's unsaved data, why not checkpoint that to disk when you receive a |
|
@eliasnaur That makes sense for unsaved data. This event would only be for desktop applications. I was thinking of tray Focused=false cannot tell that apart from switching to another application. Would a desktop-only close event make sense for that case? |
This is just the |
|
@eliasnaur understand that DestroyEvent is enough to keep a tray app alive. My point is I think a close request would better support desktop applications, where Would that desktop-specific behavior still be too narrow for the API? |
|
Why hide the window instead of letting it be destroyed, and then recreating it when the user clicks the tray icon? That seems superior in terms of resources as well. |
|
@eliasnaur Destroying and recreating a window works for tray apps. I think this event is On desktops, closing a window is a request that happens before the window is For example, closing a terminal or an application with a running task may need This would only be emitted on desktop platforms, where native window systems |
|
Alright, a running task or terminal could theoretically be checkpointed but I suppose you're right that the user expects it to be killed. I'm ok with the concept. As for the implementation, you seem to have redefined the window close button to never automatically close the window. This is not right for the Gio programs that don't need to ask their users for confirmation. It seems the functionality should be the other way around. I haven't thought long about this, but how about naming the event |
|
@eliasnaur That makes sense. If an app aborts to show a confirmation dialog, should |
Good question. I prefer to keep |
|
I will make ActionClose use the same close path and let the application decide whether to abort each close attempt. |
206201c to
1a1ccdd
Compare
|
@eliasnaur Implemented in 1a1ccdd. |
| arr[0] = C.long(w.atoms.evDelWindow) | ||
| arr[1] = C.CurrentTime | ||
| C.XSendEvent(w.x, w.xw, C.False, C.NoEventMask, &xev) | ||
| C.XFlush(w.x) |
There was a problem hiding this comment.
Is this a separate bug fix?
| } | ||
|
|
||
| type closingEventState struct { | ||
| aborted atomic.Bool |
There was a problem hiding this comment.
Why use an atomic value? There should be no concurrency: the event loop is blocking when the program is processing events, in particular ClosingEvent.
| // ClosingEvent is sent when the user requests to close a window. | ||
| // Call Abort while handling the event to keep the window open. | ||
| type ClosingEvent struct { | ||
| state *closingEventState |
There was a problem hiding this comment.
Why indirect state through a pointer, and not just embed the bool state?
1a1ccdd to
991f94a
Compare
| abort bool | ||
| } | ||
|
|
||
| func newClosingEvent() *ClosingEvent { |
There was a problem hiding this comment.
I forgot to delete it.
991f94a to
9b74b08
Compare
Desktop close actions now emit ClosingEvent before closing a window. Applications retain the existing behavior by doing nothing, or call Abort while handling the event when a confirmation is needed. ActionClose follows the same path as system close buttons and keyboard shortcuts, including custom decorations. Signed-off-by: qiannian <qianniancn@gmail.com>
9b74b08 to
9f84aff
Compare
eliasnaur
left a comment
There was a problem hiding this comment.
LGTM. What do you think, @whereswaldon ?
Applications may need a chance to stop a close before the window is destroyed.
For example, a terminal or a window with a running task can ask for confirmation
before the work is stopped.
On desktop platforms, ClosingEvent is sent when the user closes from the system
title bar, presses Alt+F4, or uses the close control in Gio decorations. The
window closes as usual unless the application calls Abort while handling the event.
Implement this for Windows, macOS, X11, and Wayland.