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 <gaming-input-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 <cstdlib> | 24 #include <cstdlib> |
24 #include <iterator> | 25 #include <iterator> |
25 #include <string> | 26 #include <string> |
26 #include <utility> | 27 #include <utility> |
27 | 28 |
28 #include "ash/common/display/display_info.h" | 29 #include "ash/common/display/display_info.h" |
29 #include "ash/common/shell_observer.h" | 30 #include "ash/common/shell_observer.h" |
30 #include "ash/common/shell_window_ids.h" | 31 #include "ash/common/shell_window_ids.h" |
31 #include "ash/common/wm_shell.h" | 32 #include "ash/common/wm_shell.h" |
32 #include "ash/display/display_manager.h" | 33 #include "ash/display/display_manager.h" |
33 #include "ash/shell.h" | 34 #include "ash/shell.h" |
34 #include "base/bind.h" | 35 #include "base/bind.h" |
35 #include "base/cancelable_callback.h" | 36 #include "base/cancelable_callback.h" |
36 #include "base/files/file_path.h" | 37 #include "base/files/file_path.h" |
37 #include "base/macros.h" | 38 #include "base/macros.h" |
38 #include "base/memory/free_deleter.h" | 39 #include "base/memory/free_deleter.h" |
39 #include "base/memory/ptr_util.h" | 40 #include "base/memory/ptr_util.h" |
40 #include "base/strings/stringprintf.h" | 41 #include "base/strings/stringprintf.h" |
41 #include "base/strings/utf_string_conversions.h" | 42 #include "base/strings/utf_string_conversions.h" |
42 #include "components/exo/buffer.h" | 43 #include "components/exo/buffer.h" |
43 #include "components/exo/display.h" | 44 #include "components/exo/display.h" |
| 45 #include "components/exo/gamepad.h" |
| 46 #include "components/exo/gamepad_delegate.h" |
44 #include "components/exo/keyboard.h" | 47 #include "components/exo/keyboard.h" |
45 #include "components/exo/keyboard_delegate.h" | 48 #include "components/exo/keyboard_delegate.h" |
46 #include "components/exo/notification_surface.h" | 49 #include "components/exo/notification_surface.h" |
47 #include "components/exo/notification_surface_manager.h" | 50 #include "components/exo/notification_surface_manager.h" |
48 #include "components/exo/pointer.h" | 51 #include "components/exo/pointer.h" |
49 #include "components/exo/pointer_delegate.h" | 52 #include "components/exo/pointer_delegate.h" |
50 #include "components/exo/shared_memory.h" | 53 #include "components/exo/shared_memory.h" |
51 #include "components/exo/shell_surface.h" | 54 #include "components/exo/shell_surface.h" |
52 #include "components/exo/sub_surface.h" | 55 #include "components/exo/sub_surface.h" |
53 #include "components/exo/surface.h" | 56 #include "components/exo/surface.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 DestroyUserData<T>); | 121 DestroyUserData<T>); |
119 } | 122 } |
120 | 123 |
121 // Convert a timestamp to a time value that can be used when interfacing | 124 // Convert a timestamp to a time value that can be used when interfacing |
122 // with wayland. Note that we cast a int64_t value to uint32_t which can | 125 // with wayland. Note that we cast a int64_t value to uint32_t which can |
123 // potentially overflow. | 126 // potentially overflow. |
124 uint32_t TimeTicksToMilliseconds(base::TimeTicks ticks) { | 127 uint32_t TimeTicksToMilliseconds(base::TimeTicks ticks) { |
125 return (ticks - base::TimeTicks()).InMilliseconds(); | 128 return (ticks - base::TimeTicks()).InMilliseconds(); |
126 } | 129 } |
127 | 130 |
| 131 uint32_t NowInMilliseconds() { |
| 132 return TimeTicksToMilliseconds(base::TimeTicks::Now()); |
| 133 } |
| 134 |
128 // A property key containing the surface resource that is associated with | 135 // A property key containing the surface resource that is associated with |
129 // window. If unset, no surface resource is associated with window. | 136 // window. If unset, no surface resource is associated with window. |
130 DEFINE_SURFACE_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); | 137 DEFINE_SURFACE_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr); |
131 | 138 |
132 // A property key containing a boolean set to true if a viewport is associated | 139 // A property key containing a boolean set to true if a viewport is associated |
133 // with window. | 140 // with window. |
134 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); | 141 DEFINE_SURFACE_PROPERTY_KEY(bool, kSurfaceHasViewportKey, false); |
135 | 142 |
136 // A property key containing a boolean set to true if a security object is | 143 // A property key containing a boolean set to true if a security object is |
137 // associated with window. | 144 // associated with window. |
(...skipping 2589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2727 void* data, | 2734 void* data, |
2728 uint32_t version, | 2735 uint32_t version, |
2729 uint32_t id) { | 2736 uint32_t id) { |
2730 wl_resource* resource = | 2737 wl_resource* resource = |
2731 wl_resource_create(client, &zwp_alpha_compositing_v1_interface, 1, id); | 2738 wl_resource_create(client, &zwp_alpha_compositing_v1_interface, 1, id); |
2732 | 2739 |
2733 wl_resource_set_implementation(resource, &alpha_compositing_implementation, | 2740 wl_resource_set_implementation(resource, &alpha_compositing_implementation, |
2734 data, nullptr); | 2741 data, nullptr); |
2735 } | 2742 } |
2736 | 2743 |
| 2744 //////////////////////////////////////////////////////////////////////////////// |
| 2745 // gaming_input_interface: |
| 2746 |
| 2747 // Gamepad delegate class that forwards gamepad events to the client resource. |
| 2748 class WaylandGamepadDelegate : public GamepadDelegate { |
| 2749 public: |
| 2750 explicit WaylandGamepadDelegate(wl_resource* gamepad_resource) |
| 2751 : gamepad_resource_(gamepad_resource), weak_factory_(this) {} |
| 2752 |
| 2753 // Overridden from GamepadDelegate: |
| 2754 void OnGamepadDestroying(Gamepad* gamepad) override { delete this; } |
| 2755 void OnStateChange(bool connected) override { |
| 2756 uint32_t status = connected ? ZWP_GAMEPAD_V1_GAMEPAD_STATE_ON |
| 2757 : ZWP_GAMEPAD_V1_GAMEPAD_STATE_OFF; |
| 2758 zwp_gamepad_v1_send_state_change(gamepad_resource_, status); |
| 2759 wl_client_flush(client()); |
| 2760 } |
| 2761 void OnAxis(int axis, double value) override { |
| 2762 zwp_gamepad_v1_send_axis(gamepad_resource_, NowInMilliseconds(), axis, |
| 2763 wl_fixed_from_double(value)); |
| 2764 } |
| 2765 void OnButton(int button, bool pressed, double value) override { |
| 2766 uint32_t state = pressed ? ZWP_GAMEPAD_V1_BUTTON_STATE_PRESSED |
| 2767 : ZWP_GAMEPAD_V1_BUTTON_STATE_RELEASED; |
| 2768 zwp_gamepad_v1_send_button(gamepad_resource_, NowInMilliseconds(), button, |
| 2769 state, wl_fixed_from_double(value)); |
| 2770 } |
| 2771 void OnFrame() override { |
| 2772 zwp_gamepad_v1_send_frame(gamepad_resource_, NowInMilliseconds()); |
| 2773 wl_client_flush(client()); |
| 2774 } |
| 2775 base::WeakPtr<GamepadDelegate> GetWeakPtr() { |
| 2776 return weak_factory_.GetWeakPtr(); |
| 2777 } |
| 2778 |
| 2779 private: |
| 2780 // The client who own this gamepad instance. |
| 2781 wl_client* client() const { |
| 2782 return wl_resource_get_client(gamepad_resource_); |
| 2783 } |
| 2784 |
| 2785 // The gamepad resource associated with the gamepad. |
| 2786 wl_resource* const gamepad_resource_; |
| 2787 |
| 2788 base::WeakPtrFactory<GamepadDelegate> weak_factory_; |
| 2789 |
| 2790 DISALLOW_COPY_AND_ASSIGN(WaylandGamepadDelegate); |
| 2791 }; |
| 2792 |
| 2793 void gamepad_destroy(wl_client* client, wl_resource* resource) { |
| 2794 wl_resource_destroy(resource); |
| 2795 } |
| 2796 |
| 2797 const struct zwp_gamepad_v1_interface gamepad_implementation = { |
| 2798 gamepad_destroy}; |
| 2799 |
| 2800 void gaming_input_get_gamepad(wl_client* client, |
| 2801 wl_resource* resource, |
| 2802 uint32_t id, |
| 2803 wl_resource* seat) { |
| 2804 wl_resource* gamepad_resource = wl_resource_create( |
| 2805 client, &zwp_gamepad_v1_interface, wl_resource_get_version(resource), id); |
| 2806 |
| 2807 SetImplementation(gamepad_resource, &gamepad_implementation, |
| 2808 base::WrapUnique(new Gamepad( |
| 2809 new WaylandGamepadDelegate(gamepad_resource)))); |
| 2810 } |
| 2811 |
| 2812 const struct zwp_gaming_input_v1_interface gaming_input_implementation = { |
| 2813 gaming_input_get_gamepad}; |
| 2814 |
| 2815 void bind_gaming_input(wl_client* client, |
| 2816 void* data, |
| 2817 uint32_t version, |
| 2818 uint32_t id) { |
| 2819 wl_resource* resource = |
| 2820 wl_resource_create(client, &zwp_gaming_input_v1_interface, version, id); |
| 2821 wl_resource_set_implementation(resource, &gaming_input_implementation, data, |
| 2822 nullptr); |
| 2823 } |
| 2824 |
2737 } // namespace | 2825 } // namespace |
2738 | 2826 |
2739 //////////////////////////////////////////////////////////////////////////////// | 2827 //////////////////////////////////////////////////////////////////////////////// |
2740 // Server, public: | 2828 // Server, public: |
2741 | 2829 |
2742 Server::Server(Display* display) | 2830 Server::Server(Display* display) |
2743 : display_(display), wl_display_(wl_display_create()) { | 2831 : display_(display), wl_display_(wl_display_create()) { |
2744 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 2832 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
2745 compositor_version, display_, bind_compositor); | 2833 compositor_version, display_, bind_compositor); |
2746 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 2834 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); |
(...skipping 18 matching lines...) Expand all Loading... |
2765 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, | 2853 wl_global_create(wl_display_.get(), &wl_seat_interface, seat_version, |
2766 display_, bind_seat); | 2854 display_, bind_seat); |
2767 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, | 2855 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, |
2768 bind_viewporter); | 2856 bind_viewporter); |
2769 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, | 2857 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, |
2770 display_, bind_secure_output); | 2858 display_, bind_secure_output); |
2771 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, | 2859 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, |
2772 display_, bind_alpha_compositing); | 2860 display_, bind_alpha_compositing); |
2773 wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface, | 2861 wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface, |
2774 remote_shell_version, display_, bind_remote_shell); | 2862 remote_shell_version, display_, bind_remote_shell); |
| 2863 wl_global_create(wl_display_.get(), &zwp_gaming_input_v1_interface, 1, |
| 2864 display_, bind_gaming_input); |
2775 } | 2865 } |
2776 | 2866 |
2777 Server::~Server() {} | 2867 Server::~Server() {} |
2778 | 2868 |
2779 // static | 2869 // static |
2780 std::unique_ptr<Server> Server::Create(Display* display) { | 2870 std::unique_ptr<Server> Server::Create(Display* display) { |
2781 std::unique_ptr<Server> server(new Server(display)); | 2871 std::unique_ptr<Server> server(new Server(display)); |
2782 | 2872 |
2783 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); | 2873 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); |
2784 if (!runtime_dir) { | 2874 if (!runtime_dir) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2836 DCHECK(event_loop); | 2926 DCHECK(event_loop); |
2837 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 2927 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
2838 } | 2928 } |
2839 | 2929 |
2840 void Server::Flush() { | 2930 void Server::Flush() { |
2841 wl_display_flush_clients(wl_display_.get()); | 2931 wl_display_flush_clients(wl_display_.get()); |
2842 } | 2932 } |
2843 | 2933 |
2844 } // namespace wayland | 2934 } // namespace wayland |
2845 } // namespace exo | 2935 } // namespace exo |
OLD | NEW |