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 <grp.h> | 7 #include <grp.h> |
8 #include <linux/input.h> | 8 #include <linux/input.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 } | 102 } |
103 | 103 |
104 template <class T> | 104 template <class T> |
105 void SetImplementation(wl_resource* resource, | 105 void SetImplementation(wl_resource* resource, |
106 const void* implementation, | 106 const void* implementation, |
107 std::unique_ptr<T> user_data) { | 107 std::unique_ptr<T> user_data) { |
108 wl_resource_set_implementation(resource, implementation, user_data.release(), | 108 wl_resource_set_implementation(resource, implementation, user_data.release(), |
109 DestroyUserData<T>); | 109 DestroyUserData<T>); |
110 } | 110 } |
111 | 111 |
112 int64_t InMilliseconds(base::TimeTicks ticks) { | |
reveman
2016/06/03 13:06:00
Can you make this "uint32_t EventTimeStampToMillis
majidvp
2016/06/03 19:14:21
Done. I used TimeTicksToMilleseconds because it wa
| |
113 return (ticks - base::TimeTicks()).InMilliseconds(); | |
114 } | |
115 | |
112 // A property key containing the surface resource that is associated with | 116 // A property key containing the surface resource that is associated with |
113 // window. If unset, no surface resource is associated with window. | 117 // window. If unset, no surface resource is associated with window. |
114 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); | 118 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); |
115 | 119 |
116 // A property key containing a boolean set to true if a viewport is associated | 120 // A property key containing a boolean set to true if a viewport is associated |
117 // with window. | 121 // with window. |
118 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); | 122 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); |
119 | 123 |
120 // A property key containing a boolean set to true if a security object is | 124 // A property key containing a boolean set to true if a security object is |
121 // associated with window. | 125 // associated with window. |
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1653 // if client's pressed button state is different from |button_flags|? | 1657 // if client's pressed button state is different from |button_flags|? |
1654 wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource, | 1658 wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource, |
1655 wl_fixed_from_double(location.x()), | 1659 wl_fixed_from_double(location.x()), |
1656 wl_fixed_from_double(location.y())); | 1660 wl_fixed_from_double(location.y())); |
1657 } | 1661 } |
1658 void OnPointerLeave(Surface* surface) override { | 1662 void OnPointerLeave(Surface* surface) override { |
1659 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 1663 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
1660 DCHECK(surface_resource); | 1664 DCHECK(surface_resource); |
1661 wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource); | 1665 wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource); |
1662 } | 1666 } |
1663 void OnPointerMotion(base::TimeDelta time_stamp, | 1667 void OnPointerMotion(base::TimeTicks time_stamp, |
1664 const gfx::PointF& location) override { | 1668 const gfx::PointF& location) override { |
1665 wl_pointer_send_motion(pointer_resource_, time_stamp.InMilliseconds(), | 1669 wl_pointer_send_motion(pointer_resource_, InMilliseconds(time_stamp), |
1666 wl_fixed_from_double(location.x()), | 1670 wl_fixed_from_double(location.x()), |
1667 wl_fixed_from_double(location.y())); | 1671 wl_fixed_from_double(location.y())); |
1668 } | 1672 } |
1669 void OnPointerButton(base::TimeDelta time_stamp, | 1673 void OnPointerButton(base::TimeTicks time_stamp, |
1670 int button_flags, | 1674 int button_flags, |
1671 bool pressed) override { | 1675 bool pressed) override { |
1672 struct { | 1676 struct { |
1673 ui::EventFlags flag; | 1677 ui::EventFlags flag; |
1674 uint32_t value; | 1678 uint32_t value; |
1675 } buttons[] = { | 1679 } buttons[] = { |
1676 {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT}, | 1680 {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT}, |
1677 {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT}, | 1681 {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT}, |
1678 {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE}, | 1682 {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE}, |
1679 {ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD}, | 1683 {ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD}, |
1680 {ui::EF_BACK_MOUSE_BUTTON, BTN_BACK}, | 1684 {ui::EF_BACK_MOUSE_BUTTON, BTN_BACK}, |
1681 }; | 1685 }; |
1682 uint32_t serial = next_serial(); | 1686 uint32_t serial = next_serial(); |
1683 for (auto button : buttons) { | 1687 for (auto button : buttons) { |
1684 if (button_flags & button.flag) { | 1688 if (button_flags & button.flag) { |
1685 wl_pointer_send_button(pointer_resource_, serial, | 1689 wl_pointer_send_button(pointer_resource_, serial, |
1686 time_stamp.InMilliseconds(), button.value, | 1690 InMilliseconds(time_stamp), button.value, |
1687 pressed ? WL_POINTER_BUTTON_STATE_PRESSED | 1691 pressed ? WL_POINTER_BUTTON_STATE_PRESSED |
1688 : WL_POINTER_BUTTON_STATE_RELEASED); | 1692 : WL_POINTER_BUTTON_STATE_RELEASED); |
1689 } | 1693 } |
1690 } | 1694 } |
1691 } | 1695 } |
1692 | 1696 |
1693 void OnPointerScroll(base::TimeDelta time_stamp, | 1697 void OnPointerScroll(base::TimeTicks time_stamp, |
1694 const gfx::Vector2dF& offset, | 1698 const gfx::Vector2dF& offset, |
1695 bool discrete) override { | 1699 bool discrete) override { |
1696 // Same as Weston, the reference compositor. | 1700 // Same as Weston, the reference compositor. |
1697 const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta; | 1701 const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta; |
1698 | 1702 |
1699 if (wl_resource_get_version(pointer_resource_) >= | 1703 if (wl_resource_get_version(pointer_resource_) >= |
1700 WL_POINTER_AXIS_SOURCE_SINCE_VERSION) { | 1704 WL_POINTER_AXIS_SOURCE_SINCE_VERSION) { |
1701 int32_t axis_source = discrete ? WL_POINTER_AXIS_SOURCE_WHEEL | 1705 int32_t axis_source = discrete ? WL_POINTER_AXIS_SOURCE_WHEEL |
1702 : WL_POINTER_AXIS_SOURCE_FINGER; | 1706 : WL_POINTER_AXIS_SOURCE_FINGER; |
1703 wl_pointer_send_axis_source(pointer_resource_, axis_source); | 1707 wl_pointer_send_axis_source(pointer_resource_, axis_source); |
1704 } | 1708 } |
1705 | 1709 |
1706 double x_value = offset.x() * kAxisStepDistance; | 1710 double x_value = offset.x() * kAxisStepDistance; |
1707 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(), | 1711 wl_pointer_send_axis(pointer_resource_, InMilliseconds(time_stamp), |
1708 WL_POINTER_AXIS_HORIZONTAL_SCROLL, | 1712 WL_POINTER_AXIS_HORIZONTAL_SCROLL, |
1709 wl_fixed_from_double(-x_value)); | 1713 wl_fixed_from_double(-x_value)); |
1710 | 1714 |
1711 double y_value = offset.y() * kAxisStepDistance; | 1715 double y_value = offset.y() * kAxisStepDistance; |
1712 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(), | 1716 wl_pointer_send_axis(pointer_resource_, InMilliseconds(time_stamp), |
1713 WL_POINTER_AXIS_VERTICAL_SCROLL, | 1717 WL_POINTER_AXIS_VERTICAL_SCROLL, |
1714 wl_fixed_from_double(-y_value)); | 1718 wl_fixed_from_double(-y_value)); |
1715 } | 1719 } |
1716 | 1720 |
1717 void OnPointerScrollCancel(base::TimeDelta time_stamp) override { | 1721 void OnPointerScrollCancel(base::TimeTicks time_stamp) override { |
1718 // Wayland doesn't know the concept of a canceling kinetic scrolling. | 1722 // Wayland doesn't know the concept of a canceling kinetic scrolling. |
1719 // But we can send a 0 distance scroll to emulate this behavior. | 1723 // But we can send a 0 distance scroll to emulate this behavior. |
1720 OnPointerScroll(time_stamp, gfx::Vector2dF(0, 0), false); | 1724 OnPointerScroll(time_stamp, gfx::Vector2dF(0, 0), false); |
1721 OnPointerScrollStop(time_stamp); | 1725 OnPointerScrollStop(time_stamp); |
1722 } | 1726 } |
1723 | 1727 |
1724 void OnPointerScrollStop(base::TimeDelta time_stamp) override { | 1728 void OnPointerScrollStop(base::TimeTicks time_stamp) override { |
1725 if (wl_resource_get_version(pointer_resource_) >= | 1729 if (wl_resource_get_version(pointer_resource_) >= |
1726 WL_POINTER_AXIS_STOP_SINCE_VERSION) { | 1730 WL_POINTER_AXIS_STOP_SINCE_VERSION) { |
1727 wl_pointer_send_axis_stop(pointer_resource_, time_stamp.InMilliseconds(), | 1731 wl_pointer_send_axis_stop(pointer_resource_, InMilliseconds(time_stamp), |
1728 WL_POINTER_AXIS_HORIZONTAL_SCROLL); | 1732 WL_POINTER_AXIS_HORIZONTAL_SCROLL); |
1729 wl_pointer_send_axis_stop(pointer_resource_, time_stamp.InMilliseconds(), | 1733 wl_pointer_send_axis_stop(pointer_resource_, InMilliseconds(time_stamp), |
1730 WL_POINTER_AXIS_VERTICAL_SCROLL); | 1734 WL_POINTER_AXIS_VERTICAL_SCROLL); |
1731 } | 1735 } |
1732 } | 1736 } |
1733 | 1737 |
1734 void OnPointerFrame() override { | 1738 void OnPointerFrame() override { |
1735 if (wl_resource_get_version(pointer_resource_) >= | 1739 if (wl_resource_get_version(pointer_resource_) >= |
1736 WL_POINTER_FRAME_SINCE_VERSION) { | 1740 WL_POINTER_FRAME_SINCE_VERSION) { |
1737 wl_pointer_send_frame(pointer_resource_); | 1741 wl_pointer_send_frame(pointer_resource_); |
1738 } | 1742 } |
1739 wl_client_flush(client()); | 1743 wl_client_flush(client()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1830 &keys); | 1834 &keys); |
1831 wl_array_release(&keys); | 1835 wl_array_release(&keys); |
1832 wl_client_flush(client()); | 1836 wl_client_flush(client()); |
1833 } | 1837 } |
1834 void OnKeyboardLeave(Surface* surface) override { | 1838 void OnKeyboardLeave(Surface* surface) override { |
1835 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 1839 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
1836 DCHECK(surface_resource); | 1840 DCHECK(surface_resource); |
1837 wl_keyboard_send_leave(keyboard_resource_, next_serial(), surface_resource); | 1841 wl_keyboard_send_leave(keyboard_resource_, next_serial(), surface_resource); |
1838 wl_client_flush(client()); | 1842 wl_client_flush(client()); |
1839 } | 1843 } |
1840 void OnKeyboardKey(base::TimeDelta time_stamp, | 1844 void OnKeyboardKey(base::TimeTicks time_stamp, |
1841 ui::DomCode key, | 1845 ui::DomCode key, |
1842 bool pressed) override { | 1846 bool pressed) override { |
1843 wl_keyboard_send_key(keyboard_resource_, next_serial(), | 1847 wl_keyboard_send_key(keyboard_resource_, next_serial(), |
1844 time_stamp.InMilliseconds(), DomCodeToKey(key), | 1848 InMilliseconds(time_stamp), DomCodeToKey(key), |
1845 pressed ? WL_KEYBOARD_KEY_STATE_PRESSED | 1849 pressed ? WL_KEYBOARD_KEY_STATE_PRESSED |
1846 : WL_KEYBOARD_KEY_STATE_RELEASED); | 1850 : WL_KEYBOARD_KEY_STATE_RELEASED); |
1847 wl_client_flush(client()); | 1851 wl_client_flush(client()); |
1848 } | 1852 } |
1849 void OnKeyboardModifiers(int modifier_flags) override { | 1853 void OnKeyboardModifiers(int modifier_flags) override { |
1850 xkb_state_update_mask(xkb_state_.get(), | 1854 xkb_state_update_mask(xkb_state_.get(), |
1851 ModifierFlagsToXkbModifiers(modifier_flags), 0, 0, 0, | 1855 ModifierFlagsToXkbModifiers(modifier_flags), 0, 0, 0, |
1852 0, 0); | 1856 0, 0); |
1853 wl_keyboard_send_modifiers( | 1857 wl_keyboard_send_modifiers( |
1854 keyboard_resource_, next_serial(), | 1858 keyboard_resource_, next_serial(), |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1939 // Overridden from TouchDelegate: | 1943 // Overridden from TouchDelegate: |
1940 void OnTouchDestroying(Touch* touch) override { delete this; } | 1944 void OnTouchDestroying(Touch* touch) override { delete this; } |
1941 bool CanAcceptTouchEventsForSurface(Surface* surface) const override { | 1945 bool CanAcceptTouchEventsForSurface(Surface* surface) const override { |
1942 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 1946 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
1943 // We can accept events for this surface if the client is the same as the | 1947 // We can accept events for this surface if the client is the same as the |
1944 // touch resource. | 1948 // touch resource. |
1945 return surface_resource && | 1949 return surface_resource && |
1946 wl_resource_get_client(surface_resource) == client(); | 1950 wl_resource_get_client(surface_resource) == client(); |
1947 } | 1951 } |
1948 void OnTouchDown(Surface* surface, | 1952 void OnTouchDown(Surface* surface, |
1949 base::TimeDelta time_stamp, | 1953 base::TimeTicks time_stamp, |
1950 int id, | 1954 int id, |
1951 const gfx::Point& location) override { | 1955 const gfx::Point& location) override { |
1952 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 1956 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
1953 DCHECK(surface_resource); | 1957 DCHECK(surface_resource); |
1954 wl_touch_send_down(touch_resource_, next_serial(), | 1958 wl_touch_send_down(touch_resource_, next_serial(), |
1955 time_stamp.InMilliseconds(), surface_resource, id, | 1959 InMilliseconds(time_stamp), surface_resource, id, |
1956 wl_fixed_from_int(location.x()), | 1960 wl_fixed_from_int(location.x()), |
1957 wl_fixed_from_int(location.y())); | 1961 wl_fixed_from_int(location.y())); |
1958 wl_client_flush(client()); | 1962 wl_client_flush(client()); |
1959 } | 1963 } |
1960 void OnTouchUp(base::TimeDelta time_stamp, int id) override { | 1964 void OnTouchUp(base::TimeTicks time_stamp, int id) override { |
1961 wl_touch_send_up(touch_resource_, next_serial(), | 1965 wl_touch_send_up(touch_resource_, next_serial(), InMilliseconds(time_stamp), |
1962 time_stamp.InMilliseconds(), id); | 1966 id); |
1963 wl_client_flush(client()); | 1967 wl_client_flush(client()); |
1964 } | 1968 } |
1965 void OnTouchMotion(base::TimeDelta time_stamp, | 1969 void OnTouchMotion(base::TimeTicks time_stamp, |
1966 int id, | 1970 int id, |
1967 const gfx::Point& location) override { | 1971 const gfx::Point& location) override { |
1968 wl_touch_send_motion(touch_resource_, time_stamp.InMilliseconds(), id, | 1972 wl_touch_send_motion(touch_resource_, InMilliseconds(time_stamp), id, |
1969 wl_fixed_from_int(location.x()), | 1973 wl_fixed_from_int(location.x()), |
1970 wl_fixed_from_int(location.y())); | 1974 wl_fixed_from_int(location.y())); |
1971 wl_client_flush(client()); | 1975 wl_client_flush(client()); |
1972 } | 1976 } |
1973 void OnTouchCancel() override { | 1977 void OnTouchCancel() override { |
1974 wl_touch_send_cancel(touch_resource_); | 1978 wl_touch_send_cancel(touch_resource_); |
1975 wl_client_flush(client()); | 1979 wl_client_flush(client()); |
1976 } | 1980 } |
1977 | 1981 |
1978 private: | 1982 private: |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2607 DCHECK(event_loop); | 2611 DCHECK(event_loop); |
2608 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2612 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
2609 } | 2613 } |
2610 | 2614 |
2611 void Server::Flush() { | 2615 void Server::Flush() { |
2612 wl_display_flush_clients(wl_display_.get()); | 2616 wl_display_flush_clients(wl_display_.get()); |
2613 } | 2617 } |
2614 | 2618 |
2615 } // namespace wayland | 2619 } // namespace wayland |
2616 } // namespace exo | 2620 } // namespace exo |
OLD | NEW |