OLD | NEW |
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 <alpha-compositing-unstable-v1-server-protocol.h> | 7 #include <alpha-compositing-unstable-v1-server-protocol.h> |
8 #include <grp.h> | 8 #include <grp.h> |
9 #include <linux/input.h> | 9 #include <linux/input.h> |
10 #include <scaler-server-protocol.h> | 10 #include <scaler-server-protocol.h> |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 95 } |
96 | 96 |
97 template <class T> | 97 template <class T> |
98 void SetImplementation(wl_resource* resource, | 98 void SetImplementation(wl_resource* resource, |
99 const void* implementation, | 99 const void* implementation, |
100 std::unique_ptr<T> user_data) { | 100 std::unique_ptr<T> user_data) { |
101 wl_resource_set_implementation(resource, implementation, user_data.release(), | 101 wl_resource_set_implementation(resource, implementation, user_data.release(), |
102 DestroyUserData<T>); | 102 DestroyUserData<T>); |
103 } | 103 } |
104 | 104 |
| 105 int64_t InMilliseconds(base::TimeTicks ticks) { |
| 106 return (ticks - base::TimeTicks()).InMilliseconds(); |
| 107 } |
| 108 |
105 // A property key containing the surface resource that is associated with | 109 // A property key containing the surface resource that is associated with |
106 // window. If unset, no surface resource is associated with window. | 110 // window. If unset, no surface resource is associated with window. |
107 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); | 111 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); |
108 | 112 |
109 // A property key containing a boolean set to true if a viewport is associated | 113 // A property key containing a boolean set to true if a viewport is associated |
110 // with window. | 114 // with window. |
111 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); | 115 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); |
112 | 116 |
113 // A property key containing a boolean set to true if a security object is | 117 // A property key containing a boolean set to true if a security object is |
114 // associated with window. | 118 // associated with window. |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 // if client's pressed button state is different from |button_flags|? | 1446 // if client's pressed button state is different from |button_flags|? |
1443 wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource, | 1447 wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource, |
1444 wl_fixed_from_double(location.x()), | 1448 wl_fixed_from_double(location.x()), |
1445 wl_fixed_from_double(location.y())); | 1449 wl_fixed_from_double(location.y())); |
1446 } | 1450 } |
1447 void OnPointerLeave(Surface* surface) override { | 1451 void OnPointerLeave(Surface* surface) override { |
1448 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 1452 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
1449 DCHECK(surface_resource); | 1453 DCHECK(surface_resource); |
1450 wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource); | 1454 wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource); |
1451 } | 1455 } |
1452 void OnPointerMotion(base::TimeDelta time_stamp, | 1456 void OnPointerMotion(base::TimeTicks time_stamp, |
1453 const gfx::PointF& location) override { | 1457 const gfx::PointF& location) override { |
1454 wl_pointer_send_motion(pointer_resource_, time_stamp.InMilliseconds(), | 1458 wl_pointer_send_motion(pointer_resource_, InMilliseconds(time_stamp), |
1455 wl_fixed_from_double(location.x()), | 1459 wl_fixed_from_double(location.x()), |
1456 wl_fixed_from_double(location.y())); | 1460 wl_fixed_from_double(location.y())); |
1457 } | 1461 } |
1458 void OnPointerButton(base::TimeDelta time_stamp, | 1462 void OnPointerButton(base::TimeTicks time_stamp, |
1459 int button_flags, | 1463 int button_flags, |
1460 bool pressed) override { | 1464 bool pressed) override { |
1461 struct { | 1465 struct { |
1462 ui::EventFlags flag; | 1466 ui::EventFlags flag; |
1463 uint32_t value; | 1467 uint32_t value; |
1464 } buttons[] = { | 1468 } buttons[] = { |
1465 {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT}, | 1469 {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT}, |
1466 {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT}, | 1470 {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT}, |
1467 {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE}, | 1471 {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE}, |
1468 {ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD}, | 1472 {ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD}, |
1469 {ui::EF_BACK_MOUSE_BUTTON, BTN_BACK}, | 1473 {ui::EF_BACK_MOUSE_BUTTON, BTN_BACK}, |
1470 }; | 1474 }; |
1471 uint32_t serial = next_serial(); | 1475 uint32_t serial = next_serial(); |
1472 for (auto button : buttons) { | 1476 for (auto button : buttons) { |
1473 if (button_flags & button.flag) { | 1477 if (button_flags & button.flag) { |
1474 wl_pointer_send_button(pointer_resource_, serial, | 1478 wl_pointer_send_button(pointer_resource_, serial, |
1475 time_stamp.InMilliseconds(), button.value, | 1479 InMilliseconds(time_stamp), button.value, |
1476 pressed ? WL_POINTER_BUTTON_STATE_PRESSED | 1480 pressed ? WL_POINTER_BUTTON_STATE_PRESSED |
1477 : WL_POINTER_BUTTON_STATE_RELEASED); | 1481 : WL_POINTER_BUTTON_STATE_RELEASED); |
1478 } | 1482 } |
1479 } | 1483 } |
1480 } | 1484 } |
1481 | 1485 |
1482 void OnPointerScroll(base::TimeDelta time_stamp, | 1486 void OnPointerScroll(base::TimeTicks time_stamp, |
1483 const gfx::Vector2dF& offset, | 1487 const gfx::Vector2dF& offset, |
1484 bool discrete) override { | 1488 bool discrete) override { |
1485 // Same as Weston, the reference compositor. | 1489 // Same as Weston, the reference compositor. |
1486 const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta; | 1490 const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta; |
1487 | 1491 |
1488 if (wl_resource_get_version(pointer_resource_) >= | 1492 if (wl_resource_get_version(pointer_resource_) >= |
1489 WL_POINTER_AXIS_SOURCE_SINCE_VERSION) { | 1493 WL_POINTER_AXIS_SOURCE_SINCE_VERSION) { |
1490 int32_t axis_source = discrete ? WL_POINTER_AXIS_SOURCE_WHEEL | 1494 int32_t axis_source = discrete ? WL_POINTER_AXIS_SOURCE_WHEEL |
1491 : WL_POINTER_AXIS_SOURCE_FINGER; | 1495 : WL_POINTER_AXIS_SOURCE_FINGER; |
1492 wl_pointer_send_axis_source(pointer_resource_, axis_source); | 1496 wl_pointer_send_axis_source(pointer_resource_, axis_source); |
1493 } | 1497 } |
1494 | 1498 |
1495 double x_value = offset.x() * kAxisStepDistance; | 1499 double x_value = offset.x() * kAxisStepDistance; |
1496 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(), | 1500 wl_pointer_send_axis(pointer_resource_, InMilliseconds(time_stamp), |
1497 WL_POINTER_AXIS_HORIZONTAL_SCROLL, | 1501 WL_POINTER_AXIS_HORIZONTAL_SCROLL, |
1498 wl_fixed_from_double(-x_value)); | 1502 wl_fixed_from_double(-x_value)); |
1499 | 1503 |
1500 double y_value = offset.y() * kAxisStepDistance; | 1504 double y_value = offset.y() * kAxisStepDistance; |
1501 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(), | 1505 wl_pointer_send_axis(pointer_resource_, InMilliseconds(time_stamp), |
1502 WL_POINTER_AXIS_VERTICAL_SCROLL, | 1506 WL_POINTER_AXIS_VERTICAL_SCROLL, |
1503 wl_fixed_from_double(-y_value)); | 1507 wl_fixed_from_double(-y_value)); |
1504 } | 1508 } |
1505 | 1509 |
1506 void OnPointerScrollCancel(base::TimeDelta time_stamp) override { | 1510 void OnPointerScrollCancel(base::TimeTicks time_stamp) override { |
1507 // Wayland doesn't know the concept of a canceling kinetic scrolling. | 1511 // Wayland doesn't know the concept of a canceling kinetic scrolling. |
1508 // But we can send a 0 distance scroll to emulate this behavior. | 1512 // But we can send a 0 distance scroll to emulate this behavior. |
1509 OnPointerScroll(time_stamp, gfx::Vector2dF(0, 0), false); | 1513 OnPointerScroll(time_stamp, gfx::Vector2dF(0, 0), false); |
1510 OnPointerScrollStop(time_stamp); | 1514 OnPointerScrollStop(time_stamp); |
1511 } | 1515 } |
1512 | 1516 |
1513 void OnPointerScrollStop(base::TimeDelta time_stamp) override { | 1517 void OnPointerScrollStop(base::TimeTicks time_stamp) override { |
1514 if (wl_resource_get_version(pointer_resource_) >= | 1518 if (wl_resource_get_version(pointer_resource_) >= |
1515 WL_POINTER_AXIS_STOP_SINCE_VERSION) { | 1519 WL_POINTER_AXIS_STOP_SINCE_VERSION) { |
1516 wl_pointer_send_axis_stop(pointer_resource_, time_stamp.InMilliseconds(), | 1520 wl_pointer_send_axis_stop(pointer_resource_, InMilliseconds(time_stamp), |
1517 WL_POINTER_AXIS_HORIZONTAL_SCROLL); | 1521 WL_POINTER_AXIS_HORIZONTAL_SCROLL); |
1518 wl_pointer_send_axis_stop(pointer_resource_, time_stamp.InMilliseconds(), | 1522 wl_pointer_send_axis_stop(pointer_resource_, InMilliseconds(time_stamp), |
1519 WL_POINTER_AXIS_VERTICAL_SCROLL); | 1523 WL_POINTER_AXIS_VERTICAL_SCROLL); |
1520 } | 1524 } |
1521 } | 1525 } |
1522 | 1526 |
1523 void OnPointerFrame() override { | 1527 void OnPointerFrame() override { |
1524 if (wl_resource_get_version(pointer_resource_) >= | 1528 if (wl_resource_get_version(pointer_resource_) >= |
1525 WL_POINTER_FRAME_SINCE_VERSION) { | 1529 WL_POINTER_FRAME_SINCE_VERSION) { |
1526 wl_pointer_send_frame(pointer_resource_); | 1530 wl_pointer_send_frame(pointer_resource_); |
1527 } | 1531 } |
1528 wl_client_flush(client()); | 1532 wl_client_flush(client()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1619 &keys); | 1623 &keys); |
1620 wl_array_release(&keys); | 1624 wl_array_release(&keys); |
1621 wl_client_flush(client()); | 1625 wl_client_flush(client()); |
1622 } | 1626 } |
1623 void OnKeyboardLeave(Surface* surface) override { | 1627 void OnKeyboardLeave(Surface* surface) override { |
1624 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 1628 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
1625 DCHECK(surface_resource); | 1629 DCHECK(surface_resource); |
1626 wl_keyboard_send_leave(keyboard_resource_, next_serial(), surface_resource); | 1630 wl_keyboard_send_leave(keyboard_resource_, next_serial(), surface_resource); |
1627 wl_client_flush(client()); | 1631 wl_client_flush(client()); |
1628 } | 1632 } |
1629 void OnKeyboardKey(base::TimeDelta time_stamp, | 1633 void OnKeyboardKey(base::TimeTicks time_stamp, |
1630 ui::DomCode key, | 1634 ui::DomCode key, |
1631 bool pressed) override { | 1635 bool pressed) override { |
1632 wl_keyboard_send_key(keyboard_resource_, next_serial(), | 1636 wl_keyboard_send_key(keyboard_resource_, next_serial(), |
1633 time_stamp.InMilliseconds(), DomCodeToKey(key), | 1637 InMilliseconds(time_stamp), DomCodeToKey(key), |
1634 pressed ? WL_KEYBOARD_KEY_STATE_PRESSED | 1638 pressed ? WL_KEYBOARD_KEY_STATE_PRESSED |
1635 : WL_KEYBOARD_KEY_STATE_RELEASED); | 1639 : WL_KEYBOARD_KEY_STATE_RELEASED); |
1636 wl_client_flush(client()); | 1640 wl_client_flush(client()); |
1637 } | 1641 } |
1638 void OnKeyboardModifiers(int modifier_flags) override { | 1642 void OnKeyboardModifiers(int modifier_flags) override { |
1639 xkb_state_update_mask(xkb_state_.get(), | 1643 xkb_state_update_mask(xkb_state_.get(), |
1640 ModifierFlagsToXkbModifiers(modifier_flags), 0, 0, 0, | 1644 ModifierFlagsToXkbModifiers(modifier_flags), 0, 0, 0, |
1641 0, 0); | 1645 0, 0); |
1642 wl_keyboard_send_modifiers( | 1646 wl_keyboard_send_modifiers( |
1643 keyboard_resource_, next_serial(), | 1647 keyboard_resource_, next_serial(), |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 // Overridden from TouchDelegate: | 1732 // Overridden from TouchDelegate: |
1729 void OnTouchDestroying(Touch* touch) override { delete this; } | 1733 void OnTouchDestroying(Touch* touch) override { delete this; } |
1730 bool CanAcceptTouchEventsForSurface(Surface* surface) const override { | 1734 bool CanAcceptTouchEventsForSurface(Surface* surface) const override { |
1731 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 1735 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
1732 // We can accept events for this surface if the client is the same as the | 1736 // We can accept events for this surface if the client is the same as the |
1733 // touch resource. | 1737 // touch resource. |
1734 return surface_resource && | 1738 return surface_resource && |
1735 wl_resource_get_client(surface_resource) == client(); | 1739 wl_resource_get_client(surface_resource) == client(); |
1736 } | 1740 } |
1737 void OnTouchDown(Surface* surface, | 1741 void OnTouchDown(Surface* surface, |
1738 base::TimeDelta time_stamp, | 1742 base::TimeTicks time_stamp, |
1739 int id, | 1743 int id, |
1740 const gfx::Point& location) override { | 1744 const gfx::Point& location) override { |
1741 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 1745 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
1742 DCHECK(surface_resource); | 1746 DCHECK(surface_resource); |
1743 wl_touch_send_down(touch_resource_, next_serial(), | 1747 wl_touch_send_down(touch_resource_, next_serial(), |
1744 time_stamp.InMilliseconds(), surface_resource, id, | 1748 InMilliseconds(time_stamp), surface_resource, id, |
1745 wl_fixed_from_int(location.x()), | 1749 wl_fixed_from_int(location.x()), |
1746 wl_fixed_from_int(location.y())); | 1750 wl_fixed_from_int(location.y())); |
1747 wl_client_flush(client()); | 1751 wl_client_flush(client()); |
1748 } | 1752 } |
1749 void OnTouchUp(base::TimeDelta time_stamp, int id) override { | 1753 void OnTouchUp(base::TimeTicks time_stamp, int id) override { |
1750 wl_touch_send_up(touch_resource_, next_serial(), | 1754 wl_touch_send_up(touch_resource_, next_serial(), InMilliseconds(time_stamp), |
1751 time_stamp.InMilliseconds(), id); | 1755 id); |
1752 wl_client_flush(client()); | 1756 wl_client_flush(client()); |
1753 } | 1757 } |
1754 void OnTouchMotion(base::TimeDelta time_stamp, | 1758 void OnTouchMotion(base::TimeTicks time_stamp, |
1755 int id, | 1759 int id, |
1756 const gfx::Point& location) override { | 1760 const gfx::Point& location) override { |
1757 wl_touch_send_motion(touch_resource_, time_stamp.InMilliseconds(), id, | 1761 wl_touch_send_motion(touch_resource_, InMilliseconds(time_stamp), id, |
1758 wl_fixed_from_int(location.x()), | 1762 wl_fixed_from_int(location.x()), |
1759 wl_fixed_from_int(location.y())); | 1763 wl_fixed_from_int(location.y())); |
1760 wl_client_flush(client()); | 1764 wl_client_flush(client()); |
1761 } | 1765 } |
1762 void OnTouchCancel() override { | 1766 void OnTouchCancel() override { |
1763 wl_touch_send_cancel(touch_resource_); | 1767 wl_touch_send_cancel(touch_resource_); |
1764 wl_client_flush(client()); | 1768 wl_client_flush(client()); |
1765 } | 1769 } |
1766 | 1770 |
1767 private: | 1771 private: |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2394 DCHECK(event_loop); | 2398 DCHECK(event_loop); |
2395 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2399 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
2396 } | 2400 } |
2397 | 2401 |
2398 void Server::Flush() { | 2402 void Server::Flush() { |
2399 wl_display_flush_clients(wl_display_.get()); | 2403 wl_display_flush_clients(wl_display_.get()); |
2400 } | 2404 } |
2401 | 2405 |
2402 } // namespace wayland | 2406 } // namespace wayland |
2403 } // namespace exo | 2407 } // namespace exo |
OLD | NEW |