+static void
+free_winids_below(winid_t win)
+{
+ if(win->type == wintype_Pair) {
+ free_winids_below(win->window_node->children->data);
+ free_winids_below(win->window_node->children->next->data);
+ }
+ win->magic = MAGIC_FREE;
+ g_free(win);
+}
+
+void
+glk_window_close(winid_t win, stream_result_t *result)
+{
+ VALID_WINDOW(win, return);
+
+ /* First close all the window streams before trashing the window tree */
+ close_window_streams_below(win, result);
+
+ /* Then destroy the widgets of this window and below */
+ destroy_widgets_below(win);
+
+ /* Then free the winid_t structures below this node, but not this one itself */
+ if(win->type == wintype_Pair) {
+ free_winids_below(win->window_node->children->data);
+ free_winids_below(win->window_node->children->next->data);
+ }
+ /* So now we should be left with a skeleton tree hanging off this node */
+
+ /* Parent window changes from a split window into the sibling window */
+ /* The parent of any window is either a pair window or NULL */