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)
58 , m_surfaceList(new MirSurfaceListModel(this))
59 , m_promptSurfaceList(new MirSurfaceListModel(this))
61 connect(m_surfaceList, &MirSurfaceListModel::countChanged,
62 this, &ApplicationInfo::onSurfaceCountChanged, Qt::QueuedConnection);
64 m_surfaceCreationTimer.setSingleShot(true);
65 m_surfaceCreationTimer.setInterval(500);
66 connect(&m_surfaceCreationTimer, &QTimer::timeout, this, &ApplicationInfo::createSurface);
69ApplicationInfo::ApplicationInfo(QObject *parent)
70 : ApplicationInfo(QString(), parent)
74ApplicationInfo::~ApplicationInfo()
78void ApplicationInfo::createSurface()
80 if (state() == ApplicationInfo::Stopped) { return; }
82 QString surfaceName = name();
83 if (m_surfaceList->count() > 0) {
84 surfaceName.append(QString(" %1").arg(m_surfaceList->count()+1));
87 auto surfaceManager = SurfaceManager::instance();
88 if (!surfaceManager) {
89 WARNING_MSG("No SurfaceManager");
93 auto surface = surfaceManager->createSurface(surfaceName,
95 fullscreen() ? Mir::FullscreenState : Mir::MaximizedState,
96 m_screenshotFileName);
98 surface->setShellChrome(m_shellChrome);
100 m_surfaceList->appendSurface(surface);
102 ++m_liveSurfaceCount;
103 connect(surface, &MirSurface::liveChanged, this, [this, surface](){
104 if (!surface->live()) {
105 --m_liveSurfaceCount;
106 if (m_liveSurfaceCount == 0) {
107 if (m_closingSurfaces.contains(surface)
108 || (m_state == Running && m_requestedState == RequestedRunning)) {
113 if (m_closingSurfaces.contains(surface) && m_requestedState == RequestedSuspended
114 && m_closingSurfaces.count() == 1) {
118 m_closingSurfaces.removeAll(surface);
121 connect(surface, &MirSurface::closeRequested, this, [this, surface](){
122 m_closingSurfaces.append(surface);
123 if (m_state == Suspended) {
124 // resume to allow application to close its surface
128 connect(surface, &MirSurface::focusRequested, this, &ApplicationInfo::focusRequested);
130 if (m_state == Starting) {
131 if (m_requestedState == RequestedRunning) {
139void ApplicationInfo::setIconId(const QString &iconId)
141 setIcon(QString("../../graphics/applicationIcons/%2@18.png")
145void ApplicationInfo::setScreenshotId(const QString &screenshotId)
147 QString screenshotFileName;
149 if (screenshotId.endsWith(".svg")) {
150 screenshotFileName = QString("qrc:///Unity/Application/screenshots/%2")
153 screenshotFileName = QString("qrc:///Unity/Application/screenshots/%2@12.png")
157 if (screenshotFileName != m_screenshotFileName) {
158 m_screenshotFileName = screenshotFileName;
162void ApplicationInfo::setName(const QString &value)
164 if (value != m_name) {
166 Q_EMIT nameChanged(value);
170void ApplicationInfo::setIcon(const QUrl &value)
172 if (value != m_icon) {
174 Q_EMIT iconChanged(value);
178void ApplicationInfo::setState(State value)
180 if (value != m_state) {
181 DEBUG_MSG(qPrintable(stateToStr(value)));
182 if (!m_manualSurfaceCreation && value == ApplicationInfo::Starting) {
183 Q_ASSERT(m_surfaceList->count() == 0);
184 m_surfaceCreationTimer.start();
185 } else if (value == ApplicationInfo::Stopped) {
186 m_surfaceCreationTimer.stop();
187 for (int i = 0; i < m_surfaceList->count(); ++i) {
188 MirSurface *surface = static_cast<MirSurface*>(m_surfaceList->get(i));
189 surface->setLive(false);
191 for (int i = 0; i < m_promptSurfaceList->count(); ++i) {
192 auto surface = static_cast<MirSurface*>(m_promptSurfaceList->get(i));
193 surface->setLive(false);
198 Q_EMIT stateChanged(value);
202void ApplicationInfo::close()
206 if (m_surfaceList->count() > 0) {
207 for (int i = 0; i < m_surfaceList->count(); ++i) {
208 MirSurface *surface = static_cast<MirSurface*>(m_surfaceList->get(i));
217void ApplicationInfo::setFullscreen(bool value)
219 m_fullscreen = value;
220 if (m_surfaceList->rowCount() > 0) {
221 m_surfaceList->get(0)->setState(Mir::FullscreenState);
225bool ApplicationInfo::fullscreen() const
227 if (m_surfaceList->rowCount() > 0) {
228 return m_surfaceList->get(0)->state() == Mir::FullscreenState;
234void ApplicationInfo::setManualSurfaceCreation(bool value)
236 if (value != m_manualSurfaceCreation) {
237 m_manualSurfaceCreation = value;
238 Q_EMIT manualSurfaceCreationChanged(value);
240 if (m_manualSurfaceCreation && m_surfaceCreationTimer.isActive()) {
241 m_surfaceCreationTimer.stop();
246Qt::ScreenOrientations ApplicationInfo::supportedOrientations() const
248 return m_supportedOrientations;
251void ApplicationInfo::setSupportedOrientations(Qt::ScreenOrientations orientations)
253 m_supportedOrientations = orientations;
256bool ApplicationInfo::rotatesWindowContents() const
258 return m_rotatesWindowContents;
261void ApplicationInfo::setRotatesWindowContents(bool value)
263 m_rotatesWindowContents = value;
266ApplicationInfo::RequestedState ApplicationInfo::requestedState() const
268 return m_requestedState;
271void ApplicationInfo::setRequestedState(RequestedState value)
273 if (m_requestedState == value) {
276 DEBUG_MSG((value == RequestedRunning ? "RequestedRunning" : "RequestedSuspended") );
278 m_requestedState = value;
279 Q_EMIT requestedStateChanged(m_requestedState);
281 if (m_requestedState == RequestedRunning) {
283 if (m_state == Suspended) {
284 Q_ASSERT(m_liveSurfaceCount > 0);
286 } else if (m_state == Stopped) {
287 Q_ASSERT(m_liveSurfaceCount == 0);
292 } else if (m_requestedState == RequestedSuspended && m_state == Running
293 && m_closingSurfaces.isEmpty()) {
298bool ApplicationInfo::isTouchApp() const
303void ApplicationInfo::setIsTouchApp(bool isTouchApp)
305 m_isTouchApp = isTouchApp;
308bool ApplicationInfo::exemptFromLifecycle() const
310 return m_exemptFromLifecycle;
313void ApplicationInfo::setExemptFromLifecycle(bool exemptFromLifecycle)
315 if (m_exemptFromLifecycle != exemptFromLifecycle)
317 m_exemptFromLifecycle = exemptFromLifecycle;
318 Q_EMIT exemptFromLifecycleChanged(m_exemptFromLifecycle);
322QSize ApplicationInfo::initialSurfaceSize() const
324 return m_initialSurfaceSize;
327void ApplicationInfo::setInitialSurfaceSize(const QSize &size)
329 if (size != m_initialSurfaceSize) {
330 m_initialSurfaceSize = size;
331 Q_EMIT initialSurfaceSizeChanged(m_initialSurfaceSize);
335void ApplicationInfo::setShellChrome(Mir::ShellChrome shellChrome)
337 m_shellChrome = shellChrome;
338 if (m_surfaceList->rowCount() > 0) {
339 static_cast<MirSurface*>(m_surfaceList->get(0))->setShellChrome(shellChrome);
343bool ApplicationInfo::focused() const
345 bool someSurfaceHasFocus = false; // to be proven wrong
346 for (int i = 0; i < m_surfaceList->count() && !someSurfaceHasFocus; ++i) {
347 someSurfaceHasFocus = m_surfaceList->get(i)->focused();
349 return someSurfaceHasFocus;
352void ApplicationInfo::setFocused(bool value)
354 if (focused() == value) {
359 if (m_surfaceList->count() > 0) {
360 m_surfaceList->get(0)->requestFocus();
363 for (int i = 0; i < m_surfaceList->count(); ++i) {
364 MirSurface *surface = static_cast<MirSurface*>(m_surfaceList->get(i));
365 if (surface->focused()) {
366 surface->setFocused(false);
372void ApplicationInfo::onSurfaceCountChanged()
374 if (m_surfaceList->count() == 0 && m_state == Running) {
379void ApplicationInfo::requestFocus()
381 if (m_surfaceList->count() == 0) {
382 Q_EMIT focusRequested();
384 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