[gnome-power-manager/wip/albfan/dark-mode] Draw correctly on dark mode
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-power-manager/wip/albfan/dark-mode] Draw correctly on dark mode
- Date: Fri, 28 Aug 2020 11:59:09 +0000 (UTC)
commit 370d2151c9bcc6c4dc6ef436dffd224f32a2ee82
Author: agurk <timothy moll+github gmail com>
Date: Sun Aug 23 16:47:00 2020 +0200
Draw correctly on dark mode
Allow to select a theme
Define colors for dark and ligth theme
data/org.gnome.power-manager.gschema.xml | 10 ++
src/egg-graph-point.h | 2 +-
src/egg-graph-widget.c | 207 ++++++++++++++++++++++++-------
src/gpm-statistics.c | 147 +++++++++++++++++++---
4 files changed, 299 insertions(+), 67 deletions(-)
---
diff --git a/data/org.gnome.power-manager.gschema.xml b/data/org.gnome.power-manager.gschema.xml
index 85b70222..db307a4d 100644
--- a/data/org.gnome.power-manager.gschema.xml
+++ b/data/org.gnome.power-manager.gschema.xml
@@ -45,5 +45,15 @@
<summary>The ID of the last device selected</summary>
<description>The identifier of the last device which is used to return focus to the correct
device.</description>
</key>
+ <key name="info-graph-colors" type="s">
+ <choices>
+ <choice value='auto'/>
+ <choice value='dark'/>
+ <choice value='light'/>
+ </choices>
+ <default>'auto'</default>
+ <summary>The colors used to draw the graphs</summary>
+ <description>The colours used to draw the graphs and if these should be autodetected.</description>
+ </key>
</schema>
</schemalist>
diff --git a/src/egg-graph-point.h b/src/egg-graph-point.h
index d78371c0..7b23e3ef 100644
--- a/src/egg-graph-point.h
+++ b/src/egg-graph-point.h
@@ -29,7 +29,7 @@ typedef struct
{
gdouble x;
gdouble y;
- guint32 color;
+ guint64 color;
} EggGraphPoint;
EggGraphPoint *egg_graph_point_new (void);
diff --git a/src/egg-graph-widget.c b/src/egg-graph-widget.c
index 2a99053c..e7e10142 100644
--- a/src/egg-graph-widget.c
+++ b/src/egg-graph-widget.c
@@ -47,6 +47,15 @@ typedef struct {
gint box_width;
gint box_height;
+ guint64 text_color;
+ guint64 line_color;
+ guint64 legend_line_color;
+ guint64 legend_text_color;
+ guint64 dot_stroke_color;
+ guint64 background_color;
+ guint64 background_stroke_color;
+ guint64 outline_color;
+
guint divs_x; /* number of divisions */
gdouble unit_x; /* box pixels per x unit */
@@ -83,6 +92,14 @@ enum
PROP_START_Y,
PROP_STOP_X,
PROP_STOP_Y,
+ PROP_TEXT_COLOR,
+ PROP_LINE_COLOR,
+ PROP_LEGEND_LINE_COLOR,
+ PROP_LEGEND_TEXT_COLOR,
+ PROP_DOT_STROKE_COLOR,
+ PROP_BACKGROUND_COLOR,
+ PROP_BACKGROUND_STROKE_COLOR,
+ PROP_OUTLINE_COLOR,
PROP_LAST
};
@@ -136,7 +153,7 @@ egg_graph_widget_get_use_legend (EggGraphWidget *graph)
}
static void
-up_graph_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+egg_graph_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
EggGraphWidget *graph = EGG_GRAPH_WIDGET (object);
EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
@@ -174,6 +191,30 @@ up_graph_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec
case PROP_STOP_Y:
g_value_set_double (value, priv->stop_y);
break;
+ case PROP_TEXT_COLOR:
+ g_value_set_uint64 (value, priv->text_color);
+ break;
+ case PROP_LINE_COLOR:
+ g_value_set_uint64 (value, priv->line_color);
+ break;
+ case PROP_LEGEND_LINE_COLOR:
+ g_value_set_uint64 (value, priv->legend_line_color);
+ break;
+ case PROP_LEGEND_TEXT_COLOR:
+ g_value_set_uint64 (value, priv->legend_text_color);
+ break;
+ case PROP_DOT_STROKE_COLOR:
+ g_value_set_uint64 (value, priv->dot_stroke_color);
+ break;
+ case PROP_BACKGROUND_COLOR:
+ g_value_set_uint64 (value, priv->background_color);
+ break;
+ case PROP_BACKGROUND_STROKE_COLOR:
+ g_value_set_uint64 (value, priv->background_stroke_color);
+ break;
+ case PROP_OUTLINE_COLOR:
+ g_value_set_uint64 (value, priv->outline_color);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -181,7 +222,7 @@ up_graph_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec
}
static void
-up_graph_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+egg_graph_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
EggGraphWidget *graph = EGG_GRAPH_WIDGET (object);
EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
@@ -220,6 +261,30 @@ up_graph_set_property (GObject *object, guint prop_id, const GValue *value, GPar
case PROP_STOP_Y:
priv->stop_y = g_value_get_double (value);
break;
+ case PROP_TEXT_COLOR:
+ priv->text_color = g_value_get_uint64 (value);
+ break;
+ case PROP_LINE_COLOR:
+ priv->line_color = g_value_get_uint64 (value);
+ break;
+ case PROP_LEGEND_LINE_COLOR:
+ priv->legend_line_color = g_value_get_uint64 (value);
+ break;
+ case PROP_LEGEND_TEXT_COLOR:
+ priv->legend_text_color = g_value_get_uint64 (value);
+ break;
+ case PROP_DOT_STROKE_COLOR:
+ priv->dot_stroke_color = g_value_get_uint64 (value);
+ break;
+ case PROP_BACKGROUND_COLOR:
+ priv->background_color = g_value_get_uint64 (value);
+ break;
+ case PROP_BACKGROUND_STROKE_COLOR:
+ priv->background_stroke_color = g_value_get_uint64 (value);
+ break;
+ case PROP_OUTLINE_COLOR:
+ priv->outline_color = g_value_get_uint64 (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -237,8 +302,8 @@ egg_graph_widget_class_init (EggGraphWidgetClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class);
widget_class->draw = egg_graph_widget_draw;
- object_class->get_property = up_graph_get_property;
- object_class->set_property = up_graph_set_property;
+ object_class->get_property = egg_graph_get_property;
+ object_class->set_property = egg_graph_set_property;
object_class->finalize = egg_graph_widget_finalize;
/* properties */
@@ -279,28 +344,68 @@ egg_graph_widget_class_init (EggGraphWidgetClass *class)
g_object_class_install_property (object_class,
PROP_DIVS_X,
g_param_spec_uint ("divs-x", NULL, NULL,
- 4, 16, 4,
- G_PARAM_READWRITE));
+ 4, 16, 4,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_START_X,
g_param_spec_double ("start-x", NULL, NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE, 0.f,
- G_PARAM_READWRITE));
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0.f,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_START_Y,
g_param_spec_double ("start-y", NULL, NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE, 0.f,
- G_PARAM_READWRITE));
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0.f,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STOP_X,
g_param_spec_double ("stop-x", NULL, NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE, 60.f,
- G_PARAM_READWRITE));
+ -G_MAXDOUBLE, G_MAXDOUBLE, 60.f,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STOP_Y,
g_param_spec_double ("stop-y", NULL, NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE, 100.f,
- G_PARAM_READWRITE));
+ -G_MAXDOUBLE, G_MAXDOUBLE, 100.f,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_TEXT_COLOR,
+ g_param_spec_uint64 ("text-color", NULL, NULL,
+ 0, G_MAXINT64, 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_LINE_COLOR,
+ g_param_spec_uint64 ("line-color", NULL, NULL,
+ 0, G_MAXINT64, 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_LEGEND_LINE_COLOR,
+ g_param_spec_uint64 ("legend-line-color", NULL, NULL,
+ 0, G_MAXINT64, 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_LEGEND_TEXT_COLOR,
+ g_param_spec_uint64 ("legend-text-color", NULL, NULL,
+ 0, G_MAXINT64, 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_DOT_STROKE_COLOR,
+ g_param_spec_uint64 ("dot-stroke-color", NULL, NULL,
+ 0, G_MAXINT64, 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_BACKGROUND_COLOR,
+ g_param_spec_uint64 ("background-color", NULL, NULL,
+ 0, G_MAXINT64, 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_BACKGROUND_STROKE_COLOR,
+ g_param_spec_uint64 ("background-stroke-color", NULL, NULL,
+ 0, G_MAXINT64, 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_OUTLINE_COLOR,
+ g_param_spec_uint64 ("outline-color", NULL, NULL,
+ 0, G_MAXINT64, 0,
+ G_PARAM_READWRITE));
}
static void
@@ -453,6 +558,23 @@ egg_graph_widget_get_axis_label (EggGraphWidgetKind axis, gdouble value)
return text;
}
+static void
+egg_color_to_rgb (guint64 color, guint8 *red, guint8 *green, guint8 *blue, guint8 *alpha)
+{
+ *red = (color & 0xff000000) / 0x1000000;
+ *green = (color & 0x00ff0000) / 0x10000;
+ *blue = (color & 0x0000ff00) / 0x100;
+ *alpha = color & 0x000000ff;
+}
+
+static void
+egg_graph_widget_set_color (cairo_t *cr, guint64 color)
+{
+ guint8 r, g, b, a;
+ egg_color_to_rgb (color, &r, &g, &b, &a);
+ cairo_set_source_rgba (cr, ((gdouble) r)/255.0f, ((gdouble) g)/255.0f, ((gdouble) b)/255.0f,
((gdouble) a)/255.0f);
+}
+
static void
egg_graph_widget_draw_grid (EggGraphWidget *graph, cairo_t *cr)
{
@@ -469,7 +591,7 @@ egg_graph_widget_draw_grid (EggGraphWidget *graph, cairo_t *cr)
cairo_set_dash (cr, dotted, 2, 0.0);
/* do vertical lines */
- cairo_set_source_rgb (cr, 0.1, 0.1, 0.1);
+ egg_graph_widget_set_color (cr, priv->line_color);
for (i = 1; i < priv->divs_x; i++) {
b = priv->box_x + ((gdouble) i * divwidth);
cairo_move_to (cr, (gint)b + 0.5f, priv->box_y);
@@ -506,7 +628,7 @@ egg_graph_widget_draw_labels (EggGraphWidget *graph, cairo_t *cr)
cairo_save (cr);
/* do x text */
- cairo_set_source_rgb (cr, 0.2f, 0.2f, 0.2f);
+ egg_graph_widget_set_color (cr, priv->text_color);
for (i = 0; i < priv->divs_x + 1; i++) {
g_autofree gchar *text = NULL;
b = priv->box_x + ((gdouble) i * divwidth);
@@ -555,14 +677,6 @@ egg_graph_widget_draw_labels (EggGraphWidget *graph, cairo_t *cr)
cairo_restore (cr);
}
-static void
-egg_color_to_rgb (guint32 color, guint8 *red, guint8 *green, guint8 *blue)
-{
- *red = (color & 0xff0000) / 0x10000;
- *green = (color & 0x00ff00) / 0x100;
- *blue = color & 0x0000ff;
-}
-
static guint
egg_graph_widget_get_y_label_max_width (EggGraphWidget *graph, cairo_t *cr)
{
@@ -839,14 +953,6 @@ egg_graph_widget_autorange_y (EggGraphWidget *graph)
priv->start_y, priv->stop_y);
}
-static void
-egg_graph_widget_set_color (cairo_t *cr, guint32 color)
-{
- guint8 r, g, b;
- egg_color_to_rgb (color, &r, &g, &b);
- cairo_set_source_rgb (cr, ((gdouble) r)/256.0f, ((gdouble) g)/256.0f, ((gdouble) b)/256.0f);
-}
-
/**
* egg_graph_widget_draw_legend_line:
* @cr: Cairo drawing context
@@ -857,8 +963,9 @@ egg_graph_widget_set_color (cairo_t *cr, guint32 color)
* Draw the legend line on the graph of a specified color
**/
static void
-egg_graph_widget_draw_legend_line (cairo_t *cr, gdouble x, gdouble y, guint32 color)
+egg_graph_widget_draw_legend_line (EggGraphWidget *graph, cairo_t *cr, gdouble x, gdouble y, guint32 color)
{
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
gdouble width = 10;
gdouble height = 6;
/* background */
@@ -867,7 +974,7 @@ egg_graph_widget_draw_legend_line (cairo_t *cr, gdouble x, gdouble y, guint32 co
cairo_fill (cr);
/* solid outline box */
cairo_rectangle (cr, (int) (x - (width/2)) + 0.5, (int) (y - (height/2)) + 0.5, width, height);
- cairo_set_source_rgb (cr, 0.1, 0.1, 0.1);
+ egg_graph_widget_set_color (cr, priv->legend_line_color);
cairo_set_line_width (cr, 1);
cairo_stroke (cr);
}
@@ -891,8 +998,9 @@ egg_graph_widget_get_pos_on_graph (EggGraphWidget *graph,
}
static void
-egg_graph_widget_draw_dot (cairo_t *cr, gdouble x, gdouble y, guint32 color)
+egg_graph_widget_draw_dot (EggGraphWidget *graph, cairo_t *cr, gdouble x, gdouble y, guint32 color)
{
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
gdouble width;
/* box */
width = 4.0;
@@ -900,7 +1008,8 @@ egg_graph_widget_draw_dot (cairo_t *cr, gdouble x, gdouble y, guint32 color)
egg_graph_widget_set_color (cr, color);
cairo_fill (cr);
cairo_rectangle (cr, (gint)x + 0.5f - (width/2), (gint)y + 0.5f - (width/2), width, width);
- cairo_set_source_rgb (cr, 0, 0, 0);
+
+ egg_graph_widget_set_color (cr, priv->dot_stroke_color);
cairo_set_line_width (cr, 0.5);
cairo_stroke (cr);
}
@@ -939,11 +1048,11 @@ egg_graph_widget_draw_line (EggGraphWidget *graph, cairo_t *cr)
/* plot points */
if (plot == EGG_GRAPH_WIDGET_PLOT_POINTS || plot == EGG_GRAPH_WIDGET_PLOT_BOTH) {
- egg_graph_widget_draw_dot (cr, x, y, point->color);
+ egg_graph_widget_draw_dot (graph, cr, x, y, point->color);
for (i = 1; i < data->len; i++) {
point = (EggGraphPoint *) g_ptr_array_index (data, i);
egg_graph_widget_get_pos_on_graph (graph, point->x, point->y, &x, &y);
- egg_graph_widget_draw_dot (cr, x, y, point->color);
+ egg_graph_widget_draw_dot (graph, cr, x, y, point->color);
}
}
@@ -1003,15 +1112,18 @@ egg_graph_widget_draw_line (EggGraphWidget *graph, cairo_t *cr)
* @height: The item height
**/
static void
-egg_graph_widget_draw_bounding_box (cairo_t *cr, gint x, gint y, gint width, gint height)
+egg_graph_widget_draw_bounding_box (EggGraphWidget *graph, cairo_t *cr, gint x, gint y, gint width, gint
height)
{
+ EggGraphWidgetPrivate *priv = GET_PRIVATE (graph);
/* background */
cairo_rectangle (cr, x, y, width, height);
- cairo_set_source_rgb (cr, 1, 1, 1);
+
+ egg_graph_widget_set_color (cr, priv->background_color);
+
cairo_fill (cr);
/* solid outline box */
cairo_rectangle (cr, x + 0.5f, y + 0.5f, width - 1, height - 1);
- cairo_set_source_rgb (cr, 0.1, 0.1, 0.1);
+ egg_graph_widget_set_color (cr, priv->background_stroke_color);
cairo_set_line_width (cr, 1);
cairo_stroke (cr);
}
@@ -1033,15 +1145,16 @@ egg_graph_widget_draw_legend (EggGraphWidget *graph, cairo_t *cr,
guint i;
EggGraphWidgetLegendData *legend_data;
- egg_graph_widget_draw_bounding_box (cr, x, y, width, height);
+ egg_graph_widget_draw_bounding_box (graph, cr, x, y, width, height);
y_count = y + 10;
/* add the line colors to the legend */
for (i = 0; i < priv->legend_list->len; i++) {
legend_data = g_ptr_array_index (priv->legend_list, i);
- egg_graph_widget_draw_legend_line (cr, x + 8, y_count, legend_data->color);
+ egg_graph_widget_draw_legend_line (graph, cr, x + 8, y_count, legend_data->color);
cairo_move_to (cr, x + 8 + 10, y_count - 6);
- cairo_set_source_rgb (cr, 0, 0, 0);
+ egg_graph_widget_set_color (cr, priv->legend_text_color);
+ //cairo_set_source_rgb (cr, 0, 0, 0);
pango_layout_set_text (priv->layout, legend_data->desc, -1);
pango_cairo_show_layout (cr, priv->layout);
y_count = y_count + EGG_GRAPH_WIDGET_LEGEND_SPACING;
@@ -1132,15 +1245,15 @@ egg_graph_widget_draw (GtkWidget *widget, cairo_t *cr)
}
/* graph background */
- egg_graph_widget_draw_bounding_box (cr, priv->box_x, priv->box_y,
- priv->box_width, priv->box_height);
+ egg_graph_widget_draw_bounding_box (graph, cr, priv->box_x, priv->box_y,
+ priv->box_width, priv->box_height);
if (priv->use_grid)
egg_graph_widget_draw_grid (graph, cr);
/* solid outline box */
cairo_rectangle (cr, priv->box_x + 0.5f, priv->box_y + 0.5f,
priv->box_width - 1, priv->box_height - 1);
- cairo_set_source_rgb (cr, 0.6f, 0.6f, 0.6f);
+ egg_graph_widget_set_color (cr, priv->outline_color);
cairo_set_line_width (cr, 1);
cairo_stroke (cr);
diff --git a/src/gpm-statistics.c b/src/gpm-statistics.c
index dce87689..f70f6085 100644
--- a/src/gpm-statistics.c
+++ b/src/gpm-statistics.c
@@ -40,6 +40,7 @@
#define GPM_SETTINGS_INFO_STATS_GRAPH_POINTS "info-stats-graph-points"
#define GPM_SETTINGS_INFO_PAGE_NUMBER "info-page-number"
#define GPM_SETTINGS_INFO_LAST_DEVICE "info-last-device"
+#define GPM_SETTINGS_INFO_COLORS "info-graph-colors"
static GtkBuilder *builder = NULL;
static GtkListStore *list_store_info = NULL;
@@ -112,6 +113,10 @@ enum {
#define GPM_UP_TIME_PRECISION 5*60 /* seconds */
#define GPM_UP_TEXT_MIN_TIME 120 /* seconds */
+#define GPM_STATS_COLOR_DARK "dark"
+#define GPM_STATS_COLOR_LIGHT "light"
+#define GPM_STATS_COLOR_AUTO "auto"
+
/**
* gpm_stats_get_device_icon_suffix:
* @device: The UpDevice
@@ -707,15 +712,49 @@ gpm_stats_set_graph_data (GtkWidget *widget, GPtrArray *data, gboolean use_smoot
}
static guint32
-gpm_color_from_rgb (guint8 red, guint8 green, guint8 blue)
+gpm_color_from_rgba (guint8 red, guint8 green, guint8 blue, guint8 alpha)
{
guint32 color = 0;
- color += (guint32) red * 0x10000;
- color += (guint32) green * 0x100;
- color += (guint32) blue;
+ color += (guint32) red * 0x1000000;
+ color += (guint32) green * 0x0010000;
+ color += (guint32) blue * 0x0000100;
+ color += (guint32) alpha;
return color;
}
+static guint32
+gpm_color_from_rgb (guint8 red, guint8 green, guint8 blue)
+{
+ return gpm_color_from_rgba (red, green, blue, 255);
+}
+
+static gboolean
+gpm_stats_is_dark_mode (GtkWidget *widget)
+{
+ g_autofree gchar *colors_preference;
+ GtkStyleContext *style_context;
+ GdkRGBA color;
+
+ colors_preference = g_settings_get_string (settings, GPM_SETTINGS_INFO_COLORS);
+ if (colors_preference == NULL)
+ colors_preference = GPM_STATS_COLOR_AUTO;
+
+ if ((g_strcmp0 (colors_preference, GPM_STATS_COLOR_AUTO) == 0))
+ {
+ style_context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (style_context, GTK_STATE_FLAG_PRELIGHT, &color);
+
+ if (color.red + color.blue + color.green > 1.5f)
+ return TRUE;
+ }
+ else if ((g_strcmp0 (colors_preference, GPM_STATS_COLOR_LIGHT) == 0))
+ return FALSE;
+ else if ((g_strcmp0 (colors_preference, GPM_STATS_COLOR_DARK) == 0))
+ return TRUE;
+
+ return FALSE;
+}
+
static void
gpm_stats_update_info_page_history (UpDevice *device)
{
@@ -738,10 +777,10 @@ gpm_stats_update_info_page_history (UpDevice *device)
"autorange-x", FALSE,
"divs-x", (guint) divs_x,
"start-x", -(gdouble) history_time,
- "stop-x", (gdouble) 0.f,
- "autorange-y", FALSE,
"start-y", (gdouble) 0.f,
+ "stop-x", (gdouble) 0.f,
"stop-y", (gdouble) 100.f,
+ "autorange-y", FALSE,
NULL);
} else if (g_strcmp0 (history_type, GPM_HISTORY_RATE_VALUE) == 0) {
g_object_set (graph_history,
@@ -791,19 +830,37 @@ gpm_stats_update_info_page_history (UpDevice *device)
point = egg_graph_point_new ();
point->x = (gint32) up_history_item_get_time (item) - offset;
point->y = up_history_item_get_value (item);
- if (up_history_item_get_state (item) == UP_DEVICE_STATE_CHARGING)
- point->color = gpm_color_from_rgb (255, 0, 0);
- else if (up_history_item_get_state (item) == UP_DEVICE_STATE_DISCHARGING)
- point->color = gpm_color_from_rgb (0, 0, 255);
- else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_CHARGE)
- point->color = gpm_color_from_rgb (200, 0, 0);
- else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_DISCHARGE)
- point->color = gpm_color_from_rgb (0, 0, 200);
- else {
- if (g_strcmp0 (history_type, GPM_HISTORY_RATE_VALUE) == 0)
- point->color = gpm_color_from_rgb (255, 255, 255);
- else
- point->color = gpm_color_from_rgb (0, 255, 0);
+ if (gpm_stats_is_dark_mode (widget))
+ {
+ if (up_history_item_get_state (item) == UP_DEVICE_STATE_CHARGING)
+ point->color = gpm_color_from_rgb (255,0,0);
+ else if (up_history_item_get_state (item) == UP_DEVICE_STATE_DISCHARGING)
+ point->color = gpm_color_from_rgb (0, 0, 255);
+ else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_CHARGE)
+ point->color = gpm_color_from_rgb (200, 0, 0);
+ else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_DISCHARGE)
+ point->color = gpm_color_from_rgb (0, 0, 200);
+ else {
+ if (g_strcmp0 (history_type, GPM_HISTORY_RATE_VALUE) == 0)
+ point->color = gpm_color_from_rgb (255, 255, 255);
+ else
+ point->color = gpm_color_from_rgb (0, 255, 0);
+ }
+ } else {
+ if (up_history_item_get_state (item) == UP_DEVICE_STATE_CHARGING)
+ point->color = gpm_color_from_rgb (255, 0, 0);
+ else if (up_history_item_get_state (item) == UP_DEVICE_STATE_DISCHARGING)
+ point->color = gpm_color_from_rgb (0, 130, 255);
+ else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_CHARGE)
+ point->color = gpm_color_from_rgb (200, 0, 0);
+ else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_DISCHARGE)
+ point->color = gpm_color_from_rgb (0, 0, 200);
+ else {
+ if (g_strcmp0 (history_type, GPM_HISTORY_RATE_VALUE) == 0)
+ point->color = gpm_color_from_rgb (255, 255, 255);
+ else
+ point->color = gpm_color_from_rgb (0, 255, 0);
+ }
}
g_ptr_array_add (new, point);
}
@@ -1406,6 +1463,32 @@ gpm_stats_startup_cb (GApplication *application,
/* add history graph */
box = GTK_BOX (gtk_builder_get_object (builder, "hbox_history"));
graph_history = egg_graph_widget_new ();
+
+ if (gpm_stats_is_dark_mode (graph_history))
+ {
+ g_object_set (graph_history,
+ "text-color", gpm_color_from_rgb (205, 205, 205),
+ "line-color", gpm_color_from_rgb (230, 230, 230),
+ "legend-line-color", gpm_color_from_rgb (230, 230, 230),
+ "legend-text-color", gpm_color_from_rgb (255, 255, 255),
+ "dot-stroke-color", gpm_color_from_rgb (255, 255, 255),
+ "background-color", gpm_color_from_rgba (0, 0, 0, 0),
+ "background-stroke-color", gpm_color_from_rgb (230, 230, 230),
+ "outline-color", gpm_color_from_rgb (100, 100, 100),
+ NULL);
+ } else {
+ g_object_set (graph_history,
+ "text-color", gpm_color_from_rgb (50, 50, 50),
+ "line-color", gpm_color_from_rgb (25, 25, 25),
+ "legend-line-color", gpm_color_from_rgb (25, 25, 25),
+ "legend-text-color", gpm_color_from_rgb (0, 0, 0),
+ "dot-stroke-color", gpm_color_from_rgb (0, 0, 0),
+ "background-color", gpm_color_from_rgb (255, 255, 255),
+ "background-stroke-color", gpm_color_from_rgb (25, 25, 25),
+ "outline-color", gpm_color_from_rgb (155, 155, 155),
+ NULL);
+ }
+
gtk_box_pack_start (box, graph_history, TRUE, TRUE, 0);
gtk_widget_set_size_request (graph_history, 400, 250);
gtk_widget_show (graph_history);
@@ -1413,6 +1496,32 @@ gpm_stats_startup_cb (GApplication *application,
/* add statistics graph */
box = GTK_BOX (gtk_builder_get_object (builder, "hbox_statistics"));
graph_statistics = egg_graph_widget_new ();
+
+ if (gpm_stats_is_dark_mode (graph_statistics))
+ {
+ g_object_set (graph_statistics,
+ "text-color", gpm_color_from_rgb (205, 205, 205),
+ "line-color", gpm_color_from_rgb (230, 230, 230),
+ "legend-line-color", gpm_color_from_rgb (230, 230, 230),
+ "legend-text-color", gpm_color_from_rgb (255, 255, 255),
+ "dot-stroke-color", gpm_color_from_rgb (255, 255, 255),
+ "background-color", gpm_color_from_rgba (0, 0, 0, 0),
+ "background-stroke-color", gpm_color_from_rgb (230, 230, 230),
+ "outline-color", gpm_color_from_rgb (100, 100, 100),
+ NULL);
+ } else {
+ g_object_set (graph_statistics,
+ "text-color", gpm_color_from_rgb (50, 50, 50),
+ "line-color", gpm_color_from_rgb (25, 25, 25),
+ "legend-line-color", gpm_color_from_rgb (0, 0, 0),
+ "legend-text-color", gpm_color_from_rgb (25, 25, 25),
+ "dot-stroke-color", gpm_color_from_rgb (0, 0, 0),
+ "background-color", gpm_color_from_rgb (255, 255, 255),
+ "background-stroke-color", gpm_color_from_rgb (25, 25, 25),
+ "outline-color", gpm_color_from_rgb (155, 155, 155),
+ NULL);
+ }
+
gtk_box_pack_start (box, graph_statistics, TRUE, TRUE, 0);
gtk_widget_set_size_request (graph_statistics, 400, 250);
gtk_widget_show (graph_statistics);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]