Ensure panel background update after some plugin was resized.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Tue, 14 Oct 2014 12:03:44 +0000 (15:03 +0300)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Tue, 14 Oct 2014 12:21:35 +0000 (15:21 +0300)
It involves keeping previous allocation on each panel plugin and checking it
on each size-allocate but that's a price.

ChangeLog
src/configurator.c
src/panel.c
src/plugin.c
src/private.h

index f785f64..9762d38 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
 * Adapted to use libmenu-cache >= 1.0.0 - it could show empty folders in
     the desktop menu.
 * Fixed crash in taskbar after visible task changed name then gone.
+* Ensured panel background update after some plugin was resized.
 
 0.7.1
 -------------------------------------------------------------------------
index 9b320af..fc75b46 100644 (file)
@@ -118,7 +118,7 @@ update_panel_geometry( LXPanel* p )
     _calculate_position(p);
     gtk_widget_set_size_request(GTK_WIDGET(p), p->priv->aw, p->priv->ah);
     gdk_window_move(gtk_widget_get_window(GTK_WIDGET(p)), p->priv->ax, p->priv->ay);
-    _panel_update_background(p);
+    _panel_queue_update_background(p);
     _panel_establish_autohide(p);
     _panel_set_wm_strut(p);
 }
index b13a850..d5171e6 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2006-2014 LxDE Developers, see the file AUTHORS for details.
  *
  * This program is free software; you can redistribute it and/or modify
@@ -60,7 +60,7 @@ static void panel_start_gui(LXPanel *p);
 static void ah_start(LXPanel *p);
 static void ah_stop(LXPanel *p);
 static void on_root_bg_changed(FbBg *bg, LXPanel* p);
-
+static void _panel_update_background(LXPanel * p);
 
 G_DEFINE_TYPE(PanelToplevel, lxpanel, GTK_TYPE_WINDOW);
 
@@ -117,11 +117,22 @@ static void lxpanel_destroy(GtkObject *object)
         p->initialized = FALSE;
     }
 
+    if (p->background_update_queued)
+    {
+        g_source_remove(p->background_update_queued);
+        p->background_update_queued = 0;
+    }
+
     GTK_OBJECT_CLASS(lxpanel_parent_class)->destroy(object);
 }
 
-static gboolean delay_update_background( GtkWidget* p )
+static gboolean idle_update_background(gpointer p)
 {
+    LXPanel *panel = LXPANEL(p);
+
+    if (g_source_is_destroyed(g_main_current_source()))
+        return FALSE;
+
     /* Panel could be destroyed while background update scheduled */
 #if GTK_CHECK_VERSION(2, 20, 0)
     if (gtk_widget_get_realized(p))
@@ -130,18 +141,27 @@ static gboolean delay_update_background( GtkWidget* p )
 #endif
     {
         gdk_display_sync( gtk_widget_get_display(p) );
-        _panel_update_background( LXPANEL(p) );
+        _panel_update_background(panel);
     }
+    panel->priv->background_update_queued = 0;
 
     return FALSE;
 }
 
+void _panel_queue_update_background(LXPanel *panel)
+{
+    if (panel->priv->background_update_queued)
+        return;
+    panel->priv->background_update_queued = g_idle_add_full(G_PRIORITY_HIGH,
+                                                            idle_update_background,
+                                                            panel, NULL);
+}
+
 static void lxpanel_realize(GtkWidget *widget)
 {
     GTK_WIDGET_CLASS(lxpanel_parent_class)->realize(widget);
 
-    g_idle_add_full( G_PRIORITY_LOW,
-            (GSourceFunc)delay_update_background, widget, NULL );
+    _panel_queue_update_background(LXPANEL(widget));
 }
 
 static void lxpanel_style_set(GtkWidget *widget, GtkStyle* prev)
@@ -149,13 +169,7 @@ static void lxpanel_style_set(GtkWidget *widget, GtkStyle* prev)
     GTK_WIDGET_CLASS(lxpanel_parent_class)->style_set(widget, prev);
 
     /* FIXME: This dirty hack is used to fix the background of systray... */
-#if GTK_CHECK_VERSION(2, 20, 0)
-    if (gtk_widget_get_realized(widget))
-#else
-    if( GTK_WIDGET_REALIZED( widget ) )
-#endif
-        g_idle_add_full( G_PRIORITY_LOW,
-                (GSourceFunc)delay_update_background, widget, NULL );
+    _panel_queue_update_background(LXPANEL(widget));
 }
 
 static void lxpanel_size_request(GtkWidget *widget, GtkRequisition *req)
@@ -196,6 +210,17 @@ static void lxpanel_size_allocate(GtkWidget *widget, GtkAllocation *a)
         gtk_window_move(GTK_WINDOW(widget), p->ax, p->ay);
         _panel_set_wm_strut(LXPANEL(widget));
     }
+    else if (p->background_update_queued)
+    {
+        g_source_remove(p->background_update_queued);
+        p->background_update_queued = 0;
+#if GTK_CHECK_VERSION(2, 20, 0)
+        if (gtk_widget_get_realized(widget))
+#else
+        if (GTK_WIDGET_REALIZED(widget))
+#endif
+            _panel_update_background(LXPANEL(widget));
+    }
 }
 
 static gboolean lxpanel_configure_event (GtkWidget *widget, GdkEventConfigure *e)
