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/shell.h"
7 #include "base/logging.h"
8 #include "ozone/wayland/display.h"
9 #include "ozone/wayland/shell/ivi-application-client-protocol.h"
10 #include "ozone/wayland/shell/ivi_shell_surface.h"
11 #include "ozone/wayland/shell/wl_shell_surface.h"
12 #include "ozone/wayland/shell/xdg-shell-client-protocol.h"
13 #include "ozone/wayland/shell/xdg_shell_surface.h"
15 namespace ozonewayland {
17 WaylandShell::WaylandShell()
20 ivi_application_(NULL) {
23 WaylandShell::~WaylandShell() {
25 wl_shell_destroy(shell_);
27 xdg_shell_destroy(xdg_shell_);
29 ivi_application_destroy(ivi_application_);
33 WaylandShell::CreateShellSurface(WaylandWindow* window,
34 WaylandWindow::ShellType type) {
35 DCHECK(shell_ || xdg_shell_ || ivi_application_);
36 WaylandDisplay* display = WaylandDisplay::GetInstance();
38 WaylandShellSurface* surface = NULL;
40 surface = new IVIShellSurface();
42 surface = new XDGShellSurface();
44 surface = new WLShellSurface();
47 surface->InitializeShellSurface(window, type);
48 wl_surface_set_user_data(surface->GetWLSurface(), window);
49 display->FlushDisplay();
54 void WaylandShell::Initialize(struct wl_registry *registry,
56 const char *interface,
58 if (strcmp(interface, "wl_shell") == 0) {
60 shell_ = static_cast<wl_shell*>(
61 wl_registry_bind(registry, name, &wl_shell_interface, 1));
62 } else if ((strcmp(interface, "xdg_shell") == 0) &&
63 getenv("OZONE_WAYLAND_USE_XDG_SHELL")) {
65 xdg_shell_ = static_cast<xdg_shell*>(
66 wl_registry_bind(registry, name, &xdg_shell_interface, 1));
67 xdg_shell_use_unstable_version(xdg_shell_, XDG_SHELL_VERSION_CURRENT);
69 static const xdg_shell_listener xdg_shell_listener = {
70 WaylandShell::XDGHandlePing
72 xdg_shell_add_listener(xdg_shell_, &xdg_shell_listener, NULL);
73 } else if (strcmp(interface, "ivi_application") == 0) {
74 DCHECK(!ivi_application_);
75 ivi_application_ = static_cast<ivi_application*>(
76 wl_registry_bind(registry, name, &ivi_application_interface, 1));
80 void WaylandShell::XDGHandlePing(void* data,
81 struct xdg_shell* xdg_shell,
83 xdg_shell_pong(xdg_shell, serial);
86 } // namespace ozonewayland