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 #include "views/touchui/touch_factory.h" | 5 #include "views/touchui/touch_factory.h" |
6 | 6 |
7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <X11/extensions/XIproto.h> | 10 #include <X11/extensions/XIproto.h> |
(...skipping 25 matching lines...) Expand all Loading... |
36 invisible_cursor_ = XCreatePixmapCursor(display, blank, blank, | 36 invisible_cursor_ = XCreatePixmapCursor(display, blank, blank, |
37 &black, &black, 0, 0); | 37 &black, &black, 0, 0); |
38 arrow_cursor_ = XCreateFontCursor(display, XC_arrow); | 38 arrow_cursor_ = XCreateFontCursor(display, XC_arrow); |
39 | 39 |
40 SetCursorVisible(false, false); | 40 SetCursorVisible(false, false); |
41 | 41 |
42 // Detect touch devices. | 42 // Detect touch devices. |
43 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does | 43 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does |
44 // not provide enough information to detect a touch device. As a result, the | 44 // not provide enough information to detect a touch device. As a result, the |
45 // old version of query function (XListInputDevices) is used instead. | 45 // old version of query function (XListInputDevices) is used instead. |
| 46 // If XInput2 is not supported, this will return null (with count of -1) so |
| 47 // we assume there cannot be any touch devices. |
46 int count = 0; | 48 int count = 0; |
47 XDeviceInfo* devlist = XListInputDevices(display, &count); | 49 XDeviceInfo* devlist = XListInputDevices(display, &count); |
48 for (int i = 0; i < count; i++) { | 50 for (int i = 0; i < count; i++) { |
49 const char* devtype = XGetAtomName(display, devlist[i].type); | 51 const char* devtype = XGetAtomName(display, devlist[i].type); |
50 if (devtype && !strcmp(devtype, XI_TOUCHSCREEN)) { | 52 if (devtype && !strcmp(devtype, XI_TOUCHSCREEN)) { |
51 touch_device_lookup_[devlist[i].id] = true; | 53 touch_device_lookup_[devlist[i].id] = true; |
52 touch_device_list_.push_back(devlist[i].id); | 54 touch_device_list_.push_back(devlist[i].id); |
53 } | 55 } |
54 } | 56 } |
55 XFreeDeviceList(devlist); | 57 if (devlist) |
| 58 XFreeDeviceList(devlist); |
56 } | 59 } |
57 | 60 |
58 TouchFactory::~TouchFactory() { | 61 TouchFactory::~TouchFactory() { |
59 SetCursorVisible(true, false); | 62 SetCursorVisible(true, false); |
60 Display* display = ui::GetXDisplay(); | 63 Display* display = ui::GetXDisplay(); |
61 XFreeCursor(display, invisible_cursor_); | 64 XFreeCursor(display, invisible_cursor_); |
62 XFreeCursor(display, arrow_cursor_); | 65 XFreeCursor(display, arrow_cursor_); |
63 } | 66 } |
64 | 67 |
65 void TouchFactory::SetTouchDeviceList( | 68 void TouchFactory::SetTouchDeviceList( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 Window window = DefaultRootWindow(display); | 139 Window window = DefaultRootWindow(display); |
137 | 140 |
138 if (is_cursor_visible_) { | 141 if (is_cursor_visible_) { |
139 XDefineCursor(display, window, arrow_cursor_); | 142 XDefineCursor(display, window, arrow_cursor_); |
140 } else { | 143 } else { |
141 XDefineCursor(display, window, invisible_cursor_); | 144 XDefineCursor(display, window, invisible_cursor_); |
142 } | 145 } |
143 } | 146 } |
144 | 147 |
145 } // namespace views | 148 } // namespace views |
OLD | NEW |