2 * empathy-call-window-fullscreen.c - Source for EmpathyCallWindowFullscreen
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-call-window-fullscreen.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
34 #define FULLSCREEN_POPUP_TIMEOUT 5
36 G_DEFINE_TYPE (EmpathyCallWindowFullscreen
, empathy_call_window_fullscreen
,
39 /* private structure */
40 typedef struct _EmpathyCallWindowFullscreenPriv
41 EmpathyCallWindowFullscreenPriv
;
43 struct _EmpathyCallWindowFullscreenPriv
45 EmpathyCallWindow
*parent_window
;
47 GtkWidget
*leave_fullscreen_popup
;
48 GtkWidget
*video_widget
;
51 gboolean popup_creation_in_progress
;
52 gboolean dispose_has_run
;
56 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_CALL_WINDOW_FULLSCREEN, \
57 EmpathyCallWindowFullscreenPriv))
59 static void empathy_call_window_fullscreen_dispose (GObject
*object
);
60 static void empathy_call_window_fullscreen_finalize (GObject
*object
);
62 static gboolean
empathy_call_window_fullscreen_hide_popup (
63 EmpathyCallWindowFullscreen
*fs
);
66 empathy_call_window_fullscreen_set_cursor_visible (
67 EmpathyCallWindowFullscreen
*fs
,
70 EmpathyCallWindowFullscreenPriv
*priv
= GET_PRIV (fs
);
72 if (priv
->video_widget
!= NULL
&& !show_cursor
)
74 gdk_window_set_cursor (gtk_widget_get_window (priv
->video_widget
),
75 gdk_cursor_new (GDK_BLANK_CURSOR
));
78 gdk_window_set_cursor (gtk_widget_get_window (priv
->video_widget
), NULL
);
82 empathy_call_window_fullscreen_add_popup_timeout (
83 EmpathyCallWindowFullscreen
*self
)
85 EmpathyCallWindowFullscreenPriv
*priv
= GET_PRIV (self
);
87 if (priv
->popup_timeout
== 0)
89 priv
->popup_timeout
= g_timeout_add_seconds (FULLSCREEN_POPUP_TIMEOUT
,
90 (GSourceFunc
) empathy_call_window_fullscreen_hide_popup
, self
);
95 empathy_call_window_fullscreen_remove_popup_timeout (
96 EmpathyCallWindowFullscreen
*self
)
98 EmpathyCallWindowFullscreenPriv
*priv
= GET_PRIV (self
);
100 if (priv
->popup_timeout
!= 0)
102 g_source_remove (priv
->popup_timeout
);
103 priv
->popup_timeout
= 0;
108 empathy_call_window_fullscreen_show_popup (EmpathyCallWindowFullscreen
*self
)
110 gint leave_fullscreen_width
, leave_fullscreen_height
;
112 GdkRectangle fullscreen_rect
;
113 EmpathyCallWindowFullscreenPriv
*priv
= GET_PRIV (self
);
115 g_assert (self
->is_fullscreen
);
117 g_return_if_fail (priv
->parent_window
!= NULL
);
119 if (priv
->popup_creation_in_progress
)
122 if (!gtk_window_is_active (GTK_WINDOW (priv
->parent_window
)))
125 priv
->popup_creation_in_progress
= TRUE
;
127 empathy_call_window_fullscreen_set_cursor_visible (self
, TRUE
);
129 /* Obtaining the screen rectangle */
130 screen
= gtk_window_get_screen (GTK_WINDOW (priv
->parent_window
));
131 gdk_screen_get_monitor_geometry (screen
,
132 gdk_screen_get_monitor_at_window (screen
,
133 gtk_widget_get_window (GTK_WIDGET (priv
->parent_window
))),
136 /* Getting the popup window sizes */
137 gtk_window_get_size (GTK_WINDOW (priv
->leave_fullscreen_popup
),
138 &leave_fullscreen_width
, &leave_fullscreen_height
);
140 /* Moving the popup to the top-right corner (if the direction is LTR) or the
141 top-left corner (if the direction is RTL).*/
142 if (gtk_widget_get_direction (priv
->leave_fullscreen_popup
)
145 gtk_window_move (GTK_WINDOW (priv
->leave_fullscreen_popup
),
146 fullscreen_rect
.width
+ fullscreen_rect
.x
- leave_fullscreen_width
,
152 gtk_window_move (GTK_WINDOW (priv
->leave_fullscreen_popup
),
153 fullscreen_rect
.x
, fullscreen_rect
.y
);
156 gtk_widget_show_all (priv
->leave_fullscreen_popup
);
157 empathy_call_window_fullscreen_add_popup_timeout (self
);
159 priv
->popup_creation_in_progress
= FALSE
;
163 empathy_call_window_fullscreen_hide_popup (EmpathyCallWindowFullscreen
*fs
)
165 EmpathyCallWindowFullscreenPriv
*priv
= GET_PRIV (fs
);
167 if (priv
->video_widget
== NULL
|| !fs
->is_fullscreen
)
170 gtk_widget_hide (priv
->leave_fullscreen_popup
);
171 empathy_call_window_fullscreen_remove_popup_timeout (fs
);
173 empathy_call_window_fullscreen_set_cursor_visible (fs
, FALSE
);
179 empathy_call_window_fullscreen_init (EmpathyCallWindowFullscreen
*self
)
181 EmpathyCallWindowFullscreenPriv
*priv
= GET_PRIV (self
);
185 filename
= empathy_file_lookup ("empathy-call-window-fullscreen.ui", "src");
186 gui
= empathy_builder_get_file (filename
,
187 "leave_fullscreen_window", &priv
->leave_fullscreen_popup
,
188 "leave_fullscreen_button", &self
->leave_fullscreen_button
,
191 gtk_widget_add_events (priv
->leave_fullscreen_popup
, GDK_POINTER_MOTION_MASK
);
193 g_object_unref (gui
);
198 empathy_call_window_fullscreen_class_init (
199 EmpathyCallWindowFullscreenClass
*klass
)
201 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
203 g_type_class_add_private (klass
, sizeof (EmpathyCallWindowFullscreenPriv
));
205 object_class
->dispose
= empathy_call_window_fullscreen_dispose
;
206 object_class
->finalize
= empathy_call_window_fullscreen_finalize
;
210 empathy_call_window_fullscreen_dispose (GObject
*object
)
212 EmpathyCallWindowFullscreen
*self
= EMPATHY_CALL_WINDOW_FULLSCREEN (object
);
213 EmpathyCallWindowFullscreenPriv
*priv
= GET_PRIV (self
);
215 if (priv
->dispose_has_run
)
218 priv
->dispose_has_run
= TRUE
;
220 if (priv
->leave_fullscreen_popup
!= NULL
)
221 gtk_widget_destroy (priv
->leave_fullscreen_popup
);
222 priv
->leave_fullscreen_popup
= NULL
;
224 if (G_OBJECT_CLASS (empathy_call_window_fullscreen_parent_class
)->dispose
)
227 empathy_call_window_fullscreen_parent_class
)->dispose (object
);
232 empathy_call_window_fullscreen_finalize (GObject
*object
)
234 EmpathyCallWindowFullscreen
*self
= EMPATHY_CALL_WINDOW_FULLSCREEN (object
);
236 empathy_call_window_fullscreen_remove_popup_timeout (self
);
239 empathy_call_window_fullscreen_parent_class
)->finalize (object
);
243 empathy_call_window_fullscreen_parent_window_notify (GtkWidget
*parent_window
,
244 GParamSpec
*property
, EmpathyCallWindowFullscreen
*fs
)
246 EmpathyCallWindowFullscreenPriv
*priv
= GET_PRIV (fs
);
248 if (!fs
->is_fullscreen
)
251 if (parent_window
== GTK_WIDGET (priv
->parent_window
) &&
252 !gtk_window_is_active (GTK_WINDOW (parent_window
)))
254 empathy_call_window_fullscreen_hide_popup (fs
);
255 empathy_call_window_fullscreen_set_cursor_visible (fs
, TRUE
);
259 EmpathyCallWindowFullscreen
*
260 empathy_call_window_fullscreen_new (EmpathyCallWindow
*parent_window
)
262 EmpathyCallWindowFullscreen
*self
= EMPATHY_CALL_WINDOW_FULLSCREEN (
263 g_object_new (EMPATHY_TYPE_CALL_WINDOW_FULLSCREEN
, NULL
));
264 EmpathyCallWindowFullscreenPriv
*priv
= GET_PRIV (self
);
266 priv
->parent_window
= parent_window
;
267 g_signal_connect (G_OBJECT (priv
->parent_window
), "notify::is-active",
268 G_CALLBACK (empathy_call_window_fullscreen_parent_window_notify
), self
);
274 empathy_call_window_fullscreen_set_fullscreen (EmpathyCallWindowFullscreen
*fs
,
275 gboolean set_fullscreen
)
279 empathy_call_window_fullscreen_remove_popup_timeout (fs
);
281 empathy_call_window_fullscreen_hide_popup (fs
);
283 empathy_call_window_fullscreen_set_cursor_visible (fs
, !set_fullscreen
);
284 fs
->is_fullscreen
= set_fullscreen
;
288 empathy_call_window_fullscreen_set_video_widget (
289 EmpathyCallWindowFullscreen
*fs
,
290 GtkWidget
*video_widget
)
292 EmpathyCallWindowFullscreenPriv
*priv
= GET_PRIV (fs
);
293 priv
->video_widget
= video_widget
;