2 * Copyright (C) 2013-2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "ApplicationInfo.h"
18#include "MirSurface.h"
19#include "SurfaceManager.h"
23#include <QGuiApplication>
26#include <QQmlComponent>
28#define APPLICATION_DEBUG 0
31#define DEBUG_MSG(params) qDebug().nospace() << "Application["<<appId()<<"]::" << __func__ << " " << params
33QString stateToStr(ApplicationInfo::State state)
36 case ApplicationInfo::Starting:
38 case ApplicationInfo::Running:
40 case ApplicationInfo::Suspended:
42 case ApplicationInfo::Stopped:
50#define DEBUG_MSG(params) ((void)0)
53#define WARNING_MSG(params) qWarning().nospace() << "Application["<<appId()<<"]::" << __func__ << " " << params
55ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
56 : ApplicationInfoInterface(appId, parent)
59 connect(&m_surfaceList, &MirSurfaceListModel::countChanged,
60 this, &ApplicationInfo::onSurfaceCountChanged, Qt::QueuedConnection);
62 m_surfaceCreationTimer.setSingleShot(true);
63 m_surfaceCreationTimer.setInterval(500);
64 connect(&m_surfaceCreationTimer, &QTimer::timeout, this, &ApplicationInfo::createSurface);
67ApplicationInfo::ApplicationInfo(QObject *parent)
68 : ApplicationInfo(QString(), parent)
72ApplicationInfo::~ApplicationInfo()
76void ApplicationInfo::createSurface()
78 if (state() == ApplicationInfo::Stopped) { return; }
80 QString surfaceName = name();
81 if (m_surfaceList.count() > 0) {
82 surfaceName.append(QString(" %1").arg(m_surfaceList.count()+1));
85 auto surfaceManager = SurfaceManager::instance();
86 if (!surfaceManager) {
87 WARNING_MSG("No SurfaceManager");
91 auto surface = surfaceManager->createSurface(surfaceName,
93 fullscreen() ? Mir::FullscreenState : Mir::MaximizedState,
94 m_screenshotFileName);
96 surface->setShellChrome(m_shellChrome);
98 m_surfaceList.appendSurface(surface);
100 ++m_liveSurfaceCount;
101 connect(surface, &MirSurface::liveChanged, this, [this, surface](){
102 if (!surface->live()) {
103 --m_liveSurfaceCount;
104 if (m_liveSurfaceCount == 0) {
105 if (m_closingSurfaces.contains(surface)
106 || (m_state == Running && m_requestedState == RequestedRunning)) {
111 if (m_closingSurfaces.contains(surface) && m_requestedState == RequestedSuspended
112 && m_closingSurfaces.count() == 1) {
116 m_closingSurfaces.removeAll(surface);
119 connect(surface, &MirSurface::closeRequested, this, [this, surface](){
120 m_closingSurfaces.append(surface);
121 if (m_state == Suspended) {
122 // resume to allow application to close its surface
126 connect(surface, &MirSurface::focusRequested, this, &ApplicationInfo::focusRequested);
128 if (m_state == Starting) {
129 if (m_requestedState == RequestedRunning) {
137void ApplicationInfo::setIconId(const QString &iconId)
139 setIcon(QString("../../tests/graphics/applicationIcons/%2@18.png")
143void ApplicationInfo::setScreenshotId(const QString &screenshotId)
145 QString screenshotFileName;
147 if (screenshotId.endsWith(".svg")) {
148 screenshotFileName = QString("qrc:///Unity/Application/screenshots/%2")
151 screenshotFileName = QString("qrc:///Unity/Application/screenshots/%2@12.png")
155 if (screenshotFileName != m_screenshotFileName) {
156 m_screenshotFileName = screenshotFileName;
160void ApplicationInfo::setName(const QString &value)
162 if (value != m_name) {
164 Q_EMIT nameChanged(value);
168void ApplicationInfo::setIcon(const QUrl &value)
170 if (value != m_icon) {
172 Q_EMIT iconChanged(value);
176void ApplicationInfo::setStage(Stage value)
178 if (value != m_stage) {
180 Q_EMIT stageChanged(value);
184void ApplicationInfo::setState(State value)
186 if (value != m_state) {
187 DEBUG_MSG(qPrintable(stateToStr(value)));
188 if (!m_manualSurfaceCreation && value == ApplicationInfo::Starting) {
189 Q_ASSERT(m_surfaceList.count() == 0);
190 m_surfaceCreationTimer.start();
191 } else if (value == ApplicationInfo::Stopped) {
192 m_surfaceCreationTimer.stop();
193 for (int i = 0; i < m_surfaceList.count(); ++i) {
194 MirSurface *surface = static_cast<MirSurface*>(m_surfaceList.get(i));
195 surface->setLive(false);
200 Q_EMIT stateChanged(value);
204void ApplicationInfo::close()
208 if (m_surfaceList.count() > 0) {
209 for (int i = 0; i < m_surfaceList.count(); ++i) {
210 MirSurface *surface = static_cast<MirSurface*>(m_surfaceList.get(i));
219void ApplicationInfo::setFullscreen(bool value)
221 m_fullscreen = value;
222 if (m_surfaceList.rowCount() > 0) {
223 m_surfaceList.get(0)->setState(Mir::FullscreenState);
227bool ApplicationInfo::fullscreen() const
229 if (m_surfaceList.rowCount() > 0) {
230 return m_surfaceList.get(0)->state() == Mir::FullscreenState;
236void ApplicationInfo::setManualSurfaceCreation(bool value)
238 if (value != m_manualSurfaceCreation) {
239 m_manualSurfaceCreation = value;
240 Q_EMIT manualSurfaceCreationChanged(value);
244Qt::ScreenOrientations ApplicationInfo::supportedOrientations() const
246 return m_supportedOrientations;
249void ApplicationInfo::setSupportedOrientations(Qt::ScreenOrientations orientations)
251 m_supportedOrientations = orientations;
254bool ApplicationInfo::rotatesWindowContents() const
256 return m_rotatesWindowContents;
259void ApplicationInfo::setRotatesWindowContents(bool value)
261 m_rotatesWindowContents = value;
264ApplicationInfo::RequestedState ApplicationInfo::requestedState() const
266 return m_requestedState;
269void ApplicationInfo::setRequestedState(RequestedState value)
271 if (m_requestedState == value) {
274 DEBUG_MSG((value == RequestedRunning ? "RequestedRunning" : "RequestedSuspended") );
276 m_requestedState = value;
277 Q_EMIT requestedStateChanged(m_requestedState);
279 if (m_requestedState == RequestedRunning) {
281 if (m_state == Suspended) {
282 Q_ASSERT(m_liveSurfaceCount > 0);
284 } else if (m_state == Stopped) {
285 Q_ASSERT(m_liveSurfaceCount == 0);
290 } else if (m_requestedState == RequestedSuspended && m_state == Running
291 && m_closingSurfaces.isEmpty()) {
296bool ApplicationInfo::isTouchApp() const
301void ApplicationInfo::setIsTouchApp(bool isTouchApp)
303 m_isTouchApp = isTouchApp;
306bool ApplicationInfo::exemptFromLifecycle() const
308 return m_exemptFromLifecycle;
311void ApplicationInfo::setExemptFromLifecycle(bool exemptFromLifecycle)
313 if (m_exemptFromLifecycle != exemptFromLifecycle)
315 m_exemptFromLifecycle = exemptFromLifecycle;
316 Q_EMIT exemptFromLifecycleChanged(m_exemptFromLifecycle);
320QSize ApplicationInfo::initialSurfaceSize() const
322 return m_initialSurfaceSize;
325void ApplicationInfo::setInitialSurfaceSize(const QSize &size)
327 if (size != m_initialSurfaceSize) {
328 m_initialSurfaceSize = size;
329 Q_EMIT initialSurfaceSizeChanged(m_initialSurfaceSize);
333void ApplicationInfo::setShellChrome(Mir::ShellChrome shellChrome)
335 m_shellChrome = shellChrome;
336 if (m_surfaceList.rowCount() > 0) {
337 static_cast<MirSurface*>(m_surfaceList.get(0))->setShellChrome(shellChrome);
341bool ApplicationInfo::focused() const
343 bool someSurfaceHasFocus = false; // to be proven wrong
344 for (int i = 0; i < m_surfaceList.count() && !someSurfaceHasFocus; ++i) {
345 someSurfaceHasFocus = m_surfaceList.get(i)->focused();
347 return someSurfaceHasFocus;
350void ApplicationInfo::setFocused(bool value)
352 if (focused() == value) {
357 if (m_surfaceList.count() > 0) {
358 m_surfaceList.get(0)->requestFocus();
361 for (int i = 0; i < m_surfaceList.count(); ++i) {
362 MirSurface *surface = static_cast<MirSurface*>(m_surfaceList.get(i));
363 if (surface->focused()) {
364 surface->setFocused(false);
370void ApplicationInfo::onSurfaceCountChanged()
372 if (m_surfaceList.count() == 0 && m_state == Running) {
377void ApplicationInfo::requestFocus()
379 if (m_surfaceList.count() == 0) {
380 Q_EMIT focusRequested();
382 m_surfaceList.get(0)->requestFocus();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list