~ubuntu-branches/ubuntu/trusty/qtubuntu/trusty

« back to all changes in this revision

Viewing changes to src/platforms/ubuntu/ubuntucommon/window.cc

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Gerry Boland, Robert Carr, Ricardo Mendoza, Ubuntu daily release
  • Date: 2013-08-14 06:06:46 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20130814060646-4gpyxhl3hl7tqbpj
Tags: 0.52+13.10.20130814.1-0ubuntu1
[ Gerry Boland ]
* Add support for building mirserver and mirclient backends to the
  QPA.

[ Robert Carr ]
* Add support for building mirserver and mirclient backends to the
  QPA.

[ Ricardo Mendoza ]
* Add support for building mirserver and mirclient backends to the
  QPA.

[ Ubuntu daily release ]
* Automatic snapshot from revision 165

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of QtUbuntu, a set of Qt components for Ubuntu.
 
2
// Copyright © 2013 Canonical Ltd.
 
3
//
 
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.
 
7
//
 
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.
 
12
//
 
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/>.
 
15
 
 
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.
 
20
 
 
21
#include "window.h"
 
22
#include "screen.h"
 
23
#include "input.h"
 
24
#include "base/logging.h"
 
25
#include <qpa/qwindowsysteminterface.h>
 
26
#include <ubuntu/application/ui/window.h>
 
27
 
 
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);
 
33
}
 
34
 
 
35
QUbuntuWindow::QUbuntuWindow(
 
36
    QWindow* w, QUbuntuScreen* screen, QUbuntuInput* input,
 
37
    bool systemSession, UApplicationInstance* instance, bool isShell)
 
38
    : QUbuntuBaseWindow(w, screen)
 
39
    , input_(input)
 
40
    , state_(window()->windowState())
 
41
    , systemSession_(systemSession)
 
42
    , uainstance_(instance)
 
43
    , screen_(screen)
 
44
    , isShell_(isShell) {
 
45
  if (!systemSession) {
 
46
    // Non-system sessions can't resize the window geometry.
 
47
    geometry_ = screen->availableGeometry();
 
48
  } else {
 
49
    // Use client geometry if set explicitly, use available screen geometry otherwise.
 
50
    geometry_ = window()->geometry() != screen->geometry() ?
 
51
        window()->geometry() : screen->availableGeometry();
 
52
  }
 
53
  createWindow();
 
54
  DLOG("QUbuntuWindow::QUbuntuWindow (this=%p, w=%p, screen=%p, input=%p)", this, w, screen, input);
 
55
}
 
56
 
 
57
QUbuntuWindow::~QUbuntuWindow() {
 
58
  DLOG("QUbuntuWindow::~QUbuntuWindow");
 
59
  ua_ui_window_destroy(window_);
 
60
}
 
61
 
 
62
void QUbuntuWindow::createWindow() {
 
63
  DLOG("QUbuntuWindow::createWindow (this=%p)", this);
 
64
 
 
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);
 
75
  }
 
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"
 
80
  };
 
81
  LOG("role: '%s'", roleString[role]);
 
82
  LOG("flags: '%s'", (flags & static_cast<uint>(1)) ? "Opaque" : "NotOpaque");
 
83
#endif
 
84
 
 
85
  // Get surface geometry.
 
86
  QRect geometry;
 
87
  if (state_ == Qt::WindowFullScreen) {
 
88
    geometry = screen()->geometry();
 
89
  } else if (state_ == Qt::WindowMaximized) {
 
90
    geometry = screen()->availableGeometry();
 
91
  } else {
 
92
    geometry = geometry_;
 
93
  }
 
94
 
 
95
  fprintf(stderr, "creating surface at (%d, %d) with size (%d, %d)", geometry.x(), geometry.y(),
 
96
       geometry.width(), geometry.height());
 
97
 
 
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);
 
103
 
 
104
  // Create platform window
 
105
  window_ = ua_ui_window_new_for_application_with_properties(uainstance_, wprops_);
 
106
 
 
107
  if (geometry.width() != 0 || geometry.height() != 0)
 
108
      ua_ui_window_resize(window_, geometry.width(), geometry.height());
 
109
 
 
110
  if (geometry.x() != 0 || geometry.y() != 0)
 
111
      ua_ui_window_move(window_, geometry.x(), geometry.y());
 
112
 
 
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_);
 
117
  }
 
118
 
 
119
  // Tell Qt about the geometry.
 
120
  QWindowSystemInterface::handleGeometryChange(window(), geometry);
 
121
  QPlatformWindow::setGeometry(geometry);
 
122
}
 
123
 
 
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);
 
131
}
 
132
 
 
133
void QUbuntuWindow::setWindowState(Qt::WindowState state) {
 
134
  DLOG("QUbuntuWindow::setWindowState (this=%p, state=%d)", this, state);
 
135
  if (state == state_)
 
136
    return;
 
137
 
 
138
  switch (state) {
 
139
    case Qt::WindowNoState: {
 
140
      DLOG("setting window state: 'NoState'");
 
141
      moveResize(geometry_);
 
142
      state_ = Qt::WindowNoState;
 
143
      break;
 
144
    }
 
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;
 
150
      break;
 
151
    }
 
152
    case Qt::WindowMaximized: {
 
153
      DLOG("setting window state: 'Maximized'");
 
154
      moveResize(screen()->availableGeometry());
 
155
      state_ = Qt::WindowMaximized;
 
156
      break;
 
157
    }
 
158
    case Qt::WindowActive:
 
159
    case Qt::WindowMinimized:
 
160
    default: {
 
161
      DLOG("setting window state: 'Active|Minimized'");
 
162
      break;
 
163
    }
 
164
  }
 
165
}
 
166
 
 
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.
 
171
    geometry_ = rect;
 
172
    if (state_ != Qt::WindowFullScreen && state_ != Qt::WindowMaximized)
 
173
      moveResize(rect);
 
174
  }
 
175
}
 
176
 
 
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);
 
181
 
 
182
  if (visible) {
 
183
    ua_ui_window_show(window_);
 
184
    QWindowSystemInterface::handleExposeEvent(window(), QRect());
 
185
  } else {
 
186
    ua_ui_window_hide(window_);
 
187
  }
 
188
}