--- mozilla-1.9.1_original/widget/src/gtk2/nsWindow.cpp Tue Nov 17 15:05:27 2009 +++ mozilla-1.9.1/widget/src/gtk2/nsWindow.cpp Wed Nov 18 11:51:07 2009 @@ -2859,7 +2859,56 @@ nsWindow::InitButtonEvent(nsMouseEvent &aEvent, } } +/* the values are gdk button numbers */ +/* first entry unused; this is to accomodate for gdk numbering buttons from 1; */ +static PRUint16 mouse_button_map[10]; +static PRUint16 context_menu_button = 3; + void +set_default_button_map(void) { + int i; + + for (i = 0; i < 10; ++i) + mouse_button_map[i] = i; +} + +/* format example: + "x3m2" + will map: + LMB -> to what it is by default, i.e. left mouse button =) + MMB -> RMB and also make it the context menu button + RMB -> MMB +*/ +void +update_mouse_button_map(const char *cstr) { + nsAutoString str; + const PRUnichar *p, *end; + int i, val; + + set_default_button_map(); + + if (!cstr) + return; + + str.AssignWithConversion(cstr); + p = str.BeginReading(); + end = str.EndReading(); + for (i = 1; p < end && i < 10; ++i, ++p) { + if (*p == PRUnichar('m')) { + --i; + if (i < 1) + continue; + context_menu_button = i; + continue; + } + val = *p - PRUnichar('0'); + if (val < 1 || val > 9) + continue; + mouse_button_map[i] = val; + } +} + +void nsWindow::OnButtonPressEvent(GtkWidget *aWidget, GdkEventButton *aEvent) { nsEventStatus status; @@ -2894,8 +2943,9 @@ nsWindow::OnButtonPressEvent(GtkWidget *aWidget, GdkEv if (gConsumeRollupEvent && rolledUp) return; + PRUint16 Button = (aEvent->button > 0 && aEvent->button <= 9) ? mouse_button_map[aEvent->button] : 0; PRUint16 domButton; - switch (aEvent->button) { + switch (Button) { case 1: domButton = nsMouseEvent::eLeftButton; break; @@ -2944,7 +2994,7 @@ nsWindow::OnButtonPressEvent(GtkWidget *aWidget, GdkEv DispatchEvent(&event, status); // right menu click on linux should also pop up a context menu - if (domButton == nsMouseEvent::eRightButton && + if (aEvent->button == context_menu_button && NS_LIKELY(!mIsDestroyed)) { nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this, nsMouseEvent::eReal); @@ -2956,10 +3006,11 @@ nsWindow::OnButtonPressEvent(GtkWidget *aWidget, GdkEv void nsWindow::OnButtonReleaseEvent(GtkWidget *aWidget, GdkEventButton *aEvent) { + PRUint16 Button = (aEvent->button > 0 && aEvent->button <= 9) ? mouse_button_map[aEvent->button] : 0; PRUint16 domButton; mLastButtonReleaseTime = aEvent->time; - switch (aEvent->button) { + switch (Button) { case 1: domButton = nsMouseEvent::eLeftButton; break; @@ -5882,6 +5933,7 @@ drag_data_received_event_cb(GtkWidget *aWidget, aInfo, aTime, aData); } + /* static */ nsresult initialize_prefs(void) @@ -5892,6 +5944,7 @@ initialize_prefs(void) PRBool val = PR_TRUE; nsresult rv; + char *s; rv = prefs->GetBoolPref("mozilla.widget.raise-on-setfocus", &val); if (NS_SUCCEEDED(rv)) @@ -5908,6 +5961,10 @@ initialize_prefs(void) rv = prefs->GetBoolPref("mozilla.widget.disable-native-theme", &val); if (NS_SUCCEEDED(rv)) gDisableNativeTheme = val; + + rv = prefs->GetCharPref("mozilla.widget.mouse-button-map", &s); + if (NS_SUCCEEDED(rv)) + update_mouse_button_map(s); return NS_OK; } --- mozilla-1.9.1_original/browser/app/profile/firefox.js Tue Nov 17 15:05:36 2009 +++ mozilla-1.9.1/browser/app/profile/firefox.js Wed Nov 18 11:09:31 2009 @@ -843,3 +843,5 @@ pref("browser.privatebrowsing.dont_prompt_on_enter", f // base url for the wifi geolocation network provider pref("geo.wifi.uri", "https://www.google.com/loc/json"); +// mouse button map +pref("mozilla.widget.mouse-button-map", "123m");