Dock used showDelay for both hiding and showing (Bug 5811)
[dana/openbox.git] / openbox / dock.c
index d1f6b29..f18683d 100644 (file)
@@ -33,6 +33,8 @@
                               ButtonMotionMask)
 
 static ObDock *dock;
+static guint show_timeout_id;
+static guint hide_timeout_id;
 
 StrutPartial dock_strut;
 
@@ -80,7 +82,7 @@ void dock_startup(gboolean reconfig)
     STRUT_PARTIAL_SET(dock_strut, 0, 0, 0, 0,
                       0, 0, 0, 0, 0, 0, 0, 0);
 
-    dock = g_new0(ObDock, 1);
+    dock = g_slice_new0(ObDock);
     dock->obwin.type = OB_WINDOW_CLASS_DOCK;
 
     dock->hidden = TRUE;
@@ -129,6 +131,8 @@ void dock_shutdown(gboolean reconfig)
     RrAppearanceFree(dock->a_frame);
     window_remove(dock->frame);
     stacking_remove(dock);
+    g_slice_free(ObDock, dock);
+    dock = NULL;
 }
 
 void dock_manage(Window icon_win, Window name_win)
@@ -137,11 +141,11 @@ void dock_manage(Window icon_win, Window name_win)
     XWindowAttributes attrib;
     gchar **data;
 
-    app = g_new0(ObDockApp, 1);
+    app = g_slice_new0(ObDockApp);
     app->name_win = name_win;
     app->icon_win = icon_win;
 
-    if (OBT_PROP_GETSS(app->name_win, WM_CLASS, locale, &data)) {
+    if (OBT_PROP_GETSS_TYPE(app->name_win, WM_CLASS, STRING_NO_CC, &data)) {
         if (data[0]) {
             app->name = g_strdup(data[0]);
             if (data[1])
@@ -224,7 +228,7 @@ void dock_unmanage(ObDockApp *app, gboolean reparent)
 
     g_free(app->name);
     g_free(app->class);
-    g_free(app);
+    g_slice_free(ObDockApp, app);
 }
 
 void dock_configure(void)
@@ -234,7 +238,7 @@ void dock_configure(void)
     gint gravity;
     gint l, r, t, b;
     gint strw, strh;
-    Rect *a;
+    const Rect *a;
     gint hidesize;
 
     RrMargins(dock->a_frame, &l, &t, &r, &b);
@@ -547,9 +551,9 @@ void dock_configure(void)
         dock->area.height += ob_rr_theme->obwidth * 2;
     }
 
+    /* screen_resize() depends on this function to call screen_update_areas(),
+       so if this changes, also update screen_resize(). */
     screen_update_areas();
-
-    g_free(a);
 }
 
 void dock_app_configure(ObDockApp *app, gint w, gint h)
@@ -628,15 +632,19 @@ static gboolean hide_timeout(gpointer data)
     dock->hidden = TRUE;
     dock_configure();
 
+    hide_timeout_id = 0;
+
     return FALSE; /* don't repeat */
 }
 
 static gboolean show_timeout(gpointer data)
 {
-    /* hide */
+    /* show */
     dock->hidden = FALSE;
     dock_configure();
 
+    show_timeout_id = 0;
+
     return FALSE; /* don't repeat */
 }
 
@@ -644,21 +652,21 @@ void dock_hide(gboolean hide)
 {
     if (!hide) {
         if (dock->hidden && config_dock_hide) {
-            obt_main_loop_timeout_add(ob_main_loop,
-                                      config_dock_show_delay * 1000,
-                                      show_timeout, NULL,
-                                      g_direct_equal, NULL);
-        } else if (!dock->hidden && config_dock_hide) {
-            obt_main_loop_timeout_remove(ob_main_loop, hide_timeout);
+            show_timeout_id = g_timeout_add_full(G_PRIORITY_DEFAULT,
+                                                 config_dock_show_delay,
+                                                 show_timeout, NULL, NULL);
+        } else if (!dock->hidden && config_dock_hide && hide_timeout_id) {
+            if (hide_timeout_id) g_source_remove(hide_timeout_id);
+            hide_timeout_id = 0;
         }
     } else {
         if (!dock->hidden && config_dock_hide) {
-            obt_main_loop_timeout_add(ob_main_loop,
-                                      config_dock_hide_delay * 1000,
-                                      hide_timeout, NULL,
-                                      g_direct_equal, NULL);
-        } else if (dock->hidden && config_dock_hide) {
-            obt_main_loop_timeout_remove(ob_main_loop, show_timeout);
+            hide_timeout_id = g_timeout_add_full(G_PRIORITY_DEFAULT,
+                                                 config_dock_hide_delay,
+                                                 hide_timeout, NULL, NULL);
+        } else if (dock->hidden && config_dock_hide && show_timeout_id) {
+            if (show_timeout_id) g_source_remove(show_timeout_id);
+            show_timeout_id = 0;
         }
     }
 }
@@ -669,6 +677,16 @@ void dock_get_area(Rect *a)
              dock->area.width, dock->area.height);
 }
 
+void dock_raise_dock(void)
+{
+    stacking_raise(DOCK_AS_WINDOW(dock));
+}
+
+void dock_lower_dock(void)
+{
+    stacking_lower(DOCK_AS_WINDOW(dock));
+}
+
 ObDockApp* dock_find_dockapp(Window xwin)
 {
     return g_hash_table_lookup(dock->dock_map, &xwin);