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/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"
15 namespace ozonewayland {
17 WaylandShell::WaylandShell()
22 WaylandShell::~WaylandShell() {
24 wl_shell_destroy(shell_);
25 #if defined(ENABLE_XDG_SHELL)
27 xdg_shell_destroy(xdg_shell_);
31 WaylandShellSurface* WaylandShell::CreateShellSurface(WaylandWindow* window,
32 WaylandWindow::ShellType type) {
33 DCHECK(shell_ || xdg_shell_);
34 WaylandDisplay* display = WaylandDisplay::GetInstance();
36 WaylandShellSurface* surface = NULL;
37 #if defined(ENABLE_XDG_SHELL)
39 surface = new XDGShellSurface();
42 surface = new WLShellSurface();
45 surface->InitializeShellSurface(window, type);
46 wl_surface_set_user_data(surface->GetWLSurface(), window);
47 display->FlushDisplay();
52 void WaylandShell::Initialize(struct wl_registry *registry,
54 const char *interface,
56 if (strcmp(interface, "wl_shell") == 0) {
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")) {
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);
67 static const xdg_shell_listener xdg_shell_listener = {
68 WaylandShell::XDGHandlePing
70 xdg_shell_add_listener(xdg_shell_, &xdg_shell_listener, NULL);
75 #if defined(ENABLE_XDG_SHELL)
76 void WaylandShell::XDGHandlePing(void* data,
77 struct xdg_shell* xdg_shell,
79 xdg_shell_pong(xdg_shell, serial);
83 } // namespace ozonewayland