Upstream version 10.38.220.0
[platform/framework/web/crosswalk.git] / src / ozone / wayland / shell / shell.cc
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.
4
5 #include "ozone/wayland/shell/shell.h"
6
7 #include "base/logging.h"
8 #include "ozone/wayland/display.h"
9 #include "ozone/wayland/shell/wl_shell_surface.h"
10 #if defined(ENABLE_XDG_SHELL)
11 #include "ozone/wayland/shell/xdg-shell-client-protocol.h"
12 #include "ozone/wayland/shell/xdg_shell_surface.h"
13 #endif
14
15 namespace ozonewayland {
16
17 WaylandShell::WaylandShell()
18     : shell_(NULL),
19       xdg_shell_(NULL) {
20 }
21
22 WaylandShell::~WaylandShell() {
23   if (shell_)
24     wl_shell_destroy(shell_);
25 #if defined(ENABLE_XDG_SHELL)
26   if (xdg_shell_)
27     xdg_shell_destroy(xdg_shell_);
28 #endif
29 }
30
31 WaylandShellSurface* WaylandShell::CreateShellSurface(WaylandWindow* window,
32                                                       WaylandWindow::ShellType type) {
33   DCHECK(shell_ || xdg_shell_);
34   WaylandDisplay* display = WaylandDisplay::GetInstance();
35   DCHECK(display);
36   WaylandShellSurface* surface = NULL;
37 #if defined(ENABLE_XDG_SHELL)
38   if (xdg_shell_)
39     surface = new XDGShellSurface();
40 #endif
41   if (!surface)
42     surface = new WLShellSurface();
43
44   DCHECK(surface);
45   surface->InitializeShellSurface(window, type);
46   wl_surface_set_user_data(surface->GetWLSurface(), window);
47   display->FlushDisplay();
48
49   return surface;
50 }
51
52 void WaylandShell::Initialize(struct wl_registry *registry,
53                               uint32_t name,
54                               const char *interface,
55                               uint32_t version) {
56   if (strcmp(interface, "wl_shell") == 0) {
57     DCHECK(!shell_);
58     shell_ = static_cast<wl_shell*>(
59         wl_registry_bind(registry, name, &wl_shell_interface, 1));
60 #if defined(ENABLE_XDG_SHELL)
61   } else if ((strcmp(interface, "xdg_shell") == 0) && getenv("OZONE_WAYLAND_USE_XDG_SHELL")) {
62       DCHECK(!xdg_shell_);
63       xdg_shell_ = static_cast<xdg_shell*>(
64           wl_registry_bind(registry, name, &xdg_shell_interface, 1));
65       xdg_shell_use_unstable_version(xdg_shell_, XDG_SHELL_VERSION_CURRENT);
66
67       static const xdg_shell_listener xdg_shell_listener = {
68         WaylandShell::XDGHandlePing
69       };
70       xdg_shell_add_listener(xdg_shell_, &xdg_shell_listener, NULL);
71 #endif
72   }
73 }
74
75 #if defined(ENABLE_XDG_SHELL)
76 void WaylandShell::XDGHandlePing(void* data,
77                                  struct xdg_shell* xdg_shell,
78                                  uint32_t serial) {
79   xdg_shell_pong(xdg_shell, serial);
80 }
81 #endif
82
83 }  // namespace ozonewayland