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 <wayland-server-core.h> | 7 #include <wayland-server-core.h> |
8 #include <wayland-server-protocol-core.h> | 8 #include <wayland-server-protocol-core.h> |
| 9 #include <xdg-shell-unstable-v5-server-protocol.h> |
9 | 10 |
10 #include <algorithm> | 11 #include <algorithm> |
11 | 12 |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/cancelable_callback.h" | 14 #include "base/cancelable_callback.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "components/exo/buffer.h" | 16 #include "components/exo/buffer.h" |
16 #include "components/exo/display.h" | 17 #include "components/exo/display.h" |
17 #include "components/exo/shared_memory.h" | 18 #include "components/exo/shared_memory.h" |
18 #include "components/exo/shell_surface.h" | 19 #include "components/exo/shell_surface.h" |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 void shell_surface_set_maximized(wl_client* client, | 633 void shell_surface_set_maximized(wl_client* client, |
633 wl_resource* resource, | 634 wl_resource* resource, |
634 wl_resource* output_resource) { | 635 wl_resource* output_resource) { |
635 GetUserDataAs<ShellSurface>(resource)->SetMaximized(); | 636 GetUserDataAs<ShellSurface>(resource)->SetMaximized(); |
636 } | 637 } |
637 | 638 |
638 void shell_surface_set_title(wl_client* client, | 639 void shell_surface_set_title(wl_client* client, |
639 wl_resource* resource, | 640 wl_resource* resource, |
640 const char* title) { | 641 const char* title) { |
641 GetUserDataAs<ShellSurface>(resource) | 642 GetUserDataAs<ShellSurface>(resource) |
642 ->SetTitle(base::string16(base::ASCIIToUTF16(title))); | 643 ->SetTitle(base::string16(base::UTF8ToUTF16(title))); |
643 } | 644 } |
644 | 645 |
645 void shell_surface_set_class(wl_client* client, | 646 void shell_surface_set_class(wl_client* client, |
646 wl_resource* resource, | 647 wl_resource* resource, |
647 const char* clazz) { | 648 const char* clazz) { |
648 GetUserDataAs<ShellSurface>(resource)->SetApplicationId(clazz); | 649 GetUserDataAs<ShellSurface>(resource)->SetApplicationId(clazz); |
649 } | 650 } |
650 | 651 |
651 const struct wl_shell_surface_interface shell_surface_implementation = { | 652 const struct wl_shell_surface_interface shell_surface_implementation = { |
652 shell_surface_pong, shell_surface_move, | 653 shell_surface_pong, shell_surface_move, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 wl_resource* resource = | 689 wl_resource* resource = |
689 wl_resource_create(client, &wl_shell_interface, 1, id); | 690 wl_resource_create(client, &wl_shell_interface, 1, id); |
690 if (!resource) { | 691 if (!resource) { |
691 wl_client_post_no_memory(client); | 692 wl_client_post_no_memory(client); |
692 return; | 693 return; |
693 } | 694 } |
694 wl_resource_set_implementation(resource, &shell_implementation, data, | 695 wl_resource_set_implementation(resource, &shell_implementation, data, |
695 nullptr); | 696 nullptr); |
696 } | 697 } |
697 | 698 |
| 699 //////////////////////////////////////////////////////////////////////////////// |
| 700 // xdg_surface_interface: |
| 701 |
| 702 void xdg_surface_destroy(wl_client* client, wl_resource* resource) { |
| 703 wl_resource_destroy(resource); |
| 704 } |
| 705 |
| 706 void xdg_surface_set_parent(wl_client* client, |
| 707 wl_resource* resource, |
| 708 wl_resource* parent) { |
| 709 NOTIMPLEMENTED(); |
| 710 } |
| 711 |
| 712 void xdg_surface_set_title(wl_client* client, |
| 713 wl_resource* resource, |
| 714 const char* title) { |
| 715 GetUserDataAs<ShellSurface>(resource) |
| 716 ->SetTitle(base::string16(base::UTF8ToUTF16(title))); |
| 717 } |
| 718 |
| 719 void xdg_surface_set_add_id(wl_client* client, |
| 720 wl_resource* resource, |
| 721 const char* app_id) { |
| 722 GetUserDataAs<ShellSurface>(resource)->SetApplicationId(app_id); |
| 723 } |
| 724 |
| 725 void xdg_surface_show_window_menu(wl_client* client, |
| 726 wl_resource* resource, |
| 727 wl_resource* seat, |
| 728 uint32_t serial, |
| 729 int32_t x, |
| 730 int32_t y) { |
| 731 NOTIMPLEMENTED(); |
| 732 } |
| 733 |
| 734 void xdg_surface_move(wl_client* client, |
| 735 wl_resource* resource, |
| 736 wl_resource* seat, |
| 737 uint32_t serial) { |
| 738 GetUserDataAs<ShellSurface>(resource)->Move(); |
| 739 } |
| 740 |
| 741 void xdg_surface_resize(wl_client* client, |
| 742 wl_resource* resource, |
| 743 wl_resource* seat, |
| 744 uint32_t serial, |
| 745 uint32_t edges) { |
| 746 NOTIMPLEMENTED(); |
| 747 } |
| 748 |
| 749 void xdg_surface_ack_configure(wl_client* client, |
| 750 wl_resource* resource, |
| 751 uint32_t serial) { |
| 752 NOTIMPLEMENTED(); |
| 753 } |
| 754 |
| 755 void xdg_surface_set_window_geometry(wl_client* client, |
| 756 wl_resource* resource, |
| 757 int32_t x, |
| 758 int32_t y, |
| 759 int32_t width, |
| 760 int32_t height) { |
| 761 NOTIMPLEMENTED(); |
| 762 } |
| 763 |
| 764 void xdg_surface_set_maximized(wl_client* client, wl_resource* resource) { |
| 765 NOTIMPLEMENTED(); |
| 766 } |
| 767 |
| 768 void xdg_surface_unset_maximized(wl_client* client, wl_resource* resource) { |
| 769 NOTIMPLEMENTED(); |
| 770 } |
| 771 |
| 772 void xdg_surface_set_fullscreen(wl_client* client, |
| 773 wl_resource* resource, |
| 774 wl_resource* output) { |
| 775 NOTIMPLEMENTED(); |
| 776 } |
| 777 |
| 778 void xdg_surface_unset_fullscreen(wl_client* client, wl_resource* resource) { |
| 779 NOTIMPLEMENTED(); |
| 780 } |
| 781 |
| 782 void xdg_surface_set_minimized(wl_client* client, wl_resource* resource) { |
| 783 NOTIMPLEMENTED(); |
| 784 } |
| 785 |
| 786 const struct xdg_surface_interface xdg_surface_implementation = { |
| 787 xdg_surface_destroy, |
| 788 xdg_surface_set_parent, |
| 789 xdg_surface_set_title, |
| 790 xdg_surface_set_add_id, |
| 791 xdg_surface_show_window_menu, |
| 792 xdg_surface_move, |
| 793 xdg_surface_resize, |
| 794 xdg_surface_ack_configure, |
| 795 xdg_surface_set_window_geometry, |
| 796 xdg_surface_set_maximized, |
| 797 xdg_surface_unset_maximized, |
| 798 xdg_surface_set_fullscreen, |
| 799 xdg_surface_unset_fullscreen, |
| 800 xdg_surface_set_minimized}; |
| 801 |
| 802 //////////////////////////////////////////////////////////////////////////////// |
| 803 // xdg_shell_interface: |
| 804 |
| 805 void xdg_shell_destroy(wl_client* client, wl_resource* resource) { |
| 806 // Nothing to do here. |
| 807 } |
| 808 |
| 809 // Currently implemented version of the unstable xdg-shell interface. |
| 810 #define XDG_SHELL_VERSION 5 |
| 811 static_assert(XDG_SHELL_VERSION == XDG_SHELL_VERSION_CURRENT, |
| 812 "Interface version doesn't match implementation version"); |
| 813 |
| 814 void xdg_shell_use_unstable_version(wl_client* client, |
| 815 wl_resource* resource, |
| 816 int32_t version) { |
| 817 if (version > XDG_SHELL_VERSION) { |
| 818 wl_resource_post_error(resource, 1, |
| 819 "xdg-shell version not implemented yet."); |
| 820 } |
| 821 } |
| 822 |
| 823 void xdg_shell_get_xdg_surface(wl_client* client, |
| 824 wl_resource* resource, |
| 825 uint32_t id, |
| 826 wl_resource* surface) { |
| 827 scoped_ptr<ShellSurface> shell_surface = |
| 828 GetUserDataAs<Display>(resource) |
| 829 ->CreateShellSurface(GetUserDataAs<Surface>(surface)); |
| 830 if (!shell_surface) { |
| 831 wl_resource_post_no_memory(resource); |
| 832 return; |
| 833 } |
| 834 |
| 835 wl_resource* xdg_surface_resource = |
| 836 wl_resource_create(client, &xdg_surface_interface, 1, id); |
| 837 if (!xdg_surface_resource) { |
| 838 wl_resource_post_no_memory(resource); |
| 839 return; |
| 840 } |
| 841 |
| 842 // An XdgSurface is a toplevel shell surface. |
| 843 shell_surface->SetToplevel(); |
| 844 |
| 845 SetImplementation(xdg_surface_resource, &xdg_surface_implementation, |
| 846 shell_surface.Pass()); |
| 847 } |
| 848 |
| 849 void xdg_shell_get_xdg_popup(wl_client* client, |
| 850 wl_resource* resource, |
| 851 uint32_t id, |
| 852 wl_resource* surface, |
| 853 wl_resource* parent, |
| 854 wl_resource* seat, |
| 855 uint32_t serial, |
| 856 int32_t x, |
| 857 int32_t y) { |
| 858 NOTIMPLEMENTED(); |
| 859 } |
| 860 |
| 861 void xdg_shell_pong(wl_client* client, wl_resource* resource, uint32_t serial) { |
| 862 NOTIMPLEMENTED(); |
| 863 } |
| 864 |
| 865 const struct xdg_shell_interface xdg_shell_implementation = { |
| 866 xdg_shell_destroy, xdg_shell_use_unstable_version, |
| 867 xdg_shell_get_xdg_surface, xdg_shell_get_xdg_popup, xdg_shell_pong}; |
| 868 |
| 869 void bind_xdg_shell(wl_client* client, |
| 870 void* data, |
| 871 uint32_t version, |
| 872 uint32_t id) { |
| 873 wl_resource* resource = |
| 874 wl_resource_create(client, &xdg_shell_interface, 1, id); |
| 875 if (!resource) { |
| 876 wl_client_post_no_memory(client); |
| 877 return; |
| 878 } |
| 879 wl_resource_set_implementation(resource, &xdg_shell_implementation, data, |
| 880 nullptr); |
| 881 } |
| 882 |
698 } // namespace | 883 } // namespace |
699 | 884 |
700 //////////////////////////////////////////////////////////////////////////////// | 885 //////////////////////////////////////////////////////////////////////////////// |
701 // Server, public: | 886 // Server, public: |
702 | 887 |
703 Server::Server(Display* display) | 888 Server::Server(Display* display) |
704 : display_(display), wl_display_(wl_display_create()) { | 889 : display_(display), wl_display_(wl_display_create()) { |
705 wl_global_create(wl_display_.get(), &wl_compositor_interface, | 890 wl_global_create(wl_display_.get(), &wl_compositor_interface, |
706 compositor_version, display_, bind_compositor); | 891 compositor_version, display_, bind_compositor); |
707 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); | 892 wl_global_create(wl_display_.get(), &wl_shm_interface, 1, display_, bind_shm); |
708 #if defined(USE_OZONE) | 893 #if defined(USE_OZONE) |
709 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_, | 894 wl_global_create(wl_display_.get(), &wl_drm_interface, drm_version, display_, |
710 bind_drm); | 895 bind_drm); |
711 #endif | 896 #endif |
712 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_, | 897 wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_, |
713 bind_subcompositor); | 898 bind_subcompositor); |
714 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, | 899 wl_global_create(wl_display_.get(), &wl_shell_interface, 1, display_, |
715 bind_shell); | 900 bind_shell); |
| 901 wl_global_create(wl_display_.get(), &xdg_shell_interface, 1, display_, |
| 902 bind_xdg_shell); |
716 } | 903 } |
717 | 904 |
718 Server::~Server() {} | 905 Server::~Server() {} |
719 | 906 |
720 // static | 907 // static |
721 scoped_ptr<Server> Server::Create(Display* display) { | 908 scoped_ptr<Server> Server::Create(Display* display) { |
722 scoped_ptr<Server> server(new Server(display)); | 909 scoped_ptr<Server> server(new Server(display)); |
723 int rv = wl_display_add_socket(server->wl_display_.get(), nullptr); | 910 int rv = wl_display_add_socket(server->wl_display_.get(), nullptr); |
724 DCHECK_EQ(rv, 0) << "wl_display_add_socket failed: " << rv; | 911 DCHECK_EQ(rv, 0) << "wl_display_add_socket failed: " << rv; |
725 return server; | 912 return server; |
(...skipping 15 matching lines...) Expand all Loading... |
741 DCHECK(event_loop); | 928 DCHECK(event_loop); |
742 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); | 929 wl_event_loop_dispatch(event_loop, timeout.InMilliseconds()); |
743 } | 930 } |
744 | 931 |
745 void Server::Flush() { | 932 void Server::Flush() { |
746 wl_display_flush_clients(wl_display_.get()); | 933 wl_display_flush_clients(wl_display_.get()); |
747 } | 934 } |
748 | 935 |
749 } // namespace wayland | 936 } // namespace wayland |
750 } // namespace exo | 937 } // namespace exo |
OLD | NEW |