2 * Copyright (C) 2015-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 "MirSurface.h"
23#include "SurfaceManager.h"
25#define MIRSURFACE_DEBUG 0
28#define DEBUG_MSG(params) qDebug().nospace() << "MirSurface[" << (void*)this << "," << m_name << "]::" << __func__ << " " << params
29#define XDEBUG_MSG(params) qDebug().nospace() << "MirSurface[" << (void*)this << "," << m_name << "]::" << params
31const char *stateToStr(Mir::State state)
34 case Mir::UnknownState:
36 case Mir::RestoredState:
38 case Mir::MinimizedState:
40 case Mir::MaximizedState:
42 case Mir::VertMaximizedState:
43 return "vertMaximized";
44 case Mir::FullscreenState:
46 case Mir::HorizMaximizedState:
47 return "horizMaximized";
48 case Mir::MaximizedLeftState:
49 return "maximizedLeft";
50 case Mir::MaximizedRightState:
51 return "maximizedRight";
52 case Mir::MaximizedTopLeftState:
53 return "maximizedTopLeft";
54 case Mir::MaximizedTopRightState:
55 return "maximizedTopRight";
56 case Mir::MaximizedBottomLeftState:
57 return "maximizedBottomLeft";
58 case Mir::MaximizedBottomRightState:
59 return "maximizedBottomRight";
60 case Mir::HiddenState:
68#define DEBUG_MSG(params) ((void)0)
69#define XDEBUG_MSG(params) ((void)0)
72using namespace unity::shell::application;
74MirSurface::MirSurface(const QString& name,
77 const QUrl& screenshot,
78 const QUrl &qmlFilePath)
79 : unity::shell::application::MirSurfaceInterface(nullptr)
83 , m_orientationAngle(Mir::Angle0)
84 , m_screenshotUrl(screenshot)
85 , m_qmlFilePath(qmlFilePath)
88 , m_activeFocus(false)
91 , m_slowToResize(false)
92 , m_shellChrome(Mir::NormalChrome)
94 DEBUG_MSG("state=" << stateToStr(state));
96 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
98 m_delayedResizeTimer.setInterval(600);
99 m_delayedResizeTimer.setSingleShot(true);
100 connect(&m_delayedResizeTimer, &QTimer::timeout, this, &MirSurface::applyDelayedResize);
102 m_zombieTimer.setInterval(100);
103 m_zombieTimer.setSingleShot(true);
104 connect(&m_zombieTimer, &QTimer::timeout, this, [this](){ this->setLive(false); });
106 updateInputBoundsAfterResize();
109MirSurface::~MirSurface()
113 // Early warning, while MirSurface methods can still be accessed.
114 Q_EMIT destroyed(this);
117QString MirSurface::name() const
122QString MirSurface::persistentId() const
127Mir::Type MirSurface::type() const
132Mir::State MirSurface::state() const
137void MirSurface::requestState(Mir::State state)
139 if (state == m_state) {
142 DEBUG_MSG(stateToStr(state));
143 Q_EMIT stateRequested(state);
146void MirSurface::setState(Mir::State state)
148 if (state == m_state) {
151 DEBUG_MSG(stateToStr(state));
153 bool oldVisible = visible();
156 Q_EMIT stateChanged(state);
158 if (visible() != oldVisible) {
159 XDEBUG_MSG("visibleChanged("<<visible()<<")");
160 Q_EMIT visibleChanged(visible());
164bool MirSurface::live() const
169bool MirSurface::visible() const
171 return m_state != Mir::MinimizedState && m_state != Mir::HiddenState;
174void MirSurface::setLive(bool live)
181 Q_EMIT liveChanged(live);
183 if (!m_live && m_views.count() == 0) {
188QUrl MirSurface::qmlFilePath() const
190 return m_qmlFilePath;
193QUrl MirSurface::screenshotUrl() const
195 return m_screenshotUrl;
198void MirSurface::setScreenshotUrl(QUrl screenshotUrl)
200 if (screenshotUrl == m_screenshotUrl)
203 m_screenshotUrl = screenshotUrl;
204 Q_EMIT screenshotUrlChanged(screenshotUrl);
207Mir::OrientationAngle MirSurface::orientationAngle() const
209 return m_orientationAngle;
212void MirSurface::setOrientationAngle(Mir::OrientationAngle angle)
214 if (angle == m_orientationAngle)
217 m_orientationAngle = angle;
218 Q_EMIT orientationAngleChanged(angle);
221void MirSurface::setKeymap(const QString &value)
223 if (value != m_keymap) {
226 Q_EMIT keymapChanged(m_keymap);
230QString MirSurface::keymap() const
235Mir::ShellChrome MirSurface::shellChrome() const
237 return m_shellChrome;
240void MirSurface::setShellChrome(Mir::ShellChrome shellChrome)
242 if (shellChrome == m_shellChrome)
245 DEBUG_MSG(shellChrome);
246 m_shellChrome = shellChrome;
247 Q_EMIT shellChromeChanged(shellChrome);
250void MirSurface::registerView(qintptr viewId)
252 m_views.insert(viewId, MirSurface::View{false});
253 DEBUG_MSG(viewId << " after=" << m_views.count());
256void MirSurface::unregisterView(qintptr viewId)
258 m_views.remove(viewId);
259 DEBUG_MSG(viewId << " after=" << m_views.count() << " live=" << m_live);
260 if (!m_live && m_views.count() == 0) {
266void MirSurface::setViewExposure(qintptr viewId, bool visible)
268 if (!m_views.contains(viewId)) return;
270 m_views[viewId].visible = visible;
274void MirSurface::updateExposure()
276 bool newExposure = false;
277 QHashIterator<qintptr, View> i(m_views);
278 while (i.hasNext()) {
280 newExposure |= i.value().visible;
283 if (newExposure != m_exposed) {
284 m_exposed = newExposure;
285 DEBUG_MSG(m_exposed);
286 Q_EMIT exposedChanged(m_exposed);
287 updateInputBoundsAfterResize();
291bool MirSurface::activeFocus() const
293 return m_activeFocus;
296void MirSurface::setActiveFocus(bool value)
298 if (m_activeFocus == value)
301 m_activeFocus = value;
303 Q_EMIT activeFocusChanged(value);
305 if (m_activeFocus && !m_focused) {
310int MirSurface::width() const
315int MirSurface::height() const
320void MirSurface::resize(int width, int height)
322 if (m_slowToResize) {
323 if (!m_delayedResizeTimer.isActive()) {
324 m_delayedResize.setWidth(width);
325 m_delayedResize.setHeight(height);
326 m_delayedResizeTimer.start();
328 m_pendingResize.setWidth(width);
329 m_pendingResize.setHeight(height);
332 doResize(width, height);
336void MirSurface::applyDelayedResize()
338 doResize(m_delayedResize.width(), m_delayedResize.height());
339 m_delayedResize.setWidth(-1);
340 m_delayedResize.setHeight(-1);
342 if (m_pendingResize.isValid()) {
343 QSize size = m_pendingResize;
344 m_pendingResize.setWidth(-1);
345 m_pendingResize.setHeight(-1);
346 resize(size.width(), size.height());
350void MirSurface::doResize(int width, int height)
352 bool changed = false;
354 if (width != m_width) {
356 Q_EMIT widthChanged();
360 if (m_height != height) {
362 Q_EMIT heightChanged();
367 XDEBUG_MSG("sizeChanged(width="<<width<<", height="<<height<<")");
368 Q_EMIT sizeChanged(QSize(width, height));
371 updateInputBoundsAfterResize();
374void MirSurface::updateInputBoundsAfterResize()
376 setInputBounds(QRect(0, 0, m_width, m_height));
379bool MirSurface::isSlowToResize() const
381 return m_slowToResize;
384void MirSurface::setSlowToResize(bool value)
386 if (m_slowToResize != value) {
388 m_slowToResize = value;
389 Q_EMIT slowToResizeChanged();
390 if (!m_slowToResize && m_delayedResizeTimer.isActive()) {
391 m_delayedResizeTimer.stop();
392 applyDelayedResize();
397void MirSurface::setMinimumWidth(int value)
399 if (value != m_minimumWidth) {
400 m_minimumWidth = value;
401 Q_EMIT minimumWidthChanged(m_minimumWidth);
405void MirSurface::setMaximumWidth(int value)
407 if (value != m_maximumWidth) {
408 m_maximumWidth = value;
409 Q_EMIT maximumWidthChanged(m_maximumWidth);
413void MirSurface::setMinimumHeight(int value)
415 if (value != m_minimumHeight) {
416 m_minimumHeight = value;
417 Q_EMIT minimumHeightChanged(m_minimumHeight);
421void MirSurface::setMaximumHeight(int value)
423 if (value != m_maximumHeight) {
424 m_maximumHeight = value;
425 Q_EMIT maximumHeightChanged(m_maximumHeight);
429void MirSurface::setWidthIncrement(int value)
431 if (value != m_widthIncrement) {
432 m_widthIncrement = value;
433 Q_EMIT widthIncrementChanged(m_widthIncrement);
437void MirSurface::setHeightIncrement(int value)
439 if (value != m_heightIncrement) {
440 m_heightIncrement = value;
441 Q_EMIT heightIncrementChanged(m_heightIncrement);
445void MirSurface::close()
448 if (!m_zombieTimer.isActive()) {
449 m_zombieTimer.start();
450 Q_EMIT closeRequested();
454void MirSurface::activate()
457 SurfaceManager::instance()->activate(this);
460void MirSurface::requestFocus()
463 Q_EMIT focusRequested();
466void MirSurface::setFocused(bool value)
468 if (m_focused == value)
471 DEBUG_MSG("(" << value << ")");
474 Q_EMIT focusedChanged(value);
477bool MirSurface::focused() const
482QRect MirSurface::inputBounds() const
484 return m_inputBounds;
487void MirSurface::setInputBounds(const QRect &boundsRect)
489 if (boundsRect != m_inputBounds) {
490 m_inputBounds = boundsRect;
491 DEBUG_MSG("(" << m_inputBounds << ")");
492 Q_EMIT inputBoundsChanged(m_inputBounds);
496void MirSurface::setRequestedPosition(const QPoint &value)
498 if (value != m_requestedPosition) {
499 m_requestedPosition = value;
500 Q_EMIT requestedPositionChanged(value);
502 // fake-miral: always comply
503 m_position = m_requestedPosition;
504 XDEBUG_MSG("positionChanged("<<m_position<<")");
505 Q_EMIT positionChanged(m_position);
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