OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "base/logging.h" | 25 #include "base/logging.h" |
26 #include "base/memory/scoped_ptr.h" | 26 #include "base/memory/scoped_ptr.h" |
27 #include "base/memory/singleton.h" | 27 #include "base/memory/singleton.h" |
28 #include "base/message_loop/message_loop.h" | 28 #include "base/message_loop/message_loop.h" |
29 #include "base/metrics/histogram.h" | 29 #include "base/metrics/histogram.h" |
30 #include "base/strings/string_number_conversions.h" | 30 #include "base/strings/string_number_conversions.h" |
31 #include "base/strings/string_util.h" | 31 #include "base/strings/string_util.h" |
32 #include "base/strings/stringprintf.h" | 32 #include "base/strings/stringprintf.h" |
33 #include "base/sys_byteorder.h" | 33 #include "base/sys_byteorder.h" |
34 #include "base/threading/thread.h" | 34 #include "base/threading/thread.h" |
| 35 #include "base/x11/x11_error_tracker.h" |
35 #include "third_party/skia/include/core/SkBitmap.h" | 36 #include "third_party/skia/include/core/SkBitmap.h" |
36 #include "third_party/skia/include/core/SkPostConfig.h" | 37 #include "third_party/skia/include/core/SkPostConfig.h" |
37 #include "ui/base/touch/touch_factory_x11.h" | 38 #include "ui/base/touch/touch_factory_x11.h" |
38 #include "ui/base/x/device_data_manager.h" | 39 #include "ui/base/x/device_data_manager.h" |
39 #include "ui/base/x/x11_error_tracker.h" | |
40 #include "ui/base/x/x11_util_internal.h" | 40 #include "ui/base/x/x11_util_internal.h" |
41 #include "ui/events/event_utils.h" | 41 #include "ui/events/event_utils.h" |
42 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 42 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
43 #include "ui/gfx/canvas.h" | 43 #include "ui/gfx/canvas.h" |
44 #include "ui/gfx/image/image_skia.h" | 44 #include "ui/gfx/image/image_skia.h" |
45 #include "ui/gfx/image/image_skia_rep.h" | 45 #include "ui/gfx/image/image_skia_rep.h" |
46 #include "ui/gfx/point.h" | 46 #include "ui/gfx/point.h" |
47 #include "ui/gfx/point_conversions.h" | 47 #include "ui/gfx/point_conversions.h" |
48 #include "ui/gfx/rect.h" | 48 #include "ui/gfx/rect.h" |
49 #include "ui/gfx/size.h" | 49 #include "ui/gfx/size.h" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 } | 358 } |
359 | 359 |
360 void* address = shmat(shmkey, NULL, 0); | 360 void* address = shmat(shmkey, NULL, 0); |
361 // Mark the shared memory region for deletion | 361 // Mark the shared memory region for deletion |
362 shmctl(shmkey, IPC_RMID, NULL); | 362 shmctl(shmkey, IPC_RMID, NULL); |
363 | 363 |
364 XShmSegmentInfo shminfo; | 364 XShmSegmentInfo shminfo; |
365 memset(&shminfo, 0, sizeof(shminfo)); | 365 memset(&shminfo, 0, sizeof(shminfo)); |
366 shminfo.shmid = shmkey; | 366 shminfo.shmid = shmkey; |
367 | 367 |
368 X11ErrorTracker err_tracker; | 368 base::X11ErrorTracker err_tracker; |
369 bool result = XShmAttach(dpy, &shminfo); | 369 bool result = XShmAttach(dpy, &shminfo); |
370 if (result) | 370 if (result) |
371 VLOG(1) << "X got shared memory segment " << shmkey; | 371 VLOG(1) << "X got shared memory segment " << shmkey; |
372 else | 372 else |
373 LOG(WARNING) << "X failed to attach to shared memory segment " << shmkey; | 373 LOG(WARNING) << "X failed to attach to shared memory segment " << shmkey; |
374 if (err_tracker.FoundNewError()) | 374 if (err_tracker.FoundNewError()) |
375 result = false; | 375 result = false; |
376 shmdt(address); | 376 shmdt(address); |
377 if (!result) { | 377 if (!result) { |
378 LOG(WARNING) << "X failed to attach to shared memory segment " << shmkey; | 378 LOG(WARNING) << "X failed to attach to shared memory segment " << shmkey; |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 const std::vector<int>& value) { | 945 const std::vector<int>& value) { |
946 DCHECK(!value.empty()); | 946 DCHECK(!value.empty()); |
947 Atom name_atom = GetAtom(name.c_str()); | 947 Atom name_atom = GetAtom(name.c_str()); |
948 Atom type_atom = GetAtom(type.c_str()); | 948 Atom type_atom = GetAtom(type.c_str()); |
949 | 949 |
950 // XChangeProperty() expects values of type 32 to be longs. | 950 // XChangeProperty() expects values of type 32 to be longs. |
951 scoped_ptr<long[]> data(new long[value.size()]); | 951 scoped_ptr<long[]> data(new long[value.size()]); |
952 for (size_t i = 0; i < value.size(); ++i) | 952 for (size_t i = 0; i < value.size(); ++i) |
953 data[i] = value[i]; | 953 data[i] = value[i]; |
954 | 954 |
955 X11ErrorTracker err_tracker; | 955 base::X11ErrorTracker err_tracker; |
956 XChangeProperty(gfx::GetXDisplay(), | 956 XChangeProperty(gfx::GetXDisplay(), |
957 window, | 957 window, |
958 name_atom, | 958 name_atom, |
959 type_atom, | 959 type_atom, |
960 32, // size in bits of items in 'value' | 960 32, // size in bits of items in 'value' |
961 PropModeReplace, | 961 PropModeReplace, |
962 reinterpret_cast<const unsigned char*>(data.get()), | 962 reinterpret_cast<const unsigned char*>(data.get()), |
963 value.size()); // num items | 963 value.size()); // num items |
964 return !err_tracker.FoundNewError(); | 964 return !err_tracker.FoundNewError(); |
965 } | 965 } |
966 | 966 |
967 bool SetAtomArrayProperty(XID window, | 967 bool SetAtomArrayProperty(XID window, |
968 const std::string& name, | 968 const std::string& name, |
969 const std::string& type, | 969 const std::string& type, |
970 const std::vector<Atom>& value) { | 970 const std::vector<Atom>& value) { |
971 DCHECK(!value.empty()); | 971 DCHECK(!value.empty()); |
972 Atom name_atom = GetAtom(name.c_str()); | 972 Atom name_atom = GetAtom(name.c_str()); |
973 Atom type_atom = GetAtom(type.c_str()); | 973 Atom type_atom = GetAtom(type.c_str()); |
974 | 974 |
975 // XChangeProperty() expects values of type 32 to be longs. | 975 // XChangeProperty() expects values of type 32 to be longs. |
976 scoped_ptr<Atom[]> data(new Atom[value.size()]); | 976 scoped_ptr<Atom[]> data(new Atom[value.size()]); |
977 for (size_t i = 0; i < value.size(); ++i) | 977 for (size_t i = 0; i < value.size(); ++i) |
978 data[i] = value[i]; | 978 data[i] = value[i]; |
979 | 979 |
980 X11ErrorTracker err_tracker; | 980 base::X11ErrorTracker err_tracker; |
981 XChangeProperty(gfx::GetXDisplay(), | 981 XChangeProperty(gfx::GetXDisplay(), |
982 window, | 982 window, |
983 name_atom, | 983 name_atom, |
984 type_atom, | 984 type_atom, |
985 32, // size in bits of items in 'value' | 985 32, // size in bits of items in 'value' |
986 PropModeReplace, | 986 PropModeReplace, |
987 reinterpret_cast<const unsigned char*>(data.get()), | 987 reinterpret_cast<const unsigned char*>(data.get()), |
988 value.size()); // num items | 988 value.size()); // num items |
989 return !err_tracker.FoundNewError(); | 989 return !err_tracker.FoundNewError(); |
990 } | 990 } |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 | 1382 |
1383 // It's possible that a window manager started earlier in this X session left | 1383 // It's possible that a window manager started earlier in this X session left |
1384 // a stale _NET_SUPPORTING_WM_CHECK property when it was replaced by a | 1384 // a stale _NET_SUPPORTING_WM_CHECK property when it was replaced by a |
1385 // non-EWMH window manager, so we trap errors in the following requests to | 1385 // non-EWMH window manager, so we trap errors in the following requests to |
1386 // avoid crashes (issue 23860). | 1386 // avoid crashes (issue 23860). |
1387 | 1387 |
1388 // EWMH requires the supporting-WM window to also have a | 1388 // EWMH requires the supporting-WM window to also have a |
1389 // _NET_SUPPORTING_WM_CHECK property pointing to itself (to avoid a stale | 1389 // _NET_SUPPORTING_WM_CHECK property pointing to itself (to avoid a stale |
1390 // property referencing an ID that's been recycled for another window), so we | 1390 // property referencing an ID that's been recycled for another window), so we |
1391 // check that too. | 1391 // check that too. |
1392 X11ErrorTracker err_tracker; | 1392 base::X11ErrorTracker err_tracker; |
1393 int wm_window_property = 0; | 1393 int wm_window_property = 0; |
1394 bool result = GetIntProperty( | 1394 bool result = GetIntProperty( |
1395 wm_window, "_NET_SUPPORTING_WM_CHECK", &wm_window_property); | 1395 wm_window, "_NET_SUPPORTING_WM_CHECK", &wm_window_property); |
1396 if (err_tracker.FoundNewError() || !result || | 1396 if (err_tracker.FoundNewError() || !result || |
1397 wm_window_property != wm_window) { | 1397 wm_window_property != wm_window) { |
1398 return false; | 1398 return false; |
1399 } | 1399 } |
1400 | 1400 |
1401 result = GetStringProperty( | 1401 result = GetStringProperty( |
1402 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name); | 1402 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1724 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1724 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1725 << "minor_code " << static_cast<int>(error_event.minor_code) | 1725 << "minor_code " << static_cast<int>(error_event.minor_code) |
1726 << " (" << request_str << ")"; | 1726 << " (" << request_str << ")"; |
1727 } | 1727 } |
1728 | 1728 |
1729 // ---------------------------------------------------------------------------- | 1729 // ---------------------------------------------------------------------------- |
1730 // End of x11_util_internal.h | 1730 // End of x11_util_internal.h |
1731 | 1731 |
1732 | 1732 |
1733 } // namespace ui | 1733 } // namespace ui |
OLD | NEW |