1 // Copyright 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ozone/wayland/shell/xdg_shell_surface.h"
7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h"
10 #include "ozone/wayland/display.h"
11 #include "ozone/wayland/input_device.h"
12 #include "ozone/wayland/shell/shell.h"
13 #include "ozone/wayland/shell/xdg-shell-client-protocol.h"
15 namespace ozonewayland {
17 XDGShellSurface::XDGShellSurface()
18 : WaylandShellSurface(),
25 XDGShellSurface::~XDGShellSurface() {
27 xdg_surface_destroy(xdg_surface_);
29 xdg_popup_destroy(xdg_popup_);
32 void XDGShellSurface::InitializeShellSurface(WaylandWindow* window,
33 WaylandWindow::ShellType type) {
34 DCHECK(!xdg_surface_);
36 WaylandDisplay* display = WaylandDisplay::GetInstance();
38 WaylandShell* shell = WaylandDisplay::GetInstance()->GetShell();
39 DCHECK(shell && shell->GetXDGShell());
41 if (type != WaylandWindow::POPUP) {
42 xdg_surface_ = xdg_shell_get_xdg_surface(shell->GetXDGShell(),
45 static const xdg_surface_listener xdg_surface_listener = {
46 XDGShellSurface::HandleConfigure,
47 XDGShellSurface::HandleChangeState,
48 XDGShellSurface::HandleActivate,
49 XDGShellSurface::HandleDeactivate,
50 XDGShellSurface::HandleDelete
53 xdg_surface_add_listener(xdg_surface_,
54 &xdg_surface_listener,
61 void XDGShellSurface::UpdateShellSurface(WaylandWindow::ShellType type,
62 WaylandShellSurface* shell_parent,
66 case WaylandWindow::TOPLEVEL: {
68 xdg_surface_request_change_state(xdg_surface_,
69 XDG_SURFACE_STATE_MAXIMIZED,
75 case WaylandWindow::POPUP: {
76 WaylandDisplay* display = WaylandDisplay::GetInstance();
77 WaylandInputDevice* input_device = display->PrimaryInput();
78 wl_surface* surface = GetWLSurface();
79 wl_surface* parent_surface = shell_parent->GetWLSurface();
80 xdg_popup_ = xdg_shell_get_xdg_popup(display->GetShell()->GetXDGShell(),
83 input_device->GetInputSeat(),
88 static const xdg_popup_listener xdg_popup_listener = {
89 XDGShellSurface::HandlePopupPopupDone
91 xdg_popup_add_listener(xdg_popup_,
97 case WaylandWindow::FULLSCREEN:
98 xdg_surface_request_change_state(xdg_surface_,
99 XDG_SURFACE_STATE_FULLSCREEN,
102 case WaylandWindow::CUSTOM:
103 NOTREACHED() << "Unsupported shell type: " << type;
109 WaylandShellSurface::FlushDisplay();
112 void XDGShellSurface::SetWindowTitle(const base::string16& title) {
113 xdg_surface_set_title(xdg_surface_, UTF16ToUTF8(title).c_str());
114 WaylandShellSurface::FlushDisplay();
117 void XDGShellSurface::Maximize() {
118 xdg_surface_request_change_state(xdg_surface_,
119 XDG_SURFACE_STATE_MAXIMIZED,
122 WaylandShellSurface::FlushDisplay();
125 void XDGShellSurface::Minimize() {
126 xdg_surface_set_minimized(xdg_surface_);
130 void XDGShellSurface::Unminimize() {
134 bool XDGShellSurface::IsMinimized() const {
138 void XDGShellSurface::HandleConfigure(void* data,
139 struct xdg_surface* xdg_surface,
142 WaylandShellSurface::WindowResized(data, width, height);
145 void XDGShellSurface::HandleChangeState(void* data,
146 struct xdg_surface* xdg_surface,
150 xdg_surface_ack_change_state(xdg_surface, state, value, serial);
153 void XDGShellSurface::HandleActivate(void* data,
154 struct xdg_surface* xdg_surface) {
155 WaylandShellSurface::WindowActivated(data);
158 void XDGShellSurface::HandleDeactivate(void* data,
159 struct xdg_surface* xdg_surface) {
160 WaylandShellSurface::WindowDeActivated(data);
163 void XDGShellSurface::HandleDelete(void* data,
164 struct xdg_surface* xdg_surface) {
167 void XDGShellSurface::HandlePopupPopupDone(void* data,
168 struct xdg_popup* xdg_popup,
170 WaylandShellSurface::PopupDone();
173 } // namespace ozonewayland