Merge lp:~desrt/notify-osd/GNOME_BACKGROUND_REPRESENTATIVE_COLORS into lp:~canonical-dx-team/notify-osd/precise

Proposed by Allison Karlitskaya
Status: Merged
Approved by: Mirco Müller
Approved revision: 454
Merge reported by: Mirco Müller
Merged at revision: not available
Proposed branch: lp:~desrt/notify-osd/GNOME_BACKGROUND_REPRESENTATIVE_COLORS
Merge into: lp:~canonical-dx-team/notify-osd/precise
Diff against target: 225 lines (+56/-73)
3 files modified
src/bubble.c (+8/-8)
src/defaults.c (+45/-64)
src/defaults.h (+3/-1)
To merge this branch: bzr merge lp:~desrt/notify-osd/GNOME_BACKGROUND_REPRESENTATIVE_COLORS
Reviewer Review Type Date Requested Status
Mirco Müller (community) Approve
Review via email: mp+96837@code.launchpad.net

Description of the change

Get background colour using _GNOME_BACKGROUND_REPRESENTATIVE_COLORS

...instead of pulling it out of Unity's GSettings.

To post a comment you must log in.
Revision history for this message
Allison Karlitskaya (desrt) wrote :

This is being added to libgnome-desktop (which is how the desktop gets set) here: https://bugzilla.gnome.org/show_bug.cgi?id=671750

Revision history for this message
David Barth (dbarth) wrote :

Looks good, but can you add some tests?

What happens if the property does not exist? Is there a corresponding default mechanism to provide a sane value?

IMO, the test should verify that changing the background color results in the right color being received in the bubble.c function. Then, that border line values don't result in a crash and trigger a reasonable fallback value.

Revision history for this message
Mirco Müller (macslow) wrote :

The way a bubble is initialized and defaults_refresh_bg_color_property() goes about updating the "bubble-bg-color", it'll fall back to the typical dark grey color, should the X-property "_GNOME_BACKGROUND_REPRESENTATIVE_COLORS" not be available. I tested that by defaults_refresh_bg_color_property() returning early not touching "bubble-bg-color" at all.

Revision history for this message
Mirco Müller (macslow) wrote :

After discussion on IRC, the effort/benefit relation forbids an automated test for this. We need a proper framework for testing such system-wide changes correctly. Until we have that in place a manual-test will have to do.

review: Needs Fixing
Revision history for this message
Mirco Müller (macslow) wrote :

