[Xfce4-commits] <xfce4-panel:master> Panel: Make sure the panel has a position on startup (bug #8287).

Nick Schermer noreply at xfce.org
Thu Dec 29 12:38:01 CET 2011


Updating branch refs/heads/master
         to cbd8b3e68f47f3bac12195774383d26281a1ba34 (commit)
       from a8ff8f775c3c07ba35ee4bfbeca5e5ffc4920791 (commit)

commit cbd8b3e68f47f3bac12195774383d26281a1ba34
Author: Nick Schermer <nick at xfce.org>
Date:   Thu Dec 29 12:31:29 2011 +0100

    Panel: Make sure the panel has a position on startup (bug #8287).
    
    If it happens the panel looses some settings and the position
    string is also lost, it won't be visible on the next restart.
    Make sure the position is set, if it is not restored, set something
    new. Although this is not the position the user defined, it is
    better then no panel at all.

 panel/panel-application.c |   20 +++++++++++++-------
 panel/panel-window.c      |   16 +++++++++++++---
 panel/panel-window.h      |    2 ++
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/panel/panel-application.c b/panel/panel-application.c
index 0d3b493..3b304a0 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -1421,6 +1421,7 @@ panel_application_new_window (PanelApplication *application,
   gint                idx;
   static const gchar *props[] = { "mode", "size", "nrows" };
   guint               i;
+  gchar              *position;
 
   panel_return_val_if_fail (PANEL_IS_APPLICATION (application), NULL);
   panel_return_val_if_fail (screen == NULL || GDK_IS_SCREEN (screen), NULL);
@@ -1444,9 +1445,6 @@ panel_application_new_window (PanelApplication *application,
       property = g_strdup_printf ("/panels/panel-%d", idx);
       xfconf_channel_reset_property (application->xfconf, property, TRUE);
       g_free (property);
-
-      /* set default position */
-      g_object_set (G_OBJECT (window), "position", "p=0;x=100;y=100", NULL);
     }
 
   /* add the itembar */
@@ -1474,10 +1472,18 @@ panel_application_new_window (PanelApplication *application,
   /* add the xfconf bindings */
   panel_application_xfconf_window_bindings (application, PANEL_WINDOW (window), FALSE);
 
-  /* make sure the position of the panel is always saved else
-   * the new window won't be visible on restart */
-  if (new_window)
-    g_object_notify (G_OBJECT (window), "position");
+  /* make sure the panel has a valid position, else it is not visible */
+  if (!panel_window_has_position (PANEL_WINDOW (window)))
+    {
+      if (!new_window)
+        g_message ("No panel position set, restoring default");
+
+      /* create a position so not all panels overlap */
+      idx = g_slist_index (application->windows, window);
+      position = g_strdup_printf ("p=0;x=100;y=%d", 100 + (idx * 48 * 2));
+      g_object_set (G_OBJECT (window), "position", position, NULL);
+      g_free (position);
+    }
 
   return PANEL_WINDOW (window);
 }
diff --git a/panel/panel-window.c b/panel/panel-window.c
index ba16a7f..f2e3ac0 100644
--- a/panel/panel-window.c
+++ b/panel/panel-window.c
@@ -142,6 +142,7 @@ static void         panel_window_plugin_set_screen_position (GtkWidget        *w
                                                              gpointer          user_data);
 
 
+
 enum
 {
   PROP_0,
@@ -670,8 +671,8 @@ panel_window_set_property (GObject      *object,
           && sscanf (val_string, "p=%d;x=%d;y=%d", &snap_position, &x, &y) == 3)
         {
           window->snap_position = CLAMP (snap_position, SNAP_POSITION_NONE, SNAP_POSITION_S);
-          window->base_x = x;
-          window->base_y = y;
+          window->base_x = MAX (x, 0);
+          window->base_y = MAX (y, 0);
 
           panel_window_screen_layout_changed (window->screen, window);
 
@@ -680,7 +681,7 @@ panel_window_set_property (GObject      *object,
         }
       else
         {
-          g_message ("no valid position defined: %s", val_string);
+          g_message ("Not a valid position defined: %s", val_string);
         }
       break;
 
@@ -2549,6 +2550,15 @@ panel_window_new (GdkScreen *screen)
 
 
 
+gboolean
+panel_window_has_position (PanelWindow *window)
+{
+  panel_return_val_if_fail (PANEL_IS_WINDOW (window), FALSE);
+  return window->base_x != -1 && window->base_y != -1;
+}
+
+
+
 void
 panel_window_set_povider_info (PanelWindow *window,
                                GtkWidget   *provider,
diff --git a/panel/panel-window.h b/panel/panel-window.h
index 99bc252..b745c48 100644
--- a/panel/panel-window.h
+++ b/panel/panel-window.h
@@ -37,6 +37,8 @@ GType      panel_window_get_type         (void) G_GNUC_CONST;
 
 GtkWidget *panel_window_new              (GdkScreen   *screen) G_GNUC_MALLOC;
 
+gboolean   panel_window_has_position     (PanelWindow *window);
+
 void       panel_window_set_povider_info (PanelWindow *window,
                                           GtkWidget   *provider,
                                           gboolean     moving_to_other_panel);


More information about the Xfce4-commits mailing list