~sil2100/unity-mir/no_change_rebuild

« back to all changes in this revision

Viewing changes to src/unity-mir/dbusscreen.cpp

  • Committer: CI bot
  • Author(s): Michael Terry
  • Date: 2014-03-11 03:40:33 UTC
  • mfrom: (161.2.4 drop-dbusscreen)
  • Revision ID: ps-jenkins@lists.canonical.com-20140311034033-dajpvn931ql4helg
Drop dbusscreen code because it has moved to unity-system-compositor. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 Canonical, Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it under
5
 
 * the terms of the GNU Lesser General Public License version 3, as published by
6
 
 * the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
 
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
 * Lesser General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 */
16
 
 
17
 
// mir
18
 
#include <mir/graphics/display.h>
19
 
#include <mir/graphics/display_configuration.h>
20
 
#include <mir/compositor/compositor.h>
21
 
#include <mir_toolkit/common.h>
22
 
 
23
 
// qt
24
 
#include <QDBusConnection>
25
 
#include <QDebug>
26
 
 
27
 
// local
28
 
#include "shellserverconfiguration.h"
29
 
#include "dbusscreen.h"
30
 
 
31
 
namespace mc = mir::compositor;
32
 
namespace mg = mir::graphics;
33
 
 
34
 
// Note: this class should be created only after when the Mir DisplayServer has started
35
 
DBusScreen::DBusScreen(ShellServerConfiguration *config, QObject *parent)
36
 
    : QObject(parent)
37
 
    , m_serverConfig(config)
38
 
{
39
 
    QDBusConnection::systemBus().registerService("com.canonical.Unity.Screen");
40
 
    // TODO ExportScriptableSlots shouldn't be needed but without it I don't get the methods :-/
41
 
    QDBusConnection::systemBus().registerObject("/com/canonical/Unity/Screen", this,
42
 
                                                QDBusConnection::ExportScriptableSlots |
43
 
                                                QDBusConnection::ExportScriptableInvokables );
44
 
}
45
 
 
46
 
bool DBusScreen::setScreenPowerMode(const QString &mode)
47
 
{
48
 
    MirPowerMode newPowerMode;
49
 
    // Note: the "standby" and "suspend" modes are mostly unused
50
 
 
51
 
    if (mode == "on") {
52
 
        newPowerMode = MirPowerMode::mir_power_mode_on;
53
 
    } else if (mode == "standby") {
54
 
        newPowerMode = MirPowerMode::mir_power_mode_standby; // higher power "off" mode (fastest resume)
55
 
    } else if (mode == "suspend") {
56
 
        newPowerMode = MirPowerMode::mir_power_mode_suspend; // medium power "off" mode
57
 
    } else if (mode == "off") {
58
 
        newPowerMode = MirPowerMode::mir_power_mode_off;     // lowest power "off" mode (slowest resume)
59
 
    } else {
60
 
        qWarning() << "DBusScreen: unknown mode type" << mode;
61
 
        return false;
62
 
    }
63
 
 
64
 
    std::shared_ptr<mg::Display> display = m_serverConfig->the_display();
65
 
    std::shared_ptr<mg::DisplayConfiguration> displayConfig = display->configuration();
66
 
    std::shared_ptr<mc::Compositor> compositor = m_serverConfig->the_compositor();
67
 
 
68
 
    displayConfig->for_each_output([&](const mg::DisplayConfigurationOutput displayConfigOutput) {
69
 
        if (displayConfigOutput.power_mode != newPowerMode) {
70
 
            displayConfig->configure_output(
71
 
                        displayConfigOutput.id,         //unchanged
72
 
                        displayConfigOutput.used,       //unchanged
73
 
                        displayConfigOutput.top_left,   //unchanged
74
 
                        displayConfigOutput.current_mode_index, //unchanged
75
 
                        displayConfigOutput.current_format,
76
 
                        newPowerMode,
77
 
                        displayConfigOutput.orientation //unchanged
78
 
                        );
79
 
        }
80
 
    });
81
 
 
82
 
    if (newPowerMode != MirPowerMode::mir_power_mode_on)
83
 
        compositor->stop();
84
 
 
85
 
    display->configure(*displayConfig.get());
86
 
 
87
 
    if (newPowerMode == MirPowerMode::mir_power_mode_on)
88
 
        compositor->start();
89
 
 
90
 
    return true;
91
 
}