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 MirSurface *parentSurface,
78 const QUrl& screenshot,
79 const QUrl &qmlFilePath)
80 : unity::shell::application::MirSurfaceInterface(nullptr)
84 , m_orientationAngle(Mir::Angle0)
85 , m_screenshotUrl(screenshot)
86 , m_qmlFilePath(qmlFilePath)
89 , m_activeFocus(false)
92 , m_slowToResize(false)
93 , m_shellChrome(Mir::NormalChrome)
94 , m_parentSurface(parentSurface)
95 , m_childSurfaceList(new MirSurfaceListModel(this))
97 DEBUG_MSG("state=" << stateToStr(state));
99 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
101 m_delayedResizeTimer.setInterval(600);
102 m_delayedResizeTimer.setSingleShot(true);
103 connect(&m_delayedResizeTimer, &QTimer::timeout, this, &MirSurface::applyDelayedResize);
105 m_zombieTimer.setInterval(100);
106 m_zombieTimer.setSingleShot(true);
107 connect(&m_zombieTimer, &QTimer::timeout, this, [this](){ this->setLive(false); });
109 updateInputBoundsAfterResize();
112MirSurface::~MirSurface()
116 // Early warning, while MirSurface methods can still be accessed.
117 Q_EMIT destroyed(this);
120QString MirSurface::name() const
125QString MirSurface::persistentId() const
130QString MirSurface::appId() const
132 return m_name+"appId";
134Mir::Type MirSurface::type() const
139Mir::State MirSurface::state() const
144void MirSurface::requestState(Mir::State state)
146 if (state == m_state) {
149 DEBUG_MSG(stateToStr(state));
150 Q_EMIT stateRequested(state);
153void MirSurface::setState(Mir::State state)
155 if (state == m_state) {
158 DEBUG_MSG(stateToStr(state));
160 bool oldVisible = visible();
163 Q_EMIT stateChanged(state);
165 if (visible() != oldVisible) {
166 XDEBUG_MSG("visibleChanged("<<visible()<<")");
167 Q_EMIT visibleChanged(visible());
171bool MirSurface::live() const
176bool MirSurface::visible() const
178 return m_state != Mir::MinimizedState && m_state != Mir::HiddenState;
181void MirSurface::setLive(bool live)
188 Q_EMIT liveChanged(live);
190 if (!m_live && m_views.count() == 0) {
195QUrl MirSurface::qmlFilePath() const
197 return m_qmlFilePath;
200QUrl MirSurface::screenshotUrl() const
202 return m_screenshotUrl;
205void MirSurface::setScreenshotUrl(QUrl screenshotUrl)
207 if (screenshotUrl == m_screenshotUrl)
210 m_screenshotUrl = screenshotUrl;
211 Q_EMIT screenshotUrlChanged(screenshotUrl);
214Mir::OrientationAngle MirSurface::orientationAngle() const
216 return m_orientationAngle;
219void MirSurface::setOrientationAngle(Mir::OrientationAngle angle)
221 if (angle == m_orientationAngle)
224 m_orientationAngle = angle;
225 Q_EMIT orientationAngleChanged(angle);
228void MirSurface::setKeymap(const QString &value)
230 if (value != m_keymap) {
233 Q_EMIT keymapChanged(m_keymap);
237QString MirSurface::keymap() const
242Mir::ShellChrome MirSurface::shellChrome() const
244 return m_shellChrome;
247void MirSurface::setShellChrome(Mir::ShellChrome shellChrome)
249 if (shellChrome == m_shellChrome)
252 DEBUG_MSG(shellChrome);
253 m_shellChrome = shellChrome;
254 Q_EMIT shellChromeChanged(shellChrome);
257void MirSurface::registerView(qintptr viewId)
259 m_views.insert(viewId, MirSurface::View{false});
260 DEBUG_MSG(viewId << " after=" << m_views.count());
263void MirSurface::unregisterView(qintptr viewId)
265 m_views.remove(viewId);
266 DEBUG_MSG(viewId << " after=" << m_views.count() << " live=" << m_live);
267 if (!m_live && m_views.count() == 0) {
273void MirSurface::setViewExposure(qintptr viewId, bool visible)
275 if (!m_views.contains(viewId)) return;
277 m_views[viewId].visible = visible;
281void MirSurface::updateExposure()
283 bool newExposure = false;
284 QHashIterator<qintptr, View> i(m_views);
285 while (i.hasNext()) {
287 newExposure |= i.value().visible;
290 if (newExposure != m_exposed) {
291 m_exposed = newExposure;
292 DEBUG_MSG(m_exposed);
293 Q_EMIT exposedChanged(m_exposed);
294 updateInputBoundsAfterResize();
298bool MirSurface::activeFocus() const
300 return m_activeFocus;
303void MirSurface::setActiveFocus(bool value)
305 if (m_activeFocus == value)
308 m_activeFocus = value;
310 Q_EMIT activeFocusChanged(value);
312 if (m_activeFocus && !m_focused) {
317int MirSurface::width() const
322int MirSurface::height() const
327void MirSurface::resize(int width, int height)
329 if (m_slowToResize) {
330 if (!m_delayedResizeTimer.isActive()) {
331 m_delayedResize.setWidth(width);
332 m_delayedResize.setHeight(height);
333 m_delayedResizeTimer.start();
335 m_pendingResize.setWidth(width);
336 m_pendingResize.setHeight(height);
339 doResize(width, height);
343void MirSurface::applyDelayedResize()
345 doResize(m_delayedResize.width(), m_delayedResize.height());
346 m_delayedResize.setWidth(-1);
347 m_delayedResize.setHeight(-1);
349 if (m_pendingResize.isValid()) {
350 QSize size = m_pendingResize;
351 m_pendingResize.setWidth(-1);
352 m_pendingResize.setHeight(-1);
353 resize(size.width(), size.height());
357void MirSurface::doResize(int width, int height)
359 bool changed = false;
361 if (width != m_width) {
363 Q_EMIT widthChanged();
367 if (m_height != height) {
369 Q_EMIT heightChanged();
374 XDEBUG_MSG("sizeChanged(width="<<width<<", height="<<height<<")");
375 Q_EMIT sizeChanged(QSize(width, height));
378 updateInputBoundsAfterResize();
381void MirSurface::updateInputBoundsAfterResize()
383 setInputBounds(QRect(0, 0, m_width, m_height));
386bool MirSurface::isSlowToResize() const
388 return m_slowToResize;
391void MirSurface::setSlowToResize(bool value)
393 if (m_slowToResize != value) {
395 m_slowToResize = value;
396 Q_EMIT slowToResizeChanged();
397 if (!m_slowToResize && m_delayedResizeTimer.isActive()) {
398 m_delayedResizeTimer.stop();
399 applyDelayedResize();
404void MirSurface::setMinimumWidth(int value)
406 if (value != m_minimumWidth) {
407 m_minimumWidth = value;
408 Q_EMIT minimumWidthChanged(m_minimumWidth);
412void MirSurface::setMaximumWidth(int value)
414 if (value != m_maximumWidth) {
415 m_maximumWidth = value;
416 Q_EMIT maximumWidthChanged(m_maximumWidth);
420void MirSurface::setMinimumHeight(int value)
422 if (value != m_minimumHeight) {
423 m_minimumHeight = value;
424 Q_EMIT minimumHeightChanged(m_minimumHeight);
428void MirSurface::setMaximumHeight(int value)
430 if (value != m_maximumHeight) {
431 m_maximumHeight = value;
432 Q_EMIT maximumHeightChanged(m_maximumHeight);
436void MirSurface::setWidthIncrement(int value)
438 if (value != m_widthIncrement) {
439 m_widthIncrement = value;
440 Q_EMIT widthIncrementChanged(m_widthIncrement);
444void MirSurface::setHeightIncrement(int value)
446 if (value != m_heightIncrement) {
447 m_heightIncrement = value;
448 Q_EMIT heightIncrementChanged(m_heightIncrement);
452void MirSurface::close()
456 for (int i = 0; i < m_childSurfaceList->count(); ++i) {
457 m_childSurfaceList->get(i)->close();
460 if (!m_zombieTimer.isActive()) {
461 m_zombieTimer.start();
462 Q_EMIT closeRequested();
466void MirSurface::activate()
469 SurfaceManager::instance()->activate(this);
472void MirSurface::requestFocus()
475 Q_EMIT focusRequested();
478void MirSurface::setFocused(bool value)
480 if (m_focused == value)
483 DEBUG_MSG("(" << value << ")");
486 Q_EMIT focusedChanged(value);
489bool MirSurface::focused() const
494QRect MirSurface::inputBounds() const
496 return m_inputBounds;
499void MirSurface::setInputBounds(const QRect &boundsRect)
501 if (boundsRect != m_inputBounds) {
502 m_inputBounds = boundsRect;
503 DEBUG_MSG("(" << m_inputBounds << ")");
504 Q_EMIT inputBoundsChanged(m_inputBounds);
508void MirSurface::openMenu(qreal x, qreal y, qreal width, qreal height)
510 auto *menu = SurfaceManager::instance()->createSurface("menu", Mir::MenuType, Mir::HiddenState,
511 this /* parentSurface */,
512 QUrl() /* screenshot */,
513 QUrl("qrc:///Unity/Application/KateMenu.qml"));
515 menu->setRequestedPosition(QPoint(x,y));
516 menu->resize(width, height);
517 menu->requestState(Mir::RestoredState);
519 SurfaceManager::instance()->notifySurfaceCreated(menu);
522void MirSurface::openDialog(qreal x, qreal y, qreal width, qreal height)
524 auto *dialog = SurfaceManager::instance()->createSurface("dialog", Mir::DialogType, Mir::HiddenState,
525 this /* parentSurface */,
526 QUrl() /* screenshot */,
527 QUrl("qrc:///Unity/Application/KateDialog.qml"));
529 dialog->setRequestedPosition(QPoint(x,y));
530 dialog->resize(width, height);
531 dialog->requestState(Mir::RestoredState);
533 SurfaceManager::instance()->notifySurfaceCreated(dialog);
535 dialog->requestFocus();
538void MirSurface::setRequestedPosition(const QPoint &value)
540 if (value != m_requestedPosition) {
541 m_requestedPosition = value;
542 Q_EMIT requestedPositionChanged(value);
544 // fake-miral: always comply
545 m_position = m_requestedPosition;
546 XDEBUG_MSG("positionChanged("<<m_position<<")");
547 Q_EMIT positionChanged(m_position);
551MirSurfaceInterface* MirSurface::parentSurface() const
553 return m_parentSurface;
556MirSurfaceListInterface* MirSurface::childSurfaceList() const
558 return m_childSurfaceList;
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