thermal: reflect panel font size configuration
authorlxpanel Fedora maintainer <lxpanel-maintainer@fedoraproject.org>
Mon, 8 Jan 2018 07:10:12 +0000 (16:10 +0900)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Mon, 8 Jan 2018 19:22:44 +0000 (21:22 +0200)
ref: https://bugzilla.redhat.com/show_bug.cgi?id=1261464
To archive this, create new API:
lxpanel_draw_label_text_with_color() to specify both text
and color to draw on panel

plugins/thermal/thermal.c
src/panel.c
src/panel.h.in

index 41bcfb1..75dba03 100644 (file)
@@ -279,9 +279,8 @@ update_display(thermal *th)
         lxpanel_draw_label_text(th->panel, th->namew, "NA", TRUE, 1, TRUE);
     else
     {
-        snprintf(buffer, sizeof(buffer), "<span color=\"#%06x\"><b>%02d</b></span>",
-                 gcolor2rgb24(&color), temp);
-        gtk_label_set_markup (GTK_LABEL(th->namew), buffer) ;
+        snprintf(buffer, sizeof(buffer), "%02d", temp);
+        lxpanel_draw_label_text_with_color(th->panel, th->namew, buffer, TRUE, 1, &color);
     }
 
     g_string_truncate(th->tip, 0);
index 38f5a49..e9ca3b5 100644 (file)
@@ -1720,9 +1720,10 @@ void panel_adjust_geometry_terminology(Panel * p)
 }
 
 /* Draw text into a label, with the user preference color and optionally bold. */
-void panel_draw_label_text(Panel * p, GtkWidget * label, const char * text,
+static
+void panel_draw_label_text_with_color(Panel * p, GtkWidget * label, const char * text,
                            gboolean bold, float custom_size_factor,
-                           gboolean custom_color)
+                           gboolean custom_color, GdkColor *gdkcolor)
 {
     if (text == NULL)
     {
@@ -1758,12 +1759,13 @@ void panel_draw_label_text(Panel * p, GtkWidget * label, const char * text,
     }
 
     gchar * formatted_text;
-    if ((custom_color) && (p->usefontcolor))
+    if (gdkcolor || ((custom_color) && (p->usefontcolor)))
     {
         /* Color, optionally bold. */
+        guint32 rgb24 = gdkcolor ? gcolor2rgb24(gdkcolor) : gcolor2rgb24(&p->gfontcolor);
         formatted_text = g_strdup_printf("<span font_desc=\"%d\" color=\"#%06x\">%s%s%s</span>",
                 font_desc,
-                gcolor2rgb24(&p->gfontcolor),
+                rgb24,
                 ((bold) ? "<b>" : ""),
                 valid_markup,
                 ((bold) ? "</b>" : ""));
@@ -1783,6 +1785,13 @@ void panel_draw_label_text(Panel * p, GtkWidget * label, const char * text,
     g_free(escaped_text);
 }
 
+void panel_draw_label_text(Panel * p, GtkWidget * label, const char * text,
+                           gboolean bold, float custom_size_factor,
+                           gboolean custom_color)
+{
+    panel_draw_label_text_with_color(p, label, text, bold, custom_size_factor, custom_color, NULL);
+}
+
 void lxpanel_draw_label_text(LXPanel * p, GtkWidget * label, const char * text,
                            gboolean bold, float custom_size_factor,
                            gboolean custom_color)
@@ -1790,6 +1799,13 @@ void lxpanel_draw_label_text(LXPanel * p, GtkWidget * label, const char * text,
     panel_draw_label_text(p->priv, label, text, bold, custom_size_factor, custom_color);
 }
 
+void lxpanel_draw_label_text_with_color(LXPanel * p, GtkWidget * label, const char * text,
+                                    gboolean bold, float custom_size_factor,
+                                    GdkColor *color)
+{
+    panel_draw_label_text_with_color(p->priv, label, text, bold, custom_size_factor, 0, color);
+}
+
 void panel_set_panel_configuration_changed(Panel *p)
 {
     _panel_set_panel_configuration_changed(p->topgwin);
index ff8a8d4..d277ed1 100644 (file)
@@ -111,6 +111,22 @@ extern void lxpanel_draw_label_text(LXPanel * p, GtkWidget * label, const char *
                                     gboolean custom_color);
 
 /**
+ * lxpanel_draw_label_text_with_color
+ * @p: a panel instance
+ * @label: a label widget
+ * @text: (allow-none): text for the label
+ * @bold: %TRUE if text should be bold
+ * @custom_size_factor: scale factor for font size
+ * @color: GdkColor for drawing text
+ *
+ * Changes @label to contain @text with appropriate attributes using the
+ * panel @p settings.
+ */
+extern void lxpanel_draw_label_text_with_color(LXPanel * p, GtkWidget * label, const char * text,
+                                    gboolean bold, float custom_size_factor,
+                                    GdkColor *color);
+
+/**
  * lxpanel_config_save
  * @p: a panel instance
  *