~walkerlee/totem/pre-interview

« back to all changes in this revision

Viewing changes to src/gsd-media-keys-window.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-05-26 00:07:51 UTC
  • mfrom: (1.6.1) (24.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130526000751-kv8ap3x1di4qq8j2
Tags: 3.8.2-0ubuntu1
* Sync with Debian. Remaining changes: 
* debian/control.in:
  - Drop build-depends on libepc-ui-dev and libgrilo-0.2-dev (in universe)
  - Drop libxtst-dev build-depends so that the (redundant) fake key presses
    for inhibiting the screensaver are disabled (LP: #1007438)
  - Build-depend on libzeitgeist-dev
  - Suggest rather than recommend gstreamer components in universe
  - Add totem-plugins-extra
  - Add XB-Npp-Description and XB-Npp-Filename header to the 
    totem-mozilla package to improve ubufox/ubuntu plugin db integration 
  - Refer to Firefox in totem-mozilla description instead of Iceweasel
  - Don't have totem-mozilla recommend any particular browser
  - Drop obsolete python library dependencies since iplayer is no longer
    included
* debian/totem-common.install, debian/source_totem.py:
  - Install Ubuntu apport debugging hook
* debian/totem-plugins-extra.install:
  - Universe plugins split out of totem-plugins (currently only gromit)
* debian/totem-plugins.install:    
  - Skip the plugins split to -extra and add the zeitgeist plugin
* debian/rules:
  - Build with --fail-missing, to ensure we install everything. 
    + Ignore libtotem.{,l}a since we delibrately don't install these.
  - Re-enable hardening, make sure both PIE and BINDNOW are used
    by setting hardening=+all. (LP: #1039604)
* debian/patches/91_quicklist_entries.patch:
  - Add static quicklist
* debian/patches/92_gst-plugins-good.patch:
  - Build without unnecessary gstreamer1.0-bad dependency
* debian/patches/93_grilo_optional.patch:
  - Allow building without grilo while grilo MIR is still pending
* debian/patches/correct_desktop_mimetypes.patch:
  - Don't list the mimetypes after the unity lists
* debian/patches/revert_shell_menu.patch: 
  - revert the use of a shell menu until indicator-appmenu can handle
    the mixed shell/traditional menus itself
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2
 
 *
3
 
 * Copyright (C) 2006-2007 William Jon McCann <mccann@jhu.edu>
4
 
 *
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU Lesser General Public
8
 
 * License as published by the Free Software Foundation; either
9
 
 * version 2, or (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be
12
 
 * useful, but WITHOUT ANY WARRANTY; without even the implied
13
 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
 
 * PURPOSE.  See the GNU Lesser General Public License for more
15
 
 * details.
16
 
 *
17
 
 * You should have received a copy of the GNU Lesser General
18
 
 * Public License along with this program; if not, write to the
19
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
 * Boston, MA 02111-1307, USA.
21
 
 *
22
 
 */
23
 
 
24
 
#include "config.h"
25
 
 
26
 
#include <stdlib.h>
27
 
#include <string.h>
28
 
#include <math.h>
29
 
#include <glib.h>
30
 
#include <glib/gi18n.h>
31
 
#include <gtk/gtk.h>
32
 
 
33
 
#include "gsd-media-keys-window.h"
34
 
 
35
 
#define GSD_MEDIA_KEYS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_MEDIA_KEYS_WINDOW, GsdMediaKeysWindowPrivate))
36
 
 
37
 
struct GsdMediaKeysWindowPrivate
38
 
{
39
 
        GsdMediaKeysWindowAction action;
40
 
        char                    *icon_name;
41
 
        gboolean                 show_level;
42
 
 
43
 
        guint                    volume_muted : 1;
44
 
        int                      volume_level;
45
 
 
46
 
        GtkImage                *image;
47
 
        GtkWidget               *progress;
48
 
};
49
 
 
50
 
G_DEFINE_TYPE (GsdMediaKeysWindow, gsd_media_keys_window, GSD_TYPE_OSD_WINDOW)
51
 
 
52
 
static void
53
 
volume_controls_set_visible (GsdMediaKeysWindow *window,
54
 
                             gboolean            visible)
55
 
{
56
 
        if (window->priv->progress == NULL)
57
 
                return;
58
 
 
59
 
        if (visible) {
60
 
                gtk_widget_show (window->priv->progress);
61
 
        } else {
62
 
                gtk_widget_hide (window->priv->progress);
63
 
        }
64
 
}
65
 
 
66
 
static void
67
 
window_set_icon_name (GsdMediaKeysWindow *window,
68
 
                      const char         *name)
69
 
{
70
 
        if (window->priv->image == NULL)
71
 
                return;
72
 
 
73
 
        gtk_image_set_from_icon_name (window->priv->image,
74
 
                                      name, GTK_ICON_SIZE_DIALOG);
75
 
}
76
 
 
77
 
static void
78
 
action_changed (GsdMediaKeysWindow *window)
79
 
{
80
 
        if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window))) {
81
 
                switch (window->priv->action) {
82
 
                case GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME:
83
 
                        volume_controls_set_visible (window, TRUE);
84
 
 
85
 
                        if (window->priv->volume_muted) {
86
 
                                window_set_icon_name (window, "audio-volume-muted");
87
 
                        } else {
88
 
                                window_set_icon_name (window, "audio-volume-high");
89
 
                        }
90
 
 
91
 
                        break;
92
 
                case GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM:
93
 
                        volume_controls_set_visible (window, window->priv->show_level);
94
 
                        window_set_icon_name (window, window->priv->icon_name);
95
 
                        break;
96
 
                default:
97
 
                        g_assert_not_reached ();
98
 
                        break;
99
 
                }
100
 
        }
101
 
 
102
 
        gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window));
