1
// This file is part of QtUbuntu, a set of Qt components for Ubuntu.
2
// Copyright © 2013 Canonical Ltd.
4
// This program is free software: you can redistribute it and/or modify it under
5
// the terms of the GNU Lesser General Public License version 3, as published by
6
// the Free Software Foundation.
8
// This program is distributed in the hope that it will be useful, but WITHOUT
9
// ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
// SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
// Lesser General Public License for more details.
13
// You should have received a copy of the GNU Lesser General Public License
14
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
// FIXME(loicm) The fullscreen API from Ubuntu Platform isn't good enough as we can't leave
17
// fullscreen. The current Ubuntu Platform fullscreen call allows the application manager to
18
// know the fullscreen state of an application, it's still the application responsibility to set
19
// the right surface geometry.
24
#include "base/logging.h"
25
#include <qpa/qwindowsysteminterface.h>
26
#include <ubuntu/application/ui/window.h>
28
static void eventCallback(void* context, const Event* event) {
29
DLOG("eventCallback (context=%p, event=%p)", context, event);
30
DASSERT(context != NULL);
31
QUbuntuWindow* window = static_cast<QUbuntuWindow*>(context);
32
window->input_->postEvent(window->window(), event);
35
QUbuntuWindow::QUbuntuWindow(
36
QWindow* w, QUbuntuScreen* screen, QUbuntuInput* input,
37
bool systemSession, UApplicationInstance* instance, bool isShell)
38
: QUbuntuBaseWindow(w, screen)
40
, state_(window()->windowState())
41
, systemSession_(systemSession)
42
, uainstance_(instance)
46
// Non-system sessions can't resize the window geometry.
47
geometry_ = screen->availableGeometry();
49
// Use client geometry if set explicitly, use available screen geometry otherwise.
50
geometry_ = window()->geometry() != screen->geometry() ?
51
window()->geometry() : screen->availableGeometry();
54
DLOG("QUbuntuWindow::QUbuntuWindow (this=%p, w=%p, screen=%p, input=%p)", this, w, screen, input);
57
QUbuntuWindow::~QUbuntuWindow() {
58
DLOG("QUbuntuWindow::~QUbuntuWindow");
59
ua_ui_window_destroy(window_);
62
void QUbuntuWindow::createWindow() {
63
DLOG("QUbuntuWindow::createWindow (this=%p)", this);
65
// Get surface role and flags.
66
QVariant roleVariant = window()->property("role");
67
int role = roleVariant.isValid() ? roleVariant.toUInt() : 1; // 1 is the default role for apps.
68
QVariant opaqueVariant = window()->property("opaque");
69
uint flags = opaqueVariant.isValid() ?
70
opaqueVariant.toUInt() ? static_cast<uint>(IS_OPAQUE_FLAG) : 0 : 0;
71
if (!systemSession_) {
72
// FIXME(loicm) Opaque flag is forced for now for non-system sessions (applications) for
73
// performance reasons.
74
flags |= static_cast<uint>(IS_OPAQUE_FLAG);
76
#if !defined(QT_NO_DEBUG)
77
//ASSERT(role <= ON_SCREEN_KEYBOARD_ACTOR_ROLE);
78
const char* const roleString[] = {
79
"Dash", "Default", "Indicator", "Notifications", "Greeter", "Launcher", "OSK", "ShutdownDialog"
81
LOG("role: '%s'", roleString[role]);
82
LOG("flags: '%s'", (flags & static_cast<uint>(1)) ? "Opaque" : "NotOpaque");
85
// Get surface geometry.
87
if (state_ == Qt::WindowFullScreen) {
88
geometry = screen()->geometry();
89
} else if (state_ == Qt::WindowMaximized) {
90
geometry = screen()->availableGeometry();
95
fprintf(stderr, "creating surface at (%d, %d) with size (%d, %d)", geometry.x(), geometry.y(),
96
geometry.width(), geometry.height());
98
// Setup platform window creation properties
99
wprops_ = ua_ui_window_properties_new_for_normal_window();
100
ua_ui_window_properties_set_titlen(wprops_, "Window 1", 8);
101
ua_ui_window_properties_set_role(wprops_, static_cast<UAUiWindowRole>(role));
102
ua_ui_window_properties_set_input_cb_and_ctx(wprops_, &eventCallback, this);
104
// Create platform window
105
window_ = ua_ui_window_new_for_application_with_properties(uainstance_, wprops_);
107
if (geometry.width() != 0 || geometry.height() != 0)
108
ua_ui_window_resize(window_, geometry.width(), geometry.height());
110
if (geometry.x() != 0 || geometry.y() != 0)
111
ua_ui_window_move(window_, geometry.x(), geometry.y());
113
ASSERT(window_ != NULL);
114
createSurface(ua_ui_window_get_native_type(window_));
115
if (state_ == Qt::WindowFullScreen) {
116
ua_ui_window_request_fullscreen(window_);
119
// Tell Qt about the geometry.
120
QWindowSystemInterface::handleGeometryChange(window(), geometry);
121
QPlatformWindow::setGeometry(geometry);
124
void QUbuntuWindow::moveResize(const QRect& rect) {
125
fprintf(stderr, "\nQUbuntuWindow::moveResize (this=%p, x=%d, y=%d, w=%d, h=%d)\n", this, rect.x(), rect.y(),
126
rect.width(), rect.height());
127
ua_ui_window_move(window_, rect.x(), rect.y());
128
ua_ui_window_resize(window_, rect.width(), rect.height());
129
QWindowSystemInterface::handleGeometryChange(window(), rect);
130
QPlatformWindow::setGeometry(rect);
133
void QUbuntuWindow::setWindowState(Qt::WindowState state) {
134
DLOG("QUbuntuWindow::setWindowState (this=%p, state=%d)", this, state);
139
case Qt::WindowNoState: {
140
DLOG("setting window state: 'NoState'");
141
moveResize(geometry_);
142
state_ = Qt::WindowNoState;
145
case Qt::WindowFullScreen: {
146
DLOG("setting window state: 'FullScreen'");
147
ua_ui_window_request_fullscreen(window_);
148
moveResize(screen()->geometry());
149
state_ = Qt::WindowFullScreen;
152
case Qt::WindowMaximized: {
153
DLOG("setting window state: 'Maximized'");
154
moveResize(screen()->availableGeometry());
155
state_ = Qt::WindowMaximized;
158
case Qt::WindowActive:
159
case Qt::WindowMinimized:
161
DLOG("setting window state: 'Active|Minimized'");
167
void QUbuntuWindow::setGeometry(const QRect& rect) {
168
fprintf(stderr, "QUbuntuWindow::setGeometry (this=%p)", this);
169
if (systemSession_) {
170
// Non-system sessions can't resize the window geometry.
172
if (state_ != Qt::WindowFullScreen && state_ != Qt::WindowMaximized)
177
void QUbuntuWindow::setVisible(bool visible) {
178
DLOG("QUbuntuWindow::setVisible (this=%p, visible=%s)", this, visible ? "true" : "false");
179
if (isShell_ == false)
180
screen_->toggleSensors(visible);
183
ua_ui_window_show(window_);
184
QWindowSystemInterface::handleExposeEvent(window(), QRect());
186
ua_ui_window_hide(window_);