[PATCH] Add multimedia key support



The attached patch adds multimedia key support to Nautilus:
http://bugzilla.gnome.org/show_bug.cgi?id=329920


-- 
Christian Neumair <chris gnome-de org>
Index: src/nautilus-navigation-window.c
===================================================================
--- src/nautilus-navigation-window.c	(Revision 12669)
+++ src/nautilus-navigation-window.c	(Arbeitskopie)
@@ -61,7 +61,9 @@
 #include <gtk/gtktreemodel.h>
 #include <gtk/gtkliststore.h>
 #include <glib/gi18n.h>
-#include <libgnome/gnome-macros.h>
+#ifdef HAVE_X11_XF86KEYSYM_H
+#include <X11/XF86keysym.h>
+#endif
 #include <libgnomeui/gnome-uidefs.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
 #include <libnautilus-private/nautilus-file-attributes.h>
@@ -133,8 +135,18 @@ static void nautilus_navigation_window_s
 static void view_as_menu_switch_views_callback	     (GtkComboBox              *combo_box,
 						      NautilusWindow           *window);
 
-GNOME_CLASS_BOILERPLATE (NautilusNavigationWindow, nautilus_navigation_window,
-			 NautilusWindow, NAUTILUS_TYPE_WINDOW)
+G_DEFINE_TYPE (NautilusNavigationWindow, nautilus_navigation_window, NAUTILUS_TYPE_WINDOW)
+#define parent_class nautilus_navigation_window_parent_class
+
+static const struct {
+	unsigned int keyval;
+	const char *action;
+} extra_navigation_window_keybindings [] = {
+#ifdef HAVE_X11_XF86KEYSYM_H
+	{ XF86XK_Back,		NAUTILUS_ACTION_BACK },
+	{ XF86XK_Forward,	NAUTILUS_ACTION_FORWARD }
+#endif
+};
 
 static void
 location_button_toggled_cb (GtkToggleButton *toggle,
@@ -179,7 +191,7 @@ location_button_create (NautilusNavigati
 }
 
 static void
-nautilus_navigation_window_instance_init (NautilusNavigationWindow *window)
+nautilus_navigation_window_init (NautilusNavigationWindow *window)
 {
 	GtkUIManager *ui_manager;
 	GtkWidget *toolbar;
@@ -636,6 +648,36 @@ nautilus_navigation_window_state_event (
 	return FALSE;
 }
 
+static gboolean
+nautilus_navigation_window_key_press_event (GtkWidget *widget,
+					    GdkEventKey *event)
+{
+	NautilusNavigationWindow *window;
+	int i;
+
+	window = NAUTILUS_NAVIGATION_WINDOW (widget);
+
+	for (i = 0; i < G_N_ELEMENTS (extra_navigation_window_keybindings); i++) {
+		if (extra_navigation_window_keybindings[i].keyval == event->keyval) {
+			GtkAction *action;
+
+			action = gtk_action_group_get_action (window->details->navigation_action_group,
+							      extra_navigation_window_keybindings[i].action);
+			g_assert (action != NULL);
+
+			g_assert (action != NULL);
+			if (gtk_action_is_sensitive (action)) {
+				gtk_action_activate (action);
+				return TRUE;
+			}
+
+			break;
+		}
+	}
+
+	return GTK_WIDGET_CLASS (nautilus_navigation_window_parent_class)->key_press_event (widget, event);
+}
+
 static void
 nautilus_navigation_window_destroy (GtkObject *object)
 {
@@ -1537,6 +1579,7 @@ nautilus_navigation_window_class_init (N
 	GTK_WIDGET_CLASS (class)->show = nautilus_navigation_window_show;
 	GTK_WIDGET_CLASS (class)->unrealize = nautilus_navigation_window_unrealize;
 	GTK_WIDGET_CLASS (class)->window_state_event = nautilus_navigation_window_state_event;
+	GTK_WIDGET_CLASS (class)->key_press_event = nautilus_navigation_window_key_press_event;
 	NAUTILUS_WINDOW_CLASS (class)->load_view_as_menu = real_load_view_as_menu;
 	NAUTILUS_WINDOW_CLASS (class)->set_content_view_widget = real_set_content_view_widget;
 	NAUTILUS_WINDOW_CLASS (class)->set_throbber_active = real_set_throbber_active;
Index: src/nautilus-actions.h
===================================================================
--- src/nautilus-actions.h	(Revision 12669)
+++ src/nautilus-actions.h	(Arbeitskopie)
@@ -38,6 +38,10 @@
 #define NAUTILUS_ACTION_SHOW_HIDE_STATUSBAR "Show Hide Statusbar"
 #define NAUTILUS_ACTION_SHOW_HIDE_LOCATION_BAR "Show Hide Location Bar"
 #define NAUTILUS_ACTION_GO_TO_BURN_CD "Go to Burn CD"
+#define NAUTILUS_ACTION_GO_TO_LOCATION "Go to Location"
+#define NAUTILUS_ACTION_GO_HOME "Home"
+#define NAUTILUS_ACTION_ADD_BOOKMARK "Add Bookmark"
+#define NAUTILUS_ACTION_EDIT_BOOKMARKS "Edit Bookmarks"
 #define NAUTILUS_ACTION_HOME "Home"
 #define NAUTILUS_ACTION_ZOOM_IN "Zoom In"
 #define NAUTILUS_ACTION_ZOOM_OUT "Zoom Out"
Index: src/nautilus-window.c
===================================================================
--- src/nautilus-window.c	(Revision 12669)
+++ src/nautilus-window.c	(Arbeitskopie)
@@ -53,6 +53,9 @@
 #include <gtk/gtktogglebutton.h>
 #include <gtk/gtkvbox.h>
 #include <glib/gi18n.h>
+#ifdef HAVE_X11_XF86KEYSYM_H
+#include <X11/XF86keysym.h>
+#endif
 #include <libgnomevfs/gnome-vfs-uri.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
 #include <libnautilus-private/nautilus-file-attributes.h>
@@ -120,6 +123,27 @@ G_DEFINE_TYPE_WITH_CODE (NautilusWindow,
 			 G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_WINDOW_INFO,
 						nautilus_window_info_iface_init));
 
+static const struct {
+	unsigned int keyval;
+	const char *action;
+} extra_window_keybindings [] = {
+#ifdef HAVE_X11_XF86KEYSYM_H
+	{ XF86XK_AddFavorite,	NAUTILUS_ACTION_ADD_BOOKMARK },
+	{ XF86XK_Favorites,	NAUTILUS_ACTION_EDIT_BOOKMARKS },
+	{ XF86XK_Go,		NAUTILUS_ACTION_GO_TO_LOCATION },
+/* TODO?{ XF86XK_History,	NAUTILUS_ACTION_HISTORY }, */
+	{ XF86XK_HomePage,      NAUTILUS_ACTION_GO_HOME },
+	{ XF86XK_OpenURL,	NAUTILUS_ACTION_GO_TO_LOCATION },
+	{ XF86XK_Refresh,	NAUTILUS_ACTION_RELOAD },
+	{ XF86XK_Reload,	NAUTILUS_ACTION_RELOAD },
+	{ XF86XK_Search,	NAUTILUS_ACTION_SEARCH },
+	{ XF86XK_Start,		NAUTILUS_ACTION_GO_HOME },
+	{ XF86XK_Stop,		NAUTILUS_ACTION_STOP },
+	{ XF86XK_ZoomIn,	NAUTILUS_ACTION_ZOOM_IN },
+	{ XF86XK_ZoomOut,	NAUTILUS_ACTION_ZOOM_OUT }
+#endif
+};
+
 static void
 icons_changed_callback (GObject *factory, NautilusWindow *window)
 {
@@ -725,6 +749,41 @@ nautilus_window_realize (GtkWidget *widg
 	update_cursor (NAUTILUS_WINDOW (widget));
 }
 
+static gboolean
+nautilus_window_key_press_event (GtkWidget *widget,
+				 GdkEventKey *event)
+{
+	NautilusWindow *window;
+	int i;
+
+	window = NAUTILUS_WINDOW (widget);
+
+	for (i = 0; i < G_N_ELEMENTS (extra_window_keybindings); i++) {
+		if (extra_window_keybindings[i].keyval == event->keyval) {
+			const GList *action_groups;
+			GtkAction *action;
+
+			action = NULL;
+
+			action_groups = gtk_ui_manager_get_action_groups (window->details->ui_manager);
+			while (action_groups != NULL && action == NULL) {
+				action = gtk_action_group_get_action (action_groups->data, extra_window_keybindings[i].action);
+				action_groups = action_groups->next;
+			}
+
+			g_assert (action != NULL);
+			if (gtk_action_is_sensitive (action)) {
+				gtk_action_activate (action);
+				return TRUE;
+			}
+
+			break;
+		}
+	}
+
+	return GTK_WIDGET_CLASS (nautilus_window_parent_class)->key_press_event (widget, event);
+}
+
 /*
  * Main API
  */
@@ -1566,6 +1625,7 @@ nautilus_window_class_init (NautilusWind
 	GTK_WIDGET_CLASS (class)->show = nautilus_window_show;
 	GTK_WIDGET_CLASS (class)->size_request = nautilus_window_size_request;
 	GTK_WIDGET_CLASS (class)->realize = nautilus_window_realize;
+	GTK_WIDGET_CLASS (class)->key_press_event = nautilus_window_key_press_event;
 	class->add_current_location_to_history_list = real_add_current_location_to_history_list;
 	class->get_title = real_get_title;
 	class->set_title = real_set_title;
Index: configure.in
===================================================================
--- configure.in	(Revision 12669)
+++ configure.in	(Arbeitskopie)
@@ -365,6 +365,9 @@ AC_SUBST(CORE_IDL_INCLUDES)
 
 DISABLE_DEPRECATED_CFLAGS=""
 
+dnl Multimedia keys
+AC_CHECK_HEADERS([X11/XF86keysym.h])
+
 
 dnl Taken out for now
 dnl	-DGDK_DISABLE_DEPRECATED \


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