~walkerlee/totem/pre-interview

« back to all changes in this revision

Viewing changes to src/backend/bacon-video-osd-actor.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
 * On-screen-display (OSD) for Totem's video widget
 
4
 *
 
5
 * Copyright (C) 2012 Red Hat, Inc.
 
6
 *
 
7
 * Authors:
 
8
 *   Bastien Nocera <hadess@hadess.net>
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or
 
11
 * modify it under the terms of the GNU Lesser General Public
 
12
 * License as published by the Free Software Foundation; either
 
13
 * version 2, or (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be
 
16
 * useful, but WITHOUT ANY WARRANTY; without even the implied
 
17
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 
18
 * PURPOSE.  See the GNU Lesser General Public License for more
 
19
 * details.
 
20
 *
 
21
 * You should have received a copy of the GNU Lesser General
 
22
 * Public License along with this program; if not, write to the
 
23
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
24
 * Boston, MA 02111-1307, USA.
 
25
 */
 
26
 
 
27
#include "config.h"
 
28
 
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
#include <math.h>
 
32
#include <glib.h>
 
33
#include <glib/gi18n.h>
 
34
#include <clutter/clutter.h>
 
35
#include <gtk/gtk.h>
 
36
 
 
37
#include "bacon-video-osd-actor.h"
 
38
#include "gsd-osd-window.h"
 
39
#include "gsd-osd-window-private.h"
 
40
 
 
41
#define BACON_VIDEO_OSD_ACTOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BACON_TYPE_VIDEO_OSD_ACTOR, BaconVideoOsdActorPrivate))
 
42
 
 
43
struct BaconVideoOsdActorPrivate
 
44
{
 
45
        ClutterCanvas     *canvas;
 
46
        char              *icon_name;
 
47
        GtkStyleContext   *style;
 
48
        GsdOsdDrawContext *ctx;
 
49
 
 
50
        guint              hide_timeout_id;
 
51
        guint              fade_timeout_id;
 
52
        double             fade_out_alpha;
 
53
};
 
54
 
 
55
G_DEFINE_TYPE (BaconVideoOsdActor, bacon_video_osd_actor, CLUTTER_TYPE_ACTOR);
 
56
 
 
57
static gboolean
 
58
fade_timeout (BaconVideoOsdActor *osd)
 
59
{
 
60
        if (osd->priv->fade_out_alpha <= 0.0) {
 
61
                bacon_video_osd_actor_hide (osd);
 
62
                return FALSE;
 
63
        } else {
 
64
                clutter_actor_set_opacity (CLUTTER_ACTOR (osd),
 
65
                                           0xff * osd->priv->fade_out_alpha);
 
66
                osd->priv->fade_out_alpha -= 0.10;
 
67
        }
 
68
 
 
69
        return TRUE;
 
70
}
 
71
 
 
72
static gboolean
 
73
hide_timeout (BaconVideoOsdActor *osd)
 
74
{
 
75
        osd->priv->hide_timeout_id = 0;
 
76
        osd->priv->fade_timeout_id = g_timeout_add (FADE_FRAME_TIMEOUT,
 
77
                                                    (GSourceFunc) fade_timeout,
 
78
                                                    osd);
 
79
 
 
80
        return FALSE;
 
81
}
 
82
 
 
83
static void
 
84
remove_hide_timeout (BaconVideoOsdActor *osd)
 
85
{
 
86
        if (osd->priv->hide_timeout_id != 0) {
 
87
                g_source_remove (osd->priv->hide_timeout_id);
 
88
                osd->priv->hide_timeout_id = 0;
 
89
        }
 
90
 
 
91
        if (osd->priv->fade_timeout_id != 0) {
 
92
                g_source_remove (osd->priv->fade_timeout_id);
 
93
                osd->priv->fade_timeout_id = 0;
 
94
                osd->priv->fade_out_alpha = 1.0;
 
95
        }
 
96
}
 
97
 
 
98
static void
 
99
add_hide_timeout (BaconVideoOsdActor *osd)
 
100
{
 
101
        osd->priv->hide_timeout_id = g_timeout_add (DIALOG_FADE_TIMEOUT,
 
102
                                                    (GSourceFunc) hide_timeout,
 
103
                                                    osd);
 
104
}
 
105
 
 
106
static void
 
107
bacon_video_osd_actor_finalize (GObject *object)
 
108
{
 
109
        BaconVideoOsdActor *osd;
 
110
 
 
111
        osd = BACON_VIDEO_OSD_ACTOR (object);
 
112
        if (osd->priv->ctx) {
 
113
                g_free (osd->priv->ctx);
 
114
                osd->priv->ctx = NULL;
 
115
        }
 
116
        if (osd->priv->style) {
 
117
                g_object_unref (osd->priv->style);
 
118
                osd->priv->style = NULL;
 
119
        }
 
120
 
 
121
        g_free (osd->priv->icon_name);
 
122
        osd->priv->icon_name = NULL;
 
123
 
 
124
        G_OBJECT_CLASS (bacon_video_osd_actor_parent_class)->finalize (object);
 
125
}
 
126
 
 
127
static void
 
128
bacon_video_osd_actor_class_init (BaconVideoOsdActorClass *klass)
 
129
{
 
130
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
131
 
 
132
//        gobject_class->constructor = bacon_video_osd_actor_constructor;
 
133
        gobject_class->finalize = bacon_video_osd_actor_finalize;
 
134
 
 
135
        g_type_class_add_private (klass, sizeof (BaconVideoOsdActorPrivate));
 
136
}
 
137
 
 
138
static gboolean
 
139
bacon_video_osd_actor_draw (ClutterCanvas      *canvas,
 
140
                            cairo_t            *cr,
 
141
                            int                 width,
 
142
                            int                 height,
 
143
                            BaconVideoOsdActor *osd)
 
144
{
 
145
        GsdOsdDrawContext *ctx;
 
146
 
 
147
        g_return_val_if_fail (osd->priv->icon_name != NULL, FALSE);
 
148
 
 
149
        ctx = osd->priv->ctx;
 
150
 
 
151
        cairo_save (cr);
 
152
        cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
 
153
        cairo_paint (cr);
 
154
 
 
155
        cairo_restore (cr);
 
156
        cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 
157
 
 
158
        ctx->size = MIN(width, height);
 
159
        ctx->icon_name = osd->priv->icon_name;
 
160
 
 
161
        gsd_osd_window_draw (ctx, cr);
 
162
 
 
163
        return FALSE;
 
164
}
 
165
 
 
166
static void
 
167
bacon_video_osd_actor_init (BaconVideoOsdActor *osd)
 
168
{
 
169
        ClutterActor *self;
 
170
        GtkWidgetPath *widget_path;
 
171
 
 
172
        self = CLUTTER_ACTOR (osd);
 
173
        osd->priv = BACON_VIDEO_OSD_ACTOR_GET_PRIVATE (osd);
 
174
 
 
175
        osd->priv->canvas = CLUTTER_CANVAS (clutter_canvas_new ());
 
176
        g_object_bind_property (self, "width",
 
177
                                osd->priv->canvas, "width",
 
178
                                G_BINDING_DEFAULT);
 
179
        g_object_bind_property (self, "height",
 
180
                                osd->priv->canvas, "height",
 
181
                                G_BINDING_DEFAULT);
 
182
        clutter_actor_set_content (self, CLUTTER_CONTENT (osd->priv->canvas));
 
183
        g_object_unref (osd->priv->canvas);
 
184
 
 
185
        osd->priv->icon_name = g_strdup ("media-playback-pause-symbolic");
 
186
 
 
187
        osd->priv->ctx = g_new0 (GsdOsdDrawContext, 1);
 
188
 
 
189
        widget_path = gtk_widget_path_new ();
 
190
        gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
 
191
        osd->priv->style = gtk_style_context_new ();
 
192
        gtk_style_context_set_path (osd->priv->style, widget_path);
 
193
        gtk_widget_path_free (widget_path);
 
194
 
 
195
        osd->priv->ctx->direction = clutter_get_default_text_direction ();
 
196
        osd->priv->ctx->theme = gtk_icon_theme_get_default ();
 
197
        osd->priv->ctx->action = GSD_OSD_WINDOW_ACTION_CUSTOM;
 
198
        osd->priv->ctx->style = osd->priv->style;
 
199
 
 
200
        g_signal_connect (osd->priv->canvas, "draw", G_CALLBACK (bacon_video_osd_actor_draw), osd);
 
201
        osd->priv->fade_out_alpha = 1.0;
 
202
}
 
203
 
 
204
ClutterActor *
 
205
bacon_video_osd_actor_new (void)
 
206
{
 
207
        return g_object_new (BACON_TYPE_VIDEO_OSD_ACTOR, NULL);
 
208
}
 
209
 
 
210
void
 
211
bacon_video_osd_actor_set_icon_name (BaconVideoOsdActor *osd,
 
212
                                     const char         *icon_name)
 
213
{
 
214
        g_return_if_fail (BACON_IS_VIDEO_OSD_ACTOR (osd));
 
215
 
 
216
        g_free (osd->priv->icon_name);
 
217
        osd->priv->icon_name = g_strdup (icon_name);
 
218
 
 
219
        if (icon_name != NULL)
 
220
                clutter_content_invalidate (CLUTTER_CONTENT (osd->priv->canvas));
 
221
}
 
222
 
 
223
void
 
224
bacon_video_osd_actor_hide (BaconVideoOsdActor *osd)
 
225
{
 
226
        g_return_if_fail (BACON_IS_VIDEO_OSD_ACTOR (osd));
 
227
 
 
228
        clutter_actor_hide (CLUTTER_ACTOR (osd));
 
229
 
 
230
        /* Reset it for the next time */
 
231
        osd->priv->fade_out_alpha = 1.0;
 
232
        osd->priv->fade_timeout_id = 0;
 
233
}
 
234
 
 
235
void
 
236
bacon_video_osd_actor_show (BaconVideoOsdActor *osd)
 
237
{
 
238
        g_return_if_fail (BACON_IS_VIDEO_OSD_ACTOR (osd));
 
239
 
 
240
        remove_hide_timeout (osd);
 
241
        clutter_actor_set_opacity (CLUTTER_ACTOR (osd), 0xff);
 
242
        clutter_actor_show (CLUTTER_ACTOR (osd));
 
243
}
 
244
 
 
245
void
 
246
bacon_video_osd_actor_show_and_fade (BaconVideoOsdActor *osd)
 
247
{
 
248
        g_return_if_fail (BACON_IS_VIDEO_OSD_ACTOR (osd));
 
249
 
 
250
        remove_hide_timeout (osd);
 
251
        clutter_actor_set_opacity (CLUTTER_ACTOR (osd), 0xff);
 
252
        clutter_actor_show (CLUTTER_ACTOR (osd));
 
253
        add_hide_timeout (osd);
 
254
}