+ GNode *retnode;
+
+ if(win == NULL)
+ retnode = glk_data->root_window;
+ else
+ {
+ GNode *node = win->window_node;
+ if( G_NODE_IS_LEAF(node) )
+ {
+ while(node && node->next == NULL)
+ node = node->parent;
+ if(node)
+ retnode = node->next;
+ else
+ retnode = NULL;
+ }
+ else
+ retnode = g_node_first_child(node);
+ }
+ winid_t retval = retnode? (winid_t)retnode->data : NULL;
+
+ /* Store the window's rock in rockptr */
+ if(retval && rockptr)
+ *rockptr = glk_window_get_rock(retval);
+
+ return retval;
+}
+
+/**
+ * glk_window_get_rock:
+ * @win: A window.
+ *
+ * Returns @win's rock value. Pair windows always have rock 0; all other windows
+ * have the rock value you created them with.
+ *
+ * Returns: A rock value.
+ */
+glui32
+glk_window_get_rock(winid_t win)
+{
+ g_return_val_if_fail(win != NULL, 0);
+ return win->rock;
+}
+
+/**
+ * glk_window_get_type:
+ * @win: A window.
+ *
+ * Returns @win's type, one of #wintype_Blank, #wintype_Pair,
+ * #wintype_TextBuffer, #wintype_TextGrid, or #wintype_Graphics.
+ *
+ * Returns: The window's type.
+ */
+glui32
+glk_window_get_type(winid_t win)
+{
+ g_return_val_if_fail(win != NULL, 0);
+ return win->type;
+}
+
+/**
+ * glk_window_get_parent:
+ * @win: A window.
+ *
+ * Returns the window @win's parent window. If @win is the root window, this
+ * returns %NULL, since the root window has no parent. Remember that the parent
+ * of every window is a pair window; other window types are always childless.
+ *
+ * Returns: A window.
+ */
+winid_t
+glk_window_get_parent(winid_t win)
+{
+ g_return_val_if_fail(win != NULL, NULL);
+ /* Value will also be NULL if win is the root window */
+ return (winid_t)win->window_node->parent->data;
+}
+
+/**
+ * glk_window_get_sibling:
+ * @win: A window.
+ *
+ * Returns the other child of the window @win's parent. If @win is the
+ * root window, this returns %NULL.
+ *
+ * Returns: A window, or %NULL.
+ */
+winid_t
+glk_window_get_sibling(winid_t win)
+{
+ g_return_val_if_fail(win != NULL, NULL);
+
+ if(G_NODE_IS_ROOT(win->window_node))
+ return NULL;
+ if(win->window_node->next)
+ return (winid_t)win->window_node->next;
+ return (winid_t)win->window_node->prev;
+}
+
+/**
+ * glk_window_get_root:
+ *
+ * Returns the root window. If there are no windows, this returns #NULL.
+ *
+ * Returns: A window, or #NULL.
+ */
+winid_t
+glk_window_get_root()
+{
+ if(glk_data->root_window == NULL)
+ return NULL;
+ return (winid_t)glk_data->root_window->data;
+}