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
130Mir::Type MirSurface::type() const
135Mir::State MirSurface::state() const
140void MirSurface::requestState(Mir::State state)
142 if (state == m_state) {
145 DEBUG_MSG(stateToStr(state));
146 Q_EMIT stateRequested(state);
149void MirSurface::setState(Mir::State state)
151 if (state == m_state) {
154 DEBUG_MSG(stateToStr(state));
156 bool oldVisible = visible();
159 Q_EMIT stateChanged(state);
161 if (visible() != oldVisible) {
162 XDEBUG_MSG("visibleChanged("<<visible()<<")");
163 Q_EMIT visibleChanged(visible());
167bool MirSurface::live() const
172bool MirSurface::visible() const
174 return m_state != Mir::MinimizedState && m_state != Mir::HiddenState;
177void MirSurface::setLive(bool live)
184 Q_EMIT liveChanged(live);
186 if (!m_live && m_views.count() == 0) {
191QUrl MirSurface::qmlFilePath() const
193 return m_qmlFilePath;
196QUrl MirSurface::screenshotUrl() const
198 return m_screenshotUrl;
201void MirSurface::setScreenshotUrl(QUrl screenshotUrl)
203 if (screenshotUrl == m_screenshotUrl)
206 m_screenshotUrl = screenshotUrl;
207 Q_EMIT screenshotUrlChanged(screenshotUrl);
210Mir::OrientationAngle MirSurface::orientationAngle() const
212 return m_orientationAngle;
215void MirSurface::setOrientationAngle(Mir::OrientationAngle angle)
217 if (angle == m_orientationAngle)
220 m_orientationAngle = angle;
221 Q_EMIT orientationAngleChanged(angle);
224void MirSurface::setKeymap(const QString &value)
226 if (value != m_keymap) {
229 Q_EMIT keymapChanged(m_keymap);
233QString MirSurface::keymap() const
238Mir::ShellChrome MirSurface::shellChrome() const
240 return m_shellChrome;
243void MirSurface::setShellChrome(Mir::ShellChrome shellChrome)
245 if (shellChrome == m_shellChrome)
248 DEBUG_MSG(shellChrome);
249 m_shellChrome = shellChrome;
250 Q_EMIT shellChromeChanged(shellChrome);
253void MirSurface::registerView(qintptr viewId)
255 m_views.insert(viewId, MirSurface::View{false});
256 DEBUG_MSG(viewId << " after=" << m_views.count());
259void MirSurface::unregisterView(qintptr viewId)
261 m_views.remove(viewId);
262 DEBUG_MSG(viewId << " after=" << m_views.count() << " live=" << m_live);
263 if (!m_live && m_views.count() == 0) {
269void MirSurface::setViewExposure(qintptr viewId, bool visible)
271 if (!m_views.contains(viewId)) return;
273 m_views[viewId].visible = visible;
277void MirSurface::updateExposure()
279 bool newExposure = false;
280 QHashIterator<qintptr, View> i(m_views);
281 while (i.hasNext()) {
283 newExposure |= i.value().visible;
286 if (newExposure != m_exposed) {
287 m_exposed = newExposure;
288 DEBUG_MSG(m_exposed);
289 Q_EMIT exposedChanged(m_exposed);
290 updateInputBoundsAfterResize();
294bool MirSurface::activeFocus() const
296 return m_activeFocus;
299void MirSurface::setActiveFocus(bool value)
301 if (m_activeFocus == value)
304 m_activeFocus = value;
306 Q_EMIT activeFocusChanged(value);
308 if (m_activeFocus && !m_focused) {
313int MirSurface::width() const
318int MirSurface::height() const
323void MirSurface::resize(int width, int height)
325 if (m_slowToResize) {
326 if (!m_delayedResizeTimer.isActive()) {
327 m_delayedResize.setWidth(width);
328 m_delayedResize.setHeight(height);
329 m_delayedResizeTimer.start();
331 m_pendingResize.setWidth(width);
332 m_pendingResize.setHeight(height);
335 doResize(width, height);
339void MirSurface::applyDelayedResize()
341 doResize(m_delayedResize.width(), m_delayedResize.height());
342 m_delayedResize.setWidth(-1);
343 m_delayedResize.setHeight(-1);
345 if (m_pendingResize.isValid()) {
346 QSize size = m_pendingResize;
347 m_pendingResize.setWidth(-1);
348 m_pendingResize.setHeight(-1);
349 resize(size.width(), size.height());
353void MirSurface::doResize(int width, int height)
355 bool changed = false;
357 if (width != m_width) {
359 Q_EMIT widthChanged();
363 if (m_height != height) {
365 Q_EMIT heightChanged();
370 XDEBUG_MSG("sizeChanged(width="<<width<<", height="<<height<<")");
371 Q_EMIT sizeChanged(QSize(width, height));
374 updateInputBoundsAfterResize();
377void MirSurface::updateInputBoundsAfterResize()
379 setInputBounds(QRect(0, 0, m_width, m_height));
382bool MirSurface::isSlowToResize() const
384 return m_slowToResize;
387void MirSurface::setSlowToResize(bool value)
389 if (m_slowToResize != value) {
391 m_slowToResize = value;
392 Q_EMIT slowToResizeChanged();
393 if (!m_slowToResize && m_delayedResizeTimer.isActive()) {
394 m_delayedResizeTimer.stop();
395 applyDelayedResize();
400void MirSurface::setMinimumWidth(int value)
402 if (value != m_minimumWidth) {
403 m_minimumWidth = value;
404 Q_EMIT minimumWidthChanged(m_minimumWidth);
408void MirSurface::setMaximumWidth(int value)
410 if (value != m_maximumWidth) {
411 m_maximumWidth = value;
412 Q_EMIT maximumWidthChanged(m_maximumWidth);
416void MirSurface::setMinimumHeight(int value)
418 if (value != m_minimumHeight) {
419 m_minimumHeight = value;
420 Q_EMIT minimumHeightChanged(m_minimumHeight);
424void MirSurface::setMaximumHeight(int value)
426 if (value != m_maximumHeight) {
427 m_maximumHeight = value;
428 Q_EMIT maximumHeightChanged(m_maximumHeight);
432void MirSurface::setWidthIncrement(int value)
434 if (value != m_widthIncrement) {
435 m_widthIncrement = value;
436 Q_EMIT widthIncrementChanged(m_widthIncrement);
440void MirSurface::setHeightIncrement(int value)
442 if (value != m_heightIncrement) {
443 m_heightIncrement = value;
444 Q_EMIT heightIncrementChanged(m_heightIncrement);
448void MirSurface::close()
451 if (!m_zombieTimer.isActive()) {
452 m_zombieTimer.start();
453 Q_EMIT closeRequested();
457void MirSurface::activate()
460 SurfaceManager::instance()->activate(this);
463void MirSurface::requestFocus()
466 Q_EMIT focusRequested();
469void MirSurface::setFocused(bool value)
471 if (m_focused == value)
474 DEBUG_MSG("(" << value << ")");
477 Q_EMIT focusedChanged(value);
480bool MirSurface::focused() const
485QRect MirSurface::inputBounds() const
487 return m_inputBounds;
490void MirSurface::setInputBounds(const QRect &boundsRect)
492 if (boundsRect != m_inputBounds) {
493 m_inputBounds = boundsRect;
494 DEBUG_MSG("(" << m_inputBounds << ")");
495 Q_EMIT inputBoundsChanged(m_inputBounds);
499void MirSurface::openMenu(qreal x, qreal y, qreal width, qreal height)
501 auto *menu = SurfaceManager::instance()->createSurface("menu", Mir::MenuType, Mir::HiddenState,
502 this /* parentSurface */,
503 QUrl() /* screenshot */,
504 QUrl("qrc:///Unity/Application/KateMenu.qml"));
506 menu->setRequestedPosition(QPoint(x,y));
507 menu->resize(width, height);
508 menu->requestState(Mir::RestoredState);
510 SurfaceManager::instance()->notifySurfaceCreated(menu);
513void MirSurface::openDialog(qreal x, qreal y, qreal width, qreal height)
515 auto *dialog = SurfaceManager::instance()->createSurface("dialog", Mir::DialogType, Mir::HiddenState,
516 this /* parentSurface */,
517 QUrl() /* screenshot */,
518 QUrl("qrc:///Unity/Application/KateDialog.qml"));
520 dialog->setRequestedPosition(QPoint(x,y));
521 dialog->resize(width, height);
522 dialog->requestState(Mir::RestoredState);
524 SurfaceManager::instance()->notifySurfaceCreated(dialog);
526 dialog->requestFocus();
529void MirSurface::setRequestedPosition(const QPoint &value)
531 if (value != m_requestedPosition) {
532 m_requestedPosition = value;
533 Q_EMIT requestedPositionChanged(value);
535 // fake-miral: always comply
536 m_position = m_requestedPosition;
537 XDEBUG_MSG("positionChanged("<<m_position<<")");
538 Q_EMIT positionChanged(m_position);
542MirSurfaceInterface* MirSurface::parentSurface() const
544 return m_parentSurface;
547MirSurfaceListInterface* MirSurface::childSurfaceList() const
549 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