| 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 <gaming-input-unstable-v1-server-protocol.h> // NOLINT |
| 18 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT | 18 #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT |
| 19 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT | 19 #include <secure-output-unstable-v1-server-protocol.h> // NOLINT |
| 20 #include <stylus-unstable-v1-server-protocol.h> // NOLINT |
| 20 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT | 21 #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT |
| 21 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT | 22 #include <vsync-feedback-unstable-v1-server-protocol.h> // NOLINT |
| 22 | 23 |
| 23 #include <algorithm> | 24 #include <algorithm> |
| 24 #include <cstdlib> | 25 #include <cstdlib> |
| 25 #include <iterator> | 26 #include <iterator> |
| 26 #include <string> | 27 #include <string> |
| 27 #include <utility> | 28 #include <utility> |
| 28 | 29 |
| 29 #include "ash/common/display/display_info.h" | 30 #include "ash/common/display/display_info.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 #include "components/exo/buffer.h" | 47 #include "components/exo/buffer.h" |
| 47 #include "components/exo/display.h" | 48 #include "components/exo/display.h" |
| 48 #include "components/exo/gamepad.h" | 49 #include "components/exo/gamepad.h" |
| 49 #include "components/exo/gamepad_delegate.h" | 50 #include "components/exo/gamepad_delegate.h" |
| 50 #include "components/exo/keyboard.h" | 51 #include "components/exo/keyboard.h" |
| 51 #include "components/exo/keyboard_delegate.h" | 52 #include "components/exo/keyboard_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" |
| 57 #include "components/exo/pointer_stylus_delegate.h" |
| 56 #include "components/exo/shared_memory.h" | 58 #include "components/exo/shared_memory.h" |
| 57 #include "components/exo/shell_surface.h" | 59 #include "components/exo/shell_surface.h" |
| 58 #include "components/exo/sub_surface.h" | 60 #include "components/exo/sub_surface.h" |
| 59 #include "components/exo/surface.h" | 61 #include "components/exo/surface.h" |
| 60 #include "components/exo/surface_property.h" | 62 #include "components/exo/surface_property.h" |
| 61 #include "components/exo/touch.h" | 63 #include "components/exo/touch.h" |
| 62 #include "components/exo/touch_delegate.h" | 64 #include "components/exo/touch_delegate.h" |
| 63 #include "ipc/unix_domain_socket_util.h" | 65 #include "ipc/unix_domain_socket_util.h" |
| 64 #include "third_party/skia/include/core/SkRegion.h" | 66 #include "third_party/skia/include/core/SkRegion.h" |
| 65 #include "ui/aura/window_property.h" | 67 #include "ui/aura/window_property.h" |
| (...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2885 | 2887 |
| 2886 std::unique_ptr<base::Thread> gaming_input_thread( | 2888 std::unique_ptr<base::Thread> gaming_input_thread( |
| 2887 new base::Thread("Exo gaming input polling thread.")); | 2889 new base::Thread("Exo gaming input polling thread.")); |
| 2888 gaming_input_thread->StartWithOptions( | 2890 gaming_input_thread->StartWithOptions( |
| 2889 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 2891 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
| 2890 | 2892 |
| 2891 SetImplementation(resource, &gaming_input_implementation, | 2893 SetImplementation(resource, &gaming_input_implementation, |
| 2892 std::move(gaming_input_thread)); | 2894 std::move(gaming_input_thread)); |
| 2893 } | 2895 } |
| 2894 | 2896 |
| 2897 //////////////////////////////////////////////////////////////////////////////// |
| 2898 // pointer_stylus interface: |
| 2899 |
| 2900 class WaylandPointerStylusDelegate : public PointerStylusDelegate { |
| 2901 public: |
| 2902 WaylandPointerStylusDelegate(wl_resource* resource, Pointer* pointer) |
| 2903 : resource_(resource), pointer_(pointer) { |
| 2904 pointer_->SetStylusDelegate(this); |
| 2905 } |
| 2906 ~WaylandPointerStylusDelegate() override { |
| 2907 if (pointer_ != nullptr) |
| 2908 pointer_->SetStylusDelegate(nullptr); |
| 2909 } |
| 2910 void OnPointerDestroying(Pointer* pointer) override { pointer_ = nullptr; } |
| 2911 void OnPointerToolChange(ui::EventPointerType type) override { |
| 2912 uint wayland_type = ZWP_POINTER_STYLUS_V1_TOOL_TYPE_MOUSE; |
| 2913 if (type == ui::EventPointerType::POINTER_TYPE_PEN) |
| 2914 wayland_type = ZWP_POINTER_STYLUS_V1_TOOL_TYPE_PEN; |
| 2915 zwp_pointer_stylus_v1_send_tool_change(resource_, wayland_type); |
| 2916 } |
| 2917 void OnPointerForce(base::TimeTicks time_stamp, float force) override { |
| 2918 zwp_pointer_stylus_v1_send_force(resource_, |
| 2919 TimeTicksToMilliseconds(time_stamp), |
| 2920 wl_fixed_from_double(force)); |
| 2921 } |
| 2922 void OnPointerTilt(base::TimeTicks time_stamp, gfx::Vector2dF tilt) override { |
| 2923 zwp_pointer_stylus_v1_send_tilt( |
| 2924 resource_, TimeTicksToMilliseconds(time_stamp), |
| 2925 wl_fixed_from_double(tilt.x()), wl_fixed_from_double(tilt.y())); |
| 2926 } |
| 2927 |
| 2928 private: |
| 2929 wl_resource* resource_; |
| 2930 Pointer* pointer_; |
| 2931 |
| 2932 // The client who own this pointer stylus instance. |
| 2933 wl_client* client() const { return wl_resource_get_client(resource_); } |
| 2934 |
| 2935 DISALLOW_COPY_AND_ASSIGN(WaylandPointerStylusDelegate); |
| 2936 }; |
| 2937 |
| 2938 void pointer_stylus_destroy(wl_client* client, wl_resource* resource) { |
| 2939 wl_resource_destroy(resource); |
| 2940 } |
| 2941 |
| 2942 const struct zwp_pointer_stylus_v1_interface pointer_stylus_implementation = { |
| 2943 pointer_stylus_destroy}; |
| 2944 |
| 2945 //////////////////////////////////////////////////////////////////////////////// |
| 2946 // stylus interface: |
| 2947 |
| 2948 void stylus_get_pointer_stylus(wl_client* client, |
| 2949 wl_resource* resource, |
| 2950 uint32_t id, |
| 2951 wl_resource* pointer_resource) { |
| 2952 Pointer* pointer = GetUserDataAs<Pointer>(pointer_resource); |
| 2953 |
| 2954 wl_resource* stylus_resource = |
| 2955 wl_resource_create(client, &zwp_pointer_stylus_v1_interface, 1, id); |
| 2956 |
| 2957 SetImplementation(stylus_resource, &pointer_stylus_implementation, |
| 2958 base::WrapUnique(new WaylandPointerStylusDelegate( |
| 2959 stylus_resource, pointer))); |
| 2960 } |
| 2961 |
| 2962 const struct zwp_stylus_v1_interface stylus_implementation = { |
| 2963 stylus_get_pointer_stylus}; |
| 2964 |
| 2965 void bind_stylus(wl_client* client, void* data, uint32_t version, uint32_t id) { |
| 2966 wl_resource* resource = |
| 2967 wl_resource_create(client, &zwp_stylus_v1_interface, version, id); |
| 2968 wl_resource_set_implementation(resource, &stylus_implementation, data, |
| 2969 nullptr); |
| 2970 } |
| 2971 |
| 2895 } // namespace | 2972 } // namespace |
| 2896 | 2973 |
| 2897 //////////////////////////////////////////////////////////////////////////////// | 2974 //////////////////////////////////////////////////////////////////////////////// |
| 2898 // Server, public: | 2975 // Server, public: |
| 2899 | 2976 |
| 2900 Server::Server(Display* display) | 2977 Server::Server(Display* display) |
| 2901 : display_(display), wl_display_(wl_display_create()) { | 2978 : display_(display), wl_display_(wl_display_create()) { |
| 2902 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 2979 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
| 2903 compositor_version, display_, bind_compositor); | 2980 compositor_version, display_, bind_compositor); |
| 2904 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 2981 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2925 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, | 3002 wl_global_create(wl_display_.get(), &wp_viewporter_interface, 1, display_, |
| 2926 bind_viewporter); | 3003 bind_viewporter); |
| 2927 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, | 3004 wl_global_create(wl_display_.get(), &zwp_secure_output_v1_interface, 1, |
| 2928 display_, bind_secure_output); | 3005 display_, bind_secure_output); |
| 2929 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, | 3006 wl_global_create(wl_display_.get(), &zwp_alpha_compositing_v1_interface, 1, |
| 2930 display_, bind_alpha_compositing); | 3007 display_, bind_alpha_compositing); |
| 2931 wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface, | 3008 wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface, |
| 2932 remote_shell_version, display_, bind_remote_shell); | 3009 remote_shell_version, display_, bind_remote_shell); |
| 2933 wl_global_create(wl_display_.get(), &zwp_gaming_input_v1_interface, 1, | 3010 wl_global_create(wl_display_.get(), &zwp_gaming_input_v1_interface, 1, |
| 2934 display_, bind_gaming_input); | 3011 display_, bind_gaming_input); |
| 3012 wl_global_create(wl_display_.get(), &zwp_stylus_v1_interface, 1, display_, |
| 3013 bind_stylus); |
| 2935 } | 3014 } |
| 2936 | 3015 |
| 2937 Server::~Server() {} | 3016 Server::~Server() {} |
| 2938 | 3017 |
| 2939 // static | 3018 // static |
| 2940 std::unique_ptr<Server> Server::Create(Display* display) { | 3019 std::unique_ptr<Server> Server::Create(Display* display) { |
| 2941 std::unique_ptr<Server> server(new Server(display)); | 3020 std::unique_ptr<Server> server(new Server(display)); |
| 2942 | 3021 |
| 2943 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); | 3022 char* runtime_dir = getenv("XDG_RUNTIME_DIR"); |
| 2944 if (!runtime_dir) { | 3023 if (!runtime_dir) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2996 DCHECK(event_loop); | 3075 DCHECK(event_loop); |
| 2997 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3076 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 2998 } | 3077 } |
| 2999 | 3078 |
| 3000 void Server::Flush() { | 3079 void Server::Flush() { |
| 3001 wl_display_flush_clients(wl_display_.get()); | 3080 wl_display_flush_clients(wl_display_.get()); |
| 3002 } | 3081 } |
| 3003 | 3082 |
| 3004 } // namespace wayland | 3083 } // namespace wayland |
| 3005 } // namespace exo | 3084 } // namespace exo |
| OLD | NEW |