103
 
}
104
 
 
105
 
static void
106
 
volume_level_changed (GsdMediaKeysWindow *window)
107
 
{
108
 
        gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window));
109
 
 
110
 
        if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window)) && window->priv->progress != NULL) {
111
 
                double fraction;
112
 
 
113
 
                fraction = (double) window->priv->volume_level / 100.0;
114
 
 
115
 
                gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (window->priv->progress),
116
 
                                               fraction);
117
 
        }
118
 
}
119
 
 
120
 
static void
121
 
volume_muted_changed (GsdMediaKeysWindow *window)
122
 
{
123
 
        gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window));
124
 
 
125
 
        if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window))) {
126
 
                if (window->priv->volume_muted) {
127
 
                        window_set_icon_name (window, "audio-volume-muted");
128
 
                } else {
129
 
                        window_set_icon_name (window, "audio-volume-high");
130
 
                }
131
 
        }
132
 
}
133
 
 
134
 
void
135
 
gsd_media_keys_window_set_action (GsdMediaKeysWindow      *window,
136
 
                                  GsdMediaKeysWindowAction action)
137
 
{
138
 
        g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window));
139
 
        g_return_if_fail (action == GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME);
140
 
 
141
 
        if (window->priv->action != action) {
142
 
                window->priv->action = action;
143
 
                action_changed (window);
144
 
        } else {
145
 
                gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window));
146
 
        }
147
 
}
148
 
 
149
 
void
150
 
gsd_media_keys_window_set_action_custom (GsdMediaKeysWindow      *window,
151
 
                                         const char              *icon_name,
152
 
                                         gboolean                 show_level)
153
 
{
154
 
        g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window));
155
 
        g_return_if_fail (icon_name != NULL);
156
 
 
157
 
        if (window->priv->action != GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM ||
158
 
            g_strcmp0 (window->priv->icon_name, icon_name) != 0 ||
159
 
            window->priv->show_level != show_level) {
160
 
                window->priv->action = GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM;
161
 
                g_free (window->priv->icon_name);
162
 
                window->priv->icon_name = g_strdup (icon_name);
163
 
                window->priv->show_level = show_level;
164
 
                action_changed (window);
165
 
        } else {
166
 
                gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window));
167
 
        }
168
 
}
169
 
 
170
 
void
171
 
gsd_media_keys_window_set_volume_muted (GsdMediaKeysWindow *window,
172
 
                                        gboolean            muted)
173
 
{
174
 
        g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window));
175
 
 
176
 
        if (window->priv->volume_muted != muted) {
177
 
                window->priv->volume_muted = muted;
178
 
                volume_muted_changed (window);
179
 
        }
180
 
}
181
 
 
182
 
void
183
 
gsd_media_keys_window_set_volume_level (GsdMediaKeysWindow *window,
184
 
                                        int                 level)
185
 
{
186
 
        g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window));
