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)
41 , m_shellChrome(Mir::NormalChrome)
43// qDebug() << "MirSurface::MirSurface() " << name;
44 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
46 m_delayedResizeTimer.setInterval(600);
47 m_delayedResizeTimer.setSingleShot(true);
48 connect(&m_delayedResizeTimer, &QTimer::timeout, this, &MirSurface::applyDelayedResize);
51MirSurface::~MirSurface()
53// qDebug() << "MirSurface::~MirSurface() " << name();
56QString MirSurface::name() const
61Mir::Type MirSurface::type() const
66Mir::State MirSurface::state() const
71void MirSurface::setState(Mir::State state)
77 Q_EMIT stateChanged(state);
80bool MirSurface::live() const
85bool MirSurface::visible() const
90void MirSurface::setLive(bool live)
92// qDebug().nospace() << "MirSurface::setLive("<<live<<") " << name();
97 Q_EMIT liveChanged(live);
99 if (!m_live && m_views.count() == 0) {
104QUrl MirSurface::qmlFilePath() const
106 return m_qmlFilePath;
109QUrl MirSurface::screenshotUrl() const
111 return m_screenshotUrl;
114void MirSurface::setScreenshotUrl(QUrl screenshotUrl)
116 if (screenshotUrl == m_screenshotUrl)
119 m_screenshotUrl = screenshotUrl;
120 Q_EMIT screenshotUrlChanged(screenshotUrl);
123Mir::OrientationAngle MirSurface::orientationAngle() const
125 return m_orientationAngle;
128void MirSurface::setOrientationAngle(Mir::OrientationAngle angle)
130 if (angle == m_orientationAngle)
133 m_orientationAngle = angle;
134 Q_EMIT orientationAngleChanged(angle);
138Mir::ShellChrome MirSurface::shellChrome() const
140 return m_shellChrome;
143void MirSurface::setShellChrome(Mir::ShellChrome shellChrome)
145 if (shellChrome == m_shellChrome)
148 m_shellChrome = shellChrome;
149 Q_EMIT shellChromeChanged(shellChrome);
154void MirSurface::registerView(qintptr viewId)
156 m_views.insert(viewId, MirSurface::View{false});
157// qDebug().nospace() << "MirSurface[" << name() << "]::registerView(" << viewId << ")"
158// << " after=" << m_views.count();
161void MirSurface::unregisterView(qintptr viewId)
163// qDebug().nospace() << "MirSurface[" << name() << "]::unregisterView(" << viewId << ")"
164// << " after=" << m_views.count() << " live=" << m_live;
165 m_views.remove(viewId);
166 if (!m_live && m_views.count() == 0) {
172void MirSurface::setViewVisibility(qintptr viewId, bool visible)
174 if (!m_views.contains(viewId)) return;
176 m_views[viewId].visible = visible;
180void MirSurface::updateVisibility()
182 bool newVisible = false;
183 QHashIterator<qintptr, View> i(m_views);
184 while (i.hasNext()) {
186 newVisible |= i.value().visible;
189 if (newVisible != visible()) {
190// qDebug().nospace() << "MirSurface[" << name() << "]::updateVisibility(" << newVisible << ")";
192 m_visible = newVisible;
193 Q_EMIT visibleChanged(m_visible);
197bool MirSurface::activeFocus() const
199 return m_activeFocus;
202void MirSurface::setActiveFocus(bool value)
204 if (m_activeFocus == value)
207 m_activeFocus = value;
209 Q_EMIT activeFocusChanged(value);
212int MirSurface::width() const
217int MirSurface::height() const
222void MirSurface::resize(int width, int height)
224 if (m_slowToResize) {
225 if (!m_delayedResizeTimer.isActive()) {
226 m_delayedResize.setWidth(width);
227 m_delayedResize.setHeight(height);
228 m_delayedResizeTimer.start();
230 m_pendingResize.setWidth(width);
231 m_pendingResize.setHeight(height);
234 doResize(width, height);
238void MirSurface::applyDelayedResize()
240 doResize(m_delayedResize.width(), m_delayedResize.height());
241 m_delayedResize.setWidth(-1);
242 m_delayedResize.setHeight(-1);
244 if (m_pendingResize.isValid()) {
245 QSize size = m_pendingResize;
246 m_pendingResize.setWidth(-1);
247 m_pendingResize.setHeight(-1);
248 resize(size.width(), size.height());
252void MirSurface::doResize(int width, int height)
254 bool changed = false;
256 if (width != m_width) {
258 Q_EMIT widthChanged();
262 if (m_height != height) {
264 Q_EMIT heightChanged();
269 Q_EMIT sizeChanged(QSize(width, height));
273bool MirSurface::isSlowToResize() const
275 return m_slowToResize;
278void MirSurface::setSlowToResize(bool value)
280 if (m_slowToResize != value) {
281 m_slowToResize = value;
282 Q_EMIT slowToResizeChanged();
283 if (!m_slowToResize && m_delayedResizeTimer.isActive()) {
284 m_delayedResizeTimer.stop();
285 applyDelayedResize();
290void MirSurface::setMinimumWidth(int value)
292 if (value != m_minimumWidth) {
293 m_minimumWidth = value;
294 Q_EMIT minimumWidthChanged(m_minimumWidth);
298void MirSurface::setMaximumWidth(int value)
300 if (value != m_maximumWidth) {
301 m_maximumWidth = value;
302 Q_EMIT maximumWidthChanged(m_maximumWidth);
306void MirSurface::setMinimumHeight(int value)
308 if (value != m_minimumHeight) {
309 m_minimumHeight = value;
310 Q_EMIT minimumHeightChanged(m_minimumHeight);
314void MirSurface::setMaximumHeight(int value)
316 if (value != m_maximumHeight) {
317 m_maximumHeight = value;
318 Q_EMIT maximumHeightChanged(m_maximumHeight);
322void MirSurface::setWidthIncrement(int value)
324 if (value != m_widthIncrement) {
325 m_widthIncrement = value;
326 Q_EMIT widthIncrementChanged(m_widthIncrement);
330void MirSurface::setHeightIncrement(int value)
332 if (value != m_heightIncrement) {
333 m_heightIncrement = value;
334 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