| 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 template <class T> | 103 template <class T> |
| 104 void SetImplementation(wl_resource* resource, | 104 void SetImplementation(wl_resource* resource, |
| 105 const void* implementation, | 105 const void* implementation, |
| 106 std::unique_ptr<T> user_data) { | 106 std::unique_ptr<T> user_data) { |
| 107 wl_resource_set_implementation(resource, implementation, user_data.release(), | 107 wl_resource_set_implementation(resource, implementation, user_data.release(), |
| 108 DestroyUserData<T>); | 108 DestroyUserData<T>); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Convert a timestamp to a time value that can be used when interfacing |
| 112 // with wayland. Note that we cast a int64_t value to uint32_t which can |
| 113 // potentially overflow. |
| 114 uint32_t TimeTicksToMilliseconds(base::TimeTicks ticks) { |
| 115 return (ticks - base::TimeTicks()).InMilliseconds(); |
| 116 } |
| 117 |
| 111 // A property key containing the surface resource that is associated with | 118 // A property key containing the surface resource that is associated with |
| 112 // window. If unset, no surface resource is associated with window. | 119 // window. If unset, no surface resource is associated with window. |
| 113 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); | 120 DEFINE_WINDOW_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); |
| 114 | 121 |
| 115 // A property key containing a boolean set to true if a viewport is associated | 122 // A property key containing a boolean set to true if a viewport is associated |
| 116 // with window. | 123 // with window. |
| 117 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); | 124 DEFINE_WINDOW_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); |
| 118 | 125 |
| 119 // A property key containing a boolean set to true if a security object is | 126 // A property key containing a boolean set to true if a security object is |
| 120 // associated with window. | 127 // associated with window. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 int32_t x, | 170 int32_t x, |
| 164 int32_t y, | 171 int32_t y, |
| 165 int32_t width, | 172 int32_t width, |
| 166 int32_t height) { | 173 int32_t height) { |
| 167 GetUserDataAs<Surface>(resource)->Damage(gfx::Rect(x, y, width, height)); | 174 GetUserDataAs<Surface>(resource)->Damage(gfx::Rect(x, y, width, height)); |
| 168 } | 175 } |
| 169 | 176 |
| 170 void HandleSurfaceFrameCallback(wl_resource* resource, | 177 void HandleSurfaceFrameCallback(wl_resource* resource, |
| 171 base::TimeTicks frame_time) { | 178 base::TimeTicks frame_time) { |
| 172 if (!frame_time.is_null()) { | 179 if (!frame_time.is_null()) { |
| 173 wl_callback_send_done(resource, | 180 wl_callback_send_done(resource, TimeTicksToMilliseconds(frame_time)); |
| 174 (frame_time - base::TimeTicks()).InMilliseconds()); | |
| 175 // TODO(reveman): Remove this potentially blocking flush and instead watch | 181 // TODO(reveman): Remove this potentially blocking flush and instead watch |
| 176 // the file descriptor to be ready for write without blocking. | 182 // the file descriptor to be ready for write without blocking. |
| 177 wl_client_flush(wl_resource_get_client(resource)); | 183 wl_client_flush(wl_resource_get_client(resource)); |
| 178 } | 184 } |
| 179 wl_resource_destroy(resource); | 185 wl_resource_destroy(resource); |
| 180 } | 186 } |
| 181 | 187 |
| 182 void surface_frame(wl_client* client, | 188 void surface_frame(wl_client* client, |
| 183 wl_resource* resource, | 189 wl_resource* resource, |
| 184 uint32_t callback) { | 190 uint32_t callback) { |
| (...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 // if client's pressed button state is different from |button_flags|? | 1726 // if client's pressed button state is different from |button_flags|? |
| 1721 wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource, | 1727 wl_pointer_send_enter(pointer_resource_, next_serial(), surface_resource, |
| 1722 wl_fixed_from_double(location.x()), | 1728 wl_fixed_from_double(location.x()), |
| 1723 wl_fixed_from_double(location.y())); | 1729 wl_fixed_from_double(location.y())); |
| 1724 } | 1730 } |
| 1725 void OnPointerLeave(Surface* surface) override { | 1731 void OnPointerLeave(Surface* surface) override { |
| 1726 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 1732 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
| 1727 DCHECK(surface_resource); | 1733 DCHECK(surface_resource); |
| 1728 wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource); | 1734 wl_pointer_send_leave(pointer_resource_, next_serial(), surface_resource); |
| 1729 } | 1735 } |
| 1730 void OnPointerMotion(base::TimeDelta time_stamp, | 1736 void OnPointerMotion(base::TimeTicks time_stamp, |
| 1731 const gfx::PointF& location) override { | 1737 const gfx::PointF& location) override { |
| 1732 wl_pointer_send_motion(pointer_resource_, time_stamp.InMilliseconds(), | 1738 wl_pointer_send_motion( |
| 1733 wl_fixed_from_double(location.x()), | 1739 pointer_resource_, TimeTicksToMilliseconds(time_stamp), |
| 1734 wl_fixed_from_double(location.y())); | 1740 wl_fixed_from_double(location.x()), wl_fixed_from_double(location.y())); |
| 1735 } | 1741 } |
| 1736 void OnPointerButton(base::TimeDelta time_stamp, | 1742 void OnPointerButton(base::TimeTicks time_stamp, |
| 1737 int button_flags, | 1743 int button_flags, |
| 1738 bool pressed) override { | 1744 bool pressed) override { |
| 1739 struct { | 1745 struct { |
| 1740 ui::EventFlags flag; | 1746 ui::EventFlags flag; |
| 1741 uint32_t value; | 1747 uint32_t value; |
| 1742 } buttons[] = { | 1748 } buttons[] = { |
| 1743 {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT}, | 1749 {ui::EF_LEFT_MOUSE_BUTTON, BTN_LEFT}, |
| 1744 {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT}, | 1750 {ui::EF_RIGHT_MOUSE_BUTTON, BTN_RIGHT}, |
| 1745 {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE}, | 1751 {ui::EF_MIDDLE_MOUSE_BUTTON, BTN_MIDDLE}, |
| 1746 {ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD}, | 1752 {ui::EF_FORWARD_MOUSE_BUTTON, BTN_FORWARD}, |
| 1747 {ui::EF_BACK_MOUSE_BUTTON, BTN_BACK}, | 1753 {ui::EF_BACK_MOUSE_BUTTON, BTN_BACK}, |
| 1748 }; | 1754 }; |
| 1749 uint32_t serial = next_serial(); | 1755 uint32_t serial = next_serial(); |
| 1750 for (auto button : buttons) { | 1756 for (auto button : buttons) { |
| 1751 if (button_flags & button.flag) { | 1757 if (button_flags & button.flag) { |
| 1752 wl_pointer_send_button(pointer_resource_, serial, | 1758 wl_pointer_send_button( |
| 1753 time_stamp.InMilliseconds(), button.value, | 1759 pointer_resource_, serial, TimeTicksToMilliseconds(time_stamp), |
| 1754 pressed ? WL_POINTER_BUTTON_STATE_PRESSED | 1760 button.value, pressed ? WL_POINTER_BUTTON_STATE_PRESSED |
| 1755 : WL_POINTER_BUTTON_STATE_RELEASED); | 1761 : WL_POINTER_BUTTON_STATE_RELEASED); |
| 1756 } | 1762 } |
| 1757 } | 1763 } |
| 1758 } | 1764 } |
| 1759 | 1765 |
| 1760 void OnPointerScroll(base::TimeDelta time_stamp, | 1766 void OnPointerScroll(base::TimeTicks time_stamp, |
| 1761 const gfx::Vector2dF& offset, | 1767 const gfx::Vector2dF& offset, |
| 1762 bool discrete) override { | 1768 bool discrete) override { |
| 1763 // Same as Weston, the reference compositor. | 1769 // Same as Weston, the reference compositor. |
| 1764 const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta; | 1770 const double kAxisStepDistance = 10.0 / ui::MouseWheelEvent::kWheelDelta; |
| 1765 | 1771 |
| 1766 if (wl_resource_get_version(pointer_resource_) >= | 1772 if (wl_resource_get_version(pointer_resource_) >= |
| 1767 WL_POINTER_AXIS_SOURCE_SINCE_VERSION) { | 1773 WL_POINTER_AXIS_SOURCE_SINCE_VERSION) { |
| 1768 int32_t axis_source = discrete ? WL_POINTER_AXIS_SOURCE_WHEEL | 1774 int32_t axis_source = discrete ? WL_POINTER_AXIS_SOURCE_WHEEL |
| 1769 : WL_POINTER_AXIS_SOURCE_FINGER; | 1775 : WL_POINTER_AXIS_SOURCE_FINGER; |
| 1770 wl_pointer_send_axis_source(pointer_resource_, axis_source); | 1776 wl_pointer_send_axis_source(pointer_resource_, axis_source); |
| 1771 } | 1777 } |
| 1772 | 1778 |
| 1773 double x_value = offset.x() * kAxisStepDistance; | 1779 double x_value = offset.x() * kAxisStepDistance; |
| 1774 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(), | 1780 wl_pointer_send_axis(pointer_resource_, TimeTicksToMilliseconds(time_stamp), |
| 1775 WL_POINTER_AXIS_HORIZONTAL_SCROLL, | 1781 WL_POINTER_AXIS_HORIZONTAL_SCROLL, |
| 1776 wl_fixed_from_double(-x_value)); | 1782 wl_fixed_from_double(-x_value)); |
| 1777 | 1783 |
| 1778 double y_value = offset.y() * kAxisStepDistance; | 1784 double y_value = offset.y() * kAxisStepDistance; |
| 1779 wl_pointer_send_axis(pointer_resource_, time_stamp.InMilliseconds(), | 1785 wl_pointer_send_axis(pointer_resource_, TimeTicksToMilliseconds(time_stamp), |
| 1780 WL_POINTER_AXIS_VERTICAL_SCROLL, | 1786 WL_POINTER_AXIS_VERTICAL_SCROLL, |
| 1781 wl_fixed_from_double(-y_value)); | 1787 wl_fixed_from_double(-y_value)); |
| 1782 } | 1788 } |
| 1783 | 1789 |
| 1784 void OnPointerScrollCancel(base::TimeDelta time_stamp) override { | 1790 void OnPointerScrollCancel(base::TimeTicks time_stamp) override { |
| 1785 // Wayland doesn't know the concept of a canceling kinetic scrolling. | 1791 // Wayland doesn't know the concept of a canceling kinetic scrolling. |
| 1786 // But we can send a 0 distance scroll to emulate this behavior. | 1792 // But we can send a 0 distance scroll to emulate this behavior. |
| 1787 OnPointerScroll(time_stamp, gfx::Vector2dF(0, 0), false); | 1793 OnPointerScroll(time_stamp, gfx::Vector2dF(0, 0), false); |
| 1788 OnPointerScrollStop(time_stamp); | 1794 OnPointerScrollStop(time_stamp); |
| 1789 } | 1795 } |
| 1790 | 1796 |
| 1791 void OnPointerScrollStop(base::TimeDelta time_stamp) override { | 1797 void OnPointerScrollStop(base::TimeTicks time_stamp) override { |
| 1792 if (wl_resource_get_version(pointer_resource_) >= | 1798 if (wl_resource_get_version(pointer_resource_) >= |
| 1793 WL_POINTER_AXIS_STOP_SINCE_VERSION) { | 1799 WL_POINTER_AXIS_STOP_SINCE_VERSION) { |
| 1794 wl_pointer_send_axis_stop(pointer_resource_, time_stamp.InMilliseconds(), | 1800 wl_pointer_send_axis_stop(pointer_resource_, |
| 1801 TimeTicksToMilliseconds(time_stamp), |
| 1795 WL_POINTER_AXIS_HORIZONTAL_SCROLL); | 1802 WL_POINTER_AXIS_HORIZONTAL_SCROLL); |
| 1796 wl_pointer_send_axis_stop(pointer_resource_, time_stamp.InMilliseconds(), | 1803 wl_pointer_send_axis_stop(pointer_resource_, |
| 1804 TimeTicksToMilliseconds(time_stamp), |
| 1797 WL_POINTER_AXIS_VERTICAL_SCROLL); | 1805 WL_POINTER_AXIS_VERTICAL_SCROLL); |
| 1798 } | 1806 } |
| 1799 } | 1807 } |
| 1800 | 1808 |
| 1801 void OnPointerFrame() override { | 1809 void OnPointerFrame() override { |
| 1802 if (wl_resource_get_version(pointer_resource_) >= | 1810 if (wl_resource_get_version(pointer_resource_) >= |
| 1803 WL_POINTER_FRAME_SINCE_VERSION) { | 1811 WL_POINTER_FRAME_SINCE_VERSION) { |
| 1804 wl_pointer_send_frame(pointer_resource_); | 1812 wl_pointer_send_frame(pointer_resource_); |
| 1805 } | 1813 } |
| 1806 wl_client_flush(client()); | 1814 wl_client_flush(client()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1897 &keys); | 1905 &keys); |
| 1898 wl_array_release(&keys); | 1906 wl_array_release(&keys); |
| 1899 wl_client_flush(client()); | 1907 wl_client_flush(client()); |
| 1900 } | 1908 } |
| 1901 void OnKeyboardLeave(Surface* surface) override { | 1909 void OnKeyboardLeave(Surface* surface) override { |
| 1902 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 1910 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
| 1903 DCHECK(surface_resource); | 1911 DCHECK(surface_resource); |
| 1904 wl_keyboard_send_leave(keyboard_resource_, next_serial(), surface_resource); | 1912 wl_keyboard_send_leave(keyboard_resource_, next_serial(), surface_resource); |
| 1905 wl_client_flush(client()); | 1913 wl_client_flush(client()); |
| 1906 } | 1914 } |
| 1907 void OnKeyboardKey(base::TimeDelta time_stamp, | 1915 void OnKeyboardKey(base::TimeTicks time_stamp, |
| 1908 ui::DomCode key, | 1916 ui::DomCode key, |
| 1909 bool pressed) override { | 1917 bool pressed) override { |
| 1910 wl_keyboard_send_key(keyboard_resource_, next_serial(), | 1918 wl_keyboard_send_key(keyboard_resource_, next_serial(), |
| 1911 time_stamp.InMilliseconds(), DomCodeToKey(key), | 1919 TimeTicksToMilliseconds(time_stamp), DomCodeToKey(key), |
| 1912 pressed ? WL_KEYBOARD_KEY_STATE_PRESSED | 1920 pressed ? WL_KEYBOARD_KEY_STATE_PRESSED |
| 1913 : WL_KEYBOARD_KEY_STATE_RELEASED); | 1921 : WL_KEYBOARD_KEY_STATE_RELEASED); |
| 1914 wl_client_flush(client()); | 1922 wl_client_flush(client()); |
| 1915 } | 1923 } |
| 1916 void OnKeyboardModifiers(int modifier_flags) override { | 1924 void OnKeyboardModifiers(int modifier_flags) override { |
| 1917 xkb_state_update_mask(xkb_state_.get(), | 1925 xkb_state_update_mask(xkb_state_.get(), |
| 1918 ModifierFlagsToXkbModifiers(modifier_flags), 0, 0, 0, | 1926 ModifierFlagsToXkbModifiers(modifier_flags), 0, 0, 0, |
| 1919 0, 0); | 1927 0, 0); |
| 1920 wl_keyboard_send_modifiers( | 1928 wl_keyboard_send_modifiers( |
| 1921 keyboard_resource_, next_serial(), | 1929 keyboard_resource_, next_serial(), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2006 // Overridden from TouchDelegate: | 2014 // Overridden from TouchDelegate: |
| 2007 void OnTouchDestroying(Touch* touch) override { delete this; } | 2015 void OnTouchDestroying(Touch* touch) override { delete this; } |
| 2008 bool CanAcceptTouchEventsForSurface(Surface* surface) const override { | 2016 bool CanAcceptTouchEventsForSurface(Surface* surface) const override { |
| 2009 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 2017 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
| 2010 // We can accept events for this surface if the client is the same as the | 2018 // We can accept events for this surface if the client is the same as the |
| 2011 // touch resource. | 2019 // touch resource. |
| 2012 return surface_resource && | 2020 return surface_resource && |
| 2013 wl_resource_get_client(surface_resource) == client(); | 2021 wl_resource_get_client(surface_resource) == client(); |
| 2014 } | 2022 } |
| 2015 void OnTouchDown(Surface* surface, | 2023 void OnTouchDown(Surface* surface, |
| 2016 base::TimeDelta time_stamp, | 2024 base::TimeTicks time_stamp, |
| 2017 int id, | 2025 int id, |
| 2018 const gfx::Point& location) override { | 2026 const gfx::Point& location) override { |
| 2019 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); | 2027 wl_resource* surface_resource = surface->GetProperty(kSurfaceResourceKey); |
| 2020 DCHECK(surface_resource); | 2028 DCHECK(surface_resource); |
| 2021 wl_touch_send_down(touch_resource_, next_serial(), | 2029 wl_touch_send_down(touch_resource_, next_serial(), |
| 2022 time_stamp.InMilliseconds(), surface_resource, id, | 2030 TimeTicksToMilliseconds(time_stamp), surface_resource, |
| 2023 wl_fixed_from_int(location.x()), | 2031 id, wl_fixed_from_int(location.x()), |
| 2024 wl_fixed_from_int(location.y())); | 2032 wl_fixed_from_int(location.y())); |
| 2025 wl_client_flush(client()); | 2033 wl_client_flush(client()); |
| 2026 } | 2034 } |
| 2027 void OnTouchUp(base::TimeDelta time_stamp, int id) override { | 2035 void OnTouchUp(base::TimeTicks time_stamp, int id) override { |
| 2028 wl_touch_send_up(touch_resource_, next_serial(), | 2036 wl_touch_send_up(touch_resource_, next_serial(), |
| 2029 time_stamp.InMilliseconds(), id); | 2037 TimeTicksToMilliseconds(time_stamp), id); |
| 2030 wl_client_flush(client()); | 2038 wl_client_flush(client()); |
| 2031 } | 2039 } |
| 2032 void OnTouchMotion(base::TimeDelta time_stamp, | 2040 void OnTouchMotion(base::TimeTicks time_stamp, |
| 2033 int id, | 2041 int id, |
| 2034 const gfx::Point& location) override { | 2042 const gfx::Point& location) override { |
| 2035 wl_touch_send_motion(touch_resource_, time_stamp.InMilliseconds(), id, | 2043 wl_touch_send_motion(touch_resource_, TimeTicksToMilliseconds(time_stamp), |
| 2036 wl_fixed_from_int(location.x()), | 2044 id, wl_fixed_from_int(location.x()), |
| 2037 wl_fixed_from_int(location.y())); | 2045 wl_fixed_from_int(location.y())); |
| 2038 wl_client_flush(client()); | 2046 wl_client_flush(client()); |
| 2039 } | 2047 } |
| 2040 void OnTouchCancel() override { | 2048 void OnTouchCancel() override { |
| 2041 wl_touch_send_cancel(touch_resource_); | 2049 wl_touch_send_cancel(touch_resource_); |
| 2042 wl_client_flush(client()); | 2050 wl_client_flush(client()); |
| 2043 } | 2051 } |
| 2044 | 2052 |
| 2045 private: | 2053 private: |
| 2046 // The client who own this touch instance. | 2054 // The client who own this touch instance. |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2568 DCHECK(event_loop); | 2576 DCHECK(event_loop); |
| 2569 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2577 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 2570 } | 2578 } |
| 2571 | 2579 |
| 2572 void Server::Flush() { | 2580 void Server::Flush() { |
| 2573 wl_display_flush_clients(wl_display_.get()); | 2581 wl_display_flush_clients(wl_display_.get()); |
| 2574 } | 2582 } |
| 2575 | 2583 |
| 2576 } // namespace wayland | 2584 } // namespace wayland |
| 2577 } // namespace exo | 2585 } // namespace exo |
| OLD | NEW |