Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: ui/base/x/scroll_factory.cc

Issue 8907005: Add support for new scroll valuators coming from CMT (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup and comments Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/base/x/scroll_factory.h"
6
7 #include <stdio.h>
8 #include <X11/cursorfont.h>
9 #include <X11/extensions/XInput.h>
10 #include <X11/extensions/XInput2.h>
11 #include <X11/extensions/XIproto.h>
12
13 #include "ui/base/x/x11_util.h"
14
15 // Copied from xserver-properties.h
16 #define AXIS_LABEL_PROP_REL_HWHEEL "Rel Horiz Wheel"
17 #define AXIS_LABEL_PROP_REL_WHEEL "Rel Vert Wheel"
18
19 namespace ui {
20
21 // static
22 ScrollFactory* ScrollFactory::GetInstance() {
23 return Singleton<ScrollFactory>::get();
24 }
25
26 void ScrollFactory::UpdateDeviceList(Display* display) {
27 int count;
28 scroll_devices_.reset();
29 device_to_valuators_.clear();
30 XDeviceInfo* dev_list = XListInputDevices(display, &count);
31 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false);
32 for (int i = 0; i < count; ++i) {
33 XDeviceInfo* dev = dev_list + i;
34 if (dev->type == xi_touchpad)
35 scroll_devices_[dev_list[i].id] = true;
36 }
37 if (dev_list)
38 XFreeDeviceList(dev_list);
39
40 XIDeviceInfo* info_list = XIQueryDevice(display, XIAllDevices, &count);
41 Atom x_axis = XInternAtom(display, AXIS_LABEL_PROP_REL_HWHEEL, false);
42 Atom y_axis = XInternAtom(display, AXIS_LABEL_PROP_REL_WHEEL, false);
43 for (int i = 0; i < count; ++i) {
44 XIDeviceInfo* info = info_list + i;
45
46 if (!scroll_devices_[info->deviceid])
47 continue;
48
49 if (info->use != XISlavePointer && info->use != XIFloatingSlave) {
50 scroll_devices_[info->deviceid] = false;
51 continue;
52 }
53
54 Valuators valuators = {-1, -1};
55 for (int j = 0; j < info->num_classes; ++j) {
56 if (info->classes[j]->type != XIValuatorClass)
57 continue;
58
59 XIValuatorClassInfo* v =
60 reinterpret_cast<XIValuatorClassInfo*>(info->classes[j]);
61 if (v->label == x_axis)
62 valuators.x_scroll = v->number;
63 else if (v->label == y_axis)
64 valuators.y_scroll = v->number;
65 }
66 if (valuators.x_scroll >= 0 && valuators.y_scroll >= 0)
67 device_to_valuators_[info->deviceid] = valuators;
68 else
69 scroll_devices_[info->deviceid] = false;
70 }
71 }
72
73 bool ScrollFactory::GetScrollOffsets(const XEvent& xev,
74 float* x_offset,
75 float* y_offset) {
76 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
77 if (!scroll_devices_[xiev->deviceid])
78 return false;
79
80 int x_scroll = device_to_valuators_[xiev->deviceid].x_scroll;
81 int y_scroll = device_to_valuators_[xiev->deviceid].y_scroll;
82
83 bool has_x_offset = XIMaskIsSet(xiev->valuators.mask, x_scroll);
84 bool has_y_offset = XIMaskIsSet(xiev->valuators.mask, y_scroll);
85 bool is_scroll = has_x_offset || has_y_offset;
86
87 if (!x_offset && !y_offset)
88 return is_scroll;
89
90 double* valuators = xiev->valuators.values;
91 for (int i = 0; i < xiev->valuators.mask_len * 8; ++i) {
92 if (XIMaskIsSet(xiev->valuators.mask, i)) {
93 if (x_offset && x_scroll == i)
94 *x_offset = -(*valuators);
95 else if (y_offset && y_scroll == i)
96 *y_offset = -(*valuators);
97 valuators++;
98 }
99 }
100
101 return is_scroll;
102 }
103
104 ScrollFactory::ScrollFactory() {
105 UpdateDeviceList(ui::GetXDisplay());
106 }
107
108 ScrollFactory::~ScrollFactory() {}
109
110 } // namespace ui
OLDNEW
« ui/base/x/scroll_factory.h ('K') | « ui/base/x/scroll_factory.h ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698