[nautilus] Let forward/back mouse buttons work



commit 9826f177cb72fc9f595356b773f51059bef6cd1e
Author: Andrew Walton <awalton gnome org>
Date:   Wed Apr 22 10:57:05 2009 +0200

    Let forward/back mouse buttons work
    
    Install a handler to link forward/back mouse buttons to
    forward/back actions in NautilusNavigationWindow, with a preference
    to set the right X button number in GConf.
    
    Signed-off-by: Cosimo Cecchi <cosimoc gnome org>
---
 .../apps_nautilus_preferences.schemas.in           |   47 ++++++++++
 libnautilus-private/nautilus-global-preferences.c  |   12 +++
 libnautilus-private/nautilus-global-preferences.h  |    5 +
 src/nautilus-navigation-window.c                   |   91 +++++++++++++++++++-
 4 files changed, 153 insertions(+), 2 deletions(-)

diff --git a/libnautilus-private/apps_nautilus_preferences.schemas.in b/libnautilus-private/apps_nautilus_preferences.schemas.in
index edb2d5e..6a70aec 100644
--- a/libnautilus-private/apps_nautilus_preferences.schemas.in
+++ b/libnautilus-private/apps_nautilus_preferences.schemas.in
@@ -316,6 +316,53 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/nautilus/preferences/mouse_use_extra_buttons</key>
+      <applyto>/apps/nautilus/preferences/mouse_use_extra_buttons</applyto>
+      <owner>nautilus</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+         <short>Use extra mouse button events in Nautilus' browser window</short>
+         <long>
+         For users with mice that have "Forward" and "Back" buttons, this key will determine
+         if any action is taken inside of Nautilus when either is pressed.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/nautilus/preferences/mouse_forward_button</key>
+      <applyto>/apps/nautilus/preferences/mouse_forward_button</applyto>
+      <owner>nautilus</owner>
+      <type>int</type>
+      <default>8</default>
+      <locale name="C">
+         <short>Mouse button to activate the "Forward" command in browser window</short>
+         <long>
+         For users with mice that have buttons for "Forward" and "Back", this key will set
+         which button activates the "Forward" command in a browser window.
+         Possible values range between 6 and 14. 
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/nautilus/preferences/mouse_back_button</key>
+      <applyto>/apps/nautilus/preferences/mouse_back_button</applyto>
+      <owner>nautilus</owner>
+      <type>int</type>
+      <default>9</default>
+      <locale name="C">
+         <short>Mouse button to activate the "Back" command in browser window</short>
+         <long>
+         For users with mice that have buttons for "Forward" and "Back", this key will set
+         which button activates the "Back" command in a browser window.
+         Possible values range between 6 and 14. 
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/nautilus/preferences/theme</key>
       <applyto>/apps/nautilus/preferences/theme</applyto>
       <owner>nautilus</owner>
diff --git a/libnautilus-private/nautilus-global-preferences.c b/libnautilus-private/nautilus-global-preferences.c
index 614c10c..e216c2e 100644
--- a/libnautilus-private/nautilus-global-preferences.c
+++ b/libnautilus-private/nautilus-global-preferences.c
@@ -547,6 +547,18 @@ static const PreferenceDefault preference_defaults[] = {
 	  PREFERENCE_INTEGER,
 	  GINT_TO_POINTER (3)
 	},
+	{ NAUTILUS_PREFERENCES_MOUSE_USE_EXTRA_BUTTONS,
+	  PREFERENCE_BOOLEAN,
+	  GINT_TO_POINTER (TRUE)
+	},
+	{ NAUTILUS_PREFERENCES_MOUSE_FORWARD_BUTTON,
+	  PREFERENCE_INTEGER,
+	  GINT_TO_POINTER (8)
+	},
+	{ NAUTILUS_PREFERENCES_MOUSE_BACK_BUTTON,
+	  PREFERENCE_INTEGER,
+	  GINT_TO_POINTER (9)
+	},
 	{ NULL }
 };
 
diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h
index 3a3fe32..65e63d9 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -71,6 +71,11 @@ G_BEGIN_DECLS
 #define NAUTILUS_PREFERENCES_SHOW_ADVANCED_PERMISSIONS		"preferences/show_advanced_permissions"
 #define NAUTILUS_PREFERENCES_DATE_FORMAT			"preferences/date_format"
 
+/* Mouse */
+#define NAUTILUS_PREFERENCES_MOUSE_USE_EXTRA_BUTTONS 		"preferences/mouse_use_extra_buttons"
+#define NAUTILUS_PREFERENCES_MOUSE_FORWARD_BUTTON		"preferences/mouse_forward_button"
+#define NAUTILUS_PREFERENCES_MOUSE_BACK_BUTTON			"preferences/mouse_back_button"
+
 typedef enum
 {
 	NAUTILUS_DATE_FORMAT_LOCALE,
diff --git a/src/nautilus-navigation-window.c b/src/nautilus-navigation-window.c
index 8bec553..04d0073 100644
--- a/src/nautilus-navigation-window.c
+++ b/src/nautilus-navigation-window.c
@@ -91,6 +91,12 @@ enum {
 
 static int side_pane_width_auto_value = 0;
 
+
+/* Forward and back buttons on the mouse */
+static gboolean mouse_extra_buttons = TRUE;
+static int mouse_forward_button = 8;
+static int mouse_back_button = 9;
+
 static void add_sidebar_panels                       (NautilusNavigationWindow *window);
 static void load_view_as_menu                        (NautilusWindow           *window);
 static void side_panel_image_changed_callback        (NautilusSidebar          *side_panel,
@@ -109,6 +115,9 @@ static void path_bar_path_set_callback               (GtkWidget                *
 static void always_use_location_entry_changed        (gpointer                  callback_data);
 static void always_use_browser_changed               (gpointer                  callback_data);
 static void enable_tabs_changed			     (gpointer                  callback_data);
+static void mouse_back_button_changed		     (gpointer                  callback_data);
+static void mouse_forward_button_changed	     (gpointer                  callback_data);
+static void use_extra_mouse_buttons_changed          (gpointer                  callback_data);
 
 static void nautilus_navigation_window_set_bar_mode  (NautilusNavigationWindow *window, 
 						      NautilusBarMode           mode);
@@ -553,6 +562,49 @@ enable_tabs_changed (gpointer callback_data)
 	nautilus_navigation_window_update_tab_menu_item_visibility (window);
 }
 
+/* Sanity check: highest mouse button value I could find was 14. 5 is our 
+ * lower threshold (well-documented to be the one of the button events for the 
+ * scrollwheel), so it's hardcoded in the functions below. However, if you have
+ * a button that registers higher and want to map it, file a bug and 
+ * we'll move the bar. Makes you wonder why the X guys don't have 
+ * defined values for these like the XKB stuff, huh?
+ */
+#define UPPER_MOUSE_LIMIT 14
+
+static void
+mouse_back_button_changed (gpointer callback_data)
+{
+	int new_back_button;	
+
+	new_back_button = eel_preferences_get_integer (NAUTILUS_PREFERENCES_MOUSE_BACK_BUTTON);
+
+	/* Bounds checking */
+	if (new_back_button < 6 || new_back_button > UPPER_MOUSE_LIMIT)
+		return;
+
+	mouse_back_button = new_back_button;
+}
+
+static void
+mouse_forward_button_changed (gpointer callback_data)
+{
+	int new_forward_button;	
+
+	new_forward_button = eel_preferences_get_integer (NAUTILUS_PREFERENCES_MOUSE_FORWARD_BUTTON);
+
+	/* Bounds checking */
+	if (new_forward_button < 6 || new_forward_button > UPPER_MOUSE_LIMIT)
+		return;
+
+	mouse_forward_button = new_forward_button;
+}
+
+static void
+use_extra_mouse_buttons_changed (gpointer callback_data)
+{
+	mouse_extra_buttons = eel_preferences_get_boolean (NAUTILUS_PREFERENCES_MOUSE_USE_EXTRA_BUTTONS);
+}
+
 static int
 bookmark_list_get_uri_index (GList *list,
 			     GFile *location)
@@ -919,7 +971,6 @@ nautilus_navigation_window_key_press_event (GtkWidget *widget,
 
 			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)) {
@@ -934,6 +985,28 @@ nautilus_navigation_window_key_press_event (GtkWidget *widget,
 	return GTK_WIDGET_CLASS (nautilus_navigation_window_parent_class)->key_press_event (widget, event);
 }
 
+static gboolean
+nautilus_navigation_window_button_press_event (GtkWidget *widget,
+					       GdkEventButton *event)
+{
+	NautilusNavigationWindow *window;
+	gboolean handled;
+	
+	handled = FALSE;
+	window = NAUTILUS_NAVIGATION_WINDOW (widget);
+	
+	if (mouse_extra_buttons && (event->button == mouse_back_button)) {
+		nautilus_navigation_window_go_back (window);
+		handled = TRUE; 
+	} else if (mouse_extra_buttons && (event->button == mouse_forward_button)) {
+		nautilus_navigation_window_go_forward (window);
+		handled = TRUE;
+	} else {
+		handled = GTK_WIDGET_CLASS (nautilus_navigation_window_parent_class)->button_press_event (widget, event);
+	}
+	return handled;
+}
+
 static void
 nautilus_navigation_window_destroy (GtkObject *object)
 {
@@ -1824,7 +1897,7 @@ nautilus_navigation_window_get_base_page_index (NautilusNavigationWindow *window
 
 /**
  * nautilus_navigation_window_show:
- * @widget:	GtkWidget
+ * @widget: a #GtkWidget.
  *
  * Call parent and then show/hide window items
  * base on user prefs.
@@ -1995,6 +2068,7 @@ nautilus_navigation_window_class_init (NautilusNavigationWindowClass *class)
 	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;
+	GTK_WIDGET_CLASS (class)->button_press_event = nautilus_navigation_window_button_press_event;
 	NAUTILUS_WINDOW_CLASS (class)->load_view_as_menu = real_load_view_as_menu;
 	NAUTILUS_WINDOW_CLASS (class)->sync_allow_stop = real_sync_allow_stop;
 	NAUTILUS_WINDOW_CLASS (class)->prompt_for_location = real_prompt_for_location;
@@ -2009,4 +2083,17 @@ nautilus_navigation_window_class_init (NautilusNavigationWindowClass *class)
 	NAUTILUS_WINDOW_CLASS (class)->close_slot = real_close_slot;
 
 	g_type_class_add_private (G_OBJECT_CLASS (class), sizeof (NautilusNavigationWindowDetails));
+
+
+	eel_preferences_add_callback (NAUTILUS_PREFERENCES_MOUSE_BACK_BUTTON, 
+				      mouse_back_button_changed, 
+				      NULL);
+
+	eel_preferences_add_callback (NAUTILUS_PREFERENCES_MOUSE_FORWARD_BUTTON, 
+				      mouse_forward_button_changed, 
+				      NULL);
+
+	eel_preferences_add_callback (NAUTILUS_PREFERENCES_MOUSE_USE_EXTRA_BUTTONS,
+				      use_extra_mouse_buttons_changed,
+				      NULL);
 }



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