Merge lp:~macslow/notify-osd/slot-allocation into lp:notify-osd/trunk

Proposed by Mirco Müller
Status: Merged
Approved by: Mirco Müller
Approved revision: 392
Merged at revision: not available
Proposed branch: lp:~macslow/notify-osd/slot-allocation
Merge into: lp:notify-osd/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~macslow/notify-osd/slot-allocation
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+11521@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Mirco Müller (macslow) wrote :

Separate gravity/placement from the slot-allocation scheme. The slot-allocation scheme can either be "fixed" or "dynamic". "Fixed" means async. bubbles are always in the top-slot and sync. bubbles are always in the button slot. "Dynamic" means the bubble (async. or sync.) can go in any of the two slots depending on which slot is vacant upon initial display. Again, this is now made independent from the chosen gravity. Before we did not have this abstraction at all.

Revision history for this message
Ted Gould (ted) wrote :

I don't see anything funny. Questions answered over IRC. Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/defaults.c'
2--- src/defaults.c 2009-09-01 11:19:59 +0000
3+++ src/defaults.c 2009-09-10 13:16:07 +0000
4@@ -864,6 +864,9 @@
5 _handle_error (self, error);
6 return;
7 }
8+
9+ // use fixed slot-allocation for async. and sync. bubbles
10+ self->slot_allocation = SLOT_ALLOCATION_FIXED;
11 }
12
13 static void
14@@ -2608,3 +2611,12 @@
15
16 return gravity;
17 }
18+
19+SlotAllocation
20+defaults_get_slot_allocation (Defaults *self)
21+{
22+ if (!self || !IS_DEFAULTS (self))
23+ return SLOT_ALLOCATION_NONE;
24+
25+ return self->slot_allocation;
26+}
27
28=== modified file 'src/defaults.h'
29--- src/defaults.h 2009-09-01 08:46:33 +0000
30+++ src/defaults.h 2009-09-10 13:11:32 +0000
31@@ -61,53 +61,61 @@
32 GRAVITY_EAST // vertically centered at right of screen
33 } Gravity;
34
35+typedef enum
36+{
37+ SLOT_ALLOCATION_NONE = 0,
38+ SLOT_ALLOCATION_FIXED, // async. always in top, sync. always in bottom
39+ SLOT_ALLOCATION_DYNAMIC // async. and sync can take top or bottom
40+} SlotAllocation;
41+
42 /* instance structure */
43 struct _Defaults
44 {
45 GObject parent;
46
47 /* private */
48- GConfClient* context;
49- guint notifier[6];
50- gint desktop_width;
51- gint desktop_height;
52- gint desktop_top;
53- gint desktop_bottom;
54- gint desktop_left;
55- gint desktop_right;
56- gdouble desktop_bottom_gap;
57- gdouble stack_height;
58- gdouble bubble_vert_gap;
59- gdouble bubble_horz_gap;
60- gdouble bubble_width;
61- gdouble bubble_min_height;
62- gdouble bubble_max_height;
63- gdouble bubble_shadow_size;
64- GString* bubble_shadow_color;
65- GString* bubble_bg_color;
66- GString* bubble_bg_opacity;
67- GString* bubble_hover_opacity;
68- gdouble bubble_corner_radius;
69- gdouble content_shadow_size;
70- GString* content_shadow_color;
71- gdouble margin_size;
72- gdouble icon_size;
73- gdouble gauge_size;
74- gdouble gauge_outline_width;
75- gint fade_in_timeout;
76- gint fade_out_timeout;
77- gint on_screen_timeout;
78- GString* text_font_face;
79- GString* text_title_color;
80- gint text_title_weight;
81- gdouble text_title_size;
82- GString* text_body_color;
83- gint text_body_weight;
84- gdouble text_body_size;
85- gdouble pixels_per_em;
86- gdouble system_font_size;
87- gdouble screen_dpi;
88- Gravity gravity;
89+ GConfClient* context;
90+ guint notifier[6];
91+ gint desktop_width;
92+ gint desktop_height;
93+ gint desktop_top;
94+ gint desktop_bottom;
95+ gint desktop_left;
96+ gint desktop_right;
97+ gdouble desktop_bottom_gap;
98+ gdouble stack_height;
99+ gdouble bubble_vert_gap;
100+ gdouble bubble_horz_gap;
101+ gdouble bubble_width;
102+ gdouble bubble_min_height;
103+ gdouble bubble_max_height;
104+ gdouble bubble_shadow_size;
105+ GString* bubble_shadow_color;
106+ GString* bubble_bg_color;
107+ GString* bubble_bg_opacity;
108+ GString* bubble_hover_opacity;
109+ gdouble bubble_corner_radius;
110+ gdouble content_shadow_size;
111+ GString* content_shadow_color;
112+ gdouble margin_size;
113+ gdouble icon_size;
114+ gdouble gauge_size;
115+ gdouble gauge_outline_width;
116+ gint fade_in_timeout;
117+ gint fade_out_timeout;
118+ gint on_screen_timeout;
119+ GString* text_font_face;
120+ GString* text_title_color;
121+ gint text_title_weight;
122+ gdouble text_title_size;
123+ GString* text_body_color;
124+ gint text_body_weight;
125+ gdouble text_body_size;
126+ gdouble pixels_per_em;
127+ gdouble system_font_size;
128+ gdouble screen_dpi;
129+ Gravity gravity;
130+ SlotAllocation slot_allocation;
131 };
132
133 /* class structure */
134@@ -252,6 +260,9 @@
135 Gravity
136 defaults_get_gravity (Defaults *self);
137
138+SlotAllocation
139+defaults_get_slot_allocation (Defaults *self);
140+
141 G_END_DECLS
142
143 #endif /* __DEFAULTS_H */
144
145=== modified file 'src/display.c'
146--- src/display.c 2009-09-08 13:26:40 +0000
147+++ src/display.c 2009-09-10 13:11:32 +0000
148@@ -83,16 +83,39 @@
149 // TODO: with multi-head, in focus follow mode, there may be enough
150 // space left on the top monitor
151
152- switch (defaults_get_gravity (d))
153+ switch (defaults_get_slot_allocation (d))
154 {
155- case GRAVITY_NORTH_EAST:
156+ case SLOT_ALLOCATION_FIXED:
157+ if (stack_is_slot_vacant (self, SLOT_TOP))
158+ {
159+ stack_get_slot_position (self,
160+ SLOT_TOP,
161+ bubble_get_height (bubble),
162+ &x,
163+ &y);
164+ if (x == -1 || y == -1)
165+ g_warning ("%s(): No slot-coords!\n",
166+ G_STRFUNC);
167+ else
168+ stack_allocate_slot (self,
169+ bubble,
170+ SLOT_TOP);
171+ }
172+ else
173+ {
174+ g_warning ("%s(): Top slot taken!\n",
175+ G_STRFUNC);
176+ }
177+ break;
178+
179+ case SLOT_ALLOCATION_DYNAMIC:
180 // see if we're call at the wrong moment, when both
181 // slots are occupied by bubbles
182 if (!stack_is_slot_vacant (self, SLOT_TOP) &&
183 !stack_is_slot_vacant (self, SLOT_BOTTOM))
184 {
185 g_warning ("%s(): Both slots taken!\n",
186- G_STRFUNC);
187+ G_STRFUNC);
188 }
189 else
190 {
191@@ -104,31 +127,31 @@
192 stack_is_slot_vacant (self, SLOT_BOTTOM))
193 {
194 stack_get_slot_position (self,
195- SLOT_TOP,
196- bubble_get_height (bubble),
197- &x,
198- &y);
199+ SLOT_TOP,
200+ bubble_get_height (bubble),
201+ &x,
202+ &y);
203 if (x == -1 || y == -1)
204 g_warning ("%s(): No coords!\n",
205 G_STRFUNC);
206 else
207 stack_allocate_slot (self,
208- bubble,
209- SLOT_TOP);
210+ bubble,
211+ SLOT_TOP);
212 }
213 // next check if top is occupied and bottom is
214 // still vacant, then place sync. bubble in
215 // bottom slot
216 else if (!stack_is_slot_vacant (self,
217- SLOT_TOP) &&
218- stack_is_slot_vacant (self,
219- SLOT_BOTTOM))
220+ SLOT_TOP) &&
221+ stack_is_slot_vacant (self,
222+ SLOT_BOTTOM))
223 {
224 stack_get_slot_position (self,
225- SLOT_BOTTOM,
226- bubble_get_height (bubble),
227- &x,
228- &y);
229+ SLOT_BOTTOM,
230+ bubble_get_height (bubble),
231+ &x,
232+ &y);
233 if (x == -1 || y == -1)
234 g_warning ("%s(): No coords!\n",
235 G_STRFUNC);
236@@ -149,44 +172,18 @@
237 // we want to avoid the "gap" between the bottom
238 // bubble and the panel
239 else if (stack_is_slot_vacant (self,
240- SLOT_TOP) &&
241- !stack_is_slot_vacant (self,
242- SLOT_BOTTOM))
243+ SLOT_TOP) &&
244+ !stack_is_slot_vacant (self,
245+ SLOT_BOTTOM))
246 {
247 g_warning ("%s(): Gap, gap, gap!!!\n",
248- G_STRFUNC);
249+ G_STRFUNC);
250 }
251 }
252 break;
253
254- case GRAVITY_EAST:
255- // see if reserved top slot for sync. bubble is really
256- // vacant
257- if (stack_is_slot_vacant (self, SLOT_TOP) == OCCUPIED)
258- {
259- g_warning ("%s(): Top slot taken!\n",
260- G_STRFUNC);
261- }
262- // if not just put sync. bubble in top slot
263- else
264- {
265- stack_get_slot_position (self,
266- SLOT_TOP,
267- bubble_get_height (bubble),
268- &x,
269- &y);
270- if (x == -1 || y == -1)
271- g_warning ("%s(): No slot-coords!\n",
272- G_STRFUNC);
273- else
274- stack_allocate_slot (self,
275- bubble,
276- SLOT_TOP);
277- }
278- break;
279-
280- default:
281- g_warning ("Unhandled gravity!\n");
282+ default :
283+ g_warning ("Unhandled slot-allocation!\n");
284 break;
285 }
286
287@@ -322,124 +319,104 @@
288
289 d = self->defaults;
290
291- switch (defaults_get_gravity (d))
292+ switch (defaults_get_slot_allocation (d))
293 {
294- case GRAVITY_NORTH_EAST:
295- if (!stack_is_slot_vacant (self, SLOT_TOP) &&
296- !stack_is_slot_vacant (self, SLOT_BOTTOM))
297- {
298- g_warning ("%s(): Both slots taken!\n",
299- G_STRFUNC);
300- }
301- else
302- {
303- if (stack_is_slot_vacant (self, SLOT_TOP))
304- {
305- stack_get_slot_position (self,
306- SLOT_TOP,
307- bubble_get_height (bubble),
308- &x,
309- &y);
310- if (x == -1 || y == -1)
311- g_warning ("%s(): No coords!\n",
312- G_STRFUNC);
313- else
314- stack_allocate_slot (self,
315- bubble,
316- SLOT_TOP);
317- }
318- else if (stack_is_slot_vacant (self,
319- SLOT_BOTTOM))
320- {
321- stack_get_slot_position (self,
322- SLOT_BOTTOM,
323- bubble_get_height (bubble),
324- &x,
325- &y);
326- if (x == -1 || y == -1)
327- g_warning ("%s(): No coords!\n",
328- G_STRFUNC);
329- else
330- stack_allocate_slot (self,
331- bubble,
332- SLOT_BOTTOM);
333- }
334- }
335-
336- if (sync_bubble != NULL &&
337- bubble_is_visible (sync_bubble) &&
338- sync_bubble == self->slots[SLOT_TOP])
339- {
340- // synchronize the sync bubble with the timeout
341- // of the bubble at the bottom
342- bubble_sync_with (sync_bubble, bubble);
343- }
344- break;
345-
346- case GRAVITY_EAST:
347- // with the new placement sync. bubbles are always to be
348- // placed in the top slot (above the "half-line")
349- if (bubble_is_synchronous (bubble))
350- {
351- // verify that the top slot is really vacant
352- if (stack_is_slot_vacant (self, SLOT_TOP))
353- {
354- stack_get_slot_position (self,
355- SLOT_TOP,
356- bubble_get_height (bubble),
357- &x,
358- &y);
359- if (x == -1 || y == -1)
360- g_warning ("%s(): No coords!\n",
361- G_STRFUNC);
362- else
363- stack_allocate_slot (self,
364- bubble,
365- SLOT_TOP);
366- }
367- // otherwise there's still an error in the
368- // layout- and queue-logic
369- else
370- {
371- g_warning ("%s(): Can't put sync. "
372- "bubble in top slot!\n",
373- G_STRFUNC);
374- }
375- }
376- // an async. bubble is always meant to be put in the
377- // bottom slot (below the "half-line")
378- else
379- {
380- // verify that the bottom slot is really vacant
381- if (stack_is_slot_vacant (self, SLOT_BOTTOM))
382- {
383- stack_get_slot_position (self,
384- SLOT_BOTTOM,
385- bubble_get_height (bubble),
386- &x,
387- &y);
388- if (x == -1 || y == -1)
389- g_warning ("%s(): No coords!\n",
390- G_STRFUNC);
391- else
392- stack_allocate_slot (
393- self,
394- bubble,
395- SLOT_BOTTOM);
396- }
397- // otherwise there's still an error in the
398- // layout- and queue-logic
399- else
400- {
401- g_warning ("%s(): Can't put async. "
402- "bubble in bottom slot!\n",
403- G_STRFUNC);
404- }
405- }
406- break;
407-
408- default:
409- g_warning ("Unhandled gravity!\n");
410+ case SLOT_ALLOCATION_FIXED:
411+ if (stack_is_slot_vacant (self, SLOT_TOP) &&
412+ bubble_is_synchronous (bubble))
413+ {
414+ stack_get_slot_position (self,
415+ SLOT_TOP,
416+ bubble_get_height (bubble),
417+ &x,
418+ &y);
419+ if (x == -1 || y == -1)
420+ g_warning ("%s(): No coords!\n",
421+ G_STRFUNC);
422+ else
423+ stack_allocate_slot (self,
424+ bubble,
425+ SLOT_TOP);
426+ }
427+ else if (stack_is_slot_vacant (self, SLOT_BOTTOM) &&
428+ !bubble_is_synchronous (bubble))
429+ {
430+ stack_get_slot_position (self,
431+ SLOT_BOTTOM,
432+ bubble_get_height (bubble),
433+ &x,
434+ &y);
435+ if (x == -1 || y == -1)
436+ g_warning ("%s(): No coords!\n",
437+ G_STRFUNC);
438+ else
439+ stack_allocate_slot (self,
440+ bubble,
441+ SLOT_BOTTOM);
442+ }
443+ else
444+ {
445+ g_warning ("%s(): Error while handling fixed "
446+ "slot-allocation!\n",
447+ G_STRFUNC);
448+ }
449+ break;
450+
451+ case SLOT_ALLOCATION_DYNAMIC:
452+ if (stack_is_slot_vacant (self, SLOT_TOP) &&
453+ stack_is_slot_vacant (self, SLOT_BOTTOM))
454+ {
455+ stack_get_slot_position (self,
456+ SLOT_TOP,
457+ bubble_get_height (bubble),
458+ &x,
459+ &y);
460+ if (x == -1 || y == -1)
461+ g_warning ("%s(): No coords!\n",
462+ G_STRFUNC);
463+ else
464+ stack_allocate_slot (self,
465+ bubble,
466+ SLOT_TOP);
467+ }
468+ else if (!stack_is_slot_vacant (self, SLOT_TOP) &&
469+ stack_is_slot_vacant (self, SLOT_BOTTOM))
470+ {
471+ stack_get_slot_position (self,
472+ SLOT_BOTTOM,
473+ bubble_get_height (bubble),
474+ &x,
475+ &y);
476+ if (x == -1 || y == -1)
477+ g_warning ("%s(): No coords!\n",
478+ G_STRFUNC);
479+ else
480+ {
481+ stack_allocate_slot (self,
482+ bubble,
483+ SLOT_BOTTOM);
484+
485+ if (sync_bubble != NULL &&
486+ bubble_is_visible (sync_bubble))
487+ {
488+ // synchronize the sync bubble with the timeout
489+ // of the bubble at the bottom
490+ bubble_sync_with (self->slots[SLOT_TOP],
491+ self->slots[SLOT_BOTTOM]);
492+ }
493+ }
494+ }
495+ else
496+ {
497+ g_warning ("%s(): Error while handling dynamic "
498+ "slot-allocation!\n",
499+ G_STRFUNC);
500+ }
501+ break;
502+
503+ default :
504+ g_warning ("%s(): Unhandled slot-allocation scheme!\n",
505+ G_STRFUNC);
506 break;
507 }
508
509
510=== modified file 'src/stack.c'
511--- src/stack.c 2009-09-09 22:42:11 +0000
512+++ src/stack.c 2009-09-10 13:11:32 +0000
513@@ -911,10 +911,25 @@
514 // top slot
515 if (slot == SLOT_BOTTOM)
516 {
517- g_assert (stack_is_slot_vacant (self, SLOT_TOP) == OCCUPIED);
518- *y += bubble_get_height (self->slots[SLOT_TOP]) +
519- EM2PIXELS (defaults_get_bubble_vert_gap (d), d) -
520- 2 * EM2PIXELS (defaults_get_bubble_shadow_size (d), d);
521+ switch (defaults_get_slot_allocation (d))
522+ {
523+ case SLOT_ALLOCATION_FIXED:
524+ *y += EM2PIXELS (defaults_get_icon_size (d), d) +
525+ 2 * EM2PIXELS (defaults_get_margin_size (d), d) +
526+ EM2PIXELS (defaults_get_bubble_vert_gap (d), d); /* +
527+ 2 * EM2PIXELS (defaults_get_bubble_shadow_size (d), d);*/
528+ break;
529+
530+ case SLOT_ALLOCATION_DYNAMIC:
531+ g_assert (stack_is_slot_vacant (self, SLOT_TOP) == OCCUPIED);
532+ *y += bubble_get_height (self->slots[SLOT_TOP]) +
533+ EM2PIXELS (defaults_get_bubble_vert_gap (d), d) -
534+ 2 * EM2PIXELS (defaults_get_bubble_shadow_size (d), d);
535+ break;
536+
537+ default:
538+ break;
539+ }
540
541 }
542 break;
543
544=== modified file 'tests/test-defaults.c'
545--- tests/test-defaults.c 2009-08-31 13:56:28 +0000
546+++ tests/test-defaults.c 2009-09-10 13:11:32 +0000
547@@ -164,6 +164,29 @@
548 g_object_unref (G_OBJECT (defaults));
549 }
550
551+static void
552+test_defaults_get_slot_allocation ()
553+{
554+ Defaults* defaults = defaults_new ();
555+
556+ // upon creation slot-allocation should not be unset
557+ g_assert_cmpint (defaults_get_slot_allocation (defaults),
558+ !=,
559+ SLOT_ALLOCATION_NONE);
560+
561+ // currently the default value should be SLOT_ALLOCATION_FIXED
562+ g_assert_cmpint (defaults_get_slot_allocation (defaults),
563+ ==,
564+ SLOT_ALLOCATION_FIXED);
565+
566+ // check if we can pass "crap" to the call without causing a crash
567+ g_assert_cmpint (defaults_get_slot_allocation (NULL),
568+ ==,
569+ SLOT_ALLOCATION_NONE);
570+
571+ g_object_unref (G_OBJECT (defaults));
572+}
573+
574 GTestSuite *
575 test_defaults_create_test_suite (void)
576 {
577@@ -184,6 +207,7 @@
578 g_test_suite_add(ts, TC(test_defaults_get_stack_height));
579 g_test_suite_add(ts, TC(test_defaults_get_bubble_width));
580 g_test_suite_add(ts, TC(test_defaults_get_gravity));
581+ g_test_suite_add(ts, TC(test_defaults_get_slot_allocation));
582
583 return ts;
584 }

Subscribers

People subscribed via source and target branches