Chromium Code Reviews| 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 2937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2997 const struct zcr_stylus_v1_interface stylus_implementation = { | 2999 const struct zcr_stylus_v1_interface stylus_implementation = { |
| 2998 stylus_get_pointer_stylus}; | 3000 stylus_get_pointer_stylus}; |
| 2999 | 3001 |
| 3000 void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) { | 3002 void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) { |
| 3001 wl_resource* resource = | 3003 wl_resource* resource = |
| 3002 wl_resource_create(client, &zcr_stylus_v1_interface, version, id); | 3004 wl_resource_create(client, &zcr_stylus_v1_interface, version, id); |
| 3003 wl_resource_set_implementation(resource, &stylus_implementation, data, | 3005 wl_resource_set_implementation(resource, &stylus_implementation, data, |
| 3004 nullptr); | 3006 nullptr); |
| 3005 } | 3007 } |
| 3006 | 3008 |
| 3009 //////////////////////////////////////////////////////////////////////////////// | |
| 3010 // keyboard_device_configuration interface: | |
| 3011 | |
| 3012 class WaylandKeyboardDeviceConfigurationDelegate | |
| 3013 : public KeyboardDeviceConfigurationDelegate { | |
| 3014 public: | |
| 3015 WaylandKeyboardDeviceConfigurationDelegate(wl_resource* resource, | |
| 3016 Keyboard* keyboard) | |
| 3017 : resource_(resource), keyboard_(keyboard) { | |
| 3018 keyboard_->SetDeviceConfigurationDelegate(this); | |
| 3019 } | |
| 3020 ~WaylandKeyboardDeviceConfigurationDelegate() override { | |
| 3021 if (keyboard_) | |
| 3022 keyboard_->SetDeviceConfigurationDelegate(nullptr); | |
| 3023 } | |
| 3024 | |
| 3025 void OnKeyboardDestroying(Keyboard* keyboard) override { | |
| 3026 keyboard_ = nullptr; | |
| 3027 } | |
| 3028 void OnKeyboardTypeChanged(bool is_physical) override { | |
| 3029 if (is_physical) { | |
|
reveman
2016/12/09 16:15:02
you can use ...send_type_change(resource_, is_phys
yhanada
2016/12/10 00:09:11
Done.
| |
| 3030 zcr_keyboard_device_configuration_v1_send_type_change( | |
| 3031 resource_, | |
| 3032 ZCR_KEYBOARD_DEVICE_CONFIGURATION_V1_KEYBOARD_TYPE_PHYSICAL); | |
| 3033 } else { | |
| 3034 zcr_keyboard_device_configuration_v1_send_type_change( | |
| 3035 resource_, | |
| 3036 ZCR_KEYBOARD_DEVICE_CONFIGURATION_V1_KEYBOARD_TYPE_VIRTUAL); | |
| 3037 } | |
| 3038 } | |
| 3039 | |
| 3040 private: | |
| 3041 wl_resource* resource_; | |
| 3042 Keyboard* keyboard_; | |
| 3043 | |
| 3044 DISALLOW_COPY_AND_ASSIGN(WaylandKeyboardDeviceConfigurationDelegate); | |
| 3045 }; | |
| 3046 | |
| 3047 void keyboard_device_configuration_destroy(wl_client* client, | |
| 3048 wl_resource* resource) { | |
| 3049 wl_resource_destroy(resource); | |
| 3050 } | |
| 3051 | |
| 3052 const struct zcr_keyboard_device_configuration_v1_interface | |
| 3053 keyboard_device_configuration_implementation = { | |
| 3054 keyboard_device_configuration_destroy}; | |
| 3055 | |
| 3056 //////////////////////////////////////////////////////////////////////////////// | |
| 3057 // keyboard configuration interface: | |
|
reveman
2016/12/09 16:15:02
nit: s/keyboard configuration/keyboard_configurati
yhanada
2016/12/10 00:09:11
Done.
| |
| 3058 | |
| 3059 void keyboard_configuration_get_keyboard_device_configuration( | |
|
reveman
2016/12/09 16:15:02
I think there's an issue here if the client reques
yhanada
2016/12/10 00:09:11
I see. I added TODO here. Should I added TODO in |
reveman
2016/12/10 00:13:55
Yes, adding a TODO for the stylus too would be nic
yhanada
2016/12/10 00:47:28
Done.
| |
| 3060 wl_client* client, | |
| 3061 wl_resource* resource, | |
| 3062 uint32_t id, | |
| 3063 wl_resource* keyboard_resource) { | |
| 3064 wl_resource* keyboard_device_configuration_resource = wl_resource_create( | |
| 3065 client, &zcr_keyboard_device_configuration_v1_interface, 1, id); | |
| 3066 | |
| 3067 SetImplementation( | |
| 3068 keyboard_device_configuration_resource, | |
| 3069 &keyboard_device_configuration_implementation, | |
| 3070 base::MakeUnique<WaylandKeyboardDeviceConfigurationDelegate>( | |
| 3071 keyboard_device_configuration_resource, | |
| 3072 GetUserDataAs<Keyboard>(keyboard_resource))); | |
| 3073 } | |
| 3074 | |
| 3075 const struct zcr_keyboard_configuration_v1_interface | |
| 3076 keyboard_configuration_implementation = { | |
| 3077 keyboard_configuration_get_keyboard_device_configuration}; | |
| 3078 | |
| 3079 void bind_keyboard_configuration(wl_client* client, | |
| 3080 void* data, | |
| 3081 uint32_t version, | |
| 3082 uint32_t id) { | |
| 3083 wl_resource* resource = wl_resource_create( | |
| 3084 client, &zcr_keyboard_configuration_v1_interface, version, id); | |
| 3085 wl_resource_set_implementation( | |
| 3086 resource, &keyboard_configuration_implementation, data, nullptr); | |
| 3087 } | |
| 3088 | |
| 3007 } // namespace | 3089 } // namespace |
| 3008 | 3090 |
| 3009 //////////////////////////////////////////////////////////////////////////////// | 3091 //////////////////////////////////////////////////////////////////////////////// |
| 3010 // Server, public: | 3092 // Server, public: |
| 3011 | 3093 |
| 3012 Server::Server(Display* display) | 3094 Server::Server(Display* display) |
| 3013 : display_(display), wl_display_(wl_display_create()) { | 3095 : display_(display), wl_display_(wl_display_create()) { |
| 3014 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 3096 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
| 3015 compositor_version, display_, bind_compositor); | 3097 compositor_version, display_, bind_compositor); |
| 3016 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 3098 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, | 3121 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, |
| 3040 display_, bind_secure_output); | 3122 display_, bind_secure_output); |
| 3041 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, | 3123 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, |
| 3042 display_, bind_alpha_compositing); | 3124 display_, bind_alpha_compositing); |
| 3043 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, | 3125 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, |
| 3044 remote_shell_version, display_, bind_remote_shell); | 3126 remote_shell_version, display_, bind_remote_shell); |
| 3045 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, | 3127 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, |
| 3046 display_, bind_gaming_input); | 3128 display_, bind_gaming_input); |
| 3047 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 1, display_, | 3129 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 1, display_, |
| 3048 bind_stylus); | 3130 bind_stylus); |
| 3131 wl_global_create(wl_display_.get(), &zcr_keyboard_configuration_v1_interface, | |
| 3132 1, display_, bind_keyboard_configuration); | |
| 3049 } | 3133 } |
| 3050 | 3134 |
| 3051 Server::~Server() {} | 3135 Server::~Server() {} |
| 3052 | 3136 |
| 3053 // static | 3137 // static |
| 3054 std::unique_ptr<Server> Server::Create(Display* display) { | 3138 std::unique_ptr<Server> Server::Create(Display* display) { |
| 3055 std::unique_ptr<Server> server(new Server(display)); | 3139 std::unique_ptr<Server> server(new Server(display)); |
| 3056 | 3140 |
| 3057 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); | 3141 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); |
| 3058 if (!runtime_dir) { | 3142 if (!runtime_dir) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3110 DCHECK(event_loop); | 3194 DCHECK(event_loop); |
| 3111 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3195 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3112 } | 3196 } |
| 3113 | 3197 |
| 3114 void Server::Flush() { | 3198 void Server::Flush() { |
| 3115 wl_display_flush_clients(wl_display_.get()); | 3199 wl_display_flush_clients(wl_display_.get()); |
| 3116 } | 3200 } |
| 3117 | 3201 |
| 3118 } // namespace wayland | 3202 } // namespace wayland |
| 3119 } // namespace exo | 3203 } // namespace exo |
| OLD | NEW |