Since I can't commit to desrt's branch I'll approve this and add the manual-test with my merge to trunk. So... approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bubble.c'
2--- src/bubble.c 2012-02-08 09:18:02 +0000
3+++ src/bubble.c 2012-03-09 21:34:18 +0000
4@@ -668,10 +668,10 @@
5 cairo_paint (cr);
6 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
7
8- GdkColor color;
9+ GdkRGBA color;
10 gchar* color_string = NULL;
11 color_string = defaults_get_bubble_bg_color (d);
12- gdk_color_parse (color_string, &color);
13+ gdk_rgba_parse (&color, color_string);
14 g_free (color_string);
15
16 if (priv->composited)
17@@ -695,16 +695,16 @@
18 cairo_fill (cr);
19 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
20 cairo_set_source_rgba (cr,
21- 0.75 * ((double) color.red / 65535.0),
22- 0.75 * ((double) color.green / 65535.0),
23- 0.75 * ((double) color.blue / 65535.0),
24+ 0.75 * color.red,
25+ 0.75 * color.green,
26+ 0.75 * color.blue,
27 BUBBLE_BG_COLOR_A);
28 }
29 else
30 cairo_set_source_rgb (cr,
31- 0.75 * ((double) color.red / 65535.0),
32- 0.75 * ((double) color.green / 65535.0),
33- 0.75 * ((double) color.blue / 65535.0));
34+ 0.75 * color.red,
35+ 0.75 * color.green,
36+ 0.75 * color.blue);
37
38 draw_round_rect (
39 cr,
40
41=== modified file 'src/defaults.c'
42--- src/defaults.c 2012-02-08 09:18:02 +0000
43+++ src/defaults.c 2012-03-09 21:34:18 +0000
44@@ -289,59 +289,50 @@
45 g_signal_emit (defaults, g_defaults_signals[GRAVITY_CHANGED], 0);
46 }
47
48-static void
49-_avg_bg_color_changed (GSettings* settings,
50- gchar* key,
51- gpointer data)
52-{
53- Defaults* defaults = NULL;
54- gchar* color_string = NULL;
55-
56- if (!data || !settings)
57- return;
58-
59- defaults = (Defaults*) data;
60- if (!IS_DEFAULTS (defaults))
61- return;
62-
63- color_string = g_settings_get_string (settings, key);
64- g_object_set (defaults, "bubble-bg-color", color_string, NULL);
65- g_free (color_string);
66-}
67-
68-GSettings*
69-_get_unity_schema ()
70-{
71- // check for availability of unity-schema
72- const gchar* const* schema_list = NULL;
73- int i = 0;
74- gboolean match = FALSE;
75- schema_list = g_settings_list_schemas (); // no need to free/unref list
76- for (i = 0; schema_list[i]; i++)
77- if (g_strcmp0 (UNITY_SCHEMA, schema_list[i]) == 0)
78- {
79- match = TRUE;
80- break;
81- }
82- if (!match)
83- return NULL;
84-
85- // be really paranoid and check for "avg. bg-color" key
86- GSettings* settings = g_settings_new (UNITY_SCHEMA);
87- gchar** keys = NULL;
88- keys = g_settings_list_keys (settings);
89- i = 0;
90- match = FALSE;
91- while (keys[i] && !match)
92+void
93+defaults_refresh_bg_color_property (Defaults *self)
94+{
95+ Atom real_type;
96+ gint result;
97+ gint real_format;
98+ gulong items_read;
99+ gulong items_left;
100+ gchar* colors;
101+ Atom representative_colors_atom;
102+ Display* display;
103+
104+ g_return_if_fail ((self != NULL) && IS_DEFAULTS (self));
105+
106+ representative_colors_atom = gdk_x11_get_xatom_by_name ("_GNOME_BACKGROUND_REPRESENTATIVE_COLORS");
107+ display = gdk_x11_display_get_xdisplay (gdk_display_get_default ());
108+
109+ gdk_error_trap_push ();
110+ result = XGetWindowProperty (display,
111+ GDK_ROOT_WINDOW (),
112+ representative_colors_atom,
113+ 0L,
114+ G_MAXLONG,
115+ False,
116+ XA_STRING,
117+ &real_type,
118+ &real_format,
119+ &items_read,
120+ &items_left,
121+ (guchar **) &colors);
122+ gdk_flush ();
123+ gdk_error_trap_pop_ignored ();
124+
125+ if (result == Success && items_read)
126 {
127- match = g_strcmp0 (keys[i], GSETTINGS_AVG_BG_COL_KEY) == 0 ? TRUE : FALSE;
128- i++;
129+ /* by treating the result as a nul-terminated string, we
130+ * select the first colour in the list.
131+ */
132+ g_object_set (self,
133+ "bubble-bg-color",
134+ colors,
135+ NULL);
136+ XFree (colors);
137 }
138- g_strfreev (keys);
139- if (!match)
140- return NULL;
141-
142- return settings;
143 }
144
145 void
146@@ -425,6 +416,7 @@
147 self = DEFAULTS (gobject);
148
149 defaults_refresh_screen_dimension_properties (self);
150+ defaults_refresh_bg_color_property (self);
151
152 /* grab system-wide font-face/size and DPI */
153 _get_font_size_dpi (self);
154@@ -462,10 +454,6 @@
155 NULL);
156 }
157
158- _avg_bg_color_changed (self->unity_settings,
159- GSETTINGS_AVG_BG_COL_KEY,
160- self);
161-
162 /* FIXME: calling this here causes a segfault */
163 /* chain up to the parent class */
164 /*G_OBJECT_CLASS (defaults_parent_class)->constructed (gobject);*/
165@@ -480,7 +468,6 @@
166
167 g_object_unref (defaults->nosd_settings);
168 g_object_unref (defaults->gnome_settings);
169- g_object_unref (defaults->unity_settings);
170
171 if (defaults->bubble_shadow_color)
172 {
173@@ -547,7 +534,6 @@
174 /* "connect" to the required GSettings schemas */
175 self->nosd_settings = g_settings_new (NOTIFY_OSD_SCHEMA);
176 self->gnome_settings = g_settings_new (GNOME_DESKTOP_SCHEMA);
177- self->unity_settings = _get_unity_schema ();
178
179 g_signal_connect (self->gnome_settings,
180 "changed",
181@@ -558,13 +544,6 @@
182 "changed",
183 G_CALLBACK (_gravity_changed),
184 self);
185- if (self->unity_settings)
186- {
187- g_signal_connect (self->unity_settings,
188- "changed",
189- G_CALLBACK (_avg_bg_color_changed),
190- self);
191- }
192
193 // use fixed slot-allocation for async. and sync. bubbles
194 self->slot_allocation = SLOT_ALLOCATION_FIXED;
195@@ -1819,6 +1798,8 @@
196 if (!self || !IS_DEFAULTS (self))
197 return NULL;
198
199+ defaults_refresh_bg_color_property (self);
200+
201 g_object_get (self,
202 "bubble-bg-color",
203 &bubble_bg_color,
204
205=== modified file 'src/defaults.h'
206--- src/defaults.h 2012-02-08 09:18:02 +0000
207+++ src/defaults.h 2012-03-09 21:34:18 +0000
208@@ -76,7 +76,6 @@
209 /* private */
210 GSettings* nosd_settings;
211 GSettings* gnome_settings;
212- GSettings* unity_settings;
213 gint desktop_width;
214 gint desktop_height;
215 gint desktop_top;
216@@ -253,6 +252,9 @@
217 defaults_get_screen_dpi (Defaults* self);
218
219 void
220+defaults_refresh_bg_property (Defaults *self);
221+
222+void
223 defaults_refresh_screen_dimension_properties (Defaults *self);
224
225 void

Subscribers

People subscribed via source and target branches