This repository has been archived by the owner on Aug 20, 2020. It is now read-only.
/
shell_surface.cc
106 lines (89 loc) · 2.96 KB
/
shell_surface.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2013 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ozone/wayland/shell_surface.h"
#include "ozone/wayland/display.h"
#include "ozone/wayland/surface.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
namespace ozonewayland {
WaylandShellSurface::WaylandShellSurface(WaylandWindow* window)
: surface_(NULL),
shell_surface_(NULL)
{
WaylandDisplay* display = WaylandDisplay::GetInstance();
if (!display)
return;
surface_ = new WaylandSurface();
if (display->shell())
shell_surface_ = wl_shell_get_shell_surface(
display->shell(),
surface_->wlSurface());
if (shell_surface_)
{
static const wl_shell_surface_listener shell_surface_listener = {
WaylandShellSurface::HandlePing,
WaylandShellSurface::HandleConfigure,
WaylandShellSurface::HandlePopupDone
};
wl_shell_surface_add_listener(shell_surface_, &shell_surface_listener, window);
}
}
WaylandShellSurface::~WaylandShellSurface() {
if (shell_surface_)
{
wl_shell_surface_destroy(shell_surface_);
shell_surface_ = NULL;
}
if (surface_)
{
delete surface_;
surface_ = NULL;
}
}
void WaylandShellSurface::UpdateShellSurface(WaylandWindow::ShellType type) const
{
switch (type) {
case WaylandWindow::TOPLEVEL:
// TODO(kalyan): Temp workaround to get menus working. This should be fixed
// properly when handling the positioning of popups.
case WaylandWindow::MENU:
wl_shell_surface_set_toplevel(shell_surface_);
break;
case WaylandWindow::FULLSCREEN:
wl_shell_surface_set_fullscreen(shell_surface_,
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
0,
NULL);
break;
case WaylandWindow::TRANSIENT:
case WaylandWindow::CUSTOM:
NOTREACHED() << "UnSupported Shell Type.";
break;
default:
break;
}
}
void WaylandShellSurface::SetWindowTitle(const string16& title) {
wl_shell_surface_set_title(shell_surface_, UTF16ToUTF8(title).c_str());
}
void WaylandShellSurface::HandleConfigure(void *data,
struct wl_shell_surface *shell_surface,
uint32_t edges,
int32_t width,
int32_t height)
{
WaylandWindow *window = static_cast<WaylandWindow*>(data);
window->SetBounds(gfx::Rect(0, 0, width, height));
}
void WaylandShellSurface::HandlePopupDone(void *data,
struct wl_shell_surface *shell_surface)
{
}
void WaylandShellSurface::HandlePing(void *data,
struct wl_shell_surface *shell_surface,
uint32_t serial)
{
wl_shell_surface_pong(shell_surface, serial);
}
} // namespace ozonewayland