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

[Draft] Multiple top-level windows (and some questions) #75

Closed
wants to merge 8 commits into from

Conversation

Dretch
Copy link
Collaborator

@Dretch Dretch commented Jan 26, 2020

This is a draft of multiple top-level windows (requested in issue #45).

The windows are created outside of the regular tree of Gtk widgets by wrapping a widget with a special "window host" widget that maintains a new top-level window in addition to the original widget. The handle to the window widget is put into the custom state field of the StateTreeNode (the original custom state of the widget is also kept).

This seems to work okay, although I am not sure the design is that elegant. Some things are worth mentioning in particular:

  1. In order to remove the windows when the wrapped widget is removed, I added a destroy method to the Patchable class. An alternative option here would be to attach a "destroy" signal handler to the wrapped widget (that then destroys the window), but I thought keeping the control within gi-gtk-declarative (rather than involving Gtk event handlers) would be more predictable. Does this design make sense?

  2. There is some code in Patch.hs that presents a problem for the destroy method design - I'll add an in-line comment to elaborate on this.

  3. I vaguely wonder if the "extra state in the widget tree" idea could be generalised to something more useful. There could be "custom attributes" that would allow hanging bits of state (with their own patching behaviour) from widgets in the tree. This could be used to easily implement new top-level windows, but also other patching behaviour that could call arbitrary methods on widgets. This would provide something similar to custom widgets, but less flexible and more re-usable - since a CustomAttribute Button Event could be attached to any Button, along with any combination of other custom or regular attributes. Does this make any sense?

Cheers!

@@ -76,6 +76,7 @@ patchInContainer (StateTreeContainer top children) container os' ns' = do
-- widget in the corresponding place, we need to replace the GTK widget with
-- one created from the declarative widget.
(i, Just oldChildState, Nothing, Just new) -> do
error "this shouldn't happen!"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to call destroy here with oldChildState, but we can't do that because destroy also requires the old declarative widget - which we don't have.

Does this situation ever actually happen? It seems to me that if oldChildState exists then we should also have the old declarative widget (since that would have been used to create oldChildState).

@Dretch Dretch requested a review from owickstrom January 26, 2020 15:07
@Dretch Dretch marked this pull request as draft April 18, 2020 14:56
Dretch added 8 commits May 2, 2020 09:37
…tDestroy.There is a stumbling block here the container Patching code, where it seems sometimes the old declarative widget is not known, even though we have the state...
Reject bad states by erroring, instead of attempting to handle them.
@Dretch
Copy link
Collaborator Author

Dretch commented Jul 19, 2020

I am closing this in order to focus my energies on #76

@Dretch Dretch closed this Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant