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 connect(surface, &QObject::destroyed, this, [=]() {
87 this->onSurfaceDestroyed(surface);
91void SurfaceManager::notifySurfaceCreated(unityapi::MirSurfaceInterface *surface)
93 Q_EMIT surfaceCreated(surface);
96void SurfaceManager::setNewSurfaceMinimumWidth(int value)
98 if (m_newSurfaceMinimumWidth != value) {
99 m_newSurfaceMinimumWidth = value;
100 Q_EMIT newSurfaceMinimumWidthChanged(m_newSurfaceMinimumWidth);
104void SurfaceManager::setNewSurfaceMaximumWidth(int value)
106 if (m_newSurfaceMaximumWidth != value) {
107 m_newSurfaceMaximumWidth = value;
108 Q_EMIT newSurfaceMaximumWidthChanged(m_newSurfaceMaximumWidth);
112void SurfaceManager::setNewSurfaceMinimumHeight(int value)
114 if (m_newSurfaceMinimumHeight != value) {
115 m_newSurfaceMinimumHeight = value;
116 Q_EMIT newSurfaceMinimumHeightChanged(m_newSurfaceMinimumHeight);
120void SurfaceManager::setNewSurfaceMaximumHeight(int value)
122 if (m_newSurfaceMaximumHeight != value) {
123 m_newSurfaceMaximumHeight = value;
124 Q_EMIT newSurfaceMaximumHeightChanged(m_newSurfaceMaximumHeight);
128void SurfaceManager::setNewSurfaceWidthIncrement(int value)
130 if (m_newSurfaceWidthIncrement != value) {
131 m_newSurfaceWidthIncrement = value;
132 Q_EMIT newSurfaceWidthIncrementChanged(m_newSurfaceWidthIncrement);
136void SurfaceManager::setNewSurfaceHeightIncrement(int value)
138 if (m_newSurfaceHeightIncrement != value) {
139 m_newSurfaceHeightIncrement = value;
140 Q_EMIT newSurfaceHeightIncrementChanged(m_newSurfaceHeightIncrement);
144void SurfaceManager::raise(unityapi::MirSurfaceInterface *surface)
146 if (m_underModification)
149 DEBUG_MSG("("<<surface<<") started");
150 Q_EMIT modificationsStarted();
151 m_underModification = true;
155 m_underModification = false;
156 Q_EMIT modificationsEnded();
157 DEBUG_MSG("("<<surface<<") ended");
160void SurfaceManager::doRaise(unityapi::MirSurfaceInterface *apiSurface)
162 auto surface = static_cast<MirSurface*>(apiSurface);
163 int index = m_surfaces.indexOf(surface);
164 Q_ASSERT(index != -1);
165 m_surfaces.move(index, 0);
167 QVector<MirSurfaceInterface*> surfaces;
168 surfaces.append(surface);
169 Q_EMIT surfacesRaised(surfaces);
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 surface->setState(Mir::RestoredState);
192 surface->setFocused(true);
195 m_focusedSurface = surface;
196 m_underModification = false;
197 Q_EMIT modificationsEnded();
198 DEBUG_MSG("("<<surface<<") ended");
201void SurfaceManager::onStateRequested(MirSurface *surface, Mir::State state)
203 Q_ASSERT(!m_underModification);
205 DEBUG_MSG("("<<surface<<","<<state<<") started");
206 Q_EMIT modificationsStarted();
207 m_underModification = true;
209 surface->setState(state);
211 if ((state == Mir::MinimizedState || state == Mir::HiddenState) && surface->focused()) {
212 Q_ASSERT(m_focusedSurface == surface);
213 surface->setFocused(false);
214 m_focusedSurface = nullptr;
215 focusFirstAvailableSurface();
218 m_underModification = false;
219 Q_EMIT modificationsEnded();
220 DEBUG_MSG("("<<surface<<","<<state<<") ended");
223void SurfaceManager::onSurfaceDestroyed(MirSurface *surface)
225 m_surfaces.removeAll(surface);
226 if (m_focusedSurface == surface) {
227 m_focusedSurface = nullptr;
229 Q_EMIT modificationsStarted();
230 m_underModification = true;
232 focusFirstAvailableSurface();
234 m_underModification = false;
235 Q_EMIT modificationsEnded();
239void SurfaceManager::focusFirstAvailableSurface()
241 MirSurface *chosenSurface = nullptr;
242 for (int i = 0; i < m_surfaces.count() && !chosenSurface; ++i) {
243 auto *surface = m_surfaces[i];
244 if (surface->state() != Mir::HiddenState && surface->state() != Mir::MinimizedState) {
245 chosenSurface = surface;
249 if (!chosenSurface) {
253 if (m_focusedSurface) {
254 m_focusedSurface->setFocused(false);
257 chosenSurface->setFocused(true);
259 m_focusedSurface = chosenSurface;
262void SurfaceManager::createInputMethodSurface()
264 if (!m_virtualKeyboard) {
265 m_virtualKeyboard = new VirtualKeyboard;
266 registerSurface(m_virtualKeyboard);
267 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