Updated Spanish translation
[empathy-mirror.git] / src / empathy-streamed-media-window-fullscreen.c
blobcaa34ffd1b249fc2338eb75bef01c30b474c0d13
1 /*
2 * empathy-streamed-media-window-fullscreen.c - Source for EmpathyStreamedMediaWindowFullscreen
3 * Copyright (C) 2009 Collabora Ltd.
5 * Some code is based on the Totem Movie Player, especially
6 * totem-fullscreen.c which has the following copyright:
7 * Copyright (C) 2001-2007 Bastien Nocera <hadess@hadess.net>
8 * Copyright (C) 2007 Sunil Mohan Adapa <sunilmohan@gnu.org.in>
10 * This library 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.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "empathy-streamed-media-window-fullscreen.h"
27 #include <gtk/gtk.h>
29 #include <libempathy/empathy-utils.h>
30 #include <libempathy-gtk/empathy-ui-utils.h>
32 /* The number of seconds for which the "leave fullscreen" popup should
33 be shown */
34 #define FULLSCREEN_POPUP_TIMEOUT 5
36 G_DEFINE_TYPE (EmpathyStreamedMediaWindowFullscreen, empathy_streamed_media_window_fullscreen,
37 G_TYPE_OBJECT)
39 /* private structure */
40 typedef struct _EmpathyStreamedMediaWindowFullscreenPriv
41 EmpathyStreamedMediaWindowFullscreenPriv;
43 struct _EmpathyStreamedMediaWindowFullscreenPriv
45 EmpathyStreamedMediaWindow *parent_window;
47 GtkWidget *leave_fullscreen_popup;
48 GtkWidget *video_widget;
50 guint popup_timeout;
51 gboolean popup_creation_in_progress;
52 gboolean dispose_has_run;
55 #define GET_PRIV(o) \
56 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_STREAMED_MEDIA_WINDOW_FULLSCREEN, \
57 EmpathyStreamedMediaWindowFullscreenPriv))
59 static void empathy_streamed_media_window_fullscreen_dispose (GObject *object);
60 static void empathy_streamed_media_window_fullscreen_finalize (GObject *object);
62 static gboolean empathy_streamed_media_window_fullscreen_hide_popup (
63 EmpathyStreamedMediaWindowFullscreen *fs);
65 static void
66 empathy_streamed_media_window_fullscreen_set_cursor_visible (
67 EmpathyStreamedMediaWindowFullscreen *fs,
68 gboolean show_cursor)
70 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (fs);
71 GdkWindow *window;
73 if (priv->video_widget == NULL)
74 return;
76 window = gtk_widget_get_window (priv->video_widget);
78 if (!show_cursor)
79 gdk_window_set_cursor (window, gdk_cursor_new (GDK_BLANK_CURSOR));
80 else
81 gdk_window_set_cursor (window, NULL);
84 static void
85 empathy_streamed_media_window_fullscreen_add_popup_timeout (
86 EmpathyStreamedMediaWindowFullscreen *self)
88 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (self);
90 if (priv->popup_timeout == 0)
92 priv->popup_timeout = g_timeout_add_seconds (FULLSCREEN_POPUP_TIMEOUT,
93 (GSourceFunc) empathy_streamed_media_window_fullscreen_hide_popup, self);
97 static void
98 empathy_streamed_media_window_fullscreen_remove_popup_timeout (
99 EmpathyStreamedMediaWindowFullscreen *self)
101 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (self);
103 if (priv->popup_timeout != 0)
105 g_source_remove (priv->popup_timeout);
106 priv->popup_timeout = 0;
110 void
111 empathy_streamed_media_window_fullscreen_show_popup (EmpathyStreamedMediaWindowFullscreen *self)
113 gint leave_fullscreen_width, leave_fullscreen_height;
114 GdkScreen *screen;
115 GdkRectangle fullscreen_rect;
116 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (self);
118 g_assert (self->is_fullscreen);
120 g_return_if_fail (priv->parent_window != NULL);
122 if (priv->popup_creation_in_progress)
123 return;
125 if (!gtk_window_is_active (GTK_WINDOW (priv->parent_window)))
126 return;
128 priv->popup_creation_in_progress = TRUE;
130 empathy_streamed_media_window_fullscreen_set_cursor_visible (self, TRUE);
132 /* Obtaining the screen rectangle */
133 screen = gtk_window_get_screen (GTK_WINDOW (priv->parent_window));
134 gdk_screen_get_monitor_geometry (screen,
135 gdk_screen_get_monitor_at_window (screen,
136 gtk_widget_get_window (GTK_WIDGET (priv->parent_window))),
137 &fullscreen_rect);
139 /* Getting the popup window sizes */
140 gtk_window_get_size (GTK_WINDOW (priv->leave_fullscreen_popup),
141 &leave_fullscreen_width, &leave_fullscreen_height);
143 /* Moving the popup to the top-right corner (if the direction is LTR) or the
144 top-left corner (if the direction is RTL).*/
145 if (gtk_widget_get_direction (priv->leave_fullscreen_popup)
146 == GTK_TEXT_DIR_LTR)
148 gtk_window_move (GTK_WINDOW (priv->leave_fullscreen_popup),
149 fullscreen_rect.width + fullscreen_rect.x - leave_fullscreen_width,
150 fullscreen_rect.y);
153 else
155 gtk_window_move (GTK_WINDOW (priv->leave_fullscreen_popup),
156 fullscreen_rect.x, fullscreen_rect.y);
159 gtk_widget_show_all (priv->leave_fullscreen_popup);
160 empathy_streamed_media_window_fullscreen_add_popup_timeout (self);
162 priv->popup_creation_in_progress = FALSE;
165 static gboolean
166 empathy_streamed_media_window_fullscreen_hide_popup (EmpathyStreamedMediaWindowFullscreen *fs)
168 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (fs);
170 if (priv->video_widget == NULL || !fs->is_fullscreen)
171 return TRUE;
173 gtk_widget_hide (priv->leave_fullscreen_popup);
174 empathy_streamed_media_window_fullscreen_remove_popup_timeout (fs);
176 empathy_streamed_media_window_fullscreen_set_cursor_visible (fs, FALSE);
178 return FALSE;
181 static void
182 empathy_streamed_media_window_fullscreen_init (EmpathyStreamedMediaWindowFullscreen *self)
184 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (self);
185 GtkBuilder *gui;
186 gchar *filename;
188 filename = empathy_file_lookup ("empathy-call-window-fullscreen.ui", "src");
189 gui = empathy_builder_get_file (filename,
190 "leave_fullscreen_window", &priv->leave_fullscreen_popup,
191 "leave_fullscreen_button", &self->leave_fullscreen_button,
192 NULL);
194 gtk_widget_add_events (priv->leave_fullscreen_popup, GDK_POINTER_MOTION_MASK);
196 g_object_unref (gui);
197 g_free (filename);
200 static void
201 empathy_streamed_media_window_fullscreen_class_init (
202 EmpathyStreamedMediaWindowFullscreenClass *klass)
204 GObjectClass *object_class = G_OBJECT_CLASS (klass);
206 g_type_class_add_private (klass, sizeof (EmpathyStreamedMediaWindowFullscreenPriv));
208 object_class->dispose = empathy_streamed_media_window_fullscreen_dispose;
209 object_class->finalize = empathy_streamed_media_window_fullscreen_finalize;
212 void
213 empathy_streamed_media_window_fullscreen_dispose (GObject *object)
215 EmpathyStreamedMediaWindowFullscreen *self = EMPATHY_STREAMED_MEDIA_WINDOW_FULLSCREEN (object);
216 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (self);
218 if (priv->dispose_has_run)
219 return;
221 priv->dispose_has_run = TRUE;
223 if (priv->leave_fullscreen_popup != NULL)
224 gtk_widget_destroy (priv->leave_fullscreen_popup);
225 priv->leave_fullscreen_popup = NULL;
227 if (G_OBJECT_CLASS (empathy_streamed_media_window_fullscreen_parent_class)->dispose)
229 G_OBJECT_CLASS (
230 empathy_streamed_media_window_fullscreen_parent_class)->dispose (object);
234 void
235 empathy_streamed_media_window_fullscreen_finalize (GObject *object)
237 EmpathyStreamedMediaWindowFullscreen *self = EMPATHY_STREAMED_MEDIA_WINDOW_FULLSCREEN (object);
239 empathy_streamed_media_window_fullscreen_remove_popup_timeout (self);
241 G_OBJECT_CLASS (
242 empathy_streamed_media_window_fullscreen_parent_class)->finalize (object);
245 static void
246 empathy_streamed_media_window_fullscreen_parent_window_notify (GtkWidget *parent_window,
247 GParamSpec *property, EmpathyStreamedMediaWindowFullscreen *fs)
249 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (fs);
251 if (!fs->is_fullscreen)
252 return;
254 if (parent_window == GTK_WIDGET (priv->parent_window) &&
255 !gtk_window_is_active (GTK_WINDOW (parent_window)))
257 empathy_streamed_media_window_fullscreen_hide_popup (fs);
258 empathy_streamed_media_window_fullscreen_set_cursor_visible (fs, TRUE);
262 EmpathyStreamedMediaWindowFullscreen *
263 empathy_streamed_media_window_fullscreen_new (EmpathyStreamedMediaWindow *parent_window)
265 EmpathyStreamedMediaWindowFullscreen *self = EMPATHY_STREAMED_MEDIA_WINDOW_FULLSCREEN (
266 g_object_new (EMPATHY_TYPE_STREAMED_MEDIA_WINDOW_FULLSCREEN, NULL));
267 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (self);
269 priv->parent_window = parent_window;
270 g_signal_connect (G_OBJECT (priv->parent_window), "notify::is-active",
271 G_CALLBACK (empathy_streamed_media_window_fullscreen_parent_window_notify), self);
273 return self;
276 void
277 empathy_streamed_media_window_fullscreen_set_fullscreen (EmpathyStreamedMediaWindowFullscreen *fs,
278 gboolean set_fullscreen)
281 if (set_fullscreen)
282 empathy_streamed_media_window_fullscreen_remove_popup_timeout (fs);
283 else
284 empathy_streamed_media_window_fullscreen_hide_popup (fs);
286 empathy_streamed_media_window_fullscreen_set_cursor_visible (fs, !set_fullscreen);
287 fs->is_fullscreen = set_fullscreen;
290 static void
291 video_widget_destroy_cb (GtkWidget *widget,
292 EmpathyStreamedMediaWindowFullscreen *self)
294 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (self);
296 priv->video_widget = NULL;
299 void
300 empathy_streamed_media_window_fullscreen_set_video_widget (
301 EmpathyStreamedMediaWindowFullscreen *fs,
302 GtkWidget *video_widget)
304 EmpathyStreamedMediaWindowFullscreenPriv *priv = GET_PRIV (fs);
305 priv->video_widget = video_widget;
307 tp_g_signal_connect_object (video_widget, "destroy",
308 G_CALLBACK (video_widget_destroy_cb), fs, 0);