~alan-griffiths/miral/debug

« back to all changes in this revision

Viewing changes to miral-qt/src/modules/Unity/Application/mirfocuscontroller.cpp

  • Committer: Gerry Boland
  • Date: 2016-06-01 22:06:51 UTC
  • mto: This revision was merged to the branch mainline in revision 178.
  • Revision ID: gerry.boland@canonical.com-20160601220651-ge508tffql4e7u7c
Import QtMir code into miral-qt subdirectory. Disabled by default, use -DMIRAL_ENABLE_QT=1 to build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 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
 */
 
16
 
 
17
#include "mirfocuscontroller.h"
 
18
 
 
19
#include "mirsurfaceinterface.h"
 
20
 
 
21
// mirserver
 
22
#include <logging.h>
 
23
 
 
24
namespace unityapp = unity::shell::application;
 
25
using namespace qtmir;
 
26
 
 
27
#define DEBUG_MSG qCDebug(QTMIR_SURFACES).nospace() << "MirFocusController::" << __func__
 
28
 
 
29
MirFocusController *MirFocusController::m_instance = nullptr;
 
30
 
 
31
void MirFocusController::setFocusedSurface(unityapp::MirSurfaceInterface *unityAppSurface)
 
32
{
 
33
    auto surface = static_cast<qtmir::MirSurfaceInterface*>(unityAppSurface);
 
34
 
 
35
    if (m_focusedSurface == surface) {
 
36
        return;
 
37
    }
 
38
 
 
39
    DEBUG_MSG << "(" << surface << ")";
 
40
 
 
41
    m_previouslyFocusedSurface = m_focusedSurface;
 
42
    m_focusedSurface = surface;
 
43
 
 
44
    if (m_previouslyFocusedSurface) {
 
45
        m_previouslyFocusedSurface->setFocused(false);
 
46
    }
 
47
 
 
48
    if (m_focusedSurface) {
 
49
        m_focusedSurface->setFocused(true);
 
50
        m_focusedSurface->raise();
 
51
    }
 
52
 
 
53
    if (m_previouslyFocusedSurface != m_focusedSurface) {
 
54
        Q_EMIT focusedSurfaceChanged();
 
55
    }
 
56
}
 
57
 
 
58
unity::shell::application::MirSurfaceInterface* MirFocusController::focusedSurface() const
 
59
{
 
60
    return m_focusedSurface;
 
61
}
 
62
 
 
63
MirFocusController* MirFocusController::instance()
 
64
{
 
65
    if (!m_instance) {
 
66
        m_instance = new MirFocusController;
 
67
    }
 
68
    return m_instance;
 
69
}