on e804c19 help sign in
unity8/tests/mocks/Unity/Application/SurfaceManager.cpp
126 lines 3.9 kB history raw
1/*
2 * Copyright (C) 2014-2016 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 "ApplicationInfo.h"
20#include "VirtualKeyboard.h"
22#include <paths.h>
24SurfaceManager *SurfaceManager::the_surface_manager = nullptr;
26SurfaceManager *SurfaceManager::instance()
28 return the_surface_manager;
31SurfaceManager::SurfaceManager(QObject *parent) :
32 QObject(parent)
33 , m_virtualKeyboard(nullptr)
35 Q_ASSERT(the_surface_manager == nullptr);
36 the_surface_manager = this;
38 m_virtualKeyboard = new VirtualKeyboard;
39 connect(m_virtualKeyboard, &QObject::destroyed, this, [this](QObject *obj) {
40 MirSurface* surface = qobject_cast<MirSurface*>(obj);
41 m_virtualKeyboard = nullptr;
42 Q_EMIT inputMethodSurfaceChanged();
43 Q_EMIT surfaceDestroyed(surface);
44 });
47SurfaceManager::~SurfaceManager()
49 Q_ASSERT(the_surface_manager == this);
50 the_surface_manager = nullptr;
53MirSurface *SurfaceManager::createSurface(const QString& name,
54 Mir::Type type,
55 Mir::State state,
56 const QUrl& screenshot)
58 MirSurface* surface = new MirSurface(name, type, state, screenshot);
59 connect(surface, &QObject::destroyed, this, [this](QObject *obj) {
60 MirSurface* surface = qobject_cast<MirSurface*>(obj);
61 Q_EMIT surfaceDestroyed(surface);
62 });
64 surface->setMinimumWidth(m_newSurfaceMinimumWidth);
65 surface->setMaximumWidth(m_newSurfaceMaximumWidth);
66 surface->setMinimumHeight(m_newSurfaceMinimumHeight);
67 surface->setMaximumHeight(m_newSurfaceMaximumHeight);
68 surface->setWidthIncrement(m_newSurfaceWidthIncrement);
69 surface->setHeightIncrement(m_newSurfaceHeightIncrement);
71 Q_EMIT surfaceCreated(surface);
72 return surface;
75MirSurface *SurfaceManager::inputMethodSurface() const
77 return m_virtualKeyboard;
80void SurfaceManager::setNewSurfaceMinimumWidth(int value)
82 if (m_newSurfaceMinimumWidth != value) {
83 m_newSurfaceMinimumWidth = value;
84 Q_EMIT newSurfaceMinimumWidthChanged(m_newSurfaceMinimumWidth);
85 }
88void SurfaceManager::setNewSurfaceMaximumWidth(int value)
90 if (m_newSurfaceMaximumWidth != value) {
91 m_newSurfaceMaximumWidth = value;
92 Q_EMIT newSurfaceMaximumWidthChanged(m_newSurfaceMaximumWidth);
93 }
96void SurfaceManager::setNewSurfaceMinimumHeight(int value)
98 if (m_newSurfaceMinimumHeight != value) {
99 m_newSurfaceMinimumHeight = value;
100 Q_EMIT newSurfaceMinimumHeightChanged(m_newSurfaceMinimumHeight);
101 }
104void SurfaceManager::setNewSurfaceMaximumHeight(int value)
106 if (m_newSurfaceMaximumHeight != value) {
107 m_newSurfaceMaximumHeight = value;
108 Q_EMIT newSurfaceMaximumHeightChanged(m_newSurfaceMaximumHeight);
109 }
112void SurfaceManager::setNewSurfaceWidthIncrement(int value)
114 if (m_newSurfaceWidthIncrement != value) {
115 m_newSurfaceWidthIncrement = value;
116 Q_EMIT newSurfaceWidthIncrementChanged(m_newSurfaceWidthIncrement);
117 }
120void SurfaceManager::setNewSurfaceHeightIncrement(int value)
122 if (m_newSurfaceHeightIncrement != value) {
123 m_newSurfaceHeightIncrement = value;
124 Q_EMIT newSurfaceHeightIncrementChanged(m_newSurfaceHeightIncrement);
125 }