[totem] Make 'Escape' pass the focus away from the playlist



commit 63e3be640eafce6678e87d6a592981597fac7f09
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Dec 15 19:32:05 2009 +0000

    Make 'Escape' pass the focus away from the playlist
    
    To the video widget. We need some hacking to avoid pinching
    key release events when pressing escape to dismiss a menu,
    or the type-ahead popup.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=313343

 src/totem-object.c  |   19 +++++++++++++++++--
 src/totem-sidebar.c |   23 ++++++++++++++++++++++-
 src/totem-sidebar.h |    2 +-
 3 files changed, 40 insertions(+), 4 deletions(-)
---
diff --git a/src/totem-object.c b/src/totem-object.c
index 20fc37f..6b0eed7 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -3817,11 +3817,26 @@ totem_action_handle_scroll (Totem *totem, GdkScrollDirection direction)
 gboolean
 window_key_press_event_cb (GtkWidget *win, GdkEventKey *event, Totem *totem)
 {
-	if (totem_sidebar_is_focused (totem) != FALSE)
-		return FALSE;
+	gboolean sidebar_handles_kbd;
+
+	/* Shortcuts disabled? */
 	if (totem->disable_kbd_shortcuts != FALSE)
 		return FALSE;
 
+	/* Check whether the sidebar needs the key events */
+	if (event->type == GDK_KEY_PRESS) {
+		if (totem_sidebar_is_focused (totem, &sidebar_handles_kbd) != FALSE) {
+			/* Make Escape pass the focus to the video widget */
+			if (sidebar_handles_kbd == FALSE &&
+			    event->keyval == GDK_Escape)
+				gtk_widget_grab_focus (GTK_WIDGET (totem->bvw));
+			return FALSE;
+		}
+	} else {
+		if (totem_sidebar_is_focused (totem, NULL) != FALSE)
+			return FALSE;
+	}
+
 	/* Special case Eject, Open, Open URI and
 	 * seeking keyboard shortcuts */
 	if (event->state != 0
diff --git a/src/totem-sidebar.c b/src/totem-sidebar.c
index 0ffd62c..9e370b1 100644
--- a/src/totem-sidebar.c
+++ b/src/totem-sidebar.c
@@ -95,11 +95,32 @@ totem_sidebar_is_visible (Totem *totem)
 	return totem->sidebar_shown;
 }
 
+static gboolean
+has_popup (void)
+{
+	GList *list, *l;
+	gboolean retval = FALSE;
+
+	list = gtk_window_list_toplevels ();
+	for (l = list; l != NULL; l = l->next) {
+		GtkWindow *window = GTK_WINDOW (l->data);
+		if (GTK_WIDGET_VISIBLE (window) && gtk_window_get_window_type (window) == GTK_WINDOW_POPUP) {
+			retval = TRUE;
+			break;
+		}
+	}
+	g_list_free (list);
+	return retval;
+}
+
 gboolean
-totem_sidebar_is_focused (Totem *totem)
+totem_sidebar_is_focused (Totem *totem, gboolean *handles_kbd)
 {
 	GtkWidget *focused;
 
+	if (handles_kbd != NULL)
+		*handles_kbd = has_popup ();
+
 	focused = gtk_window_get_focus (GTK_WINDOW (totem->win));
 	if (focused != NULL && gtk_widget_is_ancestor
 			(focused, GTK_WIDGET (totem->sidebar)) != FALSE) {
diff --git a/src/totem-sidebar.h b/src/totem-sidebar.h
index ad85496..611cc06 100644
--- a/src/totem-sidebar.h
+++ b/src/totem-sidebar.h
@@ -30,7 +30,7 @@ void totem_sidebar_setup (Totem *totem, gboolean visible,
 void totem_sidebar_toggle (Totem *totem, gboolean state);
 void totem_sidebar_set_visibility (Totem *totem, gboolean visible);
 gboolean totem_sidebar_is_visible (Totem *totem);
-gboolean totem_sidebar_is_focused (Totem *totem);
+gboolean totem_sidebar_is_focused (Totem *totem, gboolean *handles_kbd);
 char *totem_sidebar_get_current_page (Totem *totem);
 void totem_sidebar_set_current_page (Totem *totem,
 				     const char *name,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]