Skip to content
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

Add a function to close all windows and return from Fl::run() #498

Closed
Albrecht-S opened this issue Sep 11, 2022 · 4 comments
Closed

Add a function to close all windows and return from Fl::run() #498

Albrecht-S opened this issue Sep 11, 2022 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@Albrecht-S
Copy link
Member

This was requested by a user in fltk.general long ago. I'm opening this issue so the request doesn't get lost. Links to the discussion (the entire thread is very long):

  1. The OP's request: https://groups.google.com/g/fltkgeneral/c/BBDZUhlwWJM/m/kzV8RvCQAgAJ
  2. My summary and offer to add such a function: https://groups.google.com/g/fltkgeneral/c/BBDZUhlwWJM/m/NmRuwQXlAwAJ

We agreed upon adding a function called Fl::hide_all_windows(). Unfortunately this was not done yet but should be done before 1.4.0 is released.

@Albrecht-S Albrecht-S self-assigned this Sep 11, 2022
@Albrecht-S Albrecht-S added the enhancement New feature or request label Sep 11, 2022
@Albrecht-S Albrecht-S added this to the Release FLTK 1.4.0 milestone Sep 11, 2022
@ManoloFLTK
Copy link
Contributor

Here is what the user originally wrote :

The issue is that calling system exit(), although simple, does not return from Fl::run() and destructors do not get called.

I would therefore tend to believe the new function should delete all windows and subwindows rather than hide them, because if they're only hidden, Fl_Window_Driver objects will be destroyed, but Fl_Window objects won't be. Class Fl_Window_Driver is not accessible to FLTK users, so program resources are likely to be stored in Fl_Window controlled-structures.

Does this make sense at all in terms of program resources if exit() is called after window destruction ? That is, wouldn't program resources be equally freed with and without the new function? If yes, the new function would make sense only if the program continues windowless after the function call. I may have missed something from the previous discussion.

@Albrecht-S
Copy link
Member Author

@ManoloFLTK The OP also wrote:

In particular, on the Mac, I need to close message queues which are a precious resource.

I interpret this in the given context that the mentioned destructors would be called if the program came to a normal end after returning fromFl::run() but the OP was asking for a way (function) to do exactly (and only) this: close all open windows.

Destructors would normally be called at a normal program exit (return from main()) but this would not happen if the user called the system function exit() to terminate the program rather than "leaving" Fl::run() in the normal way by closing all open windows so Fl::run() returns normally to the caller.

The OP did not say which destructors he would like to be called, particularly not if for any windows. Windows can also be allocated as normal program variables in main() so that these windows would also be destroyed when main() returns (or not if they were instantiated with new).

What the user does with the mentioned message queues (for instance) is not specified. They may be allocated on the stack and would be destroyed automatically or the user could add some instructions like delete message_queue_xyz; after returning from Fl::run() which they can't do now because Fl::run() wouldn't return w/o closing all windows.

IMHO it's that simple: create a public function that closes all open windows (correctly!) w/o the issues discussed in the given thread, for instance that using Fl::next_window() would be wrong in this context (see discussion).

That said, this GitHub Issue was only meant as a reminder to implement exactly this function because my time is pretty limited right now and I didn't want to forget this task (it's attached to milestone 1.4.0 for exactly that reason). A function that would also delete all (open!) windows would really be another topic with its own problems. I won't go into further details unless someone asks for this explicitly.

@ManoloFLTK
Copy link
Contributor

OK. I see now that what the OP wants is a simple way to return from Fl::run(). What comes next is under the application's responsibility. So, yes, a new function Fl::hide_all_windows() is what's needed.

@MatthiasWM
Copy link
Contributor

MatthiasWM commented Jan 5, 2023

Added and tested in 4bff152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants