X backend window disowns child before closing

This prevents elements from drawing to a closed window (causing
xgb to print an error)
This commit is contained in:
Sasha Koshka 2023-03-16 14:42:18 -04:00
parent a4ef28cdd0
commit b90ffeb4fd

View File

@ -125,19 +125,21 @@ func (window *window) Adopt (child elements.Element) {
window.child.DrawTo(nil, image.Rectangle { }, nil) window.child.DrawTo(nil, image.Rectangle { }, nil)
} }
// adopt new child
window.child = child
child.SetParent(window)
if newChild, ok := child.(elements.Themeable); ok {
newChild.SetTheme(window.theme)
}
if newChild, ok := child.(elements.Configurable); ok {
newChild.SetConfig(window.config)
}
if child != nil { if child != nil {
if !window.childMinimumSizeChangeCallback(child.MinimumSize()) { // adopt new child
window.resizeChildToFit() window.child = child
window.redrawChildEntirely() child.SetParent(window)
if newChild, ok := child.(elements.Themeable); ok {
newChild.SetTheme(window.theme)
}
if newChild, ok := child.(elements.Configurable); ok {
newChild.SetConfig(window.config)
}
if child != nil {
if !window.childMinimumSizeChangeCallback(child.MinimumSize()) {
window.resizeChildToFit()
window.redrawChildEntirely()
}
} }
} }
} }
@ -211,6 +213,8 @@ func (window *window) Hide () {
func (window *window) Close () { func (window *window) Close () {
if window.onClose != nil { window.onClose() } if window.onClose != nil { window.onClose() }
window.Hide()
window.Adopt(nil)
delete(window.backend.windows, window.xWindow.Id) delete(window.backend.windows, window.xWindow.Id)
window.xWindow.Destroy() window.xWindow.Destroy()
} }