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> |
11 #include <viewporter-server-protocol.h> | 11 #include <viewporter-server-protocol.h> |
12 #include <wayland-server-core.h> | 12 #include <wayland-server-core.h> |
13 #include <wayland-server-protocol-core.h> | 13 #include <wayland-server-protocol-core.h> |
14 | 14 |
15 // Note: core wayland headers need to be included before protocol headers. | 15 // Note: core wayland headers need to be included before protocol headers. |
16 #include <alpha-compositing-unstable-v1-server-protocol.h> // NOLINT | 16 #include <alpha-compositing-unstable-v1-server-protocol.h> // NOLINT |
| 17 #include <gamepads-unstable-v1-server-protocol.h> // NOLINT |
17 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT | 18 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT |
18 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT | 19 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT |
19 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT | 20 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT |
20 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT | 21 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT |
21 | 22 |
22 #include <algorithm> | 23 #include <algorithm> |
23 #include <iterator> | 24 #include <iterator> |
24 #include <string> | 25 #include <string> |
25 #include <utility> | 26 #include <utility> |
26 | 27 |
27 #include "ash/common/shell_observer.h" | 28 #include "ash/common/shell_observer.h" |
28 #include "ash/common/shell_window_ids.h" | 29 #include "ash/common/shell_window_ids.h" |
29 #include "ash/common/wm_shell.h" | 30 #include "ash/common/wm_shell.h" |
30 #include "ash/display/display_info.h" | 31 #include "ash/display/display_info.h" |
31 #include "ash/display/display_manager.h" | 32 #include "ash/display/display_manager.h" |
32 #include "ash/shell.h" | 33 #include "ash/shell.h" |
33 #include "base/bind.h" | 34 #include "base/bind.h" |
34 #include "base/cancelable_callback.h" | 35 #include "base/cancelable_callback.h" |
35 #include "base/files/file_path.h" | 36 #include "base/files/file_path.h" |
36 #include "base/macros.h" | 37 #include "base/macros.h" |
37 #include "base/memory/free_deleter.h" | 38 #include "base/memory/free_deleter.h" |
38 #include "base/memory/ptr_util.h" | 39 #include "base/memory/ptr_util.h" |
39 #include "base/strings/stringprintf.h" | 40 #include "base/strings/stringprintf.h" |
40 #include "base/strings/utf_string_conversions.h" | 41 #include "base/strings/utf_string_conversions.h" |
41 #include "components/exo/buffer.h" | 42 #include "components/exo/buffer.h" |
42 #include "components/exo/display.h" | 43 #include "components/exo/display.h" |
| 44 #include "components/exo/gamepads.h" |
| 45 #include "components/exo/gamepads_delegate.h" |
43 #include "components/exo/keyboard.h" | 46 #include "components/exo/keyboard.h" |
44 #include "components/exo/keyboard_delegate.h" | 47 #include "components/exo/keyboard_delegate.h" |
45 #include "components/exo/pointer.h" | 48 #include "components/exo/pointer.h" |
46 #include "components/exo/pointer_delegate.h" | 49 #include "components/exo/pointer_delegate.h" |
47 #include "components/exo/shared_memory.h" | 50 #include "components/exo/shared_memory.h" |
48 #include "components/exo/shell_surface.h" | 51 #include "components/exo/shell_surface.h" |
49 #include "components/exo/sub_surface.h" | 52 #include "components/exo/sub_surface.h" |
50 #include "components/exo/surface.h" | 53 #include "components/exo/surface.h" |
51 #include "components/exo/surface_property.h" | 54 #include "components/exo/surface_property.h" |
52 #include "components/exo/touch.h" | 55 #include "components/exo/touch.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 DestroyUserData<T>); | 118 DestroyUserData<T>); |
116 } | 119 } |
117 | 120 |
118 // Convert a timestamp to a time value that can be used when interfacing | 121 // Convert a timestamp to a time value that can be used when interfacing |
119 // with wayland. Note that we cast a int64_t value to uint32_t which can | 122 // with wayland. Note that we cast a int64_t value to uint32_t which can |
120 // potentially overflow. | 123 // potentially overflow. |
121 uint32_t TimeTicksToMilliseconds(base::TimeTicks ticks) { | 124 uint32_t TimeTicksToMilliseconds(base::TimeTicks ticks) { |
122 return (ticks - base::TimeTicks()).InMilliseconds(); | 125 return (ticks - base::TimeTicks()).InMilliseconds(); |
123 } | 126 } |
124 | 127 |
| 128 uint32_t NowInMilliseconds() { |
| 129 return TimeTicksToMilliseconds(base::TimeTicks::Now()); |
| 130 } |
| 131 |
125 // A property key containing the surface resource that is associated with | 132 // A property key containing the surface resource that is associated with |
126 // window. If unset, no surface resource is associated with window. | 133 // window. If unset, no surface resource is associated with window. |
127 DEFINE_SURFACE_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); | 134 DEFINE_SURFACE_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); |
128 | 135 |
129 // A property key containing a boolean set to true if a viewport is associated | 136 // A property key containing a boolean set to true if a viewport is associated |
130 // with window. | 137 // with window. |
131 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); | 138 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); |
132 | 139 |
133 // A property key containing a boolean set to true if a security object is | 140 // A property key containing a boolean set to true if a security object is |
134 // associated with window. | 141 // associated with window. |
(...skipping 2521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2656 void* data, | 2663 void* data, |
2657 uint32_t version, | 2664 uint32_t version, |
2658 uint32_t id) { | 2665 uint32_t id) { |
2659 wl_resource* resource = | 2666 wl_resource* resource = |
2660 wl_resource_create(client, &zwp_alpha_compositing_v1_interface, 1, id); | 2667 wl_resource_create(client, &zwp_alpha_compositing_v1_interface, 1, id); |
2661 | 2668 |
2662 wl_resource_set_implementation(resource, &alpha_compositing_implementation, | 2669 wl_resource_set_implementation(resource, &alpha_compositing_implementation, |
2663 data, nullptr); | 2670 data, nullptr); |
2664 } | 2671 } |
2665 | 2672 |
| 2673 //////////////////////////////////////////////////////////////////////////////// |
| 2674 // zwp_gamepads_v1: |
| 2675 |
| 2676 // Gamepads delegate class that forwards gamepad events to the client resource. |
| 2677 class WaylandGamepadsDelegate : public GamepadsDelegate { |
| 2678 public: |
| 2679 explicit WaylandGamepadsDelegate(wl_resource* gamepads_resource) |
| 2680 : gamepads_resource_(gamepads_resource) {} |
| 2681 |
| 2682 // Overridden from GamepadsDelegate: |
| 2683 void OnGamepadsDestroying(Gamepads* gamepads) override { delete this; } |
| 2684 |
| 2685 void OnConnected(int id) override { |
| 2686 zwp_gamepads_v1_send_connected(gamepads_resource_, id); |
| 2687 wl_client_flush(client()); |
| 2688 } |
| 2689 void OnDisconnected(int id) override { |
| 2690 zwp_gamepads_v1_send_disconnected(gamepads_resource_, id); |
| 2691 wl_client_flush(client()); |
| 2692 } |
| 2693 void OnAxis(int id, int axis, double value) override { |
| 2694 zwp_gamepads_v1_send_axis(gamepads_resource_, NowInMilliseconds(), id, |
| 2695 axis, wl_fixed_from_double(value)); |
| 2696 } |
| 2697 void OnButton(int id, int button, bool pressed, double value) override { |
| 2698 zwp_gamepads_v1_send_button(gamepads_resource_, NowInMilliseconds(), id, |
| 2699 button, pressed, wl_fixed_from_double(value)); |
| 2700 } |
| 2701 void OnFrame(int id) override { |
| 2702 zwp_gamepads_v1_send_frame(gamepads_resource_, NowInMilliseconds(), id); |
| 2703 wl_client_flush(client()); |
| 2704 } |
| 2705 |
| 2706 private: |
| 2707 // The client who own this gamepads instance. |
| 2708 wl_client* client() const { |
| 2709 return wl_resource_get_client(gamepads_resource_); |
| 2710 } |
| 2711 |
| 2712 // The gamepads resource associated with the gamepads. |
| 2713 wl_resource* const gamepads_resource_; |
| 2714 |
| 2715 DISALLOW_COPY_AND_ASSIGN(WaylandGamepadsDelegate); |
| 2716 }; |
| 2717 |
| 2718 void gamepads_destroy(wl_client* client, wl_resource* resource) { |
| 2719 wl_resource_destroy(resource); |
| 2720 } |
| 2721 |
| 2722 const struct zwp_gamepads_v1_interface gamepads_implementation = { |
| 2723 gamepads_destroy}; |
| 2724 |
| 2725 void bind_gamepads(wl_client* client, |
| 2726 void* data, |
| 2727 uint32_t version, |
| 2728 uint32_t id) { |
| 2729 wl_resource* resource = |
| 2730 wl_resource_create(client, &zwp_gamepads_v1_interface, version, id); |
| 2731 |
| 2732 auto gamepads = new Gamepads(new WaylandGamepadsDelegate(resource)); |
| 2733 SetImplementation(resource, &gamepads_implementation, |
| 2734 base::WrapUnique(gamepads)); |
| 2735 } |
| 2736 |
2666 } // namespace | 2737 } // namespace |
2667 | 2738 |
2668 //////////////////////////////////////////////////////////////////////////////// | 2739 //////////////////////////////////////////////////////////////////////////////// |
2669 // Server, public: | 2740 // Server, public: |
2670 | 2741 |
2671 Server::Server(Display* display) | 2742 Server::Server(Display* display) |
2672 : display_(display), wl_display_(wl_display_create()) { | 2743 : display_(display), wl_display_(wl_display_create()) { |
2673 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 2744 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
2674 compositor_version, display_, bind_compositor); | 2745 compositor_version, display_, bind_compositor); |
2675 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 2746 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); |
(...skipping 18 matching lines...) Expand all Loading... |
2694 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, | 2765 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, |
2695 display_, bind_seat); | 2766 display_, bind_seat); |
2696 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, | 2767 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, |
2697 bind_viewporter); | 2768 bind_viewporter); |
2698 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, | 2769 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, |
2699 display_, bind_secure_output); | 2770 display_, bind_secure_output); |
2700 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, | 2771 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, |
2701 display_, bind_alpha_compositing); | 2772 display_, bind_alpha_compositing); |
2702 wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface, | 2773 wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface, |
2703 remote_shell_version, display_, bind_remote_shell); | 2774 remote_shell_version, display_, bind_remote_shell); |
| 2775 wl_global_create(wl_display_.get(), &zwp_gamepads_v1_interface, 1, display_, |
| 2776 bind_gamepads); |
2704 } | 2777 } |
2705 | 2778 |
2706 Server::~Server() {} | 2779 Server::~Server() {} |
2707 | 2780 |
2708 // static | 2781 // static |
2709 std::unique_ptr<Server> Server::Create(Display* display) { | 2782 std::unique_ptr<Server> Server::Create(Display* display) { |
2710 std::unique_ptr<Server> server(new Server(display)); | 2783 std::unique_ptr<Server> server(new Server(display)); |
2711 | 2784 |
2712 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); | 2785 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); |
2713 if (!runtime_dir) { | 2786 if (!runtime_dir) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2765 DCHECK(event_loop); | 2838 DCHECK(event_loop); |
2766 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2839 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
2767 } | 2840 } |
2768 | 2841 |
2769 void Server::Flush() { | 2842 void Server::Flush() { |
2770 wl_display_flush_clients(wl_display_.get()); | 2843 wl_display_flush_clients(wl_display_.get()); |
2771 } | 2844 } |
2772 | 2845 |
2773 } // namespace wayland | 2846 } // namespace wayland |
2774 } // namespace exo | 2847 } // namespace exo |
OLD | NEW |