2 * Copyright (C) 2014-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 "SurfaceManager.h"
19#include "ApplicationInfo.h"
20#include "VirtualKeyboard.h"
24#define SURFACEMANAGER_DEBUG 0
26#if SURFACEMANAGER_DEBUG
27#define DEBUG_MSG(params) qDebug().nospace() << "SurfaceManager[" << (void*)this << "]::" << __func__ << params
29#define DEBUG_MSG(params) ((void)0)
32namespace unityapi = unity::shell::application;
34SurfaceManager *SurfaceManager::m_instance = nullptr;
36SurfaceManager *SurfaceManager::instance()
41SurfaceManager::SurfaceManager(QObject *)
45 Q_ASSERT(m_instance == nullptr);
49SurfaceManager::~SurfaceManager()
53 if (m_virtualKeyboard) {
54 m_virtualKeyboard->setLive(false);
57 Q_ASSERT(m_instance == this);
61MirSurface *SurfaceManager::createSurface(const QString& name,
64 const QUrl& screenshot)
66 MirSurface* surface = new MirSurface(name, type, state, screenshot);
67 registerSurface(surface);
71void SurfaceManager::registerSurface(MirSurface *surface)
73 m_surfaces.prepend(surface);
75 surface->setMinimumWidth(m_newSurfaceMinimumWidth);
76 surface->setMaximumWidth(m_newSurfaceMaximumWidth);
77 surface->setMinimumHeight(m_newSurfaceMinimumHeight);
78 surface->setMaximumHeight(m_newSurfaceMaximumHeight);
79 surface->setWidthIncrement(m_newSurfaceWidthIncrement);
80 surface->setHeightIncrement(m_newSurfaceHeightIncrement);
82 connect(surface, &MirSurface::stateRequested, this, [=](Mir::State state) {
83 this->onStateRequested(surface, state);
86 const QString persistentId = surface->persistentId();
87 connect(surface, &QObject::destroyed, this, [=]() {
88 this->onSurfaceDestroyed(surface, persistentId);
93void SurfaceManager::notifySurfaceCreated(unityapi::MirSurfaceInterface *surface)
95 Q_EMIT surfaceCreated(surface);
98void SurfaceManager::setNewSurfaceMinimumWidth(int value)
100 if (m_newSurfaceMinimumWidth != value) {
101 m_newSurfaceMinimumWidth = value;
102 Q_EMIT newSurfaceMinimumWidthChanged(m_newSurfaceMinimumWidth);
106void SurfaceManager::setNewSurfaceMaximumWidth(int value)
108 if (m_newSurfaceMaximumWidth != value) {
109 m_newSurfaceMaximumWidth = value;
110 Q_EMIT newSurfaceMaximumWidthChanged(m_newSurfaceMaximumWidth);
114void SurfaceManager::setNewSurfaceMinimumHeight(int value)
116 if (m_newSurfaceMinimumHeight != value) {
117 m_newSurfaceMinimumHeight = value;
118 Q_EMIT newSurfaceMinimumHeightChanged(m_newSurfaceMinimumHeight);
122void SurfaceManager::setNewSurfaceMaximumHeight(int value)
124 if (m_newSurfaceMaximumHeight != value) {
125 m_newSurfaceMaximumHeight = value;
126 Q_EMIT newSurfaceMaximumHeightChanged(m_newSurfaceMaximumHeight);
130void SurfaceManager::setNewSurfaceWidthIncrement(int value)
132 if (m_newSurfaceWidthIncrement != value) {
133 m_newSurfaceWidthIncrement = value;
134 Q_EMIT newSurfaceWidthIncrementChanged(m_newSurfaceWidthIncrement);
138void SurfaceManager::setNewSurfaceHeightIncrement(int value)
140 if (m_newSurfaceHeightIncrement != value) {
141 m_newSurfaceHeightIncrement = value;
142 Q_EMIT newSurfaceHeightIncrementChanged(m_newSurfaceHeightIncrement);
146void SurfaceManager::raise(unityapi::MirSurfaceInterface *surface)
148 if (m_underModification)
151 DEBUG_MSG("("<<surface<<") started");
152 Q_EMIT modificationsStarted();
153 m_underModification = true;
157 m_underModification = false;
158 Q_EMIT modificationsEnded();
159 DEBUG_MSG("("<<surface<<") ended");
162void SurfaceManager::doRaise(unityapi::MirSurfaceInterface *apiSurface)
164 auto surface = static_cast<MirSurface*>(apiSurface);
165 int index = m_surfaces.indexOf(surface);
166 Q_ASSERT(index != -1);
167 m_surfaces.move(index, 0);
169 Q_EMIT surfacesRaised({surface});
172void SurfaceManager::activate(unityapi::MirSurfaceInterface *apiSurface)
174 auto surface = static_cast<MirSurface*>(apiSurface);
176 if (surface == m_focusedSurface) {
180 Q_ASSERT(!m_underModification);
182 DEBUG_MSG("("<<surface<<") started");
183 Q_EMIT modificationsStarted();
184 m_underModification = true;
185 if (m_focusedSurface) {
186 m_focusedSurface->setFocused(false);
189 if (surface->state() == Mir::HiddenState || surface->state() == Mir::MinimizedState) {
190 if (surface->previousState() != Mir::UnknownState) {
191 surface->setState(surface->previousState());
193 surface->setState(Mir::RestoredState);
196 surface->setFocused(true);
199 m_focusedSurface = surface;
200 m_underModification = false;
201 Q_EMIT modificationsEnded();
202 DEBUG_MSG("("<<surface<<") ended");
205void SurfaceManager::onStateRequested(MirSurface *surface, Mir::State state)
207 Q_ASSERT(!m_underModification);
209 DEBUG_MSG("("<<surface<<","<<state<<") started");
210 Q_EMIT modificationsStarted();
211 m_underModification = true;
213 surface->setPreviousState(surface->state());
214 surface->setState(state);
216 if ((state == Mir::MinimizedState || state == Mir::HiddenState) && surface->focused()) {
217 Q_ASSERT(m_focusedSurface == surface);
218 surface->setFocused(false);
219 m_focusedSurface = nullptr;
220 focusFirstAvailableSurface();
223 m_underModification = false;
224 Q_EMIT modificationsEnded();
225 DEBUG_MSG("("<<surface<<","<<state<<") ended");
228void SurfaceManager::onSurfaceDestroyed(MirSurface *surface, const QString& persistentId)
230 m_surfaces.removeAll(surface);
231 if (m_focusedSurface == surface) {
232 m_focusedSurface = nullptr;
234 Q_EMIT modificationsStarted();
235 m_underModification = true;
237 focusFirstAvailableSurface();
239 m_underModification = false;
240 Q_EMIT modificationsEnded();
242 Q_EMIT surfaceDestroyed(persistentId);
245void SurfaceManager::focusFirstAvailableSurface()
247 MirSurface *chosenSurface = nullptr;
248 for (int i = 0; i < m_surfaces.count() && !chosenSurface; ++i) {
249 auto *surface = m_surfaces[i];
250 if (surface->state() != Mir::HiddenState && surface->state() != Mir::MinimizedState) {
251 chosenSurface = surface;
255 if (!chosenSurface) {
259 if (m_focusedSurface) {
260 m_focusedSurface->setFocused(false);
263 chosenSurface->setFocused(true);
265 m_focusedSurface = chosenSurface;
268void SurfaceManager::createInputMethodSurface()
270 if (!m_virtualKeyboard) {
271 m_virtualKeyboard = new VirtualKeyboard;
272 registerSurface(m_virtualKeyboard);
273 Q_EMIT surfaceCreated(m_virtualKeyboard);
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