summaryrefslogtreecommitdiffstats
path: root/ui/display/chromeos
diff options
context:
space:
mode:
authordnicoara@chromium.org <dnicoara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-28 20:25:18 +0000
committerdnicoara@chromium.org <dnicoara@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-28 20:25:18 +0000
commit4ea262ab93ecb152370cb2e25f0d23145029857c (patch)
tree5e9f78381f295ed4105774b58953349e216e6997 /ui/display/chromeos
parent822bede1cdf417d0b5e46868571356e10c5af877 (diff)
downloadchromium_src-4ea262ab93ecb152370cb2e25f0d23145029857c.zip
chromium_src-4ea262ab93ecb152370cb2e25f0d23145029857c.tar.gz
chromium_src-4ea262ab93ecb152370cb2e25f0d23145029857c.tar.bz2
Adding a touchscreen device manager for quering of available devices
This extracts all the mapping logic between touchscreen and display from the X11 implementation into generic parser. Adding a TouchScreenDevice and a TouchScreenDeviceManager. Use these for querying purposes only. Also add the appropriate hooks for creating a TouchScreenDeviceManager for Ozone. BUG=333413 Review URL: https://codereview.chromium.org/299373004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273342 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/display/chromeos')
-rw-r--r--ui/display/chromeos/ozone/display_configurator_ozone.cc6
-rw-r--r--ui/display/chromeos/ozone/touchscreen_delegate_ozone.cc18
-rw-r--r--ui/display/chromeos/ozone/touchscreen_delegate_ozone.h28
-rw-r--r--ui/display/chromeos/touchscreen_delegate_impl.cc81
-rw-r--r--ui/display/chromeos/touchscreen_delegate_impl.h36
-rw-r--r--ui/display/chromeos/touchscreen_delegate_impl_unittest.cc167
-rw-r--r--ui/display/chromeos/x11/display_configurator_x11.cc8
-rw-r--r--ui/display/chromeos/x11/touchscreen_delegate_x11.cc132
-rw-r--r--ui/display/chromeos/x11/touchscreen_delegate_x11.h32
-rw-r--r--ui/display/chromeos/x11/touchscreen_device_manager_x11.cc82
-rw-r--r--ui/display/chromeos/x11/touchscreen_device_manager_x11.h32
11 files changed, 407 insertions, 215 deletions
diff --git a/ui/display/chromeos/ozone/display_configurator_ozone.cc b/ui/display/chromeos/ozone/display_configurator_ozone.cc
index 48f0792d..0a8528f 100644
--- a/ui/display/chromeos/ozone/display_configurator_ozone.cc
+++ b/ui/display/chromeos/ozone/display_configurator_ozone.cc
@@ -4,8 +4,9 @@
#include "ui/display/chromeos/display_configurator.h"
-#include "ui/display/chromeos/ozone/touchscreen_delegate_ozone.h"
+#include "ui/display/chromeos/touchscreen_delegate_impl.h"
#include "ui/display/types/chromeos/native_display_delegate.h"
+#include "ui/display/types/chromeos/touchscreen_device_manager.h"
#include "ui/ozone/ozone_platform.h"
namespace ui {
@@ -13,7 +14,8 @@ namespace ui {
void DisplayConfigurator::PlatformInitialize() {
InitializeDelegates(
ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(),
- scoped_ptr<TouchscreenDelegate>(new TouchscreenDelegateOzone()));
+ scoped_ptr<TouchscreenDelegate>(new TouchscreenDelegateImpl(
+ ui::OzonePlatform::GetInstance()->CreateTouchscreenDeviceManager())));
}
} // namespace ui
diff --git a/ui/display/chromeos/ozone/touchscreen_delegate_ozone.cc b/ui/display/chromeos/ozone/touchscreen_delegate_ozone.cc
deleted file mode 100644
index c302e2d..0000000
--- a/ui/display/chromeos/ozone/touchscreen_delegate_ozone.cc
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/display/chromeos/ozone/touchscreen_delegate_ozone.h"
-
-namespace ui {
-
-TouchscreenDelegateOzone::TouchscreenDelegateOzone() {}
-
-TouchscreenDelegateOzone::~TouchscreenDelegateOzone() {}
-
-void TouchscreenDelegateOzone::AssociateTouchscreens(
- std::vector<DisplayConfigurator::DisplayState>* outputs) {
- NOTIMPLEMENTED();
-}
-
-} // namespace ui
diff --git a/ui/display/chromeos/ozone/touchscreen_delegate_ozone.h b/ui/display/chromeos/ozone/touchscreen_delegate_ozone.h
deleted file mode 100644
index 7f33a03..0000000
--- a/ui/display/chromeos/ozone/touchscreen_delegate_ozone.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef UI_DISPLAY_CHROMEOS_OZONE_TOUCHSCREEN_DELEGATE_OZONE_H_
-#define UI_DISPLAY_CHROMEOS_OZONE_TOUCHSCREEN_DELEGATE_OZONE_H_
-
-#include "ui/display/chromeos/display_configurator.h"
-
-namespace ui {
-
-class TouchscreenDelegateOzone
- : public DisplayConfigurator::TouchscreenDelegate {
- public:
- TouchscreenDelegateOzone();
- virtual ~TouchscreenDelegateOzone();
-
- // DisplayConfigurator::TouchscreenDelegate overrides:
- virtual void AssociateTouchscreens(
- std::vector<DisplayConfigurator::DisplayState>* outputs) OVERRIDE;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TouchscreenDelegateOzone);
-};
-
-} // namespace ui
-
-#endif // UI_DISPLAY_CHROMEOS_OZONE_TOUCHSCREEN_DELEGATE_OZONE_H_
diff --git a/ui/display/chromeos/touchscreen_delegate_impl.cc b/ui/display/chromeos/touchscreen_delegate_impl.cc
new file mode 100644
index 0000000..5311a82
--- /dev/null
+++ b/ui/display/chromeos/touchscreen_delegate_impl.cc
@@ -0,0 +1,81 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/display/chromeos/touchscreen_delegate_impl.h"
+
+#include <cmath>
+#include <set>
+
+#include "ui/display/types/chromeos/display_mode.h"
+#include "ui/display/types/chromeos/display_snapshot.h"
+#include "ui/display/types/chromeos/touchscreen_device_manager.h"
+
+namespace ui {
+
+TouchscreenDelegateImpl::TouchscreenDelegateImpl(
+ scoped_ptr<TouchscreenDeviceManager> touch_device_manager)
+ : touch_device_manager_(touch_device_manager.Pass()) {}
+
+TouchscreenDelegateImpl::~TouchscreenDelegateImpl() {}
+
+void TouchscreenDelegateImpl::AssociateTouchscreens(
+ std::vector<DisplayConfigurator::DisplayState>* displays) {
+ std::set<int> no_match_touchscreen;
+ std::vector<TouchscreenDevice> devices = touch_device_manager_->GetDevices();
+ for (size_t i = 0; i < devices.size(); ++i) {
+ bool found_mapping = false;
+ for (size_t j = 0; j < displays->size(); ++j) {
+ DisplayConfigurator::DisplayState* state = &(*displays)[j];
+ const DisplayMode* mode = state->display->native_mode();
+ if (state->touch_device_id != 0 || !mode)
+ continue;
+
+ // Allow 1 pixel difference between screen and touchscreen
+ // resolutions. Because in some cases for monitor resolution
+ // 1024x768 touchscreen's resolution would be 1024x768, but for
+ // some 1023x767. It really depends on touchscreen's firmware
+ // configuration.
+ if (std::abs(mode->size().width() - devices[i].size.width()) <= 1 &&
+ std::abs(mode->size().height() - devices[i].size.height()) <= 1) {
+ state->touch_device_id = devices[i].id;
+
+ VLOG(2) << "Found touchscreen for display "
+ << state->display->display_id() << " touch_device_id "
+ << state->touch_device_id << " size "
+ << devices[i].size.ToString();
+ found_mapping = true;
+ break;
+ }
+ }
+
+ if (!found_mapping) {
+ no_match_touchscreen.insert(devices[i].id);
+ VLOG(2) << "No matching display for touch_device_id "
+ << devices[i].id << " size " << devices[i].size.ToString();
+ }
+ }
+
+ // Sometimes we can't find a matching screen for the touchscreen, e.g.
+ // due to the touchscreen's reporting range having no correlation with the
+ // screen's resolution. In this case, we arbitrarily assign unmatched
+ // touchscreens to unmatched screens.
+ for (std::set<int>::iterator it = no_match_touchscreen.begin();
+ it != no_match_touchscreen.end();
+ ++it) {
+ for (size_t i = 0; i < displays->size(); ++i) {
+ DisplayConfigurator::DisplayState* state = &(*displays)[i];
+ if (state->display->type() != DISPLAY_CONNECTION_TYPE_INTERNAL &&
+ state->display->native_mode() != NULL &&
+ state->touch_device_id == 0) {
+ state->touch_device_id = *it;
+ VLOG(2) << "Arbitrarily matching touchscreen "
+ << state->touch_device_id << " to display "
+ << state->display->display_id();
+ break;
+ }
+ }
+ }
+}
+
+} // namespace ui
diff --git a/ui/display/chromeos/touchscreen_delegate_impl.h b/ui/display/chromeos/touchscreen_delegate_impl.h
new file mode 100644
index 0000000..32e0b174
--- /dev/null
+++ b/ui/display/chromeos/touchscreen_delegate_impl.h
@@ -0,0 +1,36 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_DISPLAY_CHROMEOS_TOUCHSCREEN_DELEGATE_IMPL_H_
+#define UI_DISPLAY_CHROMEOS_TOUCHSCREEN_DELEGATE_IMPL_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "ui/display/chromeos/display_configurator.h"
+#include "ui/display/display_export.h"
+#include "ui/display/types/chromeos/touchscreen_device.h"
+
+namespace ui {
+
+class TouchscreenDeviceManager;
+
+class DISPLAY_EXPORT TouchscreenDelegateImpl
+ : public DisplayConfigurator::TouchscreenDelegate {
+ public:
+ explicit TouchscreenDelegateImpl(
+ scoped_ptr<TouchscreenDeviceManager> touch_device_manager);
+ virtual ~TouchscreenDelegateImpl();
+
+ // DisplayConfigurator::TouchscreenDelegate overrides:
+ virtual void AssociateTouchscreens(
+ std::vector<DisplayConfigurator::DisplayState>* displays) OVERRIDE;
+
+ private:
+ scoped_ptr<TouchscreenDeviceManager> touch_device_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(TouchscreenDelegateImpl);
+};
+
+} // namespace ui
+
+#endif // UI_DISPLAY_CHROMEOS_TOUCHSCREEN_DELEGATE_IMPL_H_
diff --git a/ui/display/chromeos/touchscreen_delegate_impl_unittest.cc b/ui/display/chromeos/touchscreen_delegate_impl_unittest.cc
new file mode 100644
index 0000000..b41fbdb
--- /dev/null
+++ b/ui/display/chromeos/touchscreen_delegate_impl_unittest.cc
@@ -0,0 +1,167 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/display/chromeos/display_configurator.h"
+#include "ui/display/chromeos/test/test_display_snapshot.h"
+#include "ui/display/chromeos/touchscreen_delegate_impl.h"
+#include "ui/display/types/chromeos/touchscreen_device_manager.h"
+
+namespace ui {
+
+namespace {
+
+class MockTouchscreenDeviceManager : public TouchscreenDeviceManager {
+ public:
+ MockTouchscreenDeviceManager() {}
+ virtual ~MockTouchscreenDeviceManager() {}
+
+ void AddDevice(const TouchscreenDevice& device) {
+ devices_.push_back(device);
+ }
+
+ // TouchscreenDeviceManager overrides:
+ virtual std::vector<TouchscreenDevice> GetDevices() OVERRIDE {
+ return devices_;
+ }
+
+ private:
+ std::vector<TouchscreenDevice> devices_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockTouchscreenDeviceManager);
+};
+
+} // namespace
+
+class TouchscreenDelegateImplTest : public testing::Test {
+ public:
+ TouchscreenDelegateImplTest() {}
+ virtual ~TouchscreenDelegateImplTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ device_manager_ = new MockTouchscreenDeviceManager();
+ delegate_.reset(new TouchscreenDelegateImpl(
+ scoped_ptr<TouchscreenDeviceManager>(device_manager_)));
+
+ // Internal display. Must not be matched to a touch screen unless the size
+ // matches.
+ TestDisplaySnapshot* snapshot = new TestDisplaySnapshot();
+ DisplayMode* mode = new DisplayMode(gfx::Size(1920, 1080), false, 60.0);
+ snapshot->set_type(DISPLAY_CONNECTION_TYPE_INTERNAL);
+ snapshot->set_modes(std::vector<const DisplayMode*>(1, mode));
+ snapshot->set_native_mode(mode);
+ displays_.push_back(snapshot);
+
+ snapshot = new TestDisplaySnapshot();
+ mode = new DisplayMode(gfx::Size(800, 600), false, 60.0);
+ snapshot->set_modes(std::vector<const DisplayMode*>(1, mode));
+ snapshot->set_native_mode(mode);
+ displays_.push_back(snapshot);
+
+ // Display without native mode. Must not be matched to any touch screen.
+ displays_.push_back(new TestDisplaySnapshot());
+
+ snapshot = new TestDisplaySnapshot();
+ mode = new DisplayMode(gfx::Size(1024, 768), false, 60.0);
+ snapshot->set_modes(std::vector<const DisplayMode*>(1, mode));
+ snapshot->set_native_mode(mode);
+ displays_.push_back(snapshot);
+ }
+
+ virtual void TearDown() OVERRIDE {
+ // The snapshots do not own the modes, so we need to delete them.
+ for (size_t i = 0; i < displays_.size(); ++i) {
+ if (displays_[i]->native_mode())
+ delete displays_[i]->native_mode();
+ }
+
+ displays_.clear();
+ }
+
+ std::vector<DisplayConfigurator::DisplayState> GetDisplayStates() {
+ std::vector<DisplayConfigurator::DisplayState> states(displays_.size());
+ for (size_t i = 0; i < displays_.size(); ++i)
+ states[i].display = displays_[i];
+
+ return states;
+ }
+
+ protected:
+ MockTouchscreenDeviceManager* device_manager_; // Not owned.
+ scoped_ptr<TouchscreenDelegateImpl> delegate_;
+ ScopedVector<DisplaySnapshot> displays_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TouchscreenDelegateImplTest);
+};
+
+TEST_F(TouchscreenDelegateImplTest, NoTouchscreens) {
+ std::vector<DisplayConfigurator::DisplayState> display_states =
+ GetDisplayStates();
+ delegate_->AssociateTouchscreens(&display_states);
+
+ for (size_t i = 0; i < display_states.size(); ++i)
+ EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[i].touch_device_id);
+}
+
+TEST_F(TouchscreenDelegateImplTest, OneToOneMapping) {
+ device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(800, 600)));
+ device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1024, 768)));
+
+ std::vector<DisplayConfigurator::DisplayState> display_states =
+ GetDisplayStates();
+ delegate_->AssociateTouchscreens(&display_states);
+
+ EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
+ EXPECT_EQ(1, display_states[1].touch_device_id);
+ EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
+ EXPECT_EQ(2, display_states[3].touch_device_id);
+}
+
+TEST_F(TouchscreenDelegateImplTest, MapToCorrectDisplaySize) {
+ device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1024, 768)));
+
+ std::vector<DisplayConfigurator::DisplayState> display_states =
+ GetDisplayStates();
+ delegate_->AssociateTouchscreens(&display_states);
+
+ EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
+ EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[1].touch_device_id);
+ EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
+ EXPECT_EQ(2, display_states[3].touch_device_id);
+}
+
+TEST_F(TouchscreenDelegateImplTest, MapWhenSizeDiffersByOne) {
+ device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(801, 600)));
+ device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1023, 768)));
+
+ std::vector<DisplayConfigurator::DisplayState> display_states =
+ GetDisplayStates();
+ delegate_->AssociateTouchscreens(&display_states);
+
+ EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
+ EXPECT_EQ(1, display_states[1].touch_device_id);
+ EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
+ EXPECT_EQ(2, display_states[3].touch_device_id);
+}
+
+TEST_F(TouchscreenDelegateImplTest, MapWhenSizesDoNotMatch) {
+ device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(1022, 768)));
+ device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(802, 600)));
+
+ std::vector<DisplayConfigurator::DisplayState> display_states =
+ GetDisplayStates();
+ delegate_->AssociateTouchscreens(&display_states);
+
+ EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
+ EXPECT_EQ(1, display_states[1].touch_device_id);
+ EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
+ EXPECT_EQ(2, display_states[3].touch_device_id);
+}
+
+} // namespace ui
diff --git a/ui/display/chromeos/x11/display_configurator_x11.cc b/ui/display/chromeos/x11/display_configurator_x11.cc
index a21219a..6e6b59fa 100644
--- a/ui/display/chromeos/x11/display_configurator_x11.cc
+++ b/ui/display/chromeos/x11/display_configurator_x11.cc
@@ -4,16 +4,18 @@
#include "ui/display/chromeos/display_configurator.h"
+#include "ui/display/chromeos/touchscreen_delegate_impl.h"
#include "ui/display/chromeos/x11/native_display_delegate_x11.h"
-#include "ui/display/chromeos/x11/touchscreen_delegate_x11.h"
-
+#include "ui/display/chromeos/x11/touchscreen_device_manager_x11.h"
namespace ui {
void DisplayConfigurator::PlatformInitialize() {
InitializeDelegates(
scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateX11()),
- scoped_ptr<TouchscreenDelegate>(new TouchscreenDelegateX11()));
+ scoped_ptr<TouchscreenDelegate>(new TouchscreenDelegateImpl(
+ scoped_ptr<TouchscreenDeviceManager>(
+ new TouchscreenDeviceManagerX11()))));
}
} // namespace ui
diff --git a/ui/display/chromeos/x11/touchscreen_delegate_x11.cc b/ui/display/chromeos/x11/touchscreen_delegate_x11.cc
deleted file mode 100644
index b76d62e..0000000
--- a/ui/display/chromeos/x11/touchscreen_delegate_x11.cc
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/display/chromeos/x11/touchscreen_delegate_x11.h"
-
-#include <X11/extensions/XInput.h>
-#include <X11/extensions/XInput2.h>
-
-#include <cmath>
-#include <set>
-
-#include "ui/display/types/chromeos/display_mode.h"
-#include "ui/display/types/chromeos/display_snapshot.h"
-#include "ui/gfx/x/x11_types.h"
-
-namespace ui {
-
-TouchscreenDelegateX11::TouchscreenDelegateX11()
- : display_(gfx::GetXDisplay()) {}
-
-TouchscreenDelegateX11::~TouchscreenDelegateX11() {}
-
-void TouchscreenDelegateX11::AssociateTouchscreens(
- DisplayConfigurator::DisplayStateList* outputs) {
- int ndevices = 0;
- Atom valuator_x = XInternAtom(display_, "Abs MT Position X", False);
- Atom valuator_y = XInternAtom(display_, "Abs MT Position Y", False);
- if (valuator_x == None || valuator_y == None)
- return;
-
- std::set<int> no_match_touchscreen;
- XIDeviceInfo* info = XIQueryDevice(display_, XIAllDevices, &ndevices);
- for (int i = 0; i < ndevices; i++) {
- if (!info[i].enabled || info[i].use != XIFloatingSlave)
- continue; // Assume all touchscreens are floating slaves
-
- double width = -1.0;
- double height = -1.0;
- bool is_direct_touch = false;
-
- for (int j = 0; j < info[i].num_classes; j++) {
- XIAnyClassInfo* class_info = info[i].classes[j];
-
- if (class_info->type == XIValuatorClass) {
- XIValuatorClassInfo* valuator_info =
- reinterpret_cast<XIValuatorClassInfo*>(class_info);
-
- if (valuator_x == valuator_info->label) {
- // Ignore X axis valuator with unexpected properties
- if (valuator_info->number == 0 && valuator_info->mode == Absolute &&
- valuator_info->min == 0.0) {
- width = valuator_info->max;
- }
- } else if (valuator_y == valuator_info->label) {
- // Ignore Y axis valuator with unexpected properties
- if (valuator_info->number == 1 && valuator_info->mode == Absolute &&
- valuator_info->min == 0.0) {
- height = valuator_info->max;
- }
- }
- }
-#if defined(USE_XI2_MT)
- if (class_info->type == XITouchClass) {
- XITouchClassInfo* touch_info =
- reinterpret_cast<XITouchClassInfo*>(class_info);
- is_direct_touch = touch_info->mode == XIDirectTouch;
- }
-#endif
- }
-
- // Touchscreens should have absolute X and Y axes,
- // and be direct touch devices.
- if (width > 0.0 && height > 0.0 && is_direct_touch) {
- size_t k = 0;
- for (; k < outputs->size(); k++) {
- DisplayConfigurator::DisplayState* output = &(*outputs)[k];
- if (output->touch_device_id != None)
- continue;
-
- const DisplayMode* mode_info = output->display->native_mode();
- if (!mode_info)
- continue;
-
- // Allow 1 pixel difference between screen and touchscreen
- // resolutions. Because in some cases for monitor resolution
- // 1024x768 touchscreen's resolution would be 1024x768, but for
- // some 1023x767. It really depends on touchscreen's firmware
- // configuration.
- if (std::abs(mode_info->size().width() - width) <= 1.0 &&
- std::abs(mode_info->size().height() - height) <= 1.0) {
- output->touch_device_id = info[i].deviceid;
-
- VLOG(2) << "Found touchscreen for output #" << k << " id "
- << output->touch_device_id << " width " << width << " height "
- << height;
- break;
- }
- }
-
- if (k == outputs->size()) {
- no_match_touchscreen.insert(info[i].deviceid);
- VLOG(2) << "No matching output for touchscreen"
- << " id " << info[i].deviceid << " width " << width
- << " height " << height;
- }
- }
- }
-
- // Sometimes we can't find a matching screen for the touchscreen, e.g.
- // due to the touchscreen's reporting range having no correlation with the
- // screen's resolution. In this case, we arbitrarily assign unmatched
- // touchscreens to unmatched screens.
- for (std::set<int>::iterator it = no_match_touchscreen.begin();
- it != no_match_touchscreen.end();
- it++) {
- for (size_t i = 0; i < outputs->size(); i++) {
- if ((*outputs)[i].display->type() != DISPLAY_CONNECTION_TYPE_INTERNAL &&
- (*outputs)[i].display->native_mode() != NULL &&
- (*outputs)[i].touch_device_id == None) {
- (*outputs)[i].touch_device_id = *it;
- VLOG(2) << "Arbitrarily matching touchscreen "
- << (*outputs)[i].touch_device_id << " to output #" << i;
- break;
- }
- }
- }
-
- XIFreeDeviceInfo(info);
-}
-
-} // namespace ui
diff --git a/ui/display/chromeos/x11/touchscreen_delegate_x11.h b/ui/display/chromeos/x11/touchscreen_delegate_x11.h
deleted file mode 100644
index 7966ddf..0000000
--- a/ui/display/chromeos/x11/touchscreen_delegate_x11.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef UI_DISPLAY_CHROMEOS_X11_TOUCHSCREEN_DELEGATE_X11_H_
-#define UI_DISPLAY_CHROMEOS_X11_TOUCHSCREEN_DELEGATE_X11_H_
-
-#include "ui/display/chromeos/display_configurator.h"
-
-struct _XDisplay;
-typedef struct _XDisplay Display;
-
-namespace ui {
-
-class TouchscreenDelegateX11 : public DisplayConfigurator::TouchscreenDelegate {
- public:
- TouchscreenDelegateX11();
- virtual ~TouchscreenDelegateX11();
-
- // DisplayConfigurator::TouchscreenDelegate implementation:
- virtual void AssociateTouchscreens(
- DisplayConfigurator::DisplayStateList* outputs) OVERRIDE;
-
- private:
- Display* display_;
-
- DISALLOW_COPY_AND_ASSIGN(TouchscreenDelegateX11);
-};
-
-} // namespace ui
-
-#endif // UI_DISPLAY_CHROMEOS_X11_TOUCHSCREEN_DELEGATE_X11_H_
diff --git a/ui/display/chromeos/x11/touchscreen_device_manager_x11.cc b/ui/display/chromeos/x11/touchscreen_device_manager_x11.cc
new file mode 100644
index 0000000..6c8137b
--- /dev/null
+++ b/ui/display/chromeos/x11/touchscreen_device_manager_x11.cc
@@ -0,0 +1,82 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/display/chromeos/x11/touchscreen_device_manager_x11.h"
+
+#include <X11/extensions/XInput.h>
+#include <X11/extensions/XInput2.h>
+
+#include <cmath>
+#include <set>
+
+#include "ui/gfx/x/x11_types.h"
+
+namespace ui {
+
+TouchscreenDeviceManagerX11::TouchscreenDeviceManagerX11()
+ : display_(gfx::GetXDisplay()) {}
+
+TouchscreenDeviceManagerX11::~TouchscreenDeviceManagerX11() {}
+
+std::vector<TouchscreenDevice> TouchscreenDeviceManagerX11::GetDevices() {
+ std::vector<TouchscreenDevice> devices;
+ int num_devices = 0;
+ Atom valuator_x = XInternAtom(display_, "Abs MT Position X", False);
+ Atom valuator_y = XInternAtom(display_, "Abs MT Position Y", False);
+ if (valuator_x == None || valuator_y == None)
+ return devices;
+
+ std::set<int> no_match_touchscreen;
+ XIDeviceInfo* info = XIQueryDevice(display_, XIAllDevices, &num_devices);
+ for (int i = 0; i < num_devices; i++) {
+ if (!info[i].enabled || info[i].use != XIFloatingSlave)
+ continue; // Assume all touchscreens are floating slaves
+
+ double width = -1.0;
+ double height = -1.0;
+ bool is_direct_touch = false;
+
+ for (int j = 0; j < info[i].num_classes; j++) {
+ XIAnyClassInfo* class_info = info[i].classes[j];
+
+ if (class_info->type == XIValuatorClass) {
+ XIValuatorClassInfo* valuator_info =
+ reinterpret_cast<XIValuatorClassInfo*>(class_info);
+
+ if (valuator_x == valuator_info->label) {
+ // Ignore X axis valuator with unexpected properties
+ if (valuator_info->number == 0 && valuator_info->mode == Absolute &&
+ valuator_info->min == 0.0) {
+ width = valuator_info->max;
+ }
+ } else if (valuator_y == valuator_info->label) {
+ // Ignore Y axis valuator with unexpected properties
+ if (valuator_info->number == 1 && valuator_info->mode == Absolute &&
+ valuator_info->min == 0.0) {
+ height = valuator_info->max;
+ }
+ }
+ }
+#if defined(USE_XI2_MT)
+ if (class_info->type == XITouchClass) {
+ XITouchClassInfo* touch_info =
+ reinterpret_cast<XITouchClassInfo*>(class_info);
+ is_direct_touch = touch_info->mode == XIDirectTouch;
+ }
+#endif
+ }
+
+ // Touchscreens should have absolute X and Y axes, and be direct touch
+ // devices.
+ if (width > 0.0 && height > 0.0 && is_direct_touch) {
+ devices.push_back(TouchscreenDevice(info[i].deviceid,
+ gfx::Size(width, height)));
+ }
+ }
+
+ XIFreeDeviceInfo(info);
+ return devices;
+}
+
+} // namespace ui
diff --git a/ui/display/chromeos/x11/touchscreen_device_manager_x11.h b/ui/display/chromeos/x11/touchscreen_device_manager_x11.h
new file mode 100644
index 0000000..594ef03
--- /dev/null
+++ b/ui/display/chromeos/x11/touchscreen_device_manager_x11.h
@@ -0,0 +1,32 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_DISPLAY_CHROMEOS_X11_TOUCHSCREEN_DEVICE_MANAGER_X11_H_
+#define UI_DISPLAY_CHROMEOS_X11_TOUCHSCREEN_DEVICE_MANAGER_X11_H_
+
+#include "base/macros.h"
+#include "ui/display/types/chromeos/touchscreen_device_manager.h"
+
+struct _XDisplay;
+typedef struct _XDisplay Display;
+
+namespace ui {
+
+class TouchscreenDeviceManagerX11 : public TouchscreenDeviceManager {
+ public:
+ TouchscreenDeviceManagerX11();
+ virtual ~TouchscreenDeviceManagerX11();
+
+ // TouchscreenDeviceManager implementation:
+ virtual std::vector<TouchscreenDevice> GetDevices() OVERRIDE;
+
+ private:
+ Display* display_;
+
+ DISALLOW_COPY_AND_ASSIGN(TouchscreenDeviceManagerX11);
+};
+
+} // namespace ui
+
+#endif // UI_DISPLAY_CHROMEOS_X11_TOUCHSCREEN_DEVICE_MANAGER_X11_H_