187
 
 
188
 
        if (window->priv->volume_level != level) {
189
 
                window->priv->volume_level = level;
190
 
                volume_level_changed (window);
191
 
        }
192
 
}
193
 
 
194
 
static GdkPixbuf *
195
 
load_pixbuf (GsdMediaKeysWindow *window,
196
 
             const char         *name,
197
 
             int                 icon_size)
198
 
{
199
 
        GtkIconTheme *theme;
200
 
        GdkPixbuf    *pixbuf;
201
 
 
202
 
        if (window != NULL && gtk_widget_has_screen (GTK_WIDGET (window))) {
203
 
                theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)));
204
 
        } else {
205
 
                theme = gtk_icon_theme_get_default ();
206
 
        }
207
 
 
208
 
        pixbuf = gtk_icon_theme_load_icon (theme,
209
 
                                           name,
210
 
                                           icon_size,
211
 
                                           GTK_ICON_LOOKUP_FORCE_SIZE,
212
 
                                           NULL);
213
 
 
214
 
        return pixbuf;
215
 
}
216
 
 
217
 
static void
218
 
draw_eject (cairo_t *cr,
219
 
            double   _x0,
220
 
            double   _y0,
221
 
            double   width,
222
 
            double   height)
223
 
{
224
 
        int box_height;
225
 
        int tri_height;
226
 
        int separation;
227
 
 
228
 
        box_height = height * 0.2;
229
 
        separation = box_height / 3;
230
 
        tri_height = height - box_height - separation;
231
 
 
232
 
        cairo_rectangle (cr, _x0, _y0 + height - box_height, width, box_height);
233
 
 
234
 
        cairo_move_to (cr, _x0, _y0 + tri_height);
235
 
        cairo_rel_line_to (cr, width, 0);
236
 
        cairo_rel_line_to (cr, -width / 2, -tri_height);
237
 
        cairo_rel_line_to (cr, -width / 2, tri_height);
238
 
        cairo_close_path (cr);
239
 
        cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, GSD_OSD_WINDOW_FG_ALPHA);
240
 
        cairo_fill_preserve (cr);
241
 
 
242
 
        cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, GSD_OSD_WINDOW_FG_ALPHA / 2);
243
 
        cairo_set_line_width (cr, 2);
244
 
        cairo_stroke (cr);
245
 
}
246
 
 
247
 
static void
248
 
draw_waves (cairo_t *cr,
249
 
            double   cx,
250
 
            double   cy,
251
 
            double   max_radius,
252
 
            int      volume_level)
253
 
{
254
 
        const int n_waves = 3;
255
 
        int last_wave;
256
 
        int i;
257
 
 
258
 
        last_wave = n_waves * volume_level / 100;
259
 
 
260
 
        for (i = 0; i < n_waves; i++) {
261
 
                double angle1;
262
 
                double angle2;
263
 
                double radius;
264
 
                double alpha;
265
 
 
266
 
                angle1 = -M_PI / 4;
267
 
                angle2 = M_PI / 4;
268
 
 
269
 
                if (i < last_wave)
270
 
                        alpha = 1.0;
271
 
                else if (i > last_wave)
272
 
                        alpha = 0.1;
273
 
                else alpha = 0.1 + 0.9 * (n_waves * volume_level % 100) / 100.0;
274
 
 
275
 
                radius = (i + 1) * (max_radius / n_waves);
276
 
                cairo_arc (cr, cx, cy, radius, angle1, angle2);
277
 
                cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, alpha / 2);
278
 
                cairo_set_line_width (cr, 14);
279
 
                cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
280
 
                cairo_stroke_preserve (cr);
281
 
 
282
 
                cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, alpha);
283
 
                cairo_set_line_width (cr, 10);
284
 
                cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
285
 
                cairo_stroke (cr);
286
 
        }
287
 
}
288
 
 
289
 
static void
290
 
draw_cross (cairo_t *cr,
291
 
            double   cx,
292
 
            double   cy,
293
 
            double   size)
294
 
{
295
 
        cairo_move_to (cr, cx, cy - size/2.0);
296
 
        cairo_rel_line_to (cr, size, size);
297
 
 
298
 
        cairo_move_to (cr, cx, cy + size/2.0);
299
 
        cairo_rel_line_to (cr, size, -size);
300
 
 
301
 
        cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, GSD_OSD_WINDOW_FG_ALPHA / 2);
