Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(879)

Side by Side Diff: components/exo/wayland/server.cc

Issue 1580033004: exo: Improve Maximize and Fullscreen support for ShellSurfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add TODO Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/touch_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <linux/input.h> 7 #include <linux/input.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <wayland-server-core.h> 10 #include <wayland-server-core.h>
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 void surface_damage(wl_client* client, 114 void surface_damage(wl_client* client,
115 wl_resource* resource, 115 wl_resource* resource,
116 int32_t x, 116 int32_t x,
117 int32_t y, 117 int32_t y,
118 int32_t width, 118 int32_t width,
119 int32_t height) { 119 int32_t height) {
120 GetUserDataAs<Surface>(resource)->Damage(gfx::Rect(x, y, width, height)); 120 GetUserDataAs<Surface>(resource)->Damage(gfx::Rect(x, y, width, height));
121 } 121 }
122 122
123 void handle_surface_frame_callback(wl_resource* resource, 123 void HandleSurfaceFrameCallback(wl_resource* resource,
124 base::TimeTicks frame_time) { 124 base::TimeTicks frame_time) {
125 if (!frame_time.is_null()) { 125 if (!frame_time.is_null()) {
126 wl_callback_send_done(resource, 126 wl_callback_send_done(resource,
127 (frame_time - base::TimeTicks()).InMilliseconds()); 127 (frame_time - base::TimeTicks()).InMilliseconds());
128 // TODO(reveman): Remove this potentially blocking flush and instead watch 128 // TODO(reveman): Remove this potentially blocking flush and instead watch
129 // the file descriptor to be ready for write without blocking. 129 // the file descriptor to be ready for write without blocking.
130 wl_client_flush(wl_resource_get_client(resource)); 130 wl_client_flush(wl_resource_get_client(resource));
131 } 131 }
132 wl_resource_destroy(resource); 132 wl_resource_destroy(resource);
133 } 133 }
134 134
135 void surface_frame(wl_client* client, 135 void surface_frame(wl_client* client,
136 wl_resource* resource, 136 wl_resource* resource,
137 uint32_t callback) { 137 uint32_t callback) {
138 wl_resource* callback_resource = 138 wl_resource* callback_resource =
139 wl_resource_create(client, &wl_callback_interface, 1, callback); 139 wl_resource_create(client, &wl_callback_interface, 1, callback);
140 if (!callback_resource) { 140 if (!callback_resource) {
141 wl_resource_post_no_memory(resource); 141 wl_resource_post_no_memory(resource);
142 return; 142 return;
143 } 143 }
144 144
145 // base::Unretained is safe as the resource owns the callback. 145 // base::Unretained is safe as the resource owns the callback.
146 scoped_ptr<base::CancelableCallback<void(base::TimeTicks)>> 146 scoped_ptr<base::CancelableCallback<void(base::TimeTicks)>>
147 cancelable_callback(new base::CancelableCallback<void(base::TimeTicks)>( 147 cancelable_callback(
148 base::Bind(&handle_surface_frame_callback, 148 new base::CancelableCallback<void(base::TimeTicks)>(base::Bind(
149 base::Unretained(callback_resource)))); 149 &HandleSurfaceFrameCallback, base::Unretained(callback_resource))));
150 150
151 GetUserDataAs<Surface>(resource) 151 GetUserDataAs<Surface>(resource)
152 ->RequestFrameCallback(cancelable_callback->callback()); 152 ->RequestFrameCallback(cancelable_callback->callback());
153 153
154 SetImplementation(callback_resource, nullptr, std::move(cancelable_callback)); 154 SetImplementation(callback_resource, nullptr, std::move(cancelable_callback));
155 } 155 }
156 156
157 void surface_set_opaque_region(wl_client* client, 157 void surface_set_opaque_region(wl_client* client,
158 wl_resource* resource, 158 wl_resource* resource,
159 wl_resource* region_resource) { 159 wl_resource* region_resource) {
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 631
632 void shell_surface_resize(wl_client* client, 632 void shell_surface_resize(wl_client* client,
633 wl_resource* resource, 633 wl_resource* resource,
634 wl_resource* seat_resource, 634 wl_resource* seat_resource,
635 uint32_t serial, 635 uint32_t serial,
636 uint32_t edges) { 636 uint32_t edges) {
637 NOTIMPLEMENTED(); 637 NOTIMPLEMENTED();
638 } 638 }
639 639
640 void shell_surface_set_toplevel(wl_client* client, wl_resource* resource) { 640 void shell_surface_set_toplevel(wl_client* client, wl_resource* resource) {
641 GetUserDataAs<ShellSurface>(resource)->SetToplevel(); 641 GetUserDataAs<ShellSurface>(resource)->Init();
642 } 642 }
643 643
644 void shell_surface_set_transient(wl_client* client, 644 void shell_surface_set_transient(wl_client* client,
645 wl_resource* resource, 645 wl_resource* resource,
646 wl_resource* parent_resource, 646 wl_resource* parent_resource,
647 int x, 647 int x,
648 int y, 648 int y,
649 uint32_t flags) { 649 uint32_t flags) {
650 NOTIMPLEMENTED(); 650 NOTIMPLEMENTED();
651 } 651 }
652 652
653 void shell_surface_set_fullscreen(wl_client* client, 653 void shell_surface_set_fullscreen(wl_client* client,
654 wl_resource* resource, 654 wl_resource* resource,
655 uint32_t method, 655 uint32_t method,
656 uint32_t framerate, 656 uint32_t framerate,
657 wl_resource* output_resource) { 657 wl_resource* output_resource) {
658 GetUserDataAs<ShellSurface>(resource)->SetFullscreen(); 658 GetUserDataAs<ShellSurface>(resource)->Init();
659 GetUserDataAs<ShellSurface>(resource)->SetFullscreen(true);
659 } 660 }
660 661
661 void shell_surface_set_popup(wl_client* client, 662 void shell_surface_set_popup(wl_client* client,
662 wl_resource* resource, 663 wl_resource* resource,
663 wl_resource* seat_resource, 664 wl_resource* seat_resource,
664 uint32_t serial, 665 uint32_t serial,
665 wl_resource* parent_resource, 666 wl_resource* parent_resource,
666 int32_t x, 667 int32_t x,
667 int32_t y, 668 int32_t y,
668 uint32_t flags) { 669 uint32_t flags) {
669 NOTIMPLEMENTED(); 670 NOTIMPLEMENTED();
670 } 671 }
671 672
672 void shell_surface_set_maximized(wl_client* client, 673 void shell_surface_set_maximized(wl_client* client,
673 wl_resource* resource, 674 wl_resource* resource,
674 wl_resource* output_resource) { 675 wl_resource* output_resource) {
675 GetUserDataAs<ShellSurface>(resource)->SetMaximized(); 676 GetUserDataAs<ShellSurface>(resource)->Init();
677 GetUserDataAs<ShellSurface>(resource)->Maximize();
676 } 678 }
677 679
678 void shell_surface_set_title(wl_client* client, 680 void shell_surface_set_title(wl_client* client,
679 wl_resource* resource, 681 wl_resource* resource,
680 const char* title) { 682 const char* title) {
681 GetUserDataAs<ShellSurface>(resource) 683 GetUserDataAs<ShellSurface>(resource)
682 ->SetTitle(base::string16(base::UTF8ToUTF16(title))); 684 ->SetTitle(base::string16(base::UTF8ToUTF16(title)));
683 } 685 }
684 686
685 void shell_surface_set_class(wl_client* client, 687 void shell_surface_set_class(wl_client* client,
686 wl_resource* resource, 688 wl_resource* resource,
687 const char* clazz) { 689 const char* clazz) {
688 GetUserDataAs<ShellSurface>(resource)->SetApplicationId(clazz); 690 GetUserDataAs<ShellSurface>(resource)->SetApplicationId(clazz);
689 } 691 }
690 692
691 const struct wl_shell_surface_interface shell_surface_implementation = { 693 const struct wl_shell_surface_interface shell_surface_implementation = {
692 shell_surface_pong, shell_surface_move, 694 shell_surface_pong, shell_surface_move,
693 shell_surface_resize, shell_surface_set_toplevel, 695 shell_surface_resize, shell_surface_set_toplevel,
694 shell_surface_set_transient, shell_surface_set_fullscreen, 696 shell_surface_set_transient, shell_surface_set_fullscreen,
695 shell_surface_set_popup, shell_surface_set_maximized, 697 shell_surface_set_popup, shell_surface_set_maximized,
696 shell_surface_set_title, shell_surface_set_class}; 698 shell_surface_set_title, shell_surface_set_class};
697 699
698 //////////////////////////////////////////////////////////////////////////////// 700 ////////////////////////////////////////////////////////////////////////////////
699 // wl_shell_interface: 701 // wl_shell_interface:
700 702
703 void HandleShellSurfaceConfigureCallback(wl_resource* resource,
704 const gfx::Size& size) {
705 wl_shell_surface_send_configure(resource, WL_SHELL_SURFACE_RESIZE_NONE,
706 size.width(), size.height());
707 }
708
701 void shell_get_shell_surface(wl_client* client, 709 void shell_get_shell_surface(wl_client* client,
702 wl_resource* resource, 710 wl_resource* resource,
703 uint32_t id, 711 uint32_t id,
704 wl_resource* surface) { 712 wl_resource* surface) {
705 scoped_ptr<ShellSurface> shell_surface = 713 scoped_ptr<ShellSurface> shell_surface =
706 GetUserDataAs<Display>(resource) 714 GetUserDataAs<Display>(resource)
707 ->CreateShellSurface(GetUserDataAs<Surface>(surface)); 715 ->CreateShellSurface(GetUserDataAs<Surface>(surface));
708 if (!shell_surface) { 716 if (!shell_surface) {
709 wl_resource_post_no_memory(resource); 717 wl_resource_post_no_memory(resource);
710 return; 718 return;
711 } 719 }
712 720
713 wl_resource* shell_surface_resource = 721 wl_resource* shell_surface_resource =
714 wl_resource_create(client, &wl_shell_surface_interface, 1, id); 722 wl_resource_create(client, &wl_shell_surface_interface, 1, id);
715 if (!shell_surface_resource) { 723 if (!shell_surface_resource) {
716 wl_resource_post_no_memory(resource); 724 wl_resource_post_no_memory(resource);
717 return; 725 return;
718 } 726 }
719 727
720 shell_surface->set_surface_destroyed_callback(base::Bind( 728 shell_surface->set_surface_destroyed_callback(base::Bind(
721 &wl_resource_destroy, base::Unretained(shell_surface_resource))); 729 &wl_resource_destroy, base::Unretained(shell_surface_resource)));
722 730
731 shell_surface->set_configure_callback(
732 base::Bind(&HandleShellSurfaceConfigureCallback,
733 base::Unretained(shell_surface_resource)));
734
723 SetImplementation(shell_surface_resource, &shell_surface_implementation, 735 SetImplementation(shell_surface_resource, &shell_surface_implementation,
724 std::move(shell_surface)); 736 std::move(shell_surface));
725 } 737 }
726 738
727 const struct wl_shell_interface shell_implementation = { 739 const struct wl_shell_interface shell_implementation = {
728 shell_get_shell_surface}; 740 shell_get_shell_surface};
729 741
730 void bind_shell(wl_client* client, void* data, uint32_t version, uint32_t id) { 742 void bind_shell(wl_client* client, void* data, uint32_t version, uint32_t id) {
731 wl_resource* resource = 743 wl_resource* resource =
732 wl_resource_create(client, &wl_shell_interface, 1, id); 744 wl_resource_create(client, &wl_shell_interface, 1, id);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 wl_resource* resource, 859 wl_resource* resource,
848 int32_t x, 860 int32_t x,
849 int32_t y, 861 int32_t y,
850 int32_t width, 862 int32_t width,
851 int32_t height) { 863 int32_t height) {
852 GetUserDataAs<ShellSurface>(resource) 864 GetUserDataAs<ShellSurface>(resource)
853 ->SetGeometry(gfx::Rect(x, y, width, height)); 865 ->SetGeometry(gfx::Rect(x, y, width, height));
854 } 866 }
855 867
856 void xdg_surface_set_maximized(wl_client* client, wl_resource* resource) { 868 void xdg_surface_set_maximized(wl_client* client, wl_resource* resource) {
857 NOTIMPLEMENTED(); 869 GetUserDataAs<ShellSurface>(resource)->Maximize();
858 } 870 }
859 871
860 void xdg_surface_unset_maximized(wl_client* client, wl_resource* resource) { 872 void xdg_surface_unset_maximized(wl_client* client, wl_resource* resource) {
861 NOTIMPLEMENTED(); 873 NOTIMPLEMENTED();
862 } 874 }
863 875
864 void xdg_surface_set_fullscreen(wl_client* client, 876 void xdg_surface_set_fullscreen(wl_client* client,
865 wl_resource* resource, 877 wl_resource* resource,
866 wl_resource* output) { 878 wl_resource* output) {
867 NOTIMPLEMENTED(); 879 GetUserDataAs<ShellSurface>(resource)->SetFullscreen(true);
868 } 880 }
869 881
870 void xdg_surface_unset_fullscreen(wl_client* client, wl_resource* resource) { 882 void xdg_surface_unset_fullscreen(wl_client* client, wl_resource* resource) {
871 NOTIMPLEMENTED(); 883 GetUserDataAs<ShellSurface>(resource)->SetFullscreen(false);
872 } 884 }
873 885
874 void xdg_surface_set_minimized(wl_client* client, wl_resource* resource) { 886 void xdg_surface_set_minimized(wl_client* client, wl_resource* resource) {
875 NOTIMPLEMENTED(); 887 NOTIMPLEMENTED();
876 } 888 }
877 889
878 const struct xdg_surface_interface xdg_surface_implementation = { 890 const struct xdg_surface_interface xdg_surface_implementation = {
879 xdg_surface_destroy, 891 xdg_surface_destroy,
880 xdg_surface_set_parent, 892 xdg_surface_set_parent,
881 xdg_surface_set_title, 893 xdg_surface_set_title,
(...skipping 23 matching lines...) Expand all
905 917
906 void xdg_shell_use_unstable_version(wl_client* client, 918 void xdg_shell_use_unstable_version(wl_client* client,
907 wl_resource* resource, 919 wl_resource* resource,
908 int32_t version) { 920 int32_t version) {
909 if (version > XDG_SHELL_VERSION) { 921 if (version > XDG_SHELL_VERSION) {
910 wl_resource_post_error(resource, 1, 922 wl_resource_post_error(resource, 1,
911 "xdg-shell version not implemented yet."); 923 "xdg-shell version not implemented yet.");
912 } 924 }
913 } 925 }
914 926
927 void HandleXdgSurfaceConfigureCallback(wl_resource* resource,
928 const gfx::Size& size) {
929 // TODO(reveman): Include the shell surface state (maximized, active, etc.)
930 // and make sure this configure callback is called when any of that state
931 // changes.
932 wl_array states;
933 wl_array_init(&states);
934 xdg_surface_send_configure(resource, size.width(), size.height(), &states,
935 wl_display_next_serial(wl_client_get_display(
936 wl_resource_get_client(resource))));
937 }
938
915 void xdg_shell_get_xdg_surface(wl_client* client, 939 void xdg_shell_get_xdg_surface(wl_client* client,
916 wl_resource* resource, 940 wl_resource* resource,
917 uint32_t id, 941 uint32_t id,
918 wl_resource* surface) { 942 wl_resource* surface) {
919 scoped_ptr<ShellSurface> shell_surface = 943 scoped_ptr<ShellSurface> shell_surface =
920 GetUserDataAs<Display>(resource) 944 GetUserDataAs<Display>(resource)
921 ->CreateShellSurface(GetUserDataAs<Surface>(surface)); 945 ->CreateShellSurface(GetUserDataAs<Surface>(surface));
922 if (!shell_surface) { 946 if (!shell_surface) {
923 wl_resource_post_no_memory(resource); 947 wl_resource_post_no_memory(resource);
924 return; 948 return;
925 } 949 }
926 950
927 wl_resource* xdg_surface_resource = 951 wl_resource* xdg_surface_resource =
928 wl_resource_create(client, &xdg_surface_interface, 1, id); 952 wl_resource_create(client, &xdg_surface_interface, 1, id);
929 if (!xdg_surface_resource) { 953 if (!xdg_surface_resource) {
930 wl_resource_post_no_memory(resource); 954 wl_resource_post_no_memory(resource);
931 return; 955 return;
932 } 956 }
933 957
934 // An XdgSurface is a toplevel shell surface. 958 // An XdgSurface is a toplevel shell surface.
935 shell_surface->SetToplevel(); 959 shell_surface->Init();
936 960
937 shell_surface->set_close_callback(base::Bind( 961 shell_surface->set_close_callback(base::Bind(
938 &xdg_surface_send_close, base::Unretained(xdg_surface_resource))); 962 &xdg_surface_send_close, base::Unretained(xdg_surface_resource)));
939 963
964 shell_surface->set_configure_callback(
965 base::Bind(&HandleXdgSurfaceConfigureCallback,
966 base::Unretained(xdg_surface_resource)));
967
940 SetImplementation(xdg_surface_resource, &xdg_surface_implementation, 968 SetImplementation(xdg_surface_resource, &xdg_surface_implementation,
941 std::move(shell_surface)); 969 std::move(shell_surface));
942 } 970 }
943 971
944 void xdg_shell_get_xdg_popup(wl_client* client, 972 void xdg_shell_get_xdg_popup(wl_client* client,
945 wl_resource* resource, 973 wl_resource* resource,
946 uint32_t id, 974 uint32_t id,
947 wl_resource* surface, 975 wl_resource* surface,
948 wl_resource* parent, 976 wl_resource* parent,
949 wl_resource* seat, 977 wl_resource* seat,
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 DCHECK(event_loop); 1542 DCHECK(event_loop);
1515 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); 1543 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds());
1516 } 1544 }
1517 1545
1518 void Server::Flush() { 1546 void Server::Flush() {
1519 wl_display_flush_clients(wl_display_.get()); 1547 wl_display_flush_clients(wl_display_.get());
1520 } 1548 }
1521 1549
1522 } // namespace wayland 1550 } // namespace wayland
1523 } // namespace exo 1551 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/touch_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698