on 337d819 help sign in
unity8/tests/mocks/Unity/Application/SurfaceManager.cpp
91 lines 2.8 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17#include "SurfaceManager.h"
19#include "GenericApp.h"
20#include "VirtualKeyboard.h"
22#include <paths.h>
24SurfaceManager *SurfaceManager::the_surface_manager = nullptr;
26SurfaceManager *SurfaceManager::singleton()
28 if (!the_surface_manager) {
29 the_surface_manager = new SurfaceManager();
30 }
31 return the_surface_manager;
34SurfaceManager::SurfaceManager(QObject *parent) :
35 QObject(parent)
36 , m_virtualKeyboard(nullptr)
40MirSurfaceItem *SurfaceManager::createSurface(const QString& name,
41 MirSurfaceItem::Type type,
42 MirSurfaceItem::State state,
43 const QUrl& screenshot)
45 MirSurfaceItem* surface = new GenericApp(name,
46 type,
47 state,
48 screenshot);
49 Q_EMIT surfaceCreated(surface);
50 return surface;
53void SurfaceManager::registerSurface(MirSurfaceItem *surface)
55 connect(surface, &MirSurfaceItem::deregister, this, [this] {
56 MirSurfaceItem* surface = qobject_cast<MirSurfaceItem*>(sender());
57 disconnect(surface, 0, this, 0);
59 surface->setLive(false);
60 Q_EMIT surfaceDestroyed(surface);
61 });
63 GenericApp *genericApp = qobject_cast<GenericApp*>(surface);
64 if (genericApp) {
65 connect(genericApp, &GenericApp::inputMethodRequested,
66 this, &SurfaceManager::showInputMethod, Qt::QueuedConnection);
67 connect(genericApp, &GenericApp::inputMethodDismissed,
68 this, &SurfaceManager::hideInputMethod, Qt::QueuedConnection);
69 }
72void SurfaceManager::showInputMethod()
74 inputMethodSurface()->setState(MirSurfaceItem::Restored);
77void SurfaceManager::hideInputMethod()
79 if (m_virtualKeyboard) {
80 m_virtualKeyboard->setState(MirSurfaceItem::Minimized);
81 }
84MirSurfaceItem *SurfaceManager::inputMethodSurface()
86 if (!m_virtualKeyboard) {
87 m_virtualKeyboard = new VirtualKeyboard;
88 Q_EMIT surfaceCreated(m_virtualKeyboard);
89 }
90 return m_virtualKeyboard;