Add "panel-font-changed" signal to LXPanel to follow font settings changes.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 22 Nov 2014 17:26:44 +0000 (19:26 +0200)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sat, 22 Nov 2014 17:26:44 +0000 (19:26 +0200)
Now widgets created with lxpanel_button_*() API follow label changes too.

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

index f33bdd1..874ecba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -71,6 +71,8 @@
     from Peter).
 * Added new API lxpanel_button_set_label() to change label of button that
     was created using some lxpanel_button_*() API.
+* Added "panel-font-changed" signal to LXPanel to be able follow settings
+    change in font configuration of panel using lxpanel_button_*() API.
 
 0.7.2
 -------------------------------------------------------------------------
index 22a6322..b8db2b0 100644 (file)
@@ -411,12 +411,15 @@ background_disable_toggle( GtkWidget *b, Panel* p )
 }
 
 static void
-on_font_color_set( GtkColorButton* clr,  Panel* p )
+on_font_color_set(GtkColorButton* clr, LXPanel* panel)
 {
+    Panel *p = panel->priv;
+
     gtk_color_button_get_color( clr, &p->gfontcolor );
     panel_set_panel_configuration_changed(p);
     p->fontcolor = gcolor2rgb24(&p->gfontcolor);
     UPDATE_GLOBAL_COLOR(p, "fontcolor", p->fontcolor);
+    _panel_emit_font_changed(panel);
 }
 
 static void
@@ -431,9 +434,11 @@ on_tint_color_set( GtkColorButton* clr,  Panel* p )
 }
 
 static void
-on_use_font_color_toggled( GtkToggleButton* btn,   Panel* p )
+on_use_font_color_toggled(GtkToggleButton* btn, LXPanel* panel)
 {
     GtkWidget* clr = (GtkWidget*)g_object_get_data( G_OBJECT(btn), "clr" );
+    Panel *p = panel->priv;
+
     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn)))
         gtk_widget_set_sensitive( clr, TRUE );
     else
@@ -441,20 +446,26 @@ on_use_font_color_toggled( GtkToggleButton* btn,   Panel* p )
     p->usefontcolor = gtk_toggle_button_get_active( btn );
     panel_set_panel_configuration_changed(p);
     UPDATE_GLOBAL_INT(p, "usefontcolor", p->usefontcolor);
+    _panel_emit_font_changed(panel);
 }
 
 static void
-on_font_size_set( GtkSpinButton* spin, Panel* p )
+on_font_size_set(GtkSpinButton* spin, LXPanel* panel)
 {
+    Panel *p = panel->priv;
+
     p->fontsize = (int)gtk_spin_button_get_value(spin);
     panel_set_panel_configuration_changed(p);
     UPDATE_GLOBAL_INT(p, "fontsize", p->fontsize);
+    _panel_emit_font_changed(panel);
 }
 
 static void
-on_use_font_size_toggled( GtkToggleButton* btn,   Panel* p )
+on_use_font_size_toggled(GtkToggleButton* btn, LXPanel* panel)
 {
     GtkWidget* clr = (GtkWidget*)g_object_get_data( G_OBJECT(btn), "clr" );
+    Panel *p = panel->priv;
+
     if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn)))
         gtk_widget_set_sensitive( clr, TRUE );
     else
@@ -462,6 +473,7 @@ on_use_font_size_toggled( GtkToggleButton* btn,   Panel* p )
     p->usefontsize = gtk_toggle_button_get_active( btn );
     panel_set_panel_configuration_changed(p);
     UPDATE_GLOBAL_INT(p, "usefontsize", p->usefontsize);
+    _panel_emit_font_changed(panel);
 }
 
 
@@ -1239,12 +1251,12 @@ void panel_configure( LXPanel* panel, int sel_page )
     /* font color */
     w = (GtkWidget*)gtk_builder_get_object( builder, "font_clr" );
     gtk_color_button_set_color( GTK_COLOR_BUTTON(w), &p->gfontcolor );
-    g_signal_connect( w, "color-set", G_CALLBACK( on_font_color_set ), p );
+    g_signal_connect(w, "color-set", G_CALLBACK( on_font_color_set ), panel);
 
     w2 = (GtkWidget*)gtk_builder_get_object( builder, "use_font_clr" );
     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(w2), p->usefontcolor );
     g_object_set_data( G_OBJECT(w2), "clr", w );
-    g_signal_connect(w2, "toggled", G_CALLBACK(on_use_font_color_toggled), p);
+    g_signal_connect(w2, "toggled", G_CALLBACK(on_use_font_color_toggled), panel);
     if( ! p->usefontcolor )
         gtk_widget_set_sensitive( w, FALSE );
 
