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)
53ApplicationInfo::ApplicationInfo(const QString &appId, QObject *parent)
54 : ApplicationInfoInterface(appId, parent)
57 connect(&m_surfaceList, &MirSurfaceListModel::countChanged,
58 this, &ApplicationInfo::onSurfaceCountChanged, Qt::QueuedConnection);
60 m_surfaceCreationTimer.setSingleShot(true);
61 m_surfaceCreationTimer.setInterval(500);
62 connect(&m_surfaceCreationTimer, &QTimer::timeout, this, &ApplicationInfo::createSurface);
65ApplicationInfo::ApplicationInfo(QObject *parent)
66 : ApplicationInfo(QString(), parent)
70ApplicationInfo::~ApplicationInfo()
74void ApplicationInfo::createSurface()
76 if (state() == ApplicationInfo::Stopped) { return; }
78 QString surfaceName = name();
79 if (m_surfaceList.count() > 0) {
80 surfaceName.append(QString(" %1").arg(m_surfaceList.count()+1));
83 auto surface = SurfaceManager::singleton()->createSurface(surfaceName,
85 fullscreen() ? Mir::FullscreenState : Mir::MaximizedState,
86 m_screenshotFileName);
88 surface->setShellChrome(m_shellChrome);
90 m_surfaceList.appendSurface(surface);
93 connect(surface, &MirSurface::liveChanged, this, [this, surface](){
94 if (!surface->live()) {
96 if (m_liveSurfaceCount == 0) {
97 if (m_closingSurfaces.contains(surface)
98 || (m_state == Running && m_requestedState == RequestedRunning)) {
103 if (m_closingSurfaces.contains(surface) && m_requestedState == RequestedSuspended
104 && m_closingSurfaces.count() == 1) {
108 m_closingSurfaces.removeAll(surface);
111 connect(surface, &MirSurface::closeRequested, this, [this, surface](){
112 m_closingSurfaces.append(surface);
113 if (m_state == Suspended) {
114 // resume to allow application to close its surface
119 if (m_state == Starting) {
120 if (m_requestedState == RequestedRunning) {
128void ApplicationInfo::setIconId(const QString &iconId)
130 setIcon(QString("../../tests/graphics/applicationIcons/%2@18.png")
134void ApplicationInfo::setScreenshotId(const QString &screenshotId)
136 QString screenshotFileName;
138 if (screenshotId.endsWith(".svg")) {
139 screenshotFileName = QString("qrc:///Unity/Application/screenshots/%2")
142 screenshotFileName = QString("qrc:///Unity/Application/screenshots/%2@12.png")
146 if (screenshotFileName != m_screenshotFileName) {
147 m_screenshotFileName = screenshotFileName;
151void ApplicationInfo::setName(const QString &value)
153 if (value != m_name) {
155 Q_EMIT nameChanged(value);
159void ApplicationInfo::setIcon(const QUrl &value)
161 if (value != m_icon) {
163 Q_EMIT iconChanged(value);
167void ApplicationInfo::setStage(Stage value)
169 if (value != m_stage) {
171 Q_EMIT stageChanged(value);
175void ApplicationInfo::setState(State value)
177 if (value != m_state) {
178 DEBUG_MSG(qPrintable(stateToStr(value)));
179 if (!m_manualSurfaceCreation && value == ApplicationInfo::Starting) {
180 Q_ASSERT(m_surfaceList.count() == 0);
181 m_surfaceCreationTimer.start();
182 } else if (value == ApplicationInfo::Stopped) {
183 m_surfaceCreationTimer.stop();
184 for (int i = 0; i < m_surfaceList.count(); ++i) {
185 MirSurface *surface = static_cast<MirSurface*>(m_surfaceList.get(i));
186 surface->setLive(false);
191 Q_EMIT stateChanged(value);
195void ApplicationInfo::close()
199 if (m_surfaceList.count() > 0) {
200 for (int i = 0; i < m_surfaceList.count(); ++i) {
201 MirSurface *surface = static_cast<MirSurface*>(m_surfaceList.get(i));
210void ApplicationInfo::setFullscreen(bool value)
212 m_fullscreen = value;
213 if (m_surfaceList.rowCount() > 0) {
214 m_surfaceList.get(0)->setState(Mir::FullscreenState);
218bool ApplicationInfo::fullscreen() const
220 if (m_surfaceList.rowCount() > 0) {
221 return m_surfaceList.get(0)->state() == Mir::FullscreenState;
227void ApplicationInfo::setManualSurfaceCreation(bool value)
229 if (value != m_manualSurfaceCreation) {
230 m_manualSurfaceCreation = value;
231 Q_EMIT manualSurfaceCreationChanged(value);
235Qt::ScreenOrientations ApplicationInfo::supportedOrientations() const
237 return m_supportedOrientations;
240void ApplicationInfo::setSupportedOrientations(Qt::ScreenOrientations orientations)
242 m_supportedOrientations = orientations;
245bool ApplicationInfo::rotatesWindowContents() const
247 return m_rotatesWindowContents;
250void ApplicationInfo::setRotatesWindowContents(bool value)
252 m_rotatesWindowContents = value;
255ApplicationInfo::RequestedState ApplicationInfo::requestedState() const
257 return m_requestedState;
260void ApplicationInfo::setRequestedState(RequestedState value)
262 if (m_requestedState == value) {
265 DEBUG_MSG((value == RequestedRunning ? "RequestedRunning" : "RequestedSuspended") );
267 m_requestedState = value;
268 Q_EMIT requestedStateChanged(m_requestedState);
270 if (m_requestedState == RequestedRunning) {
272 if (m_state == Suspended) {
273 Q_ASSERT(m_liveSurfaceCount > 0);
275 } else if (m_state == Stopped) {
276 Q_ASSERT(m_liveSurfaceCount == 0);
281 } else if (m_requestedState == RequestedSuspended && m_state == Running
282 && m_closingSurfaces.isEmpty()) {
287bool ApplicationInfo::isTouchApp() const
292void ApplicationInfo::setIsTouchApp(bool isTouchApp)
294 m_isTouchApp = isTouchApp;
297bool ApplicationInfo::exemptFromLifecycle() const
299 return m_exemptFromLifecycle;
302void ApplicationInfo::setExemptFromLifecycle(bool exemptFromLifecycle)
304 if (m_exemptFromLifecycle != exemptFromLifecycle)
306 m_exemptFromLifecycle = exemptFromLifecycle;
307 Q_EMIT exemptFromLifecycleChanged(m_exemptFromLifecycle);
311QSize ApplicationInfo::initialSurfaceSize() const
313 return m_initialSurfaceSize;
316void ApplicationInfo::setInitialSurfaceSize(const QSize &size)
318 if (size != m_initialSurfaceSize) {
319 m_initialSurfaceSize = size;
320 Q_EMIT initialSurfaceSizeChanged(m_initialSurfaceSize);
324void ApplicationInfo::setShellChrome(Mir::ShellChrome shellChrome)
326 m_shellChrome = shellChrome;
327 if (m_surfaceList.rowCount() > 0) {
328 static_cast<MirSurface*>(m_surfaceList.get(0))->setShellChrome(shellChrome);
332bool ApplicationInfo::focused() const
334 bool someSurfaceHasFocus = false; // to be proven wrong
335 for (int i = 0; i < m_surfaceList.count() && !someSurfaceHasFocus; ++i) {
336 someSurfaceHasFocus = m_surfaceList.get(i)->focused();
338 return someSurfaceHasFocus;
341void ApplicationInfo::setFocused(bool value)
343 if (focused() == value) {
348 if (m_surfaceList.count() > 0) {
349 m_surfaceList.get(0)->requestFocus();
352 for (int i = 0; i < m_surfaceList.count(); ++i) {
353 MirSurface *surface = static_cast<MirSurface*>(m_surfaceList.get(i));
354 if (surface->focused()) {
355 surface->setFocused(false);
361void ApplicationInfo::onSurfaceCountChanged()
363 if (m_surfaceList.count() == 0 && m_state == Running) {
368void ApplicationInfo::requestFocus()
370 if (m_surfaceList.count() == 0) {
371 Q_EMIT focusRequested();
373 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