| 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/memory/singleton.h" |
| 22 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
| 23 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
| 24 #include "base/string_util.h" | 24 #include "base/string_util.h" |
| 25 #include "base/stringprintf.h" | 25 #include "base/stringprintf.h" |
| 26 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
| 27 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| 27 #include "ui/base/x/x11_util_internal.h" | 28 #include "ui/base/x/x11_util_internal.h" |
| 28 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
| 29 #include "ui/gfx/size.h" | 30 #include "ui/gfx/size.h" |
| 30 | 31 |
| 31 #if defined(TOOLKIT_USES_GTK) | 32 #if defined(TOOLKIT_USES_GTK) |
| 32 #include <gdk/gdk.h> | 33 #include <gdk/gdk.h> |
| 33 #include <gdk/gdkx.h> | 34 #include <gdk/gdkx.h> |
| 34 #include <gtk/gtk.h> | 35 #include <gtk/gtk.h> |
| 35 #include "ui/base/gtk/gtk_compat.h" | 36 #include "ui/base/gtk/gtk_compat.h" |
| 36 #include "ui/base/gtk/gdk_x_compat.h" | 37 #include "ui/base/gtk/gdk_x_compat.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 max_length, // max length to get | 97 max_length, // max length to get |
| 97 False, // deleted | 98 False, // deleted |
| 98 AnyPropertyType, | 99 AnyPropertyType, |
| 99 type, | 100 type, |
| 100 format, | 101 format, |
| 101 num_items, | 102 num_items, |
| 102 &remaining_bytes, | 103 &remaining_bytes, |
| 103 property); | 104 property); |
| 104 } | 105 } |
| 105 | 106 |
| 107 // Converts ui::EventType to XKeyEvent state. |
| 108 unsigned int XKeyEventState(int flags) { |
| 109 return |
| 110 ((flags & ui::EF_SHIFT_DOWN) ? ShiftMask : 0) | |
| 111 ((flags & ui::EF_CONTROL_DOWN) ? ControlMask : 0) | |
| 112 ((flags & ui::EF_CAPS_LOCK_DOWN) ? LockMask : 0); |
| 113 } |
| 114 |
| 115 // Converts EventType to XKeyEvent type. |
| 116 int XKeyEventType(ui::EventType type) { |
| 117 switch (type) { |
| 118 case ui::ET_KEY_PRESSED: |
| 119 return KeyPress; |
| 120 case ui::ET_KEY_RELEASED: |
| 121 return KeyRelease; |
| 122 default: |
| 123 return 0; |
| 124 } |
| 125 } |
| 126 |
| 127 // Converts KeyboardCode to XKeyEvent keycode. |
| 128 unsigned int XKeyEventKeyCode(ui::KeyboardCode key_code, |
| 129 int flags, |
| 130 Display* display) { |
| 131 const int keysym = XKeysymForWindowsKeyCode(key_code, |
| 132 flags & ui::EF_SHIFT_DOWN); |
| 133 // Tests assume the keycode for XK_less is equal to the one of XK_comma, |
| 134 // but XKeysymToKeycode returns 94 for XK_less while it returns 59 for |
| 135 // XK_comma. Here we convert the value for XK_less to the value for XK_comma. |
| 136 return (keysym == XK_less) ? 59 : XKeysymToKeycode(display, keysym); |
| 137 } |
| 138 |
| 106 // A process wide singleton that manages the usage of X cursors. | 139 // A process wide singleton that manages the usage of X cursors. |
| 107 class XCursorCache { | 140 class XCursorCache { |
| 108 public: | 141 public: |
| 109 XCursorCache() {} | 142 XCursorCache() {} |
| 110 ~XCursorCache() { | 143 ~XCursorCache() { |
| 111 Clear(); | 144 Clear(); |
| 112 } | 145 } |
| 113 | 146 |
| 114 Cursor GetCursor(int cursor_shape) { | 147 Cursor GetCursor(int cursor_shape) { |
| 115 // Lookup cursor by attempting to insert a null value, which avoids | 148 // Lookup cursor by attempting to insert a null value, which avoids |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 } | 898 } |
| 866 | 899 |
| 867 int GetMappedButton(int button) { | 900 int GetMappedButton(int button) { |
| 868 return XButtonMap::GetInstance()->GetMappedButton(button); | 901 return XButtonMap::GetInstance()->GetMappedButton(button); |
| 869 } | 902 } |
| 870 | 903 |
| 871 void UpdateButtonMap() { | 904 void UpdateButtonMap() { |
| 872 XButtonMap::GetInstance()->UpdateMapping(); | 905 XButtonMap::GetInstance()->UpdateMapping(); |
| 873 } | 906 } |
| 874 | 907 |
| 908 void InitXKeyEventForTesting(EventType type, |
| 909 KeyboardCode key_code, |
| 910 int flags, |
| 911 XEvent* event) { |
| 912 CHECK(event); |
| 913 Display* display = GetXDisplay(); |
| 914 XKeyEvent key_event; |
| 915 key_event.type = XKeyEventType(type); |
| 916 CHECK_NE(0, key_event.type); |
| 917 key_event.serial = 0; |
| 918 key_event.send_event = 0; |
| 919 key_event.display = display; |
| 920 key_event.time = 0; |
| 921 key_event.window = 0; |
| 922 key_event.root = 0; |
| 923 key_event.subwindow = 0; |
| 924 key_event.x = 0; |
| 925 key_event.y = 0; |
| 926 key_event.x_root = 0; |
| 927 key_event.y_root = 0; |
| 928 key_event.state = XKeyEventState(flags); |
| 929 key_event.keycode = XKeyEventKeyCode(key_code, flags, display); |
| 930 key_event.same_screen = 1; |
| 931 event->type = key_event.type; |
| 932 event->xkey = key_event; |
| 933 } |
| 934 |
| 875 // ---------------------------------------------------------------------------- | 935 // ---------------------------------------------------------------------------- |
| 876 // These functions are declared in x11_util_internal.h because they require | 936 // These functions are declared in x11_util_internal.h because they require |
| 877 // XLib.h to be included, and it conflicts with many other headers. | 937 // XLib.h to be included, and it conflicts with many other headers. |
| 878 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { | 938 XRenderPictFormat* GetRenderARGB32Format(Display* dpy) { |
| 879 static XRenderPictFormat* pictformat = NULL; | 939 static XRenderPictFormat* pictformat = NULL; |
| 880 if (pictformat) | 940 if (pictformat) |
| 881 return pictformat; | 941 return pictformat; |
| 882 | 942 |
| 883 // First look for a 32-bit format which ignores the alpha value | 943 // First look for a 32-bit format which ignores the alpha value |
| 884 XRenderPictFormat templ; | 944 XRenderPictFormat templ; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1055 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
| 996 << "minor_code " << static_cast<int>(error_event.minor_code) | 1056 << "minor_code " << static_cast<int>(error_event.minor_code) |
| 997 << " (" << request_str << ")"; | 1057 << " (" << request_str << ")"; |
| 998 } | 1058 } |
| 999 | 1059 |
| 1000 // ---------------------------------------------------------------------------- | 1060 // ---------------------------------------------------------------------------- |
| 1001 // End of x11_util_internal.h | 1061 // End of x11_util_internal.h |
| 1002 | 1062 |
| 1003 | 1063 |
| 1004 } // namespace ui | 1064 } // namespace ui |
| OLD | NEW |