@@ -621,7 +646,7 @@ void panel_update_background(Panel * p)
     _panel_update_background(p->topgwin);
 }
 
-void _panel_update_background(LXPanel * p)
+static void _panel_update_background(LXPanel * p)
 {
     GtkWidget *w = GTK_WIDGET(p);
     GList *plugins, *l;
@@ -1457,8 +1482,7 @@ void _panel_set_panel_configuration_changed(LXPanel *panel)
     }
     g_list_free(plugins);
     /* panel geometry changed? update panel background then */
-    g_idle_add_full( G_PRIORITY_LOW,
-                    (GSourceFunc)delay_update_background, panel, NULL );
+    _panel_queue_update_background(panel);
 }
 
 static int
index 1fd3e9b..668c26e 100644 (file)
@@ -44,6 +44,7 @@ static void plugin_class_unref(PluginClass * pc);
 GQuark lxpanel_plugin_qinit;
 GQuark lxpanel_plugin_qconf;
 GQuark lxpanel_plugin_qdata;
+GQuark lxpanel_plugin_qsize;
 static GHashTable *_all_types = NULL;
 
 /* Dynamic parameter for static (built-in) plugins must be FALSE so we will not try to unload them */
@@ -440,6 +441,7 @@ void _prepare_modules(void)
     lxpanel_plugin_qdata = g_quark_from_static_string("LXPanel::plugin-data");
     lxpanel_plugin_qinit = g_quark_from_static_string("LXPanel::plugin-init");
     lxpanel_plugin_qconf = g_quark_from_static_string("LXPanel::plugin-conf");
+    lxpanel_plugin_qsize = g_quark_from_static_string("LXPanel::plugin-size");
 #ifndef DISABLE_PLUGINS_LOADING
     fm_modules_add_directory(PACKAGE_LIB_DIR "/lxpanel/plugins");
     fm_module_register_lxpanel_gtk();
@@ -524,10 +526,19 @@ static void _on_old_widget_destroy(GtkWidget *widget, Plugin *pl)
     pl->class->destructor(pl);
 }
 
-//static void on_size_allocate(GtkWidget *widget, GdkRectangle *allocation, LXPanel *p)
-//{
+static void on_size_allocate(GtkWidget *widget, GdkRectangle *allocation, LXPanel *p)
+{
+    GdkRectangle *alloc;
+
+    alloc = g_object_get_qdata(G_OBJECT(widget), lxpanel_plugin_qsize);
+    if (alloc->x == allocation->x && alloc->y == allocation->y &&
+        alloc->width == allocation->width && alloc->height == allocation->height)
+        return; /* not changed */
+    *alloc = *allocation;
+    /* g_debug("size-allocate on %s", PLUGIN_CLASS(widget)->name); */
+    _panel_queue_update_background(p);
 //    _queue_panel_calculate_size(p);
-//}
+}
 
 GtkWidget *lxpanel_add_plugin(LXPanel *p, const char *name, config_setting_t *cfg, gint at)
 {
@@ -608,10 +619,12 @@ GtkWidget *lxpanel_add_plugin(LXPanel *p, const char *name, config_setting_t *cf
     gtk_widget_set_name(widget, name);
     gtk_box_pack_start(GTK_BOX(p->priv->box), widget, expand, TRUE, padding);
     gtk_container_set_border_width(GTK_CONTAINER(widget), border);
-//    g_signal_connect(widget, "size-allocate", G_CALLBACK(on_size_allocate), p);
+    g_signal_connect(widget, "size-allocate", G_CALLBACK(on_size_allocate), p);
     gtk_widget_show(widget);
     g_object_set_qdata(G_OBJECT(widget), lxpanel_plugin_qconf, cfg);
     g_object_set_qdata(G_OBJECT(widget), lxpanel_plugin_qinit, (gpointer)init);
+    g_object_set_qdata_full(G_OBJECT(widget), lxpanel_plugin_qsize,
+                            g_new0(GdkRectangle, 1), g_free);
     return widget;
 }
 
index fb909e3..890d10b 100644 (file)
@@ -134,6 +134,7 @@ struct _Panel {
     guint initialized : 1;              /* Should be grouped better later, */
     guint ah_far : 1;                   /* placed here for binary compatibility */
     guint ah_state : 3;
+    guint background_update_queued;
     guint mouse_timeout;
     //gint dyn_space;                     /* Space for expandable plugins */
     //guint calculate_size_idle;          /* The idle handler for dyn_space calc */
@@ -220,7 +221,7 @@ void _panel_determine_background_pixmap(LXPanel * p, GtkWidget * widget);
 void _panel_establish_autohide(LXPanel *p);
 void _panel_set_wm_strut(LXPanel *p);
 void _panel_set_panel_configuration_changed(LXPanel *p);
-void _panel_update_background(LXPanel *p);
+void _panel_queue_update_background(LXPanel *p);
 
 void panel_configure(LXPanel* p, int sel_page);
 gboolean panel_edge_available(Panel* p, int edge, gint monitor);