parent
0b7a0f4344
commit
551ac2c8b8
|
@ -14,6 +14,7 @@
|
|||
#endif
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <libxfce4util/libxfce4util.h>
|
||||
|
||||
#include "monitor-label.h"
|
||||
|
||||
|
@ -28,6 +29,7 @@ struct _XnlpMonitorLabel
|
|||
{
|
||||
GtkLabel parent;
|
||||
/*<private>*/
|
||||
GtkCssProvider *css_provider;
|
||||
gint count_width;
|
||||
gint count_height;
|
||||
gint width;
|
||||
|
@ -58,6 +60,11 @@ xnlp_monitor_label_init (XnlpMonitorLabel *label)
|
|||
label->count_height = 0;
|
||||
label->width = 0;
|
||||
label->height = 0;
|
||||
label->css_provider = gtk_css_provider_new ();
|
||||
gtk_style_context_add_provider (
|
||||
GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (label))),
|
||||
GTK_STYLE_PROVIDER (label->css_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
g_signal_connect (label, "notify::label", G_CALLBACK (cb_label_changed), NULL);
|
||||
}
|
||||
|
@ -125,6 +132,33 @@ xnlp_monitor_label_new (const gchar *str)
|
|||
return GTK_WIDGET (label);
|
||||
}
|
||||
|
||||
void
|
||||
xnlp_monitor_label_set_color (XnlpMonitorLabel *label, GdkRGBA* color)
|
||||
{
|
||||
gchar * css;
|
||||
if (color != NULL)
|
||||
{
|
||||
#if GTK_CHECK_VERSION (3, 20, 0)
|
||||
css = g_strdup_printf("label { color: %s; }",
|
||||
#else
|
||||
css = g_strdup_printf(".label { color: %s; }",
|
||||
#endif
|
||||
gdk_rgba_to_string(color));
|
||||
}
|
||||
else
|
||||
{
|
||||
#if GTK_CHECK_VERSION (3, 20, 0)
|
||||
css = g_strdup_printf("label { color: inherit; }");
|
||||
#else
|
||||
css = g_strdup_printf(".label { color: inherit; }");
|
||||
#endif
|
||||
}
|
||||
DBG("setting label css: %s", gtk_css_provider_to_string (label->css_provider));
|
||||
gtk_css_provider_load_from_data (label->css_provider, css, strlen(css), NULL);
|
||||
g_free(css);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
xnlp_monitor_label_reinit_size_request (XnlpMonitorLabel *label)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@ typedef struct _XnlpMonitorLabel XnlpMonitorLabel;
|
|||
GType xnlp_monitor_label_get_type (void);
|
||||
GtkWidget * xnlp_monitor_label_new (const gchar *str);
|
||||
void xnlp_monitor_label_reinit_size_request (XnlpMonitorLabel *label);
|
||||
void xnlp_monitor_label_set_color (XnlpMonitorLabel *label, GdkRGBA* color);
|
||||
|
||||
#endif /* !MONITOR_LABEL_H */
|
||||
|
||||
|
|
|
@ -536,40 +536,6 @@ static t_global_monitor * monitor_new(XfcePanelPlugin *plugin)
|
|||
return global;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------- */
|
||||
static void set_label_csscolor(GtkWidget* label, GdkRGBA* color)
|
||||
{
|
||||
GtkCssProvider *css_provider;
|
||||
gchar * css;
|
||||
if (color != NULL)
|
||||
{
|
||||
#if GTK_CHECK_VERSION (3, 20, 0)
|
||||
css = g_strdup_printf("label { color: %s; }",
|
||||
#else
|
||||
css = g_strdup_printf(".label { color: %s; }",
|
||||
#endif
|
||||
gdk_rgba_to_string(color));
|
||||
}
|
||||
else
|
||||
{
|
||||
#if GTK_CHECK_VERSION (3, 20, 0)
|
||||
css = g_strdup_printf("label { color: inherit; }");
|
||||
#else
|
||||
css = g_strdup_printf(".label { color: inherit; }");
|
||||
#endif
|
||||
}
|
||||
css_provider = gtk_css_provider_new ();
|
||||
gtk_css_provider_load_from_data (css_provider, css, strlen(css), NULL);
|
||||
g_free(css);
|
||||
|
||||
DBG("setting label css: %s", gtk_css_provider_to_string (css_provider));
|
||||
gtk_style_context_add_provider (
|
||||
GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (label))),
|
||||
GTK_STYLE_PROVIDER (css_provider),
|
||||
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------- */
|
||||
static void set_progressbar_csscolor(GtkWidget* pbar, GdkRGBA* color)
|
||||
{
|
||||
|
@ -617,9 +583,9 @@ static void setup_monitor(t_global_monitor *global, gboolean supress_warnings)
|
|||
if (global->monitor->options.colorize_values)
|
||||
{
|
||||
#if GTK_CHECK_VERSION (3, 16, 0)
|
||||
set_label_csscolor(global->monitor->rcv_label,
|
||||
xnlp_monitor_label_set_color(XNLP_MONITOR_LABEL(global->monitor->rcv_label),
|
||||
&global->monitor->options.color[IN]);
|
||||
set_label_csscolor(global->monitor->sent_label,
|
||||
xnlp_monitor_label_set_color(XNLP_MONITOR_LABEL(global->monitor->sent_label),
|
||||
&global->monitor->options.color[OUT]);
|
||||
#else
|
||||
gtk_widget_override_color(global->monitor->rcv_label, GTK_STATE_NORMAL,
|
||||
|
@ -632,8 +598,8 @@ static void setup_monitor(t_global_monitor *global, gboolean supress_warnings)
|
|||
{
|
||||
DBG("resetting label colors");
|
||||
#if GTK_CHECK_VERSION (3, 16, 0)
|
||||
set_label_csscolor(global->monitor->rcv_label, NULL);
|
||||
set_label_csscolor(global->monitor->sent_label, NULL);
|
||||
xnlp_monitor_label_set_color(XNLP_MONITOR_LABEL(global->monitor->rcv_label), NULL);
|
||||
xnlp_monitor_label_set_color(XNLP_MONITOR_LABEL(global->monitor->sent_label), NULL);
|
||||
#else
|
||||
gtk_widget_override_color(global->monitor->rcv_label, GTK_STATE_NORMAL, NULL);
|
||||
gtk_widget_override_color(global->monitor->sent_label, GTK_STATE_NORMAL, NULL);
|
||||
|
|
Loading…
Reference in New Issue