| 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 "ui/display/chromeos/x11/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 #include "ui/display/chromeos/display_mode.h" |
| 15 #include "ui/display/chromeos/display_snapshot.h" |
| 14 | 16 |
| 15 namespace ui { | 17 namespace ui { |
| 16 | 18 |
| 17 TouchscreenDelegateX11::TouchscreenDelegateX11() | 19 TouchscreenDelegateX11::TouchscreenDelegateX11() |
| 18 : display_(base::MessagePumpX11::GetDefaultXDisplay()) {} | 20 : display_(base::MessagePumpX11::GetDefaultXDisplay()) {} |
| 19 | 21 |
| 20 TouchscreenDelegateX11::~TouchscreenDelegateX11() {} | 22 TouchscreenDelegateX11::~TouchscreenDelegateX11() {} |
| 21 | 23 |
| 22 void TouchscreenDelegateX11::AssociateTouchscreens( | 24 void TouchscreenDelegateX11::AssociateTouchscreens( |
| 23 std::vector<OutputConfigurator::OutputSnapshot>* outputs) { | 25 OutputConfigurator::DisplayStateList* outputs) { |
| 24 int ndevices = 0; | 26 int ndevices = 0; |
| 25 Atom valuator_x = XInternAtom(display_, "Abs MT Position X", False); | 27 Atom valuator_x = XInternAtom(display_, "Abs MT Position X", False); |
| 26 Atom valuator_y = XInternAtom(display_, "Abs MT Position Y", False); | 28 Atom valuator_y = XInternAtom(display_, "Abs MT Position Y", False); |
| 27 if (valuator_x == None || valuator_y == None) | 29 if (valuator_x == None || valuator_y == None) |
| 28 return; | 30 return; |
| 29 | 31 |
| 30 std::set<int> no_match_touchscreen; | 32 std::set<int> no_match_touchscreen; |
| 31 XIDeviceInfo* info = XIQueryDevice(display_, XIAllDevices, &ndevices); | 33 XIDeviceInfo* info = XIQueryDevice(display_, XIAllDevices, &ndevices); |
| 32 for (int i = 0; i < ndevices; i++) { | 34 for (int i = 0; i < ndevices; i++) { |
| 33 if (!info[i].enabled || info[i].use != XIFloatingSlave) | 35 if (!info[i].enabled || info[i].use != XIFloatingSlave) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 is_direct_touch = touch_info->mode == XIDirectTouch; | 67 is_direct_touch = touch_info->mode == XIDirectTouch; |
| 66 } | 68 } |
| 67 #endif | 69 #endif |
| 68 } | 70 } |
| 69 | 71 |
| 70 // Touchscreens should have absolute X and Y axes, | 72 // Touchscreens should have absolute X and Y axes, |
| 71 // and be direct touch devices. | 73 // and be direct touch devices. |
| 72 if (width > 0.0 && height > 0.0 && is_direct_touch) { | 74 if (width > 0.0 && height > 0.0 && is_direct_touch) { |
| 73 size_t k = 0; | 75 size_t k = 0; |
| 74 for (; k < outputs->size(); k++) { | 76 for (; k < outputs->size(); k++) { |
| 75 OutputConfigurator::OutputSnapshot* output = &(*outputs)[k]; | 77 OutputConfigurator::DisplayState* output = &(*outputs)[k]; |
| 76 if (output->native_mode == None || output->touch_device_id != None) | 78 if (output->touch_device_id != None) |
| 77 continue; | 79 continue; |
| 78 | 80 |
| 79 const OutputConfigurator::ModeInfo* mode_info = | 81 const DisplayMode* mode_info = output->display->native_mode(); |
| 80 OutputConfigurator::GetModeInfo(*output, output->native_mode); | |
| 81 if (!mode_info) | 82 if (!mode_info) |
| 82 continue; | 83 continue; |
| 83 | 84 |
| 84 // Allow 1 pixel difference between screen and touchscreen | 85 // Allow 1 pixel difference between screen and touchscreen |
| 85 // resolutions. Because in some cases for monitor resolution | 86 // resolutions. Because in some cases for monitor resolution |
| 86 // 1024x768 touchscreen's resolution would be 1024x768, but for | 87 // 1024x768 touchscreen's resolution would be 1024x768, but for |
| 87 // some 1023x767. It really depends on touchscreen's firmware | 88 // some 1023x767. It really depends on touchscreen's firmware |
| 88 // configuration. | 89 // configuration. |
| 89 if (std::abs(mode_info->width - width) <= 1.0 && | 90 if (std::abs(mode_info->size().width() - width) <= 1.0 && |
| 90 std::abs(mode_info->height - height) <= 1.0) { | 91 std::abs(mode_info->size().height() - height) <= 1.0) { |
| 91 output->touch_device_id = info[i].deviceid; | 92 output->touch_device_id = info[i].deviceid; |
| 92 | 93 |
| 93 VLOG(2) << "Found touchscreen for output #" << k << " id " | 94 VLOG(2) << "Found touchscreen for output #" << k << " id " |
| 94 << output->touch_device_id << " width " << width << " height " | 95 << output->touch_device_id << " width " << width << " height " |
| 95 << height; | 96 << height; |
| 96 break; | 97 break; |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 | 100 |
| 100 if (k == outputs->size()) { | 101 if (k == outputs->size()) { |
| 101 no_match_touchscreen.insert(info[i].deviceid); | 102 no_match_touchscreen.insert(info[i].deviceid); |
| 102 VLOG(2) << "No matching output for touchscreen" | 103 VLOG(2) << "No matching output for touchscreen" |
| 103 << " id " << info[i].deviceid << " width " << width | 104 << " id " << info[i].deviceid << " width " << width |
| 104 << " height " << height; | 105 << " height " << height; |
| 105 } | 106 } |
| 106 } | 107 } |
| 107 } | 108 } |
| 108 | 109 |
| 109 // Sometimes we can't find a matching screen for the touchscreen, e.g. | 110 // Sometimes we can't find a matching screen for the touchscreen, e.g. |
| 110 // due to the touchscreen's reporting range having no correlation with the | 111 // due to the touchscreen's reporting range having no correlation with the |
| 111 // screen's resolution. In this case, we arbitrarily assign unmatched | 112 // screen's resolution. In this case, we arbitrarily assign unmatched |
| 112 // touchscreens to unmatched screens. | 113 // touchscreens to unmatched screens. |
| 113 for (std::set<int>::iterator it = no_match_touchscreen.begin(); | 114 for (std::set<int>::iterator it = no_match_touchscreen.begin(); |
| 114 it != no_match_touchscreen.end(); | 115 it != no_match_touchscreen.end(); |
| 115 it++) { | 116 it++) { |
| 116 for (size_t i = 0; i < outputs->size(); i++) { | 117 for (size_t i = 0; i < outputs->size(); i++) { |
| 117 if ((*outputs)[i].type != ui::OUTPUT_TYPE_INTERNAL && | 118 if ((*outputs)[i].display->type() != OUTPUT_TYPE_INTERNAL && |
| 118 (*outputs)[i].native_mode != None && | 119 (*outputs)[i].display->native_mode() != NULL && |
| 119 (*outputs)[i].touch_device_id == None) { | 120 (*outputs)[i].touch_device_id == None) { |
| 120 (*outputs)[i].touch_device_id = *it; | 121 (*outputs)[i].touch_device_id = *it; |
| 121 VLOG(2) << "Arbitrarily matching touchscreen " | 122 VLOG(2) << "Arbitrarily matching touchscreen " |
| 122 << (*outputs)[i].touch_device_id << " to output #" << i; | 123 << (*outputs)[i].touch_device_id << " to output #" << i; |
| 123 break; | 124 break; |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 | 128 |
| 128 XIFreeDeviceInfo(info); | 129 XIFreeDeviceInfo(info); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 format, | 173 format, |
| 173 PropModeReplace, | 174 PropModeReplace, |
| 174 reinterpret_cast<unsigned char*>(value), | 175 reinterpret_cast<unsigned char*>(value), |
| 175 9); | 176 9); |
| 176 } | 177 } |
| 177 } | 178 } |
| 178 XIFreeDeviceInfo(info); | 179 XIFreeDeviceInfo(info); |
| 179 } | 180 } |
| 180 | 181 |
| 181 } // namespace ui | 182 } // namespace ui |
| OLD | NEW |