| 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 <keyboard-configuration-unstable-v1-server-protocol.h> // NOLINT |
| 18 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT | 18 #include <gaming-input-unstable-v1-server-protocol.h> // NOLINT |
| 19 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT | 19 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT |
| 20 #include <stylus-unstable-v1-server-protocol.h> // NOLINT | 20 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT |
| 21 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT | 21 #include <stylus-unstable-v1-server-protocol.h> // NOLINT |
| 22 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT | 22 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT |
| 23 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT |
| 23 | 24 |
| 24 #include <algorithm> | 25 #include <algorithm> |
| 25 #include <cstdlib> | 26 #include <cstdlib> |
| 26 #include <iterator> | 27 #include <iterator> |
| 27 #include <string> | 28 #include <string> |
| 28 #include <utility> | 29 #include <utility> |
| 29 | 30 |
| 30 #include "ash/common/shell_observer.h" | 31 #include "ash/common/shell_observer.h" |
| 31 #include "ash/public/cpp/shell_window_ids.h" | 32 #include "ash/public/cpp/shell_window_ids.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/memory/weak_ptr.h" | 40 #include "base/memory/weak_ptr.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 "base/threading/thread.h" | 43 #include "base/threading/thread.h" |
| 43 #include "base/threading/thread_task_runner_handle.h" | 44 #include "base/threading/thread_task_runner_handle.h" |
| 44 #include "components/exo/buffer.h" | 45 #include "components/exo/buffer.h" |
| 45 #include "components/exo/display.h" | 46 #include "components/exo/display.h" |
| 46 #include "components/exo/gamepad.h" | 47 #include "components/exo/gamepad.h" |
| 47 #include "components/exo/gamepad_delegate.h" | 48 #include "components/exo/gamepad_delegate.h" |
| 48 #include "components/exo/keyboard.h" | 49 #include "components/exo/keyboard.h" |
| 49 #include "components/exo/keyboard_delegate.h" | 50 #include "components/exo/keyboard_delegate.h" |
| 51 #include "components/exo/keyboard_device_configuration_delegate.h" |
| 50 #include "components/exo/notification_surface.h" | 52 #include "components/exo/notification_surface.h" |
| 51 #include "components/exo/notification_surface_manager.h" | 53 #include "components/exo/notification_surface_manager.h" |
| 52 #include "components/exo/pointer.h" | 54 #include "components/exo/pointer.h" |
| 53 #include "components/exo/pointer_delegate.h" | 55 #include "components/exo/pointer_delegate.h" |
| 54 #include "components/exo/pointer_stylus_delegate.h" | 56 #include "components/exo/pointer_stylus_delegate.h" |
| 55 #include "components/exo/shared_memory.h" | 57 #include "components/exo/shared_memory.h" |
| 56 #include "components/exo/shell_surface.h" | 58 #include "components/exo/shell_surface.h" |
| 57 #include "components/exo/sub_surface.h" | 59 #include "components/exo/sub_surface.h" |
| 58 #include "components/exo/surface.h" | 60 #include "components/exo/surface.h" |
| 59 #include "components/exo/surface_property.h" | 61 #include "components/exo/surface_property.h" |
| (...skipping 2917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2977 const struct zcr_pointer_stylus_v1_interface pointer_stylus_implementation = { | 2979 const struct zcr_pointer_stylus_v1_interface pointer_stylus_implementation = { |
| 2978 pointer_stylus_destroy}; | 2980 pointer_stylus_destroy}; |
| 2979 | 2981 |
| 2980 //////////////////////////////////////////////////////////////////////////////// | 2982 //////////////////////////////////////////////////////////////////////////////// |
| 2981 // stylus interface: | 2983 // stylus interface: |
| 2982 | 2984 |
| 2983 void stylus_get_pointer_stylus(wl_client* client, | 2985 void stylus_get_pointer_stylus(wl_client* client, |
| 2984 wl_resource* resource, | 2986 wl_resource* resource, |
| 2985 uint32_t id, | 2987 uint32_t id, |
| 2986 wl_resource* pointer_resource) { | 2988 wl_resource* pointer_resource) { |
| 2989 // TODO(yhanada): Produce an erorr if a delegate already exists. |
| 2987 Pointer* pointer = GetUserDataAs<Pointer>(pointer_resource); | 2990 Pointer* pointer = GetUserDataAs<Pointer>(pointer_resource); |
| 2988 | 2991 |
| 2989 wl_resource* stylus_resource = | 2992 wl_resource* stylus_resource = |
| 2990 wl_resource_create(client, &zcr_pointer_stylus_v1_interface, 1, id); | 2993 wl_resource_create(client, &zcr_pointer_stylus_v1_interface, 1, id); |
| 2991 | 2994 |
| 2992 SetImplementation( | 2995 SetImplementation( |
| 2993 stylus_resource, &pointer_stylus_implementation, | 2996 stylus_resource, &pointer_stylus_implementation, |
| 2994 base::MakeUnique<WaylandPointerStylusDelegate>(stylus_resource, pointer)); | 2997 base::MakeUnique<WaylandPointerStylusDelegate>(stylus_resource, pointer)); |
| 2995 } | 2998 } |
| 2996 | 2999 |
| 2997 const struct zcr_stylus_v1_interface stylus_implementation = { | 3000 const struct zcr_stylus_v1_interface stylus_implementation = { |
| 2998 stylus_get_pointer_stylus}; | 3001 stylus_get_pointer_stylus}; |
| 2999 | 3002 |
| 3000 void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) { | 3003 void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) { |
| 3001 wl_resource* resource = | 3004 wl_resource* resource = |
| 3002 wl_resource_create(client, &zcr_stylus_v1_interface, version, id); | 3005 wl_resource_create(client, &zcr_stylus_v1_interface, version, id); |
| 3003 wl_resource_set_implementation(resource, &stylus_implementation, data, | 3006 wl_resource_set_implementation(resource, &stylus_implementation, data, |
| 3004 nullptr); | 3007 nullptr); |
| 3005 } | 3008 } |
| 3006 | 3009 |
| 3010 //////////////////////////////////////////////////////////////////////////////// |
| 3011 // keyboard_device_configuration interface: |
| 3012 |
| 3013 class WaylandKeyboardDeviceConfigurationDelegate |
| 3014 : public KeyboardDeviceConfigurationDelegate { |
| 3015 public: |
| 3016 WaylandKeyboardDeviceConfigurationDelegate(wl_resource* resource, |
| 3017 Keyboard* keyboard) |
| 3018 : resource_(resource), keyboard_(keyboard) { |
| 3019 keyboard_->SetDeviceConfigurationDelegate(this); |
| 3020 } |
| 3021 ~WaylandKeyboardDeviceConfigurationDelegate() override { |
| 3022 if (keyboard_) |
| 3023 keyboard_->SetDeviceConfigurationDelegate(nullptr); |
| 3024 } |
| 3025 |
| 3026 void OnKeyboardDestroying(Keyboard* keyboard) override { |
| 3027 keyboard_ = nullptr; |
| 3028 } |
| 3029 void OnKeyboardTypeChanged(bool is_physical) override { |
| 3030 zcr_keyboard_device_configuration_v1_send_type_change( |
| 3031 resource_, |
| 3032 is_physical |
| 3033 ? ZCR_KEYBOARD_DEVICE_CONFIGURATION_V1_KEYBOARD_TYPE_PHYSICAL |
| 3034 : ZCR_KEYBOARD_DEVICE_CONFIGURATION_V1_KEYBOARD_TYPE_VIRTUAL); |
| 3035 } |
| 3036 |
| 3037 private: |
| 3038 wl_resource* resource_; |
| 3039 Keyboard* keyboard_; |
| 3040 |
| 3041 DISALLOW_COPY_AND_ASSIGN(WaylandKeyboardDeviceConfigurationDelegate); |
| 3042 }; |
| 3043 |
| 3044 void keyboard_device_configuration_destroy(wl_client* client, |
| 3045 wl_resource* resource) { |
| 3046 wl_resource_destroy(resource); |
| 3047 } |
| 3048 |
| 3049 const struct zcr_keyboard_device_configuration_v1_interface |
| 3050 keyboard_device_configuration_implementation = { |
| 3051 keyboard_device_configuration_destroy}; |
| 3052 |
| 3053 //////////////////////////////////////////////////////////////////////////////// |
| 3054 // keyboard_configuration interface: |
| 3055 |
| 3056 void keyboard_configuration_get_keyboard_device_configuration( |
| 3057 wl_client* client, |
| 3058 wl_resource* resource, |
| 3059 uint32_t id, |
| 3060 wl_resource* keyboard_resource) { |
| 3061 // TODO(yhanada): Produce an error if a delegate already exists. |
| 3062 wl_resource* keyboard_device_configuration_resource = wl_resource_create( |
| 3063 client, &zcr_keyboard_device_configuration_v1_interface, 1, id); |
| 3064 |
| 3065 SetImplementation( |
| 3066 keyboard_device_configuration_resource, |
| 3067 &keyboard_device_configuration_implementation, |
| 3068 base::MakeUnique<WaylandKeyboardDeviceConfigurationDelegate>( |
| 3069 keyboard_device_configuration_resource, |
| 3070 GetUserDataAs<Keyboard>(keyboard_resource))); |
| 3071 } |
| 3072 |
| 3073 const struct zcr_keyboard_configuration_v1_interface |
| 3074 keyboard_configuration_implementation = { |
| 3075 keyboard_configuration_get_keyboard_device_configuration}; |
| 3076 |
| 3077 void bind_keyboard_configuration(wl_client* client, |
| 3078 void* data, |
| 3079 uint32_t version, |
| 3080 uint32_t id) { |
| 3081 wl_resource* resource = wl_resource_create( |
| 3082 client, &zcr_keyboard_configuration_v1_interface, version, id); |
| 3083 wl_resource_set_implementation( |
| 3084 resource, &keyboard_configuration_implementation, data, nullptr); |
| 3085 } |
| 3086 |
| 3007 } // namespace | 3087 } // namespace |
| 3008 | 3088 |
| 3009 //////////////////////////////////////////////////////////////////////////////// | 3089 //////////////////////////////////////////////////////////////////////////////// |
| 3010 // Server, public: | 3090 // Server, public: |
| 3011 | 3091 |
| 3012 Server::Server(Display* display) | 3092 Server::Server(Display* display) |
| 3013 : display_(display), wl_display_(wl_display_create()) { | 3093 : display_(display), wl_display_(wl_display_create()) { |
| 3014 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 3094 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
| 3015 compositor_version, display_, bind_compositor); | 3095 compositor_version, display_, bind_compositor); |
| 3016 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 3096 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3039 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, | 3119 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, |
| 3040 display_, bind_secure_output); | 3120 display_, bind_secure_output); |
| 3041 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, | 3121 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, |
| 3042 display_, bind_alpha_compositing); | 3122 display_, bind_alpha_compositing); |
| 3043 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, | 3123 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, |
| 3044 remote_shell_version, display_, bind_remote_shell); | 3124 remote_shell_version, display_, bind_remote_shell); |
| 3045 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, | 3125 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, |
| 3046 display_, bind_gaming_input); | 3126 display_, bind_gaming_input); |
| 3047 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 1, display_, | 3127 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 1, display_, |
| 3048 bind_stylus); | 3128 bind_stylus); |
| 3129 wl_global_create(wl_display_.get(), &zcr_keyboard_configuration_v1_interface, |
| 3130 1, display_, bind_keyboard_configuration); |
| 3049 } | 3131 } |
| 3050 | 3132 |
| 3051 Server::~Server() {} | 3133 Server::~Server() {} |
| 3052 | 3134 |
| 3053 // static | 3135 // static |
| 3054 std::unique_ptr<Server> Server::Create(Display* display) { | 3136 std::unique_ptr<Server> Server::Create(Display* display) { |
| 3055 std::unique_ptr<Server> server(new Server(display)); | 3137 std::unique_ptr<Server> server(new Server(display)); |
| 3056 | 3138 |
| 3057 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); | 3139 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); |
| 3058 if (!runtime_dir) { | 3140 if (!runtime_dir) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3110 DCHECK(event_loop); | 3192 DCHECK(event_loop); |
| 3111 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3193 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3112 } | 3194 } |
| 3113 | 3195 |
| 3114 void Server::Flush() { | 3196 void Server::Flush() { |
| 3115 wl_display_flush_clients(wl_display_.get()); | 3197 wl_display_flush_clients(wl_display_.get()); |
| 3116 } | 3198 } |
| 3117 | 3199 |
| 3118 } // namespace wayland | 3200 } // namespace wayland |
| 3119 } // namespace exo | 3201 } // namespace exo |
| OLD | NEW |