| 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 <keyboard-configuration-unstable-v1-server-protocol.h> // NOLINT | 17 #include <keyboard-configuration-unstable-v1-server-protocol.h> // NOLINT |
| 18 #include <gaming-input-unstable-v1-server-protocol.h> // NOLINT | 18 #include <gaming-input-unstable-v1-server-protocol.h> // NOLINT |
| 19 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT | 19 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT |
| 20 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT | 20 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT |
| 21 #include <stylus-unstable-v1-server-protocol.h> // NOLINT | 21 #include <stylus-unstable-v1-server-protocol.h> // NOLINT |
| 22 #include <stylus-unstable-v2-server-protocol.h> // NOLINT |
| 22 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT | 23 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT |
| 23 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT | 24 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT |
| 24 | 25 |
| 25 #include <algorithm> | 26 #include <algorithm> |
| 26 #include <cstdlib> | 27 #include <cstdlib> |
| 27 #include <iterator> | 28 #include <iterator> |
| 28 #include <string> | 29 #include <string> |
| 29 #include <utility> | 30 #include <utility> |
| 30 | 31 |
| 31 #include "ash/common/shell_observer.h" | 32 #include "ash/common/shell_observer.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 46 #include "components/exo/display.h" | 47 #include "components/exo/display.h" |
| 47 #include "components/exo/gamepad.h" | 48 #include "components/exo/gamepad.h" |
| 48 #include "components/exo/gamepad_delegate.h" | 49 #include "components/exo/gamepad_delegate.h" |
| 49 #include "components/exo/keyboard.h" | 50 #include "components/exo/keyboard.h" |
| 50 #include "components/exo/keyboard_delegate.h" | 51 #include "components/exo/keyboard_delegate.h" |
| 51 #include "components/exo/keyboard_device_configuration_delegate.h" | 52 #include "components/exo/keyboard_device_configuration_delegate.h" |
| 52 #include "components/exo/notification_surface.h" | 53 #include "components/exo/notification_surface.h" |
| 53 #include "components/exo/notification_surface_manager.h" | 54 #include "components/exo/notification_surface_manager.h" |
| 54 #include "components/exo/pointer.h" | 55 #include "components/exo/pointer.h" |
| 55 #include "components/exo/pointer_delegate.h" | 56 #include "components/exo/pointer_delegate.h" |
| 56 #include "components/exo/pointer_stylus_delegate.h" | |
| 57 #include "components/exo/shared_memory.h" | 57 #include "components/exo/shared_memory.h" |
| 58 #include "components/exo/shell_surface.h" | 58 #include "components/exo/shell_surface.h" |
| 59 #include "components/exo/sub_surface.h" | 59 #include "components/exo/sub_surface.h" |
| 60 #include "components/exo/surface.h" | 60 #include "components/exo/surface.h" |
| 61 #include "components/exo/surface_property.h" | 61 #include "components/exo/surface_property.h" |
| 62 #include "components/exo/touch.h" | 62 #include "components/exo/touch.h" |
| 63 #include "components/exo/touch_delegate.h" | 63 #include "components/exo/touch_delegate.h" |
| 64 #include "components/exo/touch_stylus_delegate.h" |
| 64 #include "components/exo/wm_helper.h" | 65 #include "components/exo/wm_helper.h" |
| 65 #include "third_party/skia/include/core/SkRegion.h" | 66 #include "third_party/skia/include/core/SkRegion.h" |
| 66 #include "ui/aura/window_property.h" | 67 #include "ui/aura/window_property.h" |
| 67 #include "ui/base/hit_test.h" | 68 #include "ui/base/hit_test.h" |
| 68 #include "ui/base/ui_features.h" | 69 #include "ui/base/ui_features.h" |
| 69 #include "ui/compositor/compositor_vsync_manager.h" | 70 #include "ui/compositor/compositor_vsync_manager.h" |
| 70 #include "ui/display/display_observer.h" | 71 #include "ui/display/display_observer.h" |
| 71 #include "ui/display/manager/managed_display_info.h" | 72 #include "ui/display/manager/managed_display_info.h" |
| 72 #include "ui/display/screen.h" | 73 #include "ui/display/screen.h" |
| 73 #include "ui/events/keycodes/dom/keycode_converter.h" | 74 #include "ui/events/keycodes/dom/keycode_converter.h" |
| (...skipping 2859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2933 std::unique_ptr<base::Thread> gaming_input_thread( | 2934 std::unique_ptr<base::Thread> gaming_input_thread( |
| 2934 new base::Thread("Exo gaming input polling thread.")); | 2935 new base::Thread("Exo gaming input polling thread.")); |
| 2935 gaming_input_thread->StartWithOptions( | 2936 gaming_input_thread->StartWithOptions( |
| 2936 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 2937 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 2937 | 2938 |
| 2938 SetImplementation(resource, &gaming_input_implementation, | 2939 SetImplementation(resource, &gaming_input_implementation, |
| 2939 std::move(gaming_input_thread)); | 2940 std::move(gaming_input_thread)); |
| 2940 } | 2941 } |
| 2941 | 2942 |
| 2942 //////////////////////////////////////////////////////////////////////////////// | 2943 //////////////////////////////////////////////////////////////////////////////// |
| 2943 // pointer_stylus interface: | 2944 // touch_stylus interface: |
| 2944 | 2945 |
| 2945 class WaylandPointerStylusDelegate : public PointerStylusDelegate { | 2946 class WaylandTouchStylusDelegate : public TouchStylusDelegate { |
| 2946 public: | 2947 public: |
| 2947 WaylandPointerStylusDelegate(wl_resource* resource, Pointer* pointer) | 2948 WaylandTouchStylusDelegate(wl_resource* resource, Touch* touch) |
| 2948 : resource_(resource), pointer_(pointer) { | 2949 : resource_(resource), touch_(touch) { |
| 2949 pointer_->SetStylusDelegate(this); | 2950 touch_->SetStylusDelegate(this); |
| 2950 } | 2951 } |
| 2951 ~WaylandPointerStylusDelegate() override { | 2952 ~WaylandTouchStylusDelegate() override { |
| 2952 if (pointer_ != nullptr) | 2953 if (touch_ != nullptr) |
| 2953 pointer_->SetStylusDelegate(nullptr); | 2954 touch_->SetStylusDelegate(nullptr); |
| 2954 } | 2955 } |
| 2955 void OnPointerDestroying(Pointer* pointer) override { pointer_ = nullptr; } | 2956 void OnTouchDestroying(Touch* touch) override { touch_ = nullptr; } |
| 2956 void OnPointerToolChange(ui::EventPointerType type) override { | 2957 void OnTouchTool(int touch_id, ui::EventPointerType type) override { |
| 2957 uint wayland_type = ZCR_POINTER_STYLUS_V1_TOOL_TYPE_MOUSE; | 2958 uint wayland_type = ZCR_TOUCH_STYLUS_V2_TOOL_TYPE_TOUCH; |
| 2958 if (type == ui::EventPointerType::POINTER_TYPE_PEN) | 2959 if (type == ui::EventPointerType::POINTER_TYPE_PEN) |
| 2959 wayland_type = ZCR_POINTER_STYLUS_V1_TOOL_TYPE_PEN; | 2960 wayland_type = ZCR_TOUCH_STYLUS_V2_TOOL_TYPE_PEN; |
| 2960 else if (type == ui::EventPointerType::POINTER_TYPE_ERASER) | 2961 else if (type == ui::EventPointerType::POINTER_TYPE_ERASER) |
| 2961 wayland_type = ZCR_POINTER_STYLUS_V1_TOOL_TYPE_ERASER; | 2962 wayland_type = ZCR_TOUCH_STYLUS_V2_TOOL_TYPE_ERASER; |
| 2962 zcr_pointer_stylus_v1_send_tool_change(resource_, wayland_type); | 2963 zcr_touch_stylus_v2_send_tool(resource_, touch_id, wayland_type); |
| 2963 } | 2964 } |
| 2964 void OnPointerForce(base::TimeTicks time_stamp, float force) override { | 2965 void OnTouchForce(base::TimeTicks time_stamp, |
| 2965 zcr_pointer_stylus_v1_send_force(resource_, | 2966 int touch_id, |
| 2966 TimeTicksToMilliseconds(time_stamp), | 2967 float force) override { |
| 2967 wl_fixed_from_double(force)); | 2968 zcr_touch_stylus_v2_send_force(resource_, |
| 2969 TimeTicksToMilliseconds(time_stamp), |
| 2970 touch_id, wl_fixed_from_double(force)); |
| 2968 } | 2971 } |
| 2969 void OnPointerTilt(base::TimeTicks time_stamp, gfx::Vector2dF tilt) override { | 2972 void OnTouchTilt(base::TimeTicks time_stamp, |
| 2970 zcr_pointer_stylus_v1_send_tilt( | 2973 int touch_id, |
| 2971 resource_, TimeTicksToMilliseconds(time_stamp), | 2974 const gfx::Vector2dF& tilt) override { |
| 2975 zcr_touch_stylus_v2_send_tilt( |
| 2976 resource_, TimeTicksToMilliseconds(time_stamp), touch_id, |
| 2972 wl_fixed_from_double(tilt.x()), wl_fixed_from_double(tilt.y())); | 2977 wl_fixed_from_double(tilt.x()), wl_fixed_from_double(tilt.y())); |
| 2973 } | 2978 } |
| 2974 | 2979 |
| 2975 private: | 2980 private: |
| 2976 wl_resource* resource_; | 2981 wl_resource* resource_; |
| 2977 Pointer* pointer_; | 2982 Touch* touch_; |
| 2978 | 2983 |
| 2979 // The client who own this pointer stylus instance. | 2984 DISALLOW_COPY_AND_ASSIGN(WaylandTouchStylusDelegate); |
| 2980 wl_client* client() const { return wl_resource_get_client(resource_); } | |
| 2981 | |
| 2982 DISALLOW_COPY_AND_ASSIGN(WaylandPointerStylusDelegate); | |
| 2983 }; | 2985 }; |
| 2984 | 2986 |
| 2985 void pointer_stylus_destroy(wl_client* client, wl_resource* resource) { | 2987 void touch_stylus_destroy(wl_client* client, wl_resource* resource) { |
| 2986 wl_resource_destroy(resource); | 2988 wl_resource_destroy(resource); |
| 2987 } | 2989 } |
| 2988 | 2990 |
| 2989 const struct zcr_pointer_stylus_v1_interface pointer_stylus_implementation = { | 2991 const struct zcr_touch_stylus_v2_interface touch_stylus_implementation = { |
| 2990 pointer_stylus_destroy}; | 2992 touch_stylus_destroy}; |
| 2991 | 2993 |
| 2992 //////////////////////////////////////////////////////////////////////////////// | 2994 //////////////////////////////////////////////////////////////////////////////// |
| 2993 // stylus interface: | 2995 // stylus_v2 interface: |
| 2994 | 2996 |
| 2995 void stylus_get_pointer_stylus(wl_client* client, | 2997 void stylus_get_touch_stylus(wl_client* client, |
| 2996 wl_resource* resource, | 2998 wl_resource* resource, |
| 2997 uint32_t id, | 2999 uint32_t id, |
| 2998 wl_resource* pointer_resource) { | 3000 wl_resource* touch_resource) { |
| 2999 Pointer* pointer = GetUserDataAs<Pointer>(pointer_resource); | 3001 Touch* touch = GetUserDataAs<Touch>(touch_resource); |
| 3000 if (pointer->HasStylusDelegate()) { | 3002 if (touch->HasStylusDelegate()) { |
| 3001 wl_resource_post_error( | 3003 wl_resource_post_error( |
| 3002 resource, ZCR_STYLUS_V1_ERROR_POINTER_STYLUS_EXISTS, | 3004 resource, ZCR_STYLUS_V2_ERROR_TOUCH_STYLUS_EXISTS, |
| 3003 "pointer has already been associated with a stylus object"); | 3005 "touch has already been associated with a stylus object"); |
| 3004 return; | 3006 return; |
| 3005 } | 3007 } |
| 3006 | 3008 |
| 3007 wl_resource* stylus_resource = | 3009 wl_resource* stylus_resource = |
| 3008 wl_resource_create(client, &zcr_pointer_stylus_v1_interface, 1, id); | 3010 wl_resource_create(client, &zcr_touch_stylus_v2_interface, 1, id); |
| 3009 | 3011 |
| 3010 SetImplementation( | 3012 SetImplementation( |
| 3011 stylus_resource, &pointer_stylus_implementation, | 3013 stylus_resource, &touch_stylus_implementation, |
| 3012 base::MakeUnique<WaylandPointerStylusDelegate>(stylus_resource, pointer)); | 3014 base::MakeUnique<WaylandTouchStylusDelegate>(stylus_resource, touch)); |
| 3013 } | 3015 } |
| 3014 | 3016 |
| 3015 const struct zcr_stylus_v1_interface stylus_implementation = { | 3017 const struct zcr_stylus_v2_interface stylus_v2_implementation = { |
| 3016 stylus_get_pointer_stylus}; | 3018 stylus_get_touch_stylus}; |
| 3017 | 3019 |
| 3018 void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) { | 3020 void bind_stylus_v2(wl_client* client, |
| 3021 void* data, |
| 3022 uint32_t version, |
| 3023 uint32_t id) { |
| 3024 wl_resource* resource = |
| 3025 wl_resource_create(client, &zcr_stylus_v2_interface, version, id); |
| 3026 wl_resource_set_implementation(resource, &stylus_v2_implementation, data, |
| 3027 nullptr); |
| 3028 } |
| 3029 |
| 3030 //////////////////////////////////////////////////////////////////////////////// |
| 3031 // pointer_stylus interface (deprecated) |
| 3032 // TODO(denniskempin): Remove once client no longer depends on this interface. |
| 3033 |
| 3034 void pointer_stylus_destroy_DEPRECATED(wl_client* client, |
| 3035 wl_resource* resource) { |
| 3036 wl_resource_destroy(resource); |
| 3037 } |
| 3038 |
| 3039 const struct zcr_pointer_stylus_v1_interface |
| 3040 pointer_stylus_implementation_DEPRECATED = { |
| 3041 pointer_stylus_destroy_DEPRECATED}; |
| 3042 |
| 3043 //////////////////////////////////////////////////////////////////////////////// |
| 3044 // stylus_v1 interface (deprecated): |
| 3045 // TODO(denniskempin): Remove once client no longer depends on this interface. |
| 3046 |
| 3047 void stylus_get_pointer_stylus_DEPRECATED(wl_client* client, |
| 3048 wl_resource* resource, |
| 3049 uint32_t id, |
| 3050 wl_resource* pointer_resource) { |
| 3051 wl_resource* stylus_resource = |
| 3052 wl_resource_create(client, &zcr_pointer_stylus_v1_interface, 1, id); |
| 3053 wl_resource_set_implementation(stylus_resource, |
| 3054 &pointer_stylus_implementation_DEPRECATED, |
| 3055 nullptr, nullptr); |
| 3056 } |
| 3057 |
| 3058 const struct zcr_stylus_v1_interface stylus_v1_implementation_DEPRECATED = { |
| 3059 stylus_get_pointer_stylus_DEPRECATED}; |
| 3060 |
| 3061 void bind_stylus_v1_DEPRECATED(wl_client* client, |
| 3062 void* data, |
| 3063 uint32_t version, |
| 3064 uint32_t id) { |
| 3019 wl_resource* resource = | 3065 wl_resource* resource = |
| 3020 wl_resource_create(client, &zcr_stylus_v1_interface, version, id); | 3066 wl_resource_create(client, &zcr_stylus_v1_interface, version, id); |
| 3021 wl_resource_set_implementation(resource, &stylus_implementation, data, | 3067 wl_resource_set_implementation(resource, &stylus_v1_implementation_DEPRECATED, |
| 3022 nullptr); | 3068 data, nullptr); |
| 3023 } | 3069 } |
| 3024 | 3070 |
| 3025 //////////////////////////////////////////////////////////////////////////////// | 3071 //////////////////////////////////////////////////////////////////////////////// |
| 3026 // keyboard_device_configuration interface: | 3072 // keyboard_device_configuration interface: |
| 3027 | 3073 |
| 3028 class WaylandKeyboardDeviceConfigurationDelegate | 3074 class WaylandKeyboardDeviceConfigurationDelegate |
| 3029 : public KeyboardDeviceConfigurationDelegate { | 3075 : public KeyboardDeviceConfigurationDelegate { |
| 3030 public: | 3076 public: |
| 3031 WaylandKeyboardDeviceConfigurationDelegate(wl_resource* resource, | 3077 WaylandKeyboardDeviceConfigurationDelegate(wl_resource* resource, |
| 3032 Keyboard* keyboard) | 3078 Keyboard* keyboard) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3141 bind_viewporter); | 3187 bind_viewporter); |
| 3142 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, | 3188 wl_global_create(wl_display_.get(), &zcr_secure_output_v1_interface, 1, |
| 3143 display_, bind_secure_output); | 3189 display_, bind_secure_output); |
| 3144 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, | 3190 wl_global_create(wl_display_.get(), &zcr_alpha_compositing_v1_interface, 1, |
| 3145 display_, bind_alpha_compositing); | 3191 display_, bind_alpha_compositing); |
| 3146 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, | 3192 wl_global_create(wl_display_.get(), &zcr_remote_shell_v1_interface, |
| 3147 remote_shell_version, display_, bind_remote_shell); | 3193 remote_shell_version, display_, bind_remote_shell); |
| 3148 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, | 3194 wl_global_create(wl_display_.get(), &zcr_gaming_input_v1_interface, 1, |
| 3149 display_, bind_gaming_input); | 3195 display_, bind_gaming_input); |
| 3150 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 2, display_, | 3196 wl_global_create(wl_display_.get(), &zcr_stylus_v1_interface, 2, display_, |
| 3151 bind_stylus); | 3197 bind_stylus_v1_DEPRECATED); |
| 3198 wl_global_create(wl_display_.get(), &zcr_stylus_v2_interface, 1, display_, |
| 3199 bind_stylus_v2); |
| 3152 wl_global_create(wl_display_.get(), &zcr_keyboard_configuration_v1_interface, | 3200 wl_global_create(wl_display_.get(), &zcr_keyboard_configuration_v1_interface, |
| 3153 2, display_, bind_keyboard_configuration); | 3201 2, display_, bind_keyboard_configuration); |
| 3154 } | 3202 } |
| 3155 | 3203 |
| 3156 Server::~Server() {} | 3204 Server::~Server() {} |
| 3157 | 3205 |
| 3158 // static | 3206 // static |
| 3159 std::unique_ptr<Server> Server::Create(Display* display) { | 3207 std::unique_ptr<Server> Server::Create(Display* display) { |
| 3160 std::unique_ptr<Server> server(new Server(display)); | 3208 std::unique_ptr<Server> server(new Server(display)); |
| 3161 | 3209 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3215 DCHECK(event_loop); | 3263 DCHECK(event_loop); |
| 3216 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3264 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3217 } | 3265 } |
| 3218 | 3266 |
| 3219 void Server::Flush() { | 3267 void Server::Flush() { |
| 3220 wl_display_flush_clients(wl_display_.get()); | 3268 wl_display_flush_clients(wl_display_.get()); |
| 3221 } | 3269 } |
| 3222 | 3270 |
| 3223 } // namespace wayland | 3271 } // namespace wayland |
| 3224 } // namespace exo | 3272 } // namespace exo |
| OLD | NEW |