| 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> |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 wl_resource* resource = | 843 wl_resource* resource = |
| 844 wl_resource_create(client, &wl_subcompositor_interface, 1, id); | 844 wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
| 845 | 845 |
| 846 wl_resource_set_implementation(resource, &subcompositor_implementation, data, | 846 wl_resource_set_implementation(resource, &subcompositor_implementation, data, |
| 847 nullptr); | 847 nullptr); |
| 848 } | 848 } |
| 849 | 849 |
| 850 //////////////////////////////////////////////////////////////////////////////// | 850 //////////////////////////////////////////////////////////////////////////////// |
| 851 // wl_shell_surface_interface: | 851 // wl_shell_surface_interface: |
| 852 | 852 |
| 853 class ShellSurfaceSizeObserver : public views::WidgetObserver { | |
| 854 public: | |
| 855 ShellSurfaceSizeObserver(wl_resource* shell_surface_resource, | |
| 856 const gfx::Size& initial_size) | |
| 857 : shell_surface_resource_(shell_surface_resource), | |
| 858 old_size_(initial_size) { | |
| 859 wl_shell_surface_send_configure(shell_surface_resource, | |
| 860 WL_SHELL_SURFACE_RESIZE_NONE, | |
| 861 old_size_.width(), old_size_.height()); | |
| 862 } | |
| 863 | |
| 864 // Overridden from view::WidgetObserver: | |
| 865 void OnWidgetDestroyed(views::Widget* widget) override { delete this; } | |
| 866 void OnWidgetBoundsChanged(views::Widget* widget, | |
| 867 const gfx::Rect& new_bounds) override { | |
| 868 if (old_size_ == new_bounds.size()) | |
| 869 return; | |
| 870 | |
| 871 wl_shell_surface_send_configure(shell_surface_resource_, | |
| 872 WL_SHELL_SURFACE_RESIZE_NONE, | |
| 873 new_bounds.width(), new_bounds.height()); | |
| 874 old_size_ = new_bounds.size(); | |
| 875 } | |
| 876 | |
| 877 private: | |
| 878 wl_resource* shell_surface_resource_; | |
| 879 gfx::Size old_size_; | |
| 880 | |
| 881 DISALLOW_COPY_AND_ASSIGN(ShellSurfaceSizeObserver); | |
| 882 }; | |
| 883 | |
| 884 void shell_surface_pong(wl_client* client, | 853 void shell_surface_pong(wl_client* client, |
| 885 wl_resource* resource, | 854 wl_resource* resource, |
| 886 uint32_t serial) { | 855 uint32_t serial) { |
| 887 NOTIMPLEMENTED(); | 856 NOTIMPLEMENTED(); |
| 888 } | 857 } |
| 889 | 858 |
| 890 void shell_surface_move(wl_client* client, | 859 void shell_surface_move(wl_client* client, |
| 891 wl_resource* resource, | 860 wl_resource* resource, |
| 892 wl_resource* seat_resource, | 861 wl_resource* seat_resource, |
| 893 uint32_t serial) { | 862 uint32_t serial) { |
| 894 GetUserDataAs<ShellSurface>(resource)->Move(); | 863 GetUserDataAs<ShellSurface>(resource)->Move(); |
| 895 } | 864 } |
| 896 | 865 |
| 897 void shell_surface_resize(wl_client* client, | 866 void shell_surface_resize(wl_client* client, |
| 898 wl_resource* resource, | 867 wl_resource* resource, |
| 899 wl_resource* seat_resource, | 868 wl_resource* seat_resource, |
| 900 uint32_t serial, | 869 uint32_t serial, |
| 901 uint32_t edges) { | 870 uint32_t edges) { |
| 902 NOTIMPLEMENTED(); | 871 NOTIMPLEMENTED(); |
| 903 } | 872 } |
| 904 | 873 |
| 905 void shell_surface_set_toplevel(wl_client* client, wl_resource* resource) { | 874 void shell_surface_set_toplevel(wl_client* client, wl_resource* resource) { |
| 906 GetUserDataAs<ShellSurface>(resource)->SetEnabled(true); | 875 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); |
| 876 if (shell_surface->enabled()) |
| 877 return; |
| 878 |
| 879 shell_surface->SetFrame(true); |
| 880 shell_surface->SetRectangularShadow(true); |
| 881 shell_surface->SetEnabled(true); |
| 907 } | 882 } |
| 908 | 883 |
| 909 void shell_surface_set_transient(wl_client* client, | 884 void shell_surface_set_transient(wl_client* client, |
| 910 wl_resource* resource, | 885 wl_resource* resource, |
| 911 wl_resource* parent_resource, | 886 wl_resource* parent_resource, |
| 912 int x, | 887 int x, |
| 913 int y, | 888 int y, |
| 914 uint32_t flags) { | 889 uint32_t flags) { |
| 915 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); | 890 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); |
| 916 if (shell_surface->enabled()) | 891 if (shell_surface->enabled()) |
| 917 return; | 892 return; |
| 918 | 893 |
| 919 // Parent widget can be found by locating the closest ancestor with a widget. | 894 // Parent widget can be found by locating the closest ancestor with a widget. |
| 920 views::Widget* parent_widget = nullptr; | 895 views::Widget* parent_widget = nullptr; |
| 921 aura::Window* parent_window = | 896 aura::Window* parent_window = |
| 922 GetUserDataAs<Surface>(parent_resource)->window(); | 897 GetUserDataAs<Surface>(parent_resource)->window(); |
| 923 while (parent_window) { | 898 while (parent_window) { |
| 924 parent_widget = views::Widget::GetWidgetForNativeWindow(parent_window); | 899 parent_widget = views::Widget::GetWidgetForNativeWindow(parent_window); |
| 925 if (parent_widget) | 900 if (parent_widget) |
| 926 break; | 901 break; |
| 927 parent_window = parent_window->parent(); | 902 parent_window = parent_window->parent(); |
| 928 } | 903 } |
| 929 | 904 |
| 930 gfx::Point origin(x, y); | 905 gfx::Point origin(x, y); |
| 906 ShellSurface* parent_shell_surface = nullptr; |
| 931 | 907 |
| 932 // Set parent if found and it is associated with a shell surface. | 908 // Set parent if found and it is associated with a shell surface. |
| 933 if (parent_widget && | 909 if (parent_widget && |
| 934 ShellSurface::GetMainSurface(parent_widget->GetNativeWindow())) { | 910 ShellSurface::GetMainSurface(parent_widget->GetNativeWindow())) { |
| 935 wm::ConvertPointToScreen( | 911 wm::ConvertPointToScreen( |
| 936 ShellSurface::GetMainSurface(parent_widget->GetNativeWindow()) | 912 ShellSurface::GetMainSurface(parent_widget->GetNativeWindow()) |
| 937 ->window(), | 913 ->window(), |
| 938 &origin); | 914 &origin); |
| 939 // Shell surface widget delegate implementation of GetContentsView() | 915 // Shell surface widget delegate implementation of GetContentsView() |
| 940 // returns a pointer to the shell surface instance. | 916 // returns a pointer to the shell surface instance. |
| 941 shell_surface->SetParent(static_cast<ShellSurface*>( | 917 parent_shell_surface = static_cast<ShellSurface*>( |
| 942 parent_widget->widget_delegate()->GetContentsView())); | 918 parent_widget->widget_delegate()->GetContentsView()); |
| 943 } | 919 } |
| 944 | 920 |
| 945 shell_surface->SetOrigin(origin); | 921 if (flags & WL_SHELL_SURFACE_TRANSIENT_INACTIVE) { |
| 946 shell_surface->SetActivatable(!(flags & WL_SHELL_SURFACE_TRANSIENT_INACTIVE)); | 922 shell_surface->SetOrigin(origin); |
| 923 shell_surface->SetContainer(ash::kShellWindowId_SystemModalContainer); |
| 924 } else { |
| 925 shell_surface->SetFrame(true); |
| 926 shell_surface->SetParent(parent_shell_surface); |
| 927 } |
| 928 shell_surface->SetRectangularShadow(true); |
| 947 shell_surface->SetEnabled(true); | 929 shell_surface->SetEnabled(true); |
| 948 } | 930 } |
| 949 | 931 |
| 950 void shell_surface_set_fullscreen(wl_client* client, | 932 void shell_surface_set_fullscreen(wl_client* client, |
| 951 wl_resource* resource, | 933 wl_resource* resource, |
| 952 uint32_t method, | 934 uint32_t method, |
| 953 uint32_t framerate, | 935 uint32_t framerate, |
| 954 wl_resource* output_resource) { | 936 wl_resource* output_resource) { |
| 955 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); | 937 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); |
| 956 if (shell_surface->enabled()) | 938 if (shell_surface->enabled()) |
| 957 return; | 939 return; |
| 958 | 940 |
| 959 shell_surface->SetEnabled(true); | 941 shell_surface->SetEnabled(true); |
| 960 shell_surface->SetFullscreen(true); | 942 shell_surface->SetFullscreen(true); |
| 961 | |
| 962 views::Widget* widget = shell_surface->GetWidget(); | |
| 963 widget->AddObserver(new ShellSurfaceSizeObserver( | |
| 964 resource, widget->GetWindowBoundsInScreen().size())); | |
| 965 } | 943 } |
| 966 | 944 |
| 967 void shell_surface_set_popup(wl_client* client, | 945 void shell_surface_set_popup(wl_client* client, |
| 968 wl_resource* resource, | 946 wl_resource* resource, |
| 969 wl_resource* seat_resource, | 947 wl_resource* seat_resource, |
| 970 uint32_t serial, | 948 uint32_t serial, |
| 971 wl_resource* parent_resource, | 949 wl_resource* parent_resource, |
| 972 int32_t x, | 950 int32_t x, |
| 973 int32_t y, | 951 int32_t y, |
| 974 uint32_t flags) { | 952 uint32_t flags) { |
| 975 NOTIMPLEMENTED(); | 953 NOTIMPLEMENTED(); |
| 976 } | 954 } |
| 977 | 955 |
| 978 void shell_surface_set_maximized(wl_client* client, | 956 void shell_surface_set_maximized(wl_client* client, |
| 979 wl_resource* resource, | 957 wl_resource* resource, |
| 980 wl_resource* output_resource) { | 958 wl_resource* output_resource) { |
| 981 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); | 959 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); |
| 982 if (shell_surface->enabled()) | 960 if (shell_surface->enabled()) |
| 983 return; | 961 return; |
| 984 | 962 |
| 985 shell_surface->SetEnabled(true); | 963 shell_surface->SetEnabled(true); |
| 986 shell_surface->Maximize(); | 964 shell_surface->Maximize(); |
| 987 | |
| 988 views::Widget* widget = shell_surface->GetWidget(); | |
| 989 widget->AddObserver(new ShellSurfaceSizeObserver( | |
| 990 resource, widget->GetWindowBoundsInScreen().size())); | |
| 991 } | 965 } |
| 992 | 966 |
| 993 void shell_surface_set_title(wl_client* client, | 967 void shell_surface_set_title(wl_client* client, |
| 994 wl_resource* resource, | 968 wl_resource* resource, |
| 995 const char* title) { | 969 const char* title) { |
| 996 GetUserDataAs<ShellSurface>(resource) | 970 GetUserDataAs<ShellSurface>(resource) |
| 997 ->SetTitle(base::string16(base::UTF8ToUTF16(title))); | 971 ->SetTitle(base::string16(base::UTF8ToUTF16(title))); |
| 998 } | 972 } |
| 999 | 973 |
| 1000 void shell_surface_set_class(wl_client* client, | 974 void shell_surface_set_class(wl_client* client, |
| 1001 wl_resource* resource, | 975 wl_resource* resource, |
| 1002 const char* clazz) { | 976 const char* clazz) { |
| 1003 GetUserDataAs<ShellSurface>(resource)->SetApplicationId(clazz); | 977 GetUserDataAs<ShellSurface>(resource)->SetApplicationId(clazz); |
| 1004 } | 978 } |
| 1005 | 979 |
| 1006 const struct wl_shell_surface_interface shell_surface_implementation = { | 980 const struct wl_shell_surface_interface shell_surface_implementation = { |
| 1007 shell_surface_pong, shell_surface_move, | 981 shell_surface_pong, shell_surface_move, |
| 1008 shell_surface_resize, shell_surface_set_toplevel, | 982 shell_surface_resize, shell_surface_set_toplevel, |
| 1009 shell_surface_set_transient, shell_surface_set_fullscreen, | 983 shell_surface_set_transient, shell_surface_set_fullscreen, |
| 1010 shell_surface_set_popup, shell_surface_set_maximized, | 984 shell_surface_set_popup, shell_surface_set_maximized, |
| 1011 shell_surface_set_title, shell_surface_set_class}; | 985 shell_surface_set_title, shell_surface_set_class}; |
| 1012 | 986 |
| 1013 //////////////////////////////////////////////////////////////////////////////// | 987 //////////////////////////////////////////////////////////////////////////////// |
| 1014 // wl_shell_interface: | 988 // wl_shell_interface: |
| 1015 | 989 |
| 990 void HandleShellSurfaceCloseCallback(wl_resource* resource) { |
| 991 // Shell surface interface doesn't have a close event. Just send a ping event |
| 992 // for now. |
| 993 uint32_t serial = wl_display_next_serial( |
| 994 wl_client_get_display(wl_resource_get_client(resource))); |
| 995 wl_shell_surface_send_ping(resource, serial); |
| 996 wl_client_flush(wl_resource_get_client(resource)); |
| 997 } |
| 998 |
| 999 uint32_t HandleShellSurfaceConfigureCallback( |
| 1000 wl_resource* resource, |
| 1001 const gfx::Size& size, |
| 1002 ash::wm::WindowStateType state_type, |
| 1003 bool resizing, |
| 1004 bool activated) { |
| 1005 wl_shell_surface_send_configure(resource, WL_SHELL_SURFACE_RESIZE_NONE, |
| 1006 size.width(), size.height()); |
| 1007 wl_client_flush(wl_resource_get_client(resource)); |
| 1008 return 0; |
| 1009 } |
| 1010 |
| 1016 void shell_get_shell_surface(wl_client* client, | 1011 void shell_get_shell_surface(wl_client* client, |
| 1017 wl_resource* resource, | 1012 wl_resource* resource, |
| 1018 uint32_t id, | 1013 uint32_t id, |
| 1019 wl_resource* surface) { | 1014 wl_resource* surface) { |
| 1020 std::unique_ptr<ShellSurface> shell_surface = | 1015 std::unique_ptr<ShellSurface> shell_surface = |
| 1021 GetUserDataAs<Display>(resource)->CreateShellSurface( | 1016 GetUserDataAs<Display>(resource)->CreateShellSurface( |
| 1022 GetUserDataAs<Surface>(surface)); | 1017 GetUserDataAs<Surface>(surface)); |
| 1023 if (!shell_surface) { | 1018 if (!shell_surface) { |
| 1024 wl_resource_post_error(resource, WL_SHELL_ERROR_ROLE, | 1019 wl_resource_post_error(resource, WL_SHELL_ERROR_ROLE, |
| 1025 "surface has already been assigned a role"); | 1020 "surface has already been assigned a role"); |
| 1026 return; | 1021 return; |
| 1027 } | 1022 } |
| 1028 | 1023 |
| 1029 wl_resource* shell_surface_resource = | 1024 wl_resource* shell_surface_resource = |
| 1030 wl_resource_create(client, &wl_shell_surface_interface, 1, id); | 1025 wl_resource_create(client, &wl_shell_surface_interface, 1, id); |
| 1031 | 1026 |
| 1032 // Shell surfaces are initially disabled and needs to be explicitly mapped | 1027 // Shell surfaces are initially disabled and needs to be explicitly mapped |
| 1033 // before they are enabled and can become visible. | 1028 // before they are enabled and can become visible. |
| 1034 shell_surface->SetEnabled(false); | 1029 shell_surface->SetEnabled(false); |
| 1035 | 1030 |
| 1031 shell_surface->set_close_callback( |
| 1032 base::Bind(&HandleShellSurfaceCloseCallback, |
| 1033 base::Unretained(shell_surface_resource))); |
| 1034 |
| 1035 shell_surface->set_configure_callback( |
| 1036 base::Bind(&HandleShellSurfaceConfigureCallback, |
| 1037 base::Unretained(shell_surface_resource))); |
| 1038 |
| 1036 shell_surface->set_surface_destroyed_callback(base::Bind( | 1039 shell_surface->set_surface_destroyed_callback(base::Bind( |
| 1037 &wl_resource_destroy, base::Unretained(shell_surface_resource))); | 1040 &wl_resource_destroy, base::Unretained(shell_surface_resource))); |
| 1038 | 1041 |
| 1039 SetImplementation(shell_surface_resource, &shell_surface_implementation, | 1042 SetImplementation(shell_surface_resource, &shell_surface_implementation, |
| 1040 std::move(shell_surface)); | 1043 std::move(shell_surface)); |
| 1041 } | 1044 } |
| 1042 | 1045 |
| 1043 const struct wl_shell_interface shell_implementation = { | 1046 const struct wl_shell_interface shell_implementation = { |
| 1044 shell_get_shell_surface}; | 1047 shell_get_shell_surface}; |
| 1045 | 1048 |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 wl_fixed_t scale) { | 1494 wl_fixed_t scale) { |
| 1492 GetUserDataAs<ShellSurface>(resource)->SetScale(wl_fixed_to_double(scale)); | 1495 GetUserDataAs<ShellSurface>(resource)->SetScale(wl_fixed_to_double(scale)); |
| 1493 } | 1496 } |
| 1494 | 1497 |
| 1495 void remote_surface_set_rectangular_shadow(wl_client* client, | 1498 void remote_surface_set_rectangular_shadow(wl_client* client, |
| 1496 wl_resource* resource, | 1499 wl_resource* resource, |
| 1497 int32_t x, | 1500 int32_t x, |
| 1498 int32_t y, | 1501 int32_t y, |
| 1499 int32_t width, | 1502 int32_t width, |
| 1500 int32_t height) { | 1503 int32_t height) { |
| 1501 GetUserDataAs<ShellSurface>(resource)->SetRectangularShadow( | 1504 ShellSurface* shell_surface = GetUserDataAs<ShellSurface>(resource); |
| 1502 gfx::Rect(x, y, width, height)); | 1505 gfx::Rect content_bounds(x, y, width, height); |
| 1506 |
| 1507 shell_surface->SetRectangularShadowContentBounds(content_bounds); |
| 1508 shell_surface->SetRectangularShadow(!content_bounds.IsEmpty()); |
| 1503 } | 1509 } |
| 1504 | 1510 |
| 1505 void remote_surface_set_rectangular_shadow_background_opacity( | 1511 void remote_surface_set_rectangular_shadow_background_opacity( |
| 1506 wl_client* client, | 1512 wl_client* client, |
| 1507 wl_resource* resource, | 1513 wl_resource* resource, |
| 1508 wl_fixed_t opacity) { | 1514 wl_fixed_t opacity) { |
| 1509 GetUserDataAs<ShellSurface>(resource)->SetRectangularShadowBackgroundOpacity( | 1515 GetUserDataAs<ShellSurface>(resource)->SetRectangularShadowBackgroundOpacity( |
| 1510 wl_fixed_to_double(opacity)); | 1516 wl_fixed_to_double(opacity)); |
| 1511 } | 1517 } |
| 1512 | 1518 |
| (...skipping 1591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3104 DCHECK(event_loop); | 3110 DCHECK(event_loop); |
| 3105 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 3111 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
| 3106 } | 3112 } |
| 3107 | 3113 |
| 3108 void Server::Flush() { | 3114 void Server::Flush() { |
| 3109 wl_display_flush_clients(wl_display_.get()); | 3115 wl_display_flush_clients(wl_display_.get()); |
| 3110 } | 3116 } |
| 3111 | 3117 |
| 3112 } // namespace wayland | 3118 } // namespace wayland |
| 3113 } // namespace exo | 3119 } // namespace exo |
| OLD | NEW |