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

Side by Side Diff: ui/ozone/platform/wayland/wayland_pointer.cc

Issue 1712103002: ozone/platform/wayland: Implement pointer handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 9 months 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
OLDNEW
(Empty)
1 // Copyright 2016 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/ozone/platform/wayland/wayland_pointer.h"
6
7 #include <linux/input.h>
8 #include <wayland-client.h>
9
10 #include "ui/events/event.h"
11 #include "ui/ozone/platform/wayland/wayland_window.h"
12
13 // TODO(forney): Handle version 5 of wl_pointer.
14
15 namespace ui {
16
17 WaylandPointer::WaylandPointer(wl_pointer* pointer,
18 const EventDispatchCallback& callback)
19 : obj_(pointer), callback_(callback) {
20 static const wl_pointer_listener listener = {
21 &WaylandPointer::Enter, &WaylandPointer::Leave, &WaylandPointer::Motion,
22 &WaylandPointer::Button, &WaylandPointer::Axis,
23 };
24
25 wl_pointer_add_listener(obj_.get(), &listener, this);
26 }
27
28 WaylandPointer::~WaylandPointer() {}
29
30 // static
31 void WaylandPointer::Enter(void* data,
32 wl_pointer* obj,
33 uint32_t serial,
34 wl_surface* surface,
35 wl_fixed_t surface_x,
36 wl_fixed_t surface_y) {
37 WaylandPointer* pointer = static_cast<WaylandPointer*>(data);
38 pointer->location_.SetPoint(wl_fixed_to_double(surface_x),
39 wl_fixed_to_double(surface_y));
40 if (surface)
41 WaylandWindow::FromSurface(surface)->set_pointer_focus(true);
42 }
43
44 // static
45 void WaylandPointer::Leave(void* data,
46 wl_pointer* obj,
47 uint32_t serial,
48 wl_surface* surface) {
49 if (surface)
50 WaylandWindow::FromSurface(surface)->set_pointer_focus(false);
51 }
52
53 // static
54 void WaylandPointer::Motion(void* data,
55 wl_pointer* obj,
56 uint32_t time,
57 wl_fixed_t surface_x,
58 wl_fixed_t surface_y) {
59 WaylandPointer* pointer = static_cast<WaylandPointer*>(data);
60 pointer->location_.SetPoint(wl_fixed_to_double(surface_x),
61 wl_fixed_to_double(surface_y));
62 MouseEvent event(ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
63 base::TimeDelta::FromMilliseconds(time), pointer->flags_, 0);
64 event.set_location_f(pointer->location_);
65 event.set_root_location_f(pointer->location_);
66 pointer->callback_.Run(&event);
67 }
68
69 // static
70 void WaylandPointer::Button(void* data,
71 wl_pointer* obj,
72 uint32_t serial,
73 uint32_t time,
74 uint32_t button,
75 uint32_t state) {
76 WaylandPointer* pointer = static_cast<WaylandPointer*>(data);
77 int flag;
78 switch (button) {
79 case BTN_LEFT:
80 flag = EF_LEFT_MOUSE_BUTTON;
81 break;
82 case BTN_MIDDLE:
83 flag = EF_MIDDLE_MOUSE_BUTTON;
84 break;
85 case BTN_RIGHT:
86 flag = EF_RIGHT_MOUSE_BUTTON;
87 break;
88 case BTN_BACK:
89 flag = EF_BACK_MOUSE_BUTTON;
90 break;
91 case BTN_FORWARD:
92 flag = EF_FORWARD_MOUSE_BUTTON;
93 break;
94 default:
95 return;
96 }
97 int flags = pointer->flags_ | flag;
98 EventType type;
99 if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
100 type = ET_MOUSE_PRESSED;
101 pointer->flags_ |= flag;
102 } else {
103 type = ET_MOUSE_RELEASED;
104 pointer->flags_ &= ~flag;
105 }
106 MouseEvent event(type, gfx::Point(), gfx::Point(),
107 base::TimeDelta::FromMilliseconds(time), flags, flag);
108 event.set_location_f(pointer->location_);
109 event.set_root_location_f(pointer->location_);
110 pointer->callback_.Run(&event);
111 }
112
113 // static
114 void WaylandPointer::Axis(void* data,
115 wl_pointer* obj,
116 uint32_t time,
117 uint32_t axis,
118 wl_fixed_t value) {
119 static const double kAxisValueScale = 10.0;
120 WaylandPointer* pointer = static_cast<WaylandPointer*>(data);
121 gfx::Vector2d offset;
122 // Wayland compositors send axis events with values in the surface coordinate
123 // space. They send a value of 10 per mouse wheel click by convention, so
124 // clients (e.g. GTK+) typically scale down by this amount to convert to
125 // discrete step coordinates. wl_pointer version 5 improves the situation by
126 // adding axis sources and discrete axis events.
127 if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL)
128 offset.set_y(-wl_fixed_to_double(value) / kAxisValueScale *
129 MouseWheelEvent::kWheelDelta);
130 else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL)
131 offset.set_x(wl_fixed_to_double(value) / kAxisValueScale *
132 MouseWheelEvent::kWheelDelta);
133 else
134 return;
135 MouseWheelEvent event(offset, gfx::Point(), gfx::Point(),
136 base::TimeDelta::FromMilliseconds(time),
137 pointer->flags_, 0);
138 event.set_location_f(pointer->location_);
139 event.set_root_location_f(pointer->location_);
140 pointer->callback_.Run(&event);
141 }
142
143 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/wayland/wayland_pointer.h ('k') | ui/ozone/platform/wayland/wayland_pointer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698