~macslow/notify-osd/fix-396736

« back to all changes in this revision

Viewing changes to src/display.c

  • Committer: Mirco Müller
  • Date: 2009-09-08 13:26:40 UTC
  • mfrom: (385.1.5 notify-osd_two-slots)
  • Revision ID: mirco.mueller@ubuntu.com-20090908132640-ug05nna41xuy4rsy
Merged two-slots branch to trunk, sticking with term GRAVITY (used to be
called PLACEMENT). GRAVITY is now a setting stored in class Defaults. It
used to be living in class Stack, but didn't really belong there. This
fixes LP: #371422

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
        return y1 == y2;
72
72
}
73
73
 
74
 
 
75
74
static void
76
75
stack_display_position_sync_bubble (Stack *self, Bubble *bubble)
77
76
{
78
77
        Defaults* d = self->defaults;
79
78
        gint      y = 0;
80
79
        gint      x = 0;
81
 
        Bubble*   async;
82
80
 
83
81
        defaults_get_top_corner (d, &x, &y);
84
82
 
88
86
        switch (defaults_get_gravity (d))
89
87
        {
90
88
                case GRAVITY_NORTH_EAST:
91
 
                        async = stack_find_bubble_on_display (self);
92
 
                        if (async != NULL)
93
 
                        {
94
 
                                d = self->defaults;
95
 
                                y += bubble_get_future_height (async);
96
 
                                y += EM2PIXELS (defaults_get_bubble_vert_gap (d), d) -
97
 
                                2 * EM2PIXELS (defaults_get_bubble_shadow_size (d), d);
 
89
                        // see if we're call at the wrong moment, when both
 
90
                        // slots are occupied by bubbles
 
91
                        if (!stack_is_slot_vacant (self, SLOT_TOP) &&
 
92
                            !stack_is_slot_vacant (self, SLOT_BOTTOM))
 
93
                        {
 
94
                                g_warning ("%s(): Both slots taken!\n",
 
95
                                           G_STRFUNC);
 
96
                        }
 
97
                        else
 
98
                        {
 
99
                                // first check if we can place the sync. bubble
 
100
                                // in the top slot and the bottom slot is still
 
101
                                // vacant, this is to avoid the "gap" between
 
102
                                // bottom slot and panel
 
103
                                if (stack_is_slot_vacant (self, SLOT_TOP) &&
 
104
                                    stack_is_slot_vacant (self, SLOT_BOTTOM))
 
105
                                {
 
106
                                        stack_get_slot_position (self,
 
107
                                                                 SLOT_TOP,
 
108
                                                                 bubble_get_height (bubble),
 
109
                                                                 &x,
 
110
                                                                 &y);
 
111
                                        if (x == -1 || y == -1)
 
112
                                                g_warning ("%s(): No coords!\n",
 
113
                                                           G_STRFUNC);
 
114
                                        else
 
115
                                                stack_allocate_slot (self,
 
116
                                                                     bubble,
 
117
                                                                     SLOT_TOP);
 
118
                                }
 
119
                                // next check if top is occupied and bottom is
 
120
                                // still vacant, then place sync. bubble in
 
121
                                // bottom slot
 
122
                                else if (!stack_is_slot_vacant (self,
 
123
                                                                SLOT_TOP) &&
 
124
                                         stack_is_slot_vacant (self,
 
125
                                                               SLOT_BOTTOM))
 
126
                                {
 
127
                                        stack_get_slot_position (self,
 
128
                                                                 SLOT_BOTTOM,
 
129
                                                                 bubble_get_height (bubble),
 
130
                                                                 &x,
 
131
                                                                 &y);
 
132
                                        if (x == -1 || y == -1)
 
133
                                                g_warning ("%s(): No coords!\n",
 
134
                                                           G_STRFUNC);
 
135
                                        else
 
136
                                        {
 
137
                                                stack_allocate_slot (
 
138
                                                        self,
 
139
                                                        bubble,
 
140
                                                        SLOT_BOTTOM);
 
141
 
 
142
                                                bubble_sync_with (
 
143
                                                        bubble,
 
144
                                                        self->slots[SLOT_TOP]);
 
145
                                        }
 
146
                                }
 
147
                                // this case, top vacant, bottom occupied,
 
148
                                // should never happen for the old placement,
 
149
                                // we want to avoid the "gap" between the bottom
 
150
                                // bubble and the panel
 
151
                                else if (stack_is_slot_vacant (self,
 
152
                                                               SLOT_TOP) &&
 
153
                                         !stack_is_slot_vacant (self,
 
154
                                                                SLOT_BOTTOM))
 
155
                                {
 
156
                                        g_warning ("%s(): Gap, gap, gap!!!\n",
 
157
                                                   G_STRFUNC);
 
158
                                }
98
159
                        }
99
160
                break;
100
161
 
101
162
                case GRAVITY_EAST:
102
 
                        y += defaults_get_desktop_height (d) / 2 -
103
 
                             EM2PIXELS (defaults_get_bubble_vert_gap (d) / 2.0f, d) -
104
 
                             bubble_get_height (bubble) +
105
 
                             EM2PIXELS (defaults_get_bubble_shadow_size (d), d);
 
163
                        // see if reserved top slot for sync. bubble is really
 
164
                        // vacant
 
165
                        if (stack_is_slot_vacant (self, SLOT_TOP) == OCCUPIED)
 
166
                        {
 
167
                                g_warning ("%s(): Top slot taken!\n",
 
168
                                           G_STRFUNC);
 
169
                        }
 
170
                        // if not just put sync. bubble in top slot
 
171
                        else
 
172
                        {
 
173
                                stack_get_slot_position (self,
 
174
                                                         SLOT_TOP,
 
175
                                                         bubble_get_height (bubble),
 
176
                                                         &x,
 
177
                                                         &y);
 
178
                                if (x == -1 || y == -1)
 
179
                                        g_warning ("%s(): No slot-coords!\n",
 
180
                                                   G_STRFUNC);
 
181
                                else
 
182
                                        stack_allocate_slot (self,
 
183
                                                             bubble,
 
184
                                                             SLOT_TOP);
 
185
                        }
106
186
                break;
107
187
 
108
188
                default:
114
194
}
115
195
 
116
196
static void
 
197
 
117
198
stack_display_sync_bubble (Stack *self, Bubble *bubble)
118
199
{
119
200
        g_return_if_fail (IS_STACK (self));
244
325
        switch (defaults_get_gravity (d))
245
326
        {
246
327
                case GRAVITY_NORTH_EAST:
247
 
                        if (sync_bubble != NULL && bubble_is_visible (sync_bubble))
248
 
                        {
249
 
                                d = self->defaults;
250
 
                                y += bubble_get_height (sync_bubble);
251
 
                                y += EM2PIXELS (defaults_get_bubble_vert_gap (d), d)
252
 
                                     - 2 * EM2PIXELS (defaults_get_bubble_shadow_size (d), d);
 
328
                        if (!stack_is_slot_vacant (self, SLOT_TOP) &&
 
329
                            !stack_is_slot_vacant (self, SLOT_BOTTOM))
 
330
                        {
 
331
                                g_warning ("%s(): Both slots taken!\n",
 
332
                                           G_STRFUNC);
 
333
                        }
 
334
                        else
 
335
                        {
 
336
                                if (stack_is_slot_vacant (self, SLOT_TOP))
 
337
                                {
 
338
                                        stack_get_slot_position (self,
 
339
                                                                 SLOT_TOP,
 
340
                                                                 bubble_get_height (bubble),
 
341
                                                                 &x,
 
342
                                                                 &y);
 
343
                                        if (x == -1 || y == -1)
 
344
                                                g_warning ("%s(): No coords!\n",
 
345
                                                           G_STRFUNC);
 
346
                                        else
 
347
                                                stack_allocate_slot (self,
 
348
                                                                     bubble,
 
349
                                                                     SLOT_TOP);
 
350
                                }
 
351
                                else if (stack_is_slot_vacant (self,
 
352
                                                               SLOT_BOTTOM))
 
353
                                {
 
354
                                        stack_get_slot_position (self,
 
355
                                                                 SLOT_BOTTOM,
 
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_BOTTOM);
 
366
                                }
 
367
                        }
253
368
 
254
 
                                // synchronize the sync bubble with the timeout of the bubble at
255
 
                                // the bottom
256
 
                                if (stack_is_at_top_corner (self, sync_bubble))
257
 
                                        bubble_sync_with (sync_bubble, bubble);
 
369
                        if (sync_bubble != NULL &&
 
370
                            bubble_is_visible (sync_bubble) &&
 
371
                            sync_bubble == self->slots[SLOT_TOP])
 
372
                        {
 
373
                                // synchronize the sync bubble with the timeout
 
374
                                // of the bubble at the bottom
 
375
                                bubble_sync_with (sync_bubble, bubble);
258
376
                        }
259
377
                break;
260
378
 
261
379
                case GRAVITY_EAST:
262
 
                        if (sync_bubble != NULL && bubble_is_visible (sync_bubble))
 
380
                        // with the new placement sync. bubbles are always to be
 
381
                        // placed in the top slot (above the "half-line")
 
382
                        if (bubble_is_synchronous (bubble))
263
383
                        {
264
 
                                y += defaults_get_desktop_height (d) / 2 -
265
 
                                     EM2PIXELS (defaults_get_bubble_vert_gap (d) / 2.0f, d) -
266
 
                                     bubble_get_height (sync_bubble) +
267
 
                                     EM2PIXELS (defaults_get_bubble_shadow_size (d), d);
 
384
                                // verify that the top slot is really vacant
 
385
                                if (stack_is_slot_vacant (self, SLOT_TOP))
 
386
                                {
 
387
                                        stack_get_slot_position (self,
 
388
                                                                 SLOT_TOP,
 
389
                                                                 bubble_get_height (bubble),
 
390
                                                                 &x,
 
391
                                                                 &y);
 
392
                                        if (x == -1 || y == -1)
 
393
                                                g_warning ("%s(): No coords!\n",
 
394
                                                           G_STRFUNC);
 
395
                                        else
 
396
                                                stack_allocate_slot (self,
 
397
                                                                     bubble,
 
398
                                                                     SLOT_TOP);
 
399
                                }
 
400
                                // otherwise there's still an error in the
 
401
                                // layout- and queue-logic
 
402
                                else
 
403
                                {
 
404
                                        g_warning ("%s(): Can't put sync. "
 
405
                                                   "bubble in top slot!\n",
 
406
                                                   G_STRFUNC);
 
407
                                }
268
408
                        }
 
409
                        // an async. bubble is always meant to be put in the
 
410
                        // bottom slot (below the "half-line")
269
411
                        else
270
412
                        {
271
 
                                y += defaults_get_desktop_height (d) / 2 +
272
 
                                     EM2PIXELS (defaults_get_bubble_vert_gap (d) / 2.0f, d) -
273
 
                                     EM2PIXELS (defaults_get_bubble_shadow_size (d), d);
 
413
                                // verify that the bottom slot is really vacant
 
414
                                if (stack_is_slot_vacant (self, SLOT_BOTTOM))
 
415
                                {
 
416
                                        stack_get_slot_position (self,
 
417
                                                                 SLOT_BOTTOM,
 
418
                                                                 bubble_get_height (bubble),
 
419
                                                                 &x,
 
420
                                                                 &y);
 
421
                                        if (x == -1 || y == -1)
 
422
                                                g_warning ("%s(): No coords!\n",
 
423
                                                           G_STRFUNC);
 
424
                                        else
 
425
                                                stack_allocate_slot (
 
426
                                                        self,
 
427
                                                        bubble,
 
428
                                                        SLOT_BOTTOM);
 
429
                                }
 
430
                                // otherwise there's still an error in the
 
431
                                // layout- and queue-logic
 
432
                                else
 
433
                                {
 
434
                                        g_warning ("%s(): Can't put async. "
 
435
                                                   "bubble in bottom slot!\n",
 
436
                                                   G_STRFUNC);
 
437
                                }
274
438
                        }
275
439
                break;
276
440