2 * Copyright (C) 2015 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 "MirSurface.h"
22MirSurface::MirSurface(const QString& name,
25 const QUrl& screenshot,
26 const QUrl &qmlFilePath,
28 : unity::shell::application::MirSurfaceInterface(parent)
32 , m_orientationAngle(Mir::Angle0)
33 , m_screenshotUrl(screenshot)
34 , m_qmlFilePath(qmlFilePath)
37 , m_activeFocus(false)
40 , m_slowToResize(false)
42// qDebug() << "MirSurface::MirSurface() " << name;
43 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
45 m_delayedResizeTimer.setInterval(600);
46 m_delayedResizeTimer.setSingleShot(true);
47 connect(&m_delayedResizeTimer, &QTimer::timeout, this, &MirSurface::applyDelayedResize);
50MirSurface::~MirSurface()
52// qDebug() << "MirSurface::~MirSurface() " << name();
55QString MirSurface::name() const
60Mir::Type MirSurface::type() const
65Mir::State MirSurface::state() const
70void MirSurface::setState(Mir::State state)
76 Q_EMIT stateChanged(state);
79bool MirSurface::live() const
84bool MirSurface::visible() const
89void MirSurface::setLive(bool live)
91// qDebug().nospace() << "MirSurface::setLive("<<live<<") " << name();
96 Q_EMIT liveChanged(live);
98 if (!m_live && m_views.count() == 0) {
103QUrl MirSurface::qmlFilePath() const
105 return m_qmlFilePath;
108QUrl MirSurface::screenshotUrl() const
110 return m_screenshotUrl;
113void MirSurface::setScreenshotUrl(QUrl screenshotUrl)
115 if (screenshotUrl == m_screenshotUrl)
118 m_screenshotUrl = screenshotUrl;
119 Q_EMIT screenshotUrlChanged(screenshotUrl);
122Mir::OrientationAngle MirSurface::orientationAngle() const
124 return m_orientationAngle;
127void MirSurface::setOrientationAngle(Mir::OrientationAngle angle)
129 if (angle == m_orientationAngle)
132 m_orientationAngle = angle;
133 Q_EMIT orientationAngleChanged(angle);
138void MirSurface::registerView(qintptr viewId)
140 m_views.insert(viewId, MirSurface::View{false});
141// qDebug().nospace() << "MirSurface[" << name() << "]::registerView(" << viewId << ")"
142// << " after=" << m_views.count();
145void MirSurface::unregisterView(qintptr viewId)
147// qDebug().nospace() << "MirSurface[" << name() << "]::unregisterView(" << viewId << ")"
148// << " after=" << m_views.count() << " live=" << m_live;
149 m_views.remove(viewId);
150 if (!m_live && m_views.count() == 0) {
156void MirSurface::setViewVisibility(qintptr viewId, bool visible)
158 if (!m_views.contains(viewId)) return;
160 m_views[viewId].visible = visible;
164void MirSurface::updateVisibility()
166 bool newVisible = false;
167 QHashIterator<qintptr, View> i(m_views);
168 while (i.hasNext()) {
170 newVisible |= i.value().visible;
173 if (newVisible != visible()) {
174// qDebug().nospace() << "MirSurface[" << name() << "]::updateVisibility(" << newVisible << ")";
176 m_visible = newVisible;
177 Q_EMIT visibleChanged(m_visible);
181bool MirSurface::activeFocus() const
183 return m_activeFocus;
186void MirSurface::setActiveFocus(bool value)
188 if (m_activeFocus == value)
191 m_activeFocus = value;
193 Q_EMIT activeFocusChanged(value);
196int MirSurface::width() const
201int MirSurface::height() const
206void MirSurface::resize(int width, int height)
208 if (m_slowToResize) {
209 if (!m_delayedResizeTimer.isActive()) {
210 m_delayedResize.setWidth(width);
211 m_delayedResize.setHeight(height);
212 m_delayedResizeTimer.start();
214 m_pendingResize.setWidth(width);
215 m_pendingResize.setHeight(height);
218 doResize(width, height);
222void MirSurface::applyDelayedResize()
224 doResize(m_delayedResize.width(), m_delayedResize.height());
225 m_delayedResize.setWidth(-1);
226 m_delayedResize.setHeight(-1);
228 if (m_pendingResize.isValid()) {
229 QSize size = m_pendingResize;
230 m_pendingResize.setWidth(-1);
231 m_pendingResize.setHeight(-1);
232 resize(size.width(), size.height());
236void MirSurface::doResize(int width, int height)
238 bool changed = false;
240 if (width != m_width) {
242 Q_EMIT widthChanged();
246 if (m_height != height) {
248 Q_EMIT heightChanged();
253 Q_EMIT sizeChanged(QSize(width, height));
257bool MirSurface::isSlowToResize() const
259 return m_slowToResize;
262void MirSurface::setSlowToResize(bool value)
264 if (m_slowToResize != value) {
265 m_slowToResize = value;
266 Q_EMIT slowToResizeChanged();
267 if (!m_slowToResize && m_delayedResizeTimer.isActive()) {
268 m_delayedResizeTimer.stop();
269 applyDelayedResize();
274void MirSurface::setMinimumWidth(int value)
276 if (value != m_minimumWidth) {
277 m_minimumWidth = value;
278 Q_EMIT minimumWidthChanged(m_minimumWidth);
282void MirSurface::setMaximumWidth(int value)
284 if (value != m_maximumWidth) {
285 m_maximumWidth = value;
286 Q_EMIT maximumWidthChanged(m_maximumWidth);
290void MirSurface::setMinimumHeight(int value)
292 if (value != m_minimumHeight) {
293 m_minimumHeight = value;
294 Q_EMIT minimumHeightChanged(m_minimumHeight);
298void MirSurface::setMaximumHeight(int value)
300 if (value != m_maximumHeight) {
301 m_maximumHeight = value;
302 Q_EMIT maximumHeightChanged(m_maximumHeight);
306void MirSurface::setWidthIncrement(int value)
308 if (value != m_widthIncrement) {
309 m_widthIncrement = value;
310 Q_EMIT widthIncrementChanged(m_widthIncrement);
314void MirSurface::setHeightIncrement(int value)
316 if (value != m_heightIncrement) {
317 m_heightIncrement = value;
318 Q_EMIT heightIncrementChanged(m_heightIncrement);
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