OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
9 #include "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
11 #include <sys/ipc.h> | 11 #include <sys/ipc.h> |
12 #include <sys/shm.h> | 12 #include <sys/shm.h> |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "base/bind.h" | 18 #include "base/bind.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/memory/singleton.h" |
21 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
22 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
23 #include "base/string_util.h" | 24 #include "base/string_util.h" |
24 #include "base/stringprintf.h" | 25 #include "base/stringprintf.h" |
25 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
26 #include "ui/base/x/x11_util_internal.h" | 27 #include "ui/base/x/x11_util_internal.h" |
27 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
28 #include "ui/gfx/size.h" | 29 #include "ui/gfx/size.h" |
29 | 30 |
30 #if defined(TOOLKIT_USES_GTK) | 31 #if defined(TOOLKIT_USES_GTK) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 cache_.clear(); | 132 cache_.clear(); |
132 } | 133 } |
133 | 134 |
134 private: | 135 private: |
135 // Maps X11 font cursor shapes to Cursor IDs. | 136 // Maps X11 font cursor shapes to Cursor IDs. |
136 std::map<int, Cursor> cache_; | 137 std::map<int, Cursor> cache_; |
137 | 138 |
138 DISALLOW_COPY_AND_ASSIGN(XCursorCache); | 139 DISALLOW_COPY_AND_ASSIGN(XCursorCache); |
139 }; | 140 }; |
140 | 141 |
| 142 // A singleton object that remembers remappings of mouse buttons. |
| 143 class XButtonMap { |
| 144 public: |
| 145 static XButtonMap* GetInstance() { |
| 146 return Singleton<XButtonMap>::get(); |
| 147 } |
| 148 |
| 149 void UpdateMapping() { |
| 150 count_ = XGetPointerMapping(ui::GetXDisplay(), map_, arraysize(map_)); |
| 151 } |
| 152 |
| 153 int GetMappedButton(int button) { |
| 154 return button > 0 && button <= count_ ? map_[button - 1] : button; |
| 155 } |
| 156 |
| 157 private: |
| 158 friend struct DefaultSingletonTraits<XButtonMap>; |
| 159 |
| 160 XButtonMap() { |
| 161 UpdateMapping(); |
| 162 } |
| 163 |
| 164 ~XButtonMap() {} |
| 165 |
| 166 unsigned char map_[256]; |
| 167 int count_; |
| 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(XButtonMap); |
| 170 }; |
| 171 |
141 } // namespace | 172 } // namespace |
142 | 173 |
143 bool XDisplayExists() { | 174 bool XDisplayExists() { |
144 return (GetXDisplay() != NULL); | 175 return (GetXDisplay() != NULL); |
145 } | 176 } |
146 | 177 |
147 Display* GetXDisplay() { | 178 Display* GetXDisplay() { |
148 return base::MessagePumpForUI::GetDefaultXDisplay(); | 179 return base::MessagePumpForUI::GetDefaultXDisplay(); |
149 } | 180 } |
150 | 181 |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 return monitor_rect.x == window_rect.x() && | 857 return monitor_rect.x == window_rect.x() && |
827 monitor_rect.y == window_rect.y() && | 858 monitor_rect.y == window_rect.y() && |
828 monitor_rect.width == window_rect.width() && | 859 monitor_rect.width == window_rect.width() && |
829 monitor_rect.height == window_rect.height(); | 860 monitor_rect.height == window_rect.height(); |
830 #else | 861 #else |
831 NOTIMPLEMENTED(); | 862 NOTIMPLEMENTED(); |
832 return false; | 863 return false; |
833 #endif | 864 #endif |
834 } | 865 } |
835 | 866 |
| 867 int GetMappedButton(int button) { |
| 868 return XButtonMap::GetInstance()->GetMappedButton(button); |
| 869 } |
| 870 |
| 871 void UpdateButtonMap() { |
| 872 XButtonMap::GetInstance()->UpdateMapping(); |
| 873 } |
| 874 |
836 // ---------------------------------------------------------------------------- | 875 // ---------------------------------------------------------------------------- |
837 // These functions are declared in x11_util_internal.h because they require | 876 // These functions are declared in x11_util_internal.h because they require |
838 // XLib.h to be included, and it conflicts with many other headers. | 877 // XLib.h to be included, and it conflicts with many other headers. |
839 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { | 878 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { |
840 static XRenderPictFormat* pictformat = NULL; | 879 static XRenderPictFormat* pictformat = NULL; |
841 if (pictformat) | 880 if (pictformat) |
842 return pictformat; | 881 return pictformat; |
843 | 882 |
844 // First look for a 32-bit format which ignores the alpha value | 883 // First look for a 32-bit format which ignores the alpha value |
845 XRenderPictFormat templ; | 884 XRenderPictFormat templ; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 995 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
957 << "minor_code " << static_cast<int>(error_event.minor_code) | 996 << "minor_code " << static_cast<int>(error_event.minor_code) |
958 << " (" << request_str << ")"; | 997 << " (" << request_str << ")"; |
959 } | 998 } |
960 | 999 |
961 // ---------------------------------------------------------------------------- | 1000 // ---------------------------------------------------------------------------- |
962 // End of x11_util_internal.h | 1001 // End of x11_util_internal.h |
963 | 1002 |
964 | 1003 |
965 } // namespace ui | 1004 } // namespace ui |
OLD | NEW |