on f292b58 help sign in
200 lines 4.1 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17#include "MirSurface.h"
19#include <QDebug>
21MirSurface::MirSurface(const QString& name,
22 Mir::Type type,
23 Mir::State state,
24 const QUrl& screenshot,
25 const QString &qmlFilePath)
26 : unity::shell::application::MirSurfaceInterface(nullptr)
27 , m_name(name)
28 , m_type(type)
29 , m_state(state)
30 , m_orientationAngle(Mir::Angle0)
31 , m_screenshotUrl(screenshot)
32 , m_qmlFilePath(qmlFilePath)
33 , m_live(true)
34 , m_visibility(Mir::Exposed)
35 , m_viewCount(0)
36 , m_activeFocus(false)
37 , m_width(-1)
38 , m_height(-1)
40 qDebug() << "MirSurface::MirSurface() " << name;
43MirSurface::~MirSurface()
45 qDebug() << "MirSurface::~MirSurface() " << name();
48QString MirSurface::name() const
50 return m_name;
53Mir::Type MirSurface::type() const
55 return m_type;
58Mir::State MirSurface::state() const
60 return m_state;
63void MirSurface::setState(Mir::State state)
65 if (state == m_state)
66 return;
68 m_state = state;
69 Q_EMIT stateChanged(state);
72bool MirSurface::live() const
74 return m_live;
77Mir::Visibility MirSurface::visibility() const
79 return m_visibility;
82void MirSurface::setLive(bool live)
84 qDebug().nospace() << "MirSurface::setLive("<<live<<") " << name();
85 if (live == m_live)
86 return;
88 m_live = live;
89 Q_EMIT liveChanged(live);
91 if (!m_live && m_viewCount == 0) {
92 deleteLater();
93 }
96QString MirSurface::qmlFilePath() const
98 return m_qmlFilePath;
101QUrl MirSurface::screenshotUrl() const
103 return m_screenshotUrl;
106void MirSurface::setScreenshotUrl(QUrl screenshotUrl)
108 if (screenshotUrl == m_screenshotUrl)
109 return;
111 m_screenshotUrl = screenshotUrl;
112 Q_EMIT screenshotUrlChanged(screenshotUrl);
115Mir::OrientationAngle MirSurface::orientationAngle() const
117 return m_orientationAngle;
120void MirSurface::setOrientationAngle(Mir::OrientationAngle angle)
122 if (angle == m_orientationAngle)
123 return;
125 m_orientationAngle = angle;
126 Q_EMIT orientationAngleChanged(angle);
129void MirSurface::incrementViewCount()
131 ++m_viewCount;
132 qDebug().nospace() << "MirSurface::incrementViewCount() viewCount(after)=" << m_viewCount << " " << name();
135void MirSurface::decrementViewCount()
137 --m_viewCount;
138 qDebug().nospace() << "MirSurface::decrementViewCount() viewCount(after)=" << m_viewCount << " " << name();
140 Q_ASSERT(m_viewCount >= 0);
142 if (!m_live && m_viewCount == 0) {
143 deleteLater();
144 }
147int MirSurface::viewCount() const
149 return m_viewCount;
152bool MirSurface::activeFocus() const
154 return m_activeFocus;
157void MirSurface::setActiveFocus(bool value)
159 if (m_activeFocus == value)
160 return;
162 m_activeFocus = value;
164 Q_EMIT activeFocusChanged(value);
167void MirSurface::setVisibility(Mir::Visibility visibility)
169 qDebug() << "MirSurface::setVisibility(visibility=" << visibility << ")";
171 if (m_visibility == visibility)
172 return;
174 m_visibility = visibility;
176 Q_EMIT visibilityChanged(m_visibility);
179int MirSurface::width() const
181 return m_width;
184int MirSurface::height() const
186 return m_height;
189void MirSurface::resize(int width, int height)
191 if (width != m_width) {
192 m_width = width;
193 Q_EMIT widthChanged();
194 }
196 if (m_height != height) {
197 m_height = height;
198 Q_EMIT heightChanged();
199 }