302
 
        cairo_set_line_width (cr, 14);
303
 
        cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
304
 
        cairo_stroke_preserve (cr);
305
 
 
306
 
        cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, GSD_OSD_WINDOW_FG_ALPHA);
307
 
        cairo_set_line_width (cr, 10);
308
 
        cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
309
 
        cairo_stroke (cr);
310
 
}
311
 
 
312
 
static void
313
 
draw_speaker (cairo_t *cr,
314
 
              double   cx,
315
 
              double   cy,
316
 
              double   width,
317
 
              double   height)
318
 
{
319
 
        double box_width;
320
 
        double box_height;
321
 
        double _x0;
322
 
        double _y0;
323
 
 
324
 
        box_width = width / 3;
325
 
        box_height = height / 3;
326
 
 
327
 
        _x0 = cx - (width / 2) + box_width;
328
 
        _y0 = cy - box_height / 2;
329
 
 
330
 
        cairo_move_to (cr, _x0, _y0);
331
 
        cairo_rel_line_to (cr, - box_width, 0);
332
 
        cairo_rel_line_to (cr, 0, box_height);
333
 
        cairo_rel_line_to (cr, box_width, 0);
334
 
 
335
 
        cairo_line_to (cr, cx + box_width, cy + height / 2);
336
 
        cairo_rel_line_to (cr, 0, -height);
337
 
        cairo_line_to (cr, _x0, _y0);
338
 
        cairo_close_path (cr);
339
 
 
340
 
        cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, GSD_OSD_WINDOW_FG_ALPHA);
341
 
        cairo_fill_preserve (cr);
342
 
 
343
 
        cairo_set_source_rgba (cr, 0.6, 0.6, 0.6, GSD_OSD_WINDOW_FG_ALPHA / 2);
344
 
        cairo_set_line_width (cr, 2);
345
 
        cairo_stroke (cr);
346
 
}
347
 
 
348
 
static gboolean
349
 
render_speaker (GsdMediaKeysWindow *window,
350
 
                cairo_t            *cr,
351
 
                double              _x0,
352
 
                double              _y0,
353
 
                double              width,
354
 
                double              height)
355
 
{
356
 
        GdkPixbuf         *pixbuf;
357
 
        int                icon_size;
358
 
        int                n;
359
 
        static const char *icon_names[] = {
360
 
                "audio-volume-muted",
361
 
                "audio-volume-low",
362
 
                "audio-volume-medium",
363
 
                "audio-volume-high",
364
 
                NULL
365
 
        };
366
 
 
367
 
        if (window->priv->volume_muted) {
368
 
                n = 0;
369
 
        } else {
370
 
                /* select image */
371
 
                n = 3 * window->priv->volume_level / 100 + 1;
372
 
                if (n < 1) {
373
 
                        n = 1;
374
 
                } else if (n > 3) {
375
 
                        n = 3;
376
 
                }
377
 
        }
378
 
 
379
 
        icon_size = (int)width;
380
 
 
381
 
        pixbuf = load_pixbuf (window, icon_names[n], icon_size);
382
 
 
383
 
        if (pixbuf == NULL) {
384
 
                return FALSE;
385
 
        }
386
 
 
387
 
        gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0);
388
 
        cairo_paint_with_alpha (cr, GSD_OSD_WINDOW_FG_ALPHA);
389
 
 
390
 
        g_object_unref (pixbuf);
391
 
 
392
 
        return TRUE;
393
 
}
394
 
 
395
 
#define LIGHTNESS_MULT  1.3
396
 
#define DARKNESS_MULT   0.7
397
 
 
398
 
static void
399
 
draw_volume_boxes (GsdMediaKeysWindow *window,
400
 
                   cairo_t            *cr,
401
 
                   double              percentage,
402
 
                   double              _x0,
403
 
                   double              _y0,
404
 
                   double              width,
405
 
                   double              height)
406
 
