summaryrefslogtreecommitdiffstats
path: root/ui/wayland/wayland_window.cc
blob: cd84a450f628439f4c1fbe84b0fd615391013d42 (plain)
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
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/wayland/wayland_window.h"

#include <wayland-egl.h>

#include "base/wayland/wayland_event.h"
#include "ui/wayland/wayland_display.h"
#include "ui/wayland/wayland_widget.h"

using base::wayland::WaylandEvent;

namespace ui {

WaylandWindow::WaylandWindow(WaylandWidget* widget, WaylandDisplay* display)
    : widget_(widget),
      display_(display),
      parent_window_(NULL),
      relative_position_(),
      surface_(display->CreateSurface()),
      fullscreen_(false) {
  wl_surface_set_user_data(surface_, this);
}

WaylandWindow::WaylandWindow(
    WaylandWidget* widget,
    WaylandDisplay* display,
    WaylandWindow* parent,
    int32_t x,
    int32_t y)
    : widget_(widget),
      display_(display),
      parent_window_(parent),
      relative_position_(x, y),
      surface_(display->CreateSurface()),
      fullscreen_(false) {
  wl_surface_set_user_data(surface_, this);
}

WaylandWindow::~WaylandWindow() {
  if (surface_)
    wl_surface_destroy(surface_);
}

void WaylandWindow::SetVisible(bool visible) {
  if (visible) {
    if (fullscreen_) {
      wl_shell_set_fullscreen(display_->shell(), surface_);
    } else if (!parent_window_) {
      wl_shell_set_toplevel(display_->shell(), surface_);
    } else {
      wl_shell_set_transient(display_->shell(),
                             surface_,
                             parent_window_->surface(),
                             relative_position_.x(),
                             relative_position_.y(),
                             0);
    }
  } else {
    // TODO(dnicoara) What is the correct way of hiding a wl_surface?
  }
}

bool WaylandWindow::IsVisible() const {
  return surface_ != NULL;
}

void WaylandWindow::Configure(uint32_t time,
                              uint32_t edges,
                              int32_t x,
                              int32_t y,
                              int32_t width,
                              int32_t height) {
  WaylandEvent event;
  event.geometry_change.time = time;
  event.geometry_change.x = x;
  event.geometry_change.y = y;
  event.geometry_change.width = width;
  event.geometry_change.height = height;

  widget_->OnGeometryChange(event);
}

}  // namespace ui