@@ -1252,12 +1264,12 @@ void panel_configure( LXPanel* panel, int sel_page )
     w = (GtkWidget*)gtk_builder_get_object( builder, "font_size" );
     gtk_spin_button_set_value( GTK_SPIN_BUTTON(w), p->fontsize );
     g_signal_connect( w, "value-changed",
-                      G_CALLBACK(on_font_size_set), p);
+                      G_CALLBACK(on_font_size_set), panel);
 
     w2 = (GtkWidget*)gtk_builder_get_object( builder, "use_font_size" );
     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(w2), p->usefontsize );
     g_object_set_data( G_OBJECT(w2), "clr", w );
-    g_signal_connect(w2, "toggled", G_CALLBACK(on_use_font_size_toggled), p);
+    g_signal_connect(w2, "toggled", G_CALLBACK(on_use_font_size_toggled), panel);
     if( ! p->usefontsize )
         gtk_widget_set_sensitive( w, FALSE );
 
index 785d5f3..b6c8e90 100644 (file)
@@ -39,6 +39,7 @@ typedef struct {
     FmIcon *icon;
     guint theme_changed_handler;
     guint icon_changed_handler;
+    guint font_changed_handler;
     GdkPixbuf* pixbuf;
     GdkPixbuf* hilight;
     gulong hicolor;
@@ -928,6 +929,8 @@ static void img_data_free(ImgData * data)
     {
         g_object_remove_weak_pointer(G_OBJECT(data->panel), (gpointer *)&data->panel);
         g_signal_handler_disconnect(data->panel, data->icon_changed_handler);
+        if (data->font_changed_handler != 0)
+            g_signal_handler_disconnect(data->panel, data->font_changed_handler);
     }
     if (data->pixbuf != NULL)
         g_object_unref(data->pixbuf);
@@ -1253,6 +1256,12 @@ static gboolean fb_button_leave(GtkImage * widget, GdkEventCrossing * event, gpo
     return TRUE;
 }
 
+static void on_font_changed(LXPanel * panel, GtkLabel * lbl)
+{
+    const char *label = gtk_label_get_text(lbl);
+    lxpanel_draw_label_text(panel, GTK_WIDGET(lbl), label, FALSE, 1, TRUE);
+}
+
 static GtkWidget *_lxpanel_button_compose(GtkWidget *event_box, GtkWidget *image,
                                           gulong highlight_color, const gchar *label)
 {
@@ -1283,7 +1292,13 @@ static GtkWidget *_lxpanel_button_compose(GtkWidget *event_box, GtkWidget *image
 
         lbl = gtk_label_new("");
         if (G_LIKELY(data != NULL && data->panel != NULL))
+        {
             lxpanel_draw_label_text(data->panel, lbl, label, FALSE, 1, TRUE);
+            data->font_changed_handler = g_signal_connect(data->panel,
+                                                          "panel-font-changed",
+                                                          G_CALLBACK(on_font_changed),
+                                                          lbl);
+        }
         else
             gtk_label_set_text(GTK_LABEL(lbl), label);
         gtk_misc_set_padding(GTK_MISC(lbl), 2, 0);
index b98ccf8..7c89c4b 100644 (file)
@@ -61,6 +61,7 @@ static void _panel_update_background(LXPanel * p);
 enum
 {
     ICON_SIZE_CHANGED,
+    PANEL_FONT_CHANGED,
     N_SIGNALS
 };
 
@@ -327,6 +328,15 @@ static void lxpanel_class_init(PanelToplevelClass *klass)
                      NULL, NULL,
                      g_cclosure_marshal_VOID__VOID,
                      G_TYPE_NONE, 0, G_TYPE_NONE);
+
+    signals[PANEL_FONT_CHANGED] =
+        g_signal_new("panel-font-changed",
+                     G_TYPE_FROM_CLASS(klass),
+                     G_SIGNAL_RUN_LAST,
+                     G_STRUCT_OFFSET(PanelToplevelClass, panel_font_changed),
+                     NULL, NULL,
+                     g_cclosure_marshal_VOID__VOID,
+                     G_TYPE_NONE, 0, G_TYPE_NONE);
 }
 
 static void lxpanel_init(PanelToplevel *self)
@@ -382,6 +392,11 @@ void _panel_emit_icon_size_changed(LXPanel *p)
     g_signal_emit(p, signals[ICON_SIZE_CHANGED], 0);
 }
 
+void _panel_emit_font_changed(LXPanel *p)
+{
+    g_signal_emit(p, signals[PANEL_FONT_CHANGED], 0);
+}
+
 /* Normalize panel configuration after load from file or reconfiguration. */
 static void panel_normalize_configuration(Panel* p)
 {
index 561813d..a3b2f10 100644 (file)
@@ -233,6 +233,7 @@ void _panel_set_wm_strut(LXPanel *p);
 void _panel_set_panel_configuration_changed(LXPanel *p);
 void _panel_queue_update_background(LXPanel *p);
 void _panel_emit_icon_size_changed(LXPanel *p);
+void _panel_emit_font_changed(LXPanel *p);
 
 void panel_configure(LXPanel* p, int sel_page);
 gboolean panel_edge_available(Panel* p, int edge, gint monitor);