{
407
 
        gdouble   x1;
408
 
        GtkStyleContext *context;
409
 
        GdkRGBA  acolor;
410
 
 
411
 
        _x0 += 0.5;
412
 
        _y0 += 0.5;
413
 
        height = round (height) - 1;
414
 
        width = round (width) - 1;
415
 
        x1 = round ((width - 1) * percentage);
416
 
        context = gtk_widget_get_style_context (GTK_WIDGET (window));
417
 
 
418
 
        /* bar background */
419
 
        gtk_style_context_get_background_color (context, GTK_STATE_NORMAL, &acolor);
420
 
        gsd_osd_window_color_shade (&acolor, DARKNESS_MULT);
421
 
        gsd_osd_window_color_reverse (&acolor);
422
 
        acolor.alpha = GSD_OSD_WINDOW_FG_ALPHA / 2;
423
 
        gsd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0, _y0, height / 6, width, height);
424
 
        gdk_cairo_set_source_rgba (cr, &acolor);
425
 
        cairo_fill_preserve (cr);
426
 
 
427
 
        /* bar border */
428
 
        gtk_style_context_get_background_color (context, GTK_STATE_NORMAL, &acolor);
429
 
        gsd_osd_window_color_shade (&acolor, LIGHTNESS_MULT);
430
 
        gsd_osd_window_color_reverse (&acolor);
431
 
        acolor.alpha = GSD_OSD_WINDOW_FG_ALPHA / 2;
432
 
        gdk_cairo_set_source_rgba (cr, &acolor);
433
 
        cairo_set_line_width (cr, 1);
434
 
        cairo_stroke (cr);
435
 
 
436
 
        /* bar progress */
437
 
        if (percentage < 0.01)
438
 
                return;
439
 
        gtk_style_context_get_background_color (context, GTK_STATE_NORMAL, &acolor);
440
 
        acolor.alpha = GSD_OSD_WINDOW_FG_ALPHA;
441
 
        gsd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0 + 0.5, _y0 + 0.5, height / 6 - 0.5, x1, height - 1);
442
 
        gdk_cairo_set_source_rgba (cr, &acolor);
443
 
        cairo_fill (cr);
444
 
}
445
 
 
446
 
static void
447
 
draw_action_volume (GsdMediaKeysWindow *window,
448
 
                    cairo_t            *cr)
449
 
{
450
 
        int window_width;
451
 
        int window_height;
452
 
        double icon_box_width;
453
 
        double icon_box_height;
454
 
        double icon_box_x0;
455
 
        double icon_box_y0;
456
 
        double volume_box_x0;
457
 
        double volume_box_y0;
458
 
        double volume_box_width;
459
 
        double volume_box_height;
460
 
        gboolean res;
461
 
 
462
 
        gtk_window_get_size (GTK_WINDOW (window), &window_width, &window_height);
463
 
 
464
 
        icon_box_width = round (window_width * 0.65);
465
 
        icon_box_height = round (window_height * 0.65);
466
 
        volume_box_width = icon_box_width;
467
 
        volume_box_height = round (window_height * 0.05);
468
 
 
469
 
        icon_box_x0 = (window_width - icon_box_width) / 2;
470
 
        icon_box_y0 = (window_height - icon_box_height - volume_box_height) / 2;
471
 
        volume_box_x0 = round (icon_box_x0);
472
 
        volume_box_y0 = round (icon_box_height + icon_box_y0);
473
 
 
474
 
#if 0
475
 
        g_message ("icon box: w=%f h=%f _x0=%f _y0=%f",
476
 
                   icon_box_width,
477
 
                   icon_box_height,
478
 
                   icon_box_x0,
479
 
                   icon_box_y0);
480
 
        g_message ("volume box: w=%f h=%f _x0=%f _y0=%f",
481
 
                   volume_box_width,
482
 
                   volume_box_height,
483
 
                   volume_box_x0,
484
 
                   volume_box_y0);
485
 
#endif
486
 
 
487
 
        res = render_speaker (window,
488
 
                              cr,
489
 
                              icon_box_x0, icon_box_y0,
490
 
                              icon_box_width, icon_box_height);
491
 
        if (! res) {
492
 
                double speaker_width;
493
 
                double speaker_height;
494
 
                double speaker_cx;
495
 
                double speaker_cy;
496
 
 
497
 
                speaker_width = icon_box_width * 0.5;
498
 
                speaker_height = icon_box_height * 0.75;
499
 
                speaker_cx = icon_box_x0 + speaker_width / 2;
500
 
                speaker_cy = icon_box_y0 + speaker_height / 2;
501
 
 
502
 
#if 0
503
 
                g_message ("speaker box: w=%f h=%f cx=%f cy=%f",
504
 
                           speaker_width,
505
 
                           speaker_height,
506
 
                           speaker_cx,
507
 
                           speaker_cy);
508
 
#endif
509
 
 
510
 
                /* draw speaker symbol */
511
 
                draw_speaker (cr, speaker_cx, speaker_cy, speaker_width, speaker_height);
512
 
 
513
 
                if (! window->priv->volume_muted) {
514
 
                        /* draw sound waves */
515
 
                        double wave_x0;
516
 
                        double wave_y0;
517
 
                        double wave_radius;
518
 
 
519
 
                        wave_x0 = window_width / 2;
520
 
                        wave_y0 = speaker_cy;
521
 
                        wave_radius = icon_box_width / 2;
522
 
 
523
 
                        draw_waves (cr, wave_x0, wave_y0, wave_radius, window->priv->volume_level);
524
 
                } else {
525
 
                        /* draw 'mute' cross */
526
 
                        double cross_x0;
527
 
                        double cross_y0;
528
 
                        double cross_size;
529
 
 
530
 
                        cross_size = speaker_width * 3 / 4;
531
 
                        cross_x0 = icon_box_x0 + icon_box_width - cross_size;
532
 
                        cross_y0 = speaker_cy;
533
 
 
534
 
                        draw_cross (cr, cross_x0, cross_y0, cross_size);
535
 
                }
536
 
        }
537
 
 
538
 
        /* draw volume meter */
539
 
        draw_volume_boxes (window,
540
 
                           cr,
541
 
                           (double)window->priv->volume_level / 100.0,
542
 
                           volume_box_x0,
543
 
                           volume_box_y0,
544
 
                           volume_box_width,
545
 
                           volume_box_height);
546
 
}
547
 
 
548
 
static gboolean
549
 
render_custom (GsdMediaKeysWindow *window,
550
 
               cairo_t            *cr,
551
 
               double              _x0,
552
 
               double              _y0,
553
 
               double              width,
554
 
               double              height)
555
 
{
556
 
        GdkPixbuf         *pixbuf;
557
 
        int                icon_size;
558
 
 
559
 
        icon_size = (int)width;
560
 
 
561
 
        pixbuf = load_pixbuf (window, window->priv->icon_name, icon_size);
562
 
 
563
 
        if (pixbuf == NULL) {
564
 
                char *name;
565
 
                if (gtk_widget_get_direction (GTK_WIDGET (window)) == GTK_TEXT_DIR_RTL)
566
 
                        name = g_strdup_printf ("%s-rtl", window->priv->icon_name);
567
 
                else
568
 
                        name = g_strdup_printf ("%s-ltr", window->priv->icon_name);
569
 
                pixbuf = load_pixbuf (window, name, icon_size);
570
 
                g_free (name);
571
 
                if (pixbuf == NULL)
572
 
                        return FALSE;
573
 
        }
574
 
 
575
 
        gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0);
576
 
        cairo_paint_with_alpha (cr, GSD_OSD_WINDOW_FG_ALPHA);
577
 
 
578
 
        g_object_unref (pixbuf);
579
 
 
580
 
        return TRUE;
581
 
}
582
 
 
583
 
static void
584
 
draw_action_custom (GsdMediaKeysWindow *window,
585
 
                    cairo_t            *cr)
586
 
{
587
 
        int window_width;
588
 
        int window_height;
589
 
        double icon_box_width;
590
 
        double icon_box_height;
591
 
        double icon_box_x0;
592
 
        double icon_box_y0;
593
 
        double bright_box_x0;
594
 
        double bright_box_y0;
595
 
        double bright_box_width;
596
 
        double bright_box_height;
597
 
        gboolean res;
598
 
 
599
 
        gtk_window_get_size (GTK_WINDOW (window), &window_width, &window_height);
600
 
 
601
 
        icon_box_width = round (window_width * 0.65);
602
 
        icon_box_height = round (window_height * 0.65);
603
 
        bright_box_width = round (icon_box_width);
604
 
        bright_box_height = round (window_height * 0.05);
605
 
 
606
 
        icon_box_x0 = (window_width - icon_box_width) / 2;
607
 
        icon_box_y0 = (window_height - icon_box_height - bright_box_height) / 2;
608
 
        bright_box_x0 = round (icon_box_x0);
609
 
        bright_box_y0 = round (icon_box_height + icon_box_y0);
610
 
 
611
 
#if 0
612
 
        g_message ("icon box: w=%f h=%f _x0=%f _y0=%f",
613
 
                   icon_box_width,
614
 
                   icon_box_height,
615
 
                   icon_box_x0,
616
 
                   icon_box_y0);
617
 
        g_message ("brightness box: w=%f h=%f _x0=%f _y0=%f",
618
 
                   bright_box_width,
619
 
                   bright_box_height,
620
 
                   bright_box_x0,
621
 
                   bright_box_y0);
622
 
#endif
623
 
 
624
 
        res = render_custom (window,
625
 
                             cr,
626
 
                             icon_box_x0, icon_box_y0,
627
 
                             icon_box_width, icon_box_height);
628
 
        if (! res && g_strcmp0 (window->priv->icon_name, "media-eject") == 0) {
629
 
                /* draw eject symbol */
630
 
                draw_eject (cr,
631
 
                            icon_box_x0, icon_box_y0,
632
 
                            icon_box_width, icon_box_height);
633
 
        }
634
 
 
635
 
        if (window->priv->show_level != FALSE) {
636
 
                /* draw volume meter */
637
 
                draw_volume_boxes (window,
638
 
                                   cr,
639
 
                                   (double)window->priv->volume_level / 100.0,
640
 
                                   bright_box_x0,
641
 
                                   bright_box_y0,
642
 
                                   bright_box_width,
643
 
                                   bright_box_height);
644
 
        }
645
 
}
646
 
 
647
 
static void
648
 
gsd_media_keys_window_draw_when_composited (GsdOsdWindow *osd_window,
649
 
                                            cairo_t      *cr)
650
 
{
651
 
        GsdMediaKeysWindow *window = GSD_MEDIA_KEYS_WINDOW (osd_window);
652
 
 
653
 
        switch (window->priv->action) {
654
 
        case GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME:
655
 
                draw_action_volume (window, cr);
656
 
                break;
657
 
        case GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM:
658
 
                draw_action_custom (window, cr);
659
 
                break;
660
 
        default:
661
 
                break;
662
 
        }
663
 
}
664
 
 
665
 
static void
666
 
gsd_media_keys_window_class_init (GsdMediaKeysWindowClass *klass)
667
 
{
668
 
        GsdOsdWindowClass *osd_window_class = GSD_OSD_WINDOW_CLASS (klass);
669
 
 
670
 
        osd_window_class->draw_when_composited = gsd_media_keys_window_draw_when_composited;
671
 
 
672
 
        g_type_class_add_private (klass, sizeof (GsdMediaKeysWindowPrivate));
673
 
}
674
 
 
675
 
static void
676
 
gsd_media_keys_window_init (GsdMediaKeysWindow *window)
677
 
{
678
 
        window->priv = GSD_MEDIA_KEYS_WINDOW_GET_PRIVATE (window);
679
 
 
680
 
        if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window))) {
681
 
                GtkBuilder *builder;
682
 
                const gchar *objects[] = {"acme_box", NULL};
683
 
                GtkWidget *box;
684
 
 
685
 
                builder = gtk_builder_new ();
686
 
                gtk_builder_add_objects_from_file (builder,
687
 
                                                   GTKBUILDERDIR "/acme.ui",
688
 
                                                   (char **) objects,
689
 
                                                   NULL);
690
 
 
691
 
                window->priv->image = GTK_IMAGE (gtk_builder_get_object (builder, "acme_image"));
692
 
                window->priv->progress = GTK_WIDGET (gtk_builder_get_object (builder, "acme_volume_progressbar"));
693
 
                box = GTK_WIDGET (gtk_builder_get_object (builder, "acme_box"));
694
 
 
695
 
                if (box != NULL) {
696
 
                        gtk_container_add (GTK_CONTAINER (window), box);
697
 
                        gtk_widget_show_all (box);
698
 
                }
699
 
 
700
 
                /* The builder needs to stay alive until the window
701
 
                   takes ownership of the box (and its children)  */
702
 
                g_object_unref (builder);
703
 
        }
704
 
}
705
 
 
706
 
GtkWidget *
707
 
gsd_media_keys_window_new (void)
708
 
{
709
 
        return g_object_new (GSD_TYPE_MEDIA_KEYS_WINDOW, NULL);
710
 
}