1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Copyright 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #include "ozone/wayland/window.h"
8 #include "base/logging.h"
9 #include "ozone/wayland/display.h"
10 #include "ozone/wayland/egl/egl_window.h"
11 #include "ozone/wayland/input_device.h"
12 #include "ozone/wayland/shell/shell.h"
13 #include "ozone/wayland/shell/shell_surface.h"
15 namespace ozonewayland {
17 WaylandWindow::WaylandWindow(unsigned handle) : shell_surface_(NULL),
21 allocation_(gfx::Rect(0, 0, 1, 1)) {
24 WaylandWindow::~WaylandWindow() {
26 delete shell_surface_;
29 void WaylandWindow::SetShellAttributes(ShellType type) {
33 if (!shell_surface_) {
35 WaylandDisplay::GetInstance()->GetShell()->CreateShellSurface(this, type);
39 shell_surface_->UpdateShellSurface(type_, NULL, 0, 0);
42 void WaylandWindow::SetShellAttributes(ShellType type,
43 WaylandShellSurface* shell_parent,
46 DCHECK(shell_parent && (type == POPUP));
48 if (!shell_surface_) {
50 WaylandDisplay::GetInstance()->GetShell()->CreateShellSurface(this, type);
51 WaylandInputDevice* input = WaylandDisplay::GetInstance()->PrimaryInput();
52 input->SetGrabWindowHandle(handle_, 0);
56 shell_surface_->UpdateShellSurface(type_, shell_parent, x, y);
59 void WaylandWindow::SetWindowTitle(const base::string16& title) {
60 shell_surface_->SetWindowTitle(title);
63 void WaylandWindow::Maximize() {
64 if (type_ != FULLSCREEN)
65 shell_surface_->Maximize();
68 void WaylandWindow::Minimize() {
69 shell_surface_->Minimize();
72 void WaylandWindow::Restore() {
73 // If window is created as fullscreen, we don't set/restore any window states
75 if (type_ != FULLSCREEN)
76 shell_surface_->UpdateShellSurface(type_, NULL, 0, 0);
79 void WaylandWindow::SetFullscreen() {
80 if (type_ != FULLSCREEN)
81 shell_surface_->UpdateShellSurface(FULLSCREEN, NULL, 0, 0);
84 void WaylandWindow::RealizeAcceleratedWidget() {
85 if (!shell_surface_) {
86 LOG(ERROR) << "Shell type not set. Setting it to TopLevel";
87 SetShellAttributes(TOPLEVEL);
91 window_ = new EGLWindow(shell_surface_->GetWLSurface(),
93 allocation_.height());
96 wl_egl_window* WaylandWindow::egl_window() const {
98 return window_->egl_window();
101 void WaylandWindow::Resize(unsigned width, unsigned height) {
102 if ((allocation_.width() == width) && (allocation_.height() == height))
105 allocation_ = gfx::Rect(allocation_.x(), allocation_.y(), width, height);
106 if (!shell_surface_ || !window_)
109 window_->Resize(width, height);
110 WaylandDisplay* display = WaylandDisplay::GetInstance();
112 display->FlushDisplay();
115 } // namespace ozonewayland