Index: ui/base/x/x11_util.cc |
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc |
index fed7764d7b2b3058f2bad0e780076b3d4614a8f4..690a9c770f26545d32e2c93712126c3d6d3693ac 100644 |
--- a/ui/base/x/x11_util.cc |
+++ b/ui/base/x/x11_util.cc |
@@ -18,6 +18,7 @@ |
#include "base/bind.h" |
#include "base/command_line.h" |
#include "base/logging.h" |
+#include "base/memory/singleton.h" |
#include "base/message_loop.h" |
#include "base/string_number_conversions.h" |
#include "base/string_util.h" |
@@ -138,6 +139,36 @@ class XCursorCache { |
DISALLOW_COPY_AND_ASSIGN(XCursorCache); |
}; |
+// A singleton object that remembers remappings of mouse buttons. |
+class XButtonMap { |
+ public: |
+ static XButtonMap* GetInstance() { |
+ return Singleton<XButtonMap>::get(); |
+ } |
+ |
+ void UpdateMapping() { |
+ count_ = XGetPointerMapping(ui::GetXDisplay(), map_, arraysize(map_)); |
+ } |
+ |
+ int GetMappedButton(int button) { |
+ return button > 0 && button <= count_ ? map_[button - 1] : button; |
+ } |
+ |
+ private: |
+ friend struct DefaultSingletonTraits<XButtonMap>; |
+ |
+ XButtonMap() { |
+ UpdateMapping(); |
+ } |
+ |
+ ~XButtonMap() {} |
+ |
+ unsigned char map_[256]; |
+ int count_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(XButtonMap); |
+}; |
+ |
} // namespace |
bool XDisplayExists() { |
@@ -833,6 +864,14 @@ bool IsX11WindowFullScreen(XID window) { |
#endif |
} |
+int GetMappedButton(int button) { |
+ return XButtonMap::GetInstance()->GetMappedButton(button); |
+} |
+ |
+void UpdateButtonMap() { |
+ XButtonMap::GetInstance()->UpdateMapping(); |
+} |
+ |
// ---------------------------------------------------------------------------- |
// These functions are declared in x11_util_internal.h because they require |
// XLib.h to be included, and it conflicts with many other headers. |