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

Side by Side Diff: components/exo/wayland/server.cc

Issue 1750633002: components/exo: Extend pointer to use v5 protocol (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed nits 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
« no previous file with comments | « components/exo/pointer_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/exo/wayland/server.h" 5 #include "components/exo/wayland/server.h"
6 6
7 #include <grp.h> 7 #include <grp.h>
8 #include <linux/input.h> 8 #include <linux/input.h>
9 #include <scaler-server-protocol.h> 9 #include <scaler-server-protocol.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 void OnPointerEnter(Surface* surface, 1232 void OnPointerEnter(Surface* surface,
1233 const gfx::Point& location, 1233 const gfx::Point& location,
1234 int button_flags) override { 1234 int button_flags) override {
1235 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); 1235 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey);
1236 DCHECK(surface_resource); 1236 DCHECK(surface_resource);
1237 // Should we be sending button events to the client before the enter event 1237 // Should we be sending button events to the client before the enter event
1238 // if client's pressed button state is different from |button_flags|? 1238 // if client's pressed button state is different from |button_flags|?
1239 wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource, 1239 wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource,
1240 wl_fixed_from_int(location.x()), 1240 wl_fixed_from_int(location.x()),
1241 wl_fixed_from_int(location.y())); 1241 wl_fixed_from_int(location.y()));
1242 wl_client_flush(client());
1243 } 1242 }
1244 void OnPointerLeave(Surface* surface) override { 1243 void OnPointerLeave(Surface* surface) override {
1245 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); 1244 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey);
1246 DCHECK(surface_resource); 1245 DCHECK(surface_resource);
1247 wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource); 1246 wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource);
1248 wl_client_flush(client());
1249 } 1247 }
1250 void OnPointerMotion(base::TimeDelta time_stamp, 1248 void OnPointerMotion(base::TimeDelta time_stamp,
1251 const gfx::Point& location) override { 1249 const gfx::Point& location) override {
1252 wl_pointer_send_motion(pointer_resource_, time_stamp.InMilliseconds(), 1250 wl_pointer_send_motion(pointer_resource_, time_stamp.InMilliseconds(),
1253 wl_fixed_from_int(location.x()), 1251 wl_fixed_from_int(location.x()),
1254 wl_fixed_from_int(location.y())); 1252 wl_fixed_from_int(location.y()));
1255 wl_client_flush(client());
1256 } 1253 }
1257 void OnPointerButton(base::TimeDelta time_stamp, 1254 void OnPointerButton(base::TimeDelta time_stamp,
1258 int button_flags, 1255 int button_flags,
1259 bool pressed) override { 1256 bool pressed) override {
1260 struct { 1257 struct {
1261 ui::EventFlags flag; 1258 ui::EventFlags flag;
1262 uint32_t value; 1259 uint32_t value;
1263 } buttons[] = { 1260 } buttons[] = {
1264 {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT}, 1261 {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT},
1265 {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT}, 1262 {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT},
1266 {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE}, 1263 {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE},
1267 {ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD}, 1264 {ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD},
1268 {ui::EF_BACK_MOUSE_BUTTON, BTN_BACK}, 1265 {ui::EF_BACK_MOUSE_BUTTON, BTN_BACK},
1269 }; 1266 };
1270 uint32_t serial = next_serial(); 1267 uint32_t serial = next_serial();
1271 for (auto button : buttons) { 1268 for (auto button : buttons) {
1272 if (button_flags & button.flag) { 1269 if (button_flags & button.flag) {
1273 wl_pointer_send_button(pointer_resource_, serial, 1270 wl_pointer_send_button(pointer_resource_, serial,
1274 time_stamp.InMilliseconds(), button.value, 1271 time_stamp.InMilliseconds(), button.value,
1275 pressed ? WL_POINTER_BUTTON_STATE_PRESSED 1272 pressed ? WL_POINTER_BUTTON_STATE_PRESSED
1276 : WL_POINTER_BUTTON_STATE_RELEASED); 1273 : WL_POINTER_BUTTON_STATE_RELEASED);
1277 } 1274 }
1278 } 1275 }
1279 wl_client_flush(client());
1280 } 1276 }
1281 void OnPointerWheel(base::TimeDelta time_stamp, 1277
1282 const gfx::Vector2d& offset) override { 1278 void OnPointerScroll(base::TimeDelta time_stamp,
1279 const gfx::Vector2dF& offset,
1280 bool discrete) override {
1283 // Same as Weston, the reference compositor. 1281 // Same as Weston, the reference compositor.
1284 const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta; 1282 const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta;
1285 1283
1284 if (wl_resource_get_version(pointer_resource_) >=
1285 WL_POINTER_AXIS_SOURCE_SINCE_VERSION) {
1286 int32_t axis_source = discrete ? WL_POINTER_AXIS_SOURCE_WHEEL
1287 : WL_POINTER_AXIS_SOURCE_FINGER;
1288 wl_pointer_send_axis_source(pointer_resource_, axis_source);
1289 }
1290
1286 double x_value = offset.x() * kAxisStepDistance; 1291 double x_value = offset.x() * kAxisStepDistance;
1287 if (x_value) { 1292 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(),
1288 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(), 1293 WL_POINTER_AXIS_HORIZONTAL_SCROLL,
1289 WL_POINTER_AXIS_HORIZONTAL_SCROLL, 1294 wl_fixed_from_double(-x_value));
1290 wl_fixed_from_double(-x_value)); 1295
1296 double y_value = offset.y() * kAxisStepDistance;
1297 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(),
1298 WL_POINTER_AXIS_VERTICAL_SCROLL,
1299 wl_fixed_from_double(-y_value));
1300 }
1301
1302 void OnPointerScrollCancel(base::TimeDelta time_stamp) override {
1303 // Wayland doesn't know the concept of a canceling kinetic scrolling.
1304 // But we can send a 0 distance scroll to emulate this behavior.
1305 OnPointerScroll(time_stamp, gfx::Vector2dF(0, 0), false);
1306 OnPointerScrollStop(time_stamp);
1307 }
1308
1309 void OnPointerScrollStop(base::TimeDelta time_stamp) override {
1310 if (wl_resource_get_version(pointer_resource_) >=
1311 WL_POINTER_AXIS_STOP_SINCE_VERSION) {
1312 wl_pointer_send_axis_stop(pointer_resource_, time_stamp.InMilliseconds(),
1313 WL_POINTER_AXIS_HORIZONTAL_SCROLL);
1314 wl_pointer_send_axis_stop(pointer_resource_, time_stamp.InMilliseconds(),
1315 WL_POINTER_AXIS_VERTICAL_SCROLL);
1291 } 1316 }
1292 double y_value = offset.y() * kAxisStepDistance; 1317 }
1293 if (y_value) { 1318
1294 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(), 1319 void OnPointerFrame() override {
1295 WL_POINTER_AXIS_VERTICAL_SCROLL, 1320 if (wl_resource_get_version(pointer_resource_) >=
1296 wl_fixed_from_double(-y_value)); 1321 WL_POINTER_FRAME_SINCE_VERSION) {
1322 wl_pointer_send_frame(pointer_resource_);
1297 } 1323 }
1298 wl_client_flush(client()); 1324 wl_client_flush(client());
1299 } 1325 }
1300 1326
1301 private: 1327 private:
1302 // The client who own this pointer instance. 1328 // The client who own this pointer instance.
1303 wl_client* client() const { 1329 wl_client* client() const {
1304 return wl_resource_get_client(pointer_resource_); 1330 return wl_resource_get_client(pointer_resource_);
1305 } 1331 }
1306 1332
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 1613
1588 void seat_get_touch(wl_client* client, wl_resource* resource, uint32_t id) { 1614 void seat_get_touch(wl_client* client, wl_resource* resource, uint32_t id) {
1589 wl_resource* touch_resource = wl_resource_create( 1615 wl_resource* touch_resource = wl_resource_create(
1590 client, &wl_touch_interface, wl_resource_get_version(resource), id); 1616 client, &wl_touch_interface, wl_resource_get_version(resource), id);
1591 1617
1592 SetImplementation( 1618 SetImplementation(
1593 touch_resource, &touch_implementation, 1619 touch_resource, &touch_implementation,
1594 make_scoped_ptr(new Touch(new WaylandTouchDelegate(touch_resource)))); 1620 make_scoped_ptr(new Touch(new WaylandTouchDelegate(touch_resource))));
1595 } 1621 }
1596 1622
1623 void seat_release(wl_client* client, wl_resource* resource) {
1624 wl_resource_destroy(resource);
1625 }
1626
1597 const struct wl_seat_interface seat_implementation = { 1627 const struct wl_seat_interface seat_implementation = {
1598 seat_get_pointer, seat_get_keyboard, seat_get_touch}; 1628 seat_get_pointer, seat_get_keyboard, seat_get_touch, seat_release};
1599 1629
1600 const uint32_t seat_version = 4; 1630 const uint32_t seat_version = 5;
1601 1631
1602 void bind_seat(wl_client* client, void* data, uint32_t version, uint32_t id) { 1632 void bind_seat(wl_client* client, void* data, uint32_t version, uint32_t id) {
1603 wl_resource* resource = wl_resource_create( 1633 wl_resource* resource = wl_resource_create(
1604 client, &wl_seat_interface, std::min(version, seat_version), id); 1634 client, &wl_seat_interface, std::min(version, seat_version), id);
1605 1635
1606 wl_resource_set_implementation(resource, &seat_implementation, data, nullptr); 1636 wl_resource_set_implementation(resource, &seat_implementation, data, nullptr);
1607 1637
1608 if (version >= WL_SEAT_NAME_SINCE_VERSION) 1638 if (version >= WL_SEAT_NAME_SINCE_VERSION)
1609 wl_seat_send_name(resource, "default"); 1639 wl_seat_send_name(resource, "default");
1610 1640
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 DCHECK(event_loop); 1865 DCHECK(event_loop);
1836 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 1866 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
1837 } 1867 }
1838 1868
1839 void Server::Flush() { 1869 void Server::Flush() {
1840 wl_display_flush_clients(wl_display_.get()); 1870 wl_display_flush_clients(wl_display_.get());
1841 } 1871 }
1842 1872
1843 } // namespace wayland 1873 } // namespace wayland
1844 } // namespace exo 1874 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/pointer_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698