* examples/hildon-stackable-window-example.c * src/hildon-stackable-window.c * src...
[hildon] / src / hildon-stackable-window.c
index 4a24e33..03830b4 100644 (file)
  * SECTION:hildon-stackable-window
  * @short_description: Widget representing a stackable, top-level window in the Hildon framework.
  *
- * The @HildonStackableWindow is a GTK+ widget which represents a
+ * The #HildonStackableWindow is a GTK+ widget which represents a
  * top-level window in the Hildon framework. It is derived from
- * @HildonWindow. Applications that use stackable windows are organized
+ * #HildonWindow. Applications that use stackable windows are organized
  * in a hierarchical way so users can go from any window back to the
  * application's root window.
  */
 
+#include                                        <X11/X.h>
+#include                                        <X11/Xatom.h>
 #include                                        "hildon-stackable-window.h"
 #include                                        "hildon-program.h"
 #include                                        "hildon-window-private.h"
@@ -90,21 +92,22 @@ get_window_list                                 (GtkWidget *widget)
 static GtkWidget*
 get_last_window                                 (GtkWidget *widget)
 {
-    GtkWidget *retval;
+    GtkWidget *retval = NULL;
     GSList *windows = get_window_list (widget);
+    GSList *last = NULL;
 
     g_return_val_if_fail (windows != NULL, NULL);
 
-    retval = GTK_WIDGET (g_slist_last (windows)->data);
-
-    if (retval == widget)
+    /* Go to the end of the window list */
+    while (windows->next != NULL)
     {
-        gint l = g_slist_length (windows);
-        retval = GTK_WIDGET (g_slist_nth_data (windows, l - 2));
+        last = windows;
+        windows = windows->next;
     }
-    else
+
+    if ((windows->data == widget) && (last != NULL))
     {
-        retval = NULL;
+        retval = GTK_WIDGET (last->data);
     }
 
     return retval;
@@ -159,6 +162,24 @@ hildon_stackable_window_unset_program           (HildonWindow *hwin)
 }
 
 static void
+hildon_stackable_window_realize                 (GtkWidget *widget)
+{
+    GdkDisplay *display;
+    Atom atom;
+
+    GTK_WIDGET_CLASS (hildon_stackable_window_parent_class)->realize (widget);
+
+    /* Set the window type to "_HILDON_WM_WINDOW_TYPE_STACKABLE", to allow the WM to manage
+       it properly.  */
+    display = gdk_drawable_get_display (widget->window);
+    atom = gdk_x11_get_xatom_by_name_for_display (display, "_HILDON_WM_WINDOW_TYPE_STACKABLE");
+    XChangeProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (widget->window),
+                    gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_WINDOW_TYPE"),
+                    XA_ATOM, 32, PropModeAppend,
+                    (guchar *)&atom, 1);
+}
+
+static void
 hildon_stackable_window_class_init              (HildonStackableWindowClass *klass)
 {
     GtkWidgetClass    *widget_class = GTK_WIDGET_CLASS (klass);
@@ -166,10 +187,11 @@ hildon_stackable_window_class_init              (HildonStackableWindowClass *kla
 
     widget_class->map               = hildon_stackable_window_map;
     widget_class->unmap             = hildon_stackable_window_unmap;
+    widget_class->realize           = hildon_stackable_window_realize;
 
     window_class->unset_program     = hildon_stackable_window_unset_program;
 
-    g_type_class_add_private (klass, sizeof (HildonWindowPrivate));
+    g_type_class_add_private (klass, sizeof (HildonStackableWindowPrivate));
 }
 
 static void
@@ -181,9 +203,9 @@ hildon_stackable_window_init                    (HildonStackableWindow *self)
 /**
  * hildon_stackable_window_new:
  *
- * Creates a new @HildonStackableWindow.
+ * Creates a new #HildonStackableWindow.
  *
- * Return value: A @HildonStackableWindow
+ * Return value: A #HildonStackableWindow
  **/
 GtkWidget*
 hildon_stackable_window_new                     (void)
@@ -194,14 +216,14 @@ hildon_stackable_window_new                     (void)
 }
 
 /**
- * hildon_stackable_window_go_home:
+ * hildon_stackable_window_go_to_root_window:
  * @self: A #HildonStackableWindow
  *
  * Will pop out all the stackable windows in the @HildonProgram but the
  * first one, which can be considered as the "home" window.
  */
 void
-hildon_stackable_window_go_home                 (HildonStackableWindow *self)
+hildon_stackable_window_go_to_root_window       (HildonStackableWindow *self)
 {
     g_return_if_fail (HILDON_IS_STACKABLE_WINDOW (self));
 
@@ -225,5 +247,5 @@ hildon_stackable_window_go_home                 (HildonStackableWindow *self)
     }
 
     if (!GTK_WIDGET_VISIBLE (rootwin))
-        gtk_widget_show (rootwin);
+        gtk_widget_show (GTK_WIDGET (rootwin));
 }