| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromeos/display/touchscreen_delegate_x11.h" | 5 #include "ui/display/chromeos/x11/touchscreen_delegate_x11.h" |
| 6 | 6 |
| 7 #include <X11/extensions/XInput.h> | 7 #include <X11/extensions/XInput.h> |
| 8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/message_loop/message_pump_x11.h" | 13 #include "base/message_loop/message_pump_x11.h" |
| 14 | 14 |
| 15 namespace chromeos { | 15 namespace ui { |
| 16 | 16 |
| 17 TouchscreenDelegateX11::TouchscreenDelegateX11() | 17 TouchscreenDelegateX11::TouchscreenDelegateX11() |
| 18 : display_(base::MessagePumpX11::GetDefaultXDisplay()) {} | 18 : display_(base::MessagePumpX11::GetDefaultXDisplay()) {} |
| 19 | 19 |
| 20 TouchscreenDelegateX11::~TouchscreenDelegateX11() {} | 20 TouchscreenDelegateX11::~TouchscreenDelegateX11() {} |
| 21 | 21 |
| 22 void TouchscreenDelegateX11::AssociateTouchscreens( | 22 void TouchscreenDelegateX11::AssociateTouchscreens( |
| 23 std::vector<OutputConfigurator::OutputSnapshot>* outputs) { | 23 std::vector<OutputConfigurator::OutputSnapshot>* outputs) { |
| 24 int ndevices = 0; | 24 int ndevices = 0; |
| 25 Atom valuator_x = XInternAtom(display_, "Abs MT Position X", False); | 25 Atom valuator_x = XInternAtom(display_, "Abs MT Position X", False); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 // Allow 1 pixel difference between screen and touchscreen | 84 // Allow 1 pixel difference between screen and touchscreen |
| 85 // resolutions. Because in some cases for monitor resolution | 85 // resolutions. Because in some cases for monitor resolution |
| 86 // 1024x768 touchscreen's resolution would be 1024x768, but for | 86 // 1024x768 touchscreen's resolution would be 1024x768, but for |
| 87 // some 1023x767. It really depends on touchscreen's firmware | 87 // some 1023x767. It really depends on touchscreen's firmware |
| 88 // configuration. | 88 // configuration. |
| 89 if (std::abs(mode_info->width - width) <= 1.0 && | 89 if (std::abs(mode_info->width - width) <= 1.0 && |
| 90 std::abs(mode_info->height - height) <= 1.0) { | 90 std::abs(mode_info->height - height) <= 1.0) { |
| 91 output->touch_device_id = info[i].deviceid; | 91 output->touch_device_id = info[i].deviceid; |
| 92 | 92 |
| 93 VLOG(2) << "Found touchscreen for output #" << k | 93 VLOG(2) << "Found touchscreen for output #" << k << " id " |
| 94 << " id " << output->touch_device_id | 94 << output->touch_device_id << " width " << width << " height " |
| 95 << " width " << width | 95 << height; |
| 96 << " height " << height; | |
| 97 break; | 96 break; |
| 98 } | 97 } |
| 99 } | 98 } |
| 100 | 99 |
| 101 if (k == outputs->size()) { | 100 if (k == outputs->size()) { |
| 102 no_match_touchscreen.insert(info[i].deviceid); | 101 no_match_touchscreen.insert(info[i].deviceid); |
| 103 VLOG(2) << "No matching output for touchscreen" | 102 VLOG(2) << "No matching output for touchscreen" |
| 104 << " id " << info[i].deviceid | 103 << " id " << info[i].deviceid << " width " << width |
| 105 << " width " << width | |
| 106 << " height " << height; | 104 << " height " << height; |
| 107 } | 105 } |
| 108 | |
| 109 } | 106 } |
| 110 } | 107 } |
| 111 | 108 |
| 112 // Sometimes we can't find a matching screen for the touchscreen, e.g. | 109 // Sometimes we can't find a matching screen for the touchscreen, e.g. |
| 113 // due to the touchscreen's reporting range having no correlation with the | 110 // due to the touchscreen's reporting range having no correlation with the |
| 114 // screen's resolution. In this case, we arbitrarily assign unmatched | 111 // screen's resolution. In this case, we arbitrarily assign unmatched |
| 115 // touchscreens to unmatched screens. | 112 // touchscreens to unmatched screens. |
| 116 for (std::set<int>::iterator it = no_match_touchscreen.begin(); | 113 for (std::set<int>::iterator it = no_match_touchscreen.begin(); |
| 117 it != no_match_touchscreen.end(); | 114 it != no_match_touchscreen.end(); |
| 118 it++) { | 115 it++) { |
| 119 for (size_t i = 0; i < outputs->size(); i++) { | 116 for (size_t i = 0; i < outputs->size(); i++) { |
| 120 if ((*outputs)[i].type != ui::OUTPUT_TYPE_INTERNAL && | 117 if ((*outputs)[i].type != ui::OUTPUT_TYPE_INTERNAL && |
| 121 (*outputs)[i].native_mode != None && | 118 (*outputs)[i].native_mode != None && |
| 122 (*outputs)[i].touch_device_id == None) { | 119 (*outputs)[i].touch_device_id == None) { |
| 123 (*outputs)[i].touch_device_id = *it; | 120 (*outputs)[i].touch_device_id = *it; |
| 124 VLOG(2) << "Arbitrarily matching touchscreen " | 121 VLOG(2) << "Arbitrarily matching touchscreen " |
| 125 << (*outputs)[i].touch_device_id << " to output #" << i; | 122 << (*outputs)[i].touch_device_id << " to output #" << i; |
| 126 break; | 123 break; |
| 127 } | 124 } |
| 128 } | 125 } |
| 129 } | 126 } |
| 130 | 127 |
| 131 XIFreeDeviceInfo(info); | 128 XIFreeDeviceInfo(info); |
| 132 } | 129 } |
| 133 | 130 |
| 134 void TouchscreenDelegateX11::ConfigureCTM( | 131 void TouchscreenDelegateX11::ConfigureCTM( |
| 135 int touch_device_id, | 132 int touch_device_id, |
| 136 const OutputConfigurator::CoordinateTransformation& ctm) { | 133 const OutputConfigurator::CoordinateTransformation& ctm) { |
| 137 VLOG(1) << "ConfigureCTM: id=" << touch_device_id | 134 VLOG(1) << "ConfigureCTM: id=" << touch_device_id << " scale=" << ctm.x_scale |
| 138 << " scale=" << ctm.x_scale << "x" << ctm.y_scale | 135 << "x" << ctm.y_scale << " offset=(" << ctm.x_offset << ", " |
| 139 << " offset=(" << ctm.x_offset << ", " << ctm.y_offset << ")"; | 136 << ctm.y_offset << ")"; |
| 140 int ndevices = 0; | 137 int ndevices = 0; |
| 141 XIDeviceInfo* info = XIQueryDevice(display_, touch_device_id, &ndevices); | 138 XIDeviceInfo* info = XIQueryDevice(display_, touch_device_id, &ndevices); |
| 142 Atom prop = XInternAtom(display_, "Coordinate Transformation Matrix", False); | 139 Atom prop = XInternAtom(display_, "Coordinate Transformation Matrix", False); |
| 143 Atom float_atom = XInternAtom(display_, "FLOAT", False); | 140 Atom float_atom = XInternAtom(display_, "FLOAT", False); |
| 144 if (ndevices == 1 && prop != None && float_atom != None) { | 141 if (ndevices == 1 && prop != None && float_atom != None) { |
| 145 Atom type; | 142 Atom type; |
| 146 int format; | 143 int format; |
| 147 unsigned long num_items; | 144 unsigned long num_items; |
| 148 unsigned long bytes_after; | 145 unsigned long bytes_after; |
| 149 unsigned char* data = NULL; | 146 unsigned char* data = NULL; |
| 150 // Verify that the property exists with correct format, type, etc. | 147 // Verify that the property exists with correct format, type, etc. |
| 151 int status = XIGetProperty(display_, info->deviceid, prop, 0, 0, False, | 148 int status = XIGetProperty(display_, |
| 152 AnyPropertyType, &type, &format, &num_items, &bytes_after, &data); | 149 info->deviceid, |
| 150 prop, |
| 151 0, |
| 152 0, |
| 153 False, |
| 154 AnyPropertyType, |
| 155 &type, |
| 156 &format, |
| 157 &num_items, |
| 158 &bytes_after, |
| 159 &data); |
| 153 if (data) | 160 if (data) |
| 154 XFree(data); | 161 XFree(data); |
| 155 if (status == Success && type == float_atom && format == 32) { | 162 if (status == Success && type == float_atom && format == 32) { |
| 156 float value[3][3] = { | 163 float value[3][3] = { |
| 157 { ctm.x_scale, 0.0, ctm.x_offset }, | 164 { ctm.x_scale, 0.0, ctm.x_offset }, |
| 158 { 0.0, ctm.y_scale, ctm.y_offset }, | 165 { 0.0, ctm.y_scale, ctm.y_offset }, |
| 159 { 0.0, 0.0, 1.0 } | 166 { 0.0, 0.0, 1.0 } |
| 160 }; | 167 }; |
| 161 XIChangeProperty(display_, | 168 XIChangeProperty(display_, |
| 162 info->deviceid, | 169 info->deviceid, |
| 163 prop, | 170 prop, |
| 164 type, | 171 type, |
| 165 format, | 172 format, |
| 166 PropModeReplace, | 173 PropModeReplace, |
| 167 reinterpret_cast<unsigned char*>(value), | 174 reinterpret_cast<unsigned char*>(value), |
| 168 9); | 175 9); |
| 169 } | 176 } |
| 170 } | 177 } |
| 171 XIFreeDeviceInfo(info); | 178 XIFreeDeviceInfo(info); |
| 172 } | 179 } |
| 173 | 180 |
| 174 } // namespace chromeos | 181 } // namespace ui |
| OLD | NEW |