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 2931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2991 const struct zcr_stylus_v1_interface stylus_implementation = { | 2993 const struct zcr_stylus_v1_interface stylus_implementation = { |
| 2992 stylus_get_pointer_stylus}; | 2994 stylus_get_pointer_stylus}; |
| 2993 | 2995 |
| 2994 void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) { | 2996 void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) { |
| 2995 wl_resource* resource = | 2997 wl_resource* resource = |
| 2996 wl_resource_create(client, &zcr_stylus_v1_interface, version, id); | 2998 wl_resource_create(client, &zcr_stylus_v1_interface, version, id); |
| 2997 wl_resource_set_implementation(resource, &stylus_implementation, data, | 2999 wl_resource_set_implementation(resource, &stylus_implementation, data, |
| 2998 nullptr); | 3000 nullptr); |
| 2999 } | 3001 } |
| 3000 | 3002 |
| 3003 //////////////////////////////////////////////////////////////////////////////// | |
| 3004 // keyboard_device_configuration interface: | |
| 3005 | |
| 3006 class WaylandKeyboardDeviceConfigurationDelegate | |
| 3007 : public KeyboardDeviceConfigurationDelegate { | |
| 3008 public: | |
| 3009 WaylandKeyboardDeviceConfigurationDelegate(wl_resource* resource, | |
| 3010 Keyboard* keyboard) | |
| 3011 : resource_(resource), keyboard_(keyboard) { | |
| 3012 keyboard_->SetKeyboardDeviceConfigurationDelegate(this); | |
|
reveman
2016/12/09 00:18:37
what if the keyboard already has a device config d
yhanada
2016/12/09 14:54:04
I added a call of |OnKeyboardDestroying| in |Keybo
| |
| 3013 } | |
| 3014 ~WaylandKeyboardDeviceConfigurationDelegate() override { | |
| 3015 if (keyboard_ != nullptr) | |
|
reveman
2016/12/09 00:18:37
s/keyboard_ != nullptr/keyboard/
but how can keyb
yhanada
2016/12/09 14:54:04
In order to avoid referencing a invalid pointer, I
| |
| 3016 keyboard_->SetKeyboardDeviceConfigurationDelegate(nullptr); | |
| 3017 } | |
| 3018 | |
| 3019 void OnKeyboardTypeChanged(bool is_physical) override { | |
| 3020 const uint32_t type = | |
|
reveman
2016/12/09 00:18:37
nit: remove "const" or maybe even better, remove t
yhanada
2016/12/09 14:54:04
Done.
| |
| 3021 is_physical | |
| 3022 ? ZCR_KEYBOARD_DEVICE_CONFIGURATION_V1_KEYBOARD_TYPE_PHYSICAL | |
| 3023 : ZCR_KEYBOARD_DEVICE_CONFIGURATION_V1_KEYBOARD_TYPE_VIRTUAL; | |
| 3024 zcr_keyboard_device_configuration_v1_send_type_change(resource_, type); | |
| 3025 } | |
| 3026 | |
| 3027 private: | |
| 3028 wl_resource* resource_; | |
| 3029 Keyboard* keyboard_; | |
| 3030 | |
| 3031 DISALLOW_COPY_AND_ASSIGN(WaylandKeyboardDeviceConfigurationDelegate); | |
| 3032 }; | |
| 3033 | |
| 3034 void keyboard_device_configuration_destroy(wl_client* client, | |
| 3035 wl_resource* resource) { | |
| 3036 wl_resource_destroy(resource); | |
| 3037 } | |
| 3038 | |
| 3039 const struct zcr_keyboard_device_configuration_v1_interface | |
| 3040 keyboard_device_configuration_implementation = { | |
| 3041 keyboard_device_configuration_destroy}; | |
| 3042 | |
| 3043 //////////////////////////////////////////////////////////////////////////////// | |
| 3044 // keyboard extension interface: | |
|
reveman
2016/12/09 00:18:37
// keyboard configuration interface:
yhanada
2016/12/09 14:54:04
Done.
| |
| 3045 | |
| 3046 void keyboard_extension_get_keyboard_device_configuration( | |
|
reveman
2016/12/09 00:18:37
keyboard_configuration_get_keyboard_device_configu
yhanada
2016/12/09 14:54:04
Done.
| |
| 3047 wl_client* client, | |
| 3048 wl_resource* resource, | |
| 3049 uint32_t id, | |
| 3050 wl_resource* keyboard_resource) { | |
| 3051 Keyboard* keyboard = GetUserDataAs<Keyboard>(keyboard_resource); | |
|
reveman
2016/12/09 00:18:37
move this down to where it's first used. do you ne
yhanada
2016/12/09 14:54:04
Done.
| |
| 3052 wl_resource* keyboard_device_configuration_resource = wl_resource_create( | |
| 3053 client, &zcr_keyboard_device_configuration_v1_interface, 1, id); | |
| 3054 | |
| 3055 SetImplementation( | |
| 3056 keyboard_device_configuration_resource, | |
| 3057 &keyboard_device_configuration_implementation, | |
| 3058 base::MakeUnique<WaylandKeyboardDeviceConfigurationDelegate>( | |
| 3059 keyboard_device_configuration_resource, keyboard)); | |
| 3060 } | |
| 3061 | |
| 3062 const struct zcr_keyboard_configuration_v1_interface | |
| 3063 keyboard_configuration_implementation = { | |
| 3064 keyboard_extension_get_keyboard_device_configuration}; | |
| 3065 | |
| 3066 void bind_keyboard_configuration(wl_client* client, | |
| 3067 void* data, | |
| 3068 uint32_t version, | |
| 3069 uint32_t id) { | |
| 3070 wl_resource* resource = wl_resource_create( | |
| 3071 client, &zcr_keyboard_configuration_v1_interface, version, id); | |
| 3072 wl_resource_set_implementation( | |
| 3073 resource, &keyboard_configuration_implementation, data, nullptr); | |
| 3074 } | |
| 3075 | |
| 3001 } // namespace | 3076 } // namespace |
| 3002 | 3077 |
| 3003 //////////////////////////////////////////////////////////////////////////////// | 3078 //////////////////////////////////////////////////////////////////////////////// |
| 3004 // Server, public: | 3079 // Server, public: |
| 3005 | 3080 |
| 3006 Server::Server(Display* display) | 3081 Server::Server(Display* display) |
| 3007 : display_(display), wl_display_(wl_display_create()) { | 3082 : display_(display), wl_display_(wl_display_create()) { |
| 3008 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 3083 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
| 3009 compositor_version, display_, bind_compositor); | 3084 compositor_version, display_, bind_compositor); |
| 3010 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 3085 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 3033 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, | 3108 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, |
| 3034 display_, bind_secure_output); | 3109 display_, bind_secure_output); |
| 3035 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, | 3110 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, |
| 3036 display_, bind_alpha_compositing); | 3111 display_, bind_alpha_compositing); |
| 3037 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, | 3112 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, |
| 3038 remote_shell_version, display_, bind_remote_shell); | 3113 remote_shell_version, display_, bind_remote_shell); |
| 3039 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, | 3114 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, |
| 3040 display_, bind_gaming_input); | 3115 display_, bind_gaming_input); |
| 3041 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 1, display_, | 3116 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 1, display_, |
| 3042 bind_stylus); | 3117 bind_stylus); |
| 3118 wl_global_create(wl_display_.get(), &zcr_keyboard_configuration_v1_interface, | |
| 3119 1, display_, bind_keyboard_configuration); | |
| 3043 } | 3120 } |
| 3044 | 3121 |
| 3045 Server::~Server() {} | 3122 Server::~Server() {} |
| 3046 | 3123 |
| 3047 // static | 3124 // static |
| 3048 std::unique_ptr<Server> Server::Create(Display* display) { | 3125 std::unique_ptr<Server> Server::Create(Display* display) { |
| 3049 std::unique_ptr<Server> server(new Server(display)); | 3126 std::unique_ptr<Server> server(new Server(display)); |
| 3050 | 3127 |
| 3051 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); | 3128 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); |
| 3052 if (!runtime_dir) { | 3129 if (!runtime_dir) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3104 DCHECK(event_loop); | 3181 DCHECK(event_loop); |
| 3105 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3182 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3106 } | 3183 } |
| 3107 | 3184 |
| 3108 void Server::Flush() { | 3185 void Server::Flush() { |
| 3109 wl_display_flush_clients(wl_display_.get()); | 3186 wl_display_flush_clients(wl_display_.get()); |
| 3110 } | 3187 } |
| 3111 | 3188 |
| 3112 } // namespace wayland | 3189 } // namespace wayland |
| 3113 } // namespace exo | 3190 } // namespace exo |
| OLD | NEW |