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"
21MirSurface::MirSurface(const QString& name,
24 const QUrl& screenshot,
25 const QUrl &qmlFilePath)
26 : unity::shell::application::MirSurfaceInterface(nullptr)
30 , m_orientationAngle(Mir::Angle0)
31 , m_screenshotUrl(screenshot)
32 , m_qmlFilePath(qmlFilePath)
35 , m_activeFocus(false)
38 , m_slowToResize(false)
40// qDebug() << "MirSurface::MirSurface() " << name;
41 m_delayedResizeTimer.setInterval(600);
42 m_delayedResizeTimer.setSingleShot(true);
43 connect(&m_delayedResizeTimer, &QTimer::timeout, this, &MirSurface::applyDelayedResize);
46MirSurface::~MirSurface()
48// qDebug() << "MirSurface::~MirSurface() " << name();
51QString MirSurface::name() const
56Mir::Type MirSurface::type() const
61Mir::State MirSurface::state() const
66void MirSurface::setState(Mir::State state)
72 Q_EMIT stateChanged(state);
75bool MirSurface::live() const
80bool MirSurface::visible() const
85void MirSurface::setLive(bool live)
87// qDebug().nospace() << "MirSurface::setLive("<<live<<") " << name();
92 Q_EMIT liveChanged(live);
94 if (!m_live && m_views.count() == 0) {
99QUrl MirSurface::qmlFilePath() const
101 return m_qmlFilePath;
104QUrl MirSurface::screenshotUrl() const
106 return m_screenshotUrl;
109void MirSurface::setScreenshotUrl(QUrl screenshotUrl)
111 if (screenshotUrl == m_screenshotUrl)
114 m_screenshotUrl = screenshotUrl;
115 Q_EMIT screenshotUrlChanged(screenshotUrl);
118Mir::OrientationAngle MirSurface::orientationAngle() const
120 return m_orientationAngle;
123void MirSurface::setOrientationAngle(Mir::OrientationAngle angle)
125 if (angle == m_orientationAngle)
128 m_orientationAngle = angle;
129 Q_EMIT orientationAngleChanged(angle);
134void MirSurface::registerView(qintptr viewId)
136 m_views.insert(viewId, MirSurface::View{false});
137// qDebug().nospace() << "MirSurface[" << name() << "]::registerView(" << viewId << ")"
138// << " after=" << m_views.count();
141void MirSurface::unregisterView(qintptr viewId)
143// qDebug().nospace() << "MirSurface[" << name() << "]::unregisterView(" << viewId << ")"
144// << " after=" << m_views.count() << " live=" << m_live;
145 m_views.remove(viewId);
146 if (!m_live && m_views.count() == 0) {
152void MirSurface::setViewVisibility(qintptr viewId, bool visible)
154 if (!m_views.contains(viewId)) return;
156 m_views[viewId].visible = visible;
160void MirSurface::updateVisibility()
162 bool newVisible = false;
163 QHashIterator<qintptr, View> i(m_views);
164 while (i.hasNext()) {
166 newVisible |= i.value().visible;
169 if (newVisible != visible()) {
170// qDebug().nospace() << "MirSurface[" << name() << "]::updateVisibility(" << newVisible << ")";
172 m_visible = newVisible;
173 Q_EMIT visibleChanged(m_visible);
177bool MirSurface::activeFocus() const
179 return m_activeFocus;
182void MirSurface::setActiveFocus(bool value)
184 if (m_activeFocus == value)
187 m_activeFocus = value;
189 Q_EMIT activeFocusChanged(value);
192int MirSurface::width() const
197int MirSurface::height() const
202void MirSurface::resize(int width, int height)
204 if (m_slowToResize) {
205 if (!m_delayedResizeTimer.isActive()) {
206 m_delayedResize.setWidth(width);
207 m_delayedResize.setHeight(height);
208 m_delayedResizeTimer.start();
210 m_pendingResize.setWidth(width);
211 m_pendingResize.setHeight(height);
214 doResize(width, height);
218void MirSurface::applyDelayedResize()
220 doResize(m_delayedResize.width(), m_delayedResize.height());
221 m_delayedResize.setWidth(-1);
222 m_delayedResize.setHeight(-1);
224 if (m_pendingResize.isValid()) {
225 QSize size = m_pendingResize;
226 m_pendingResize.setWidth(-1);
227 m_pendingResize.setHeight(-1);
228 resize(size.width(), size.height());
232void MirSurface::doResize(int width, int height)
234 bool changed = false;
236 if (width != m_width) {
238 Q_EMIT widthChanged();
242 if (m_height != height) {
244 Q_EMIT heightChanged();
249 Q_EMIT sizeChanged(QSize(width, height));
253bool MirSurface::isSlowToResize() const
255 return m_slowToResize;
258void MirSurface::setSlowToResize(bool value)
260 if (m_slowToResize != value) {
261 m_slowToResize = value;
262 Q_EMIT slowToResizeChanged();
263 if (!m_slowToResize && m_delayedResizeTimer.isActive()) {
264 m_delayedResizeTimer.stop();
265 applyDelayedResize();
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