2
* Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
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>
24
#include <QDBusConnection>
28
#include "shellserverconfiguration.h"
29
#include "dbusscreen.h"
31
namespace mc = mir::compositor;
32
namespace mg = mir::graphics;
34
// Note: this class should be created only after when the Mir DisplayServer has started
35
DBusScreen::DBusScreen(ShellServerConfiguration *config, QObject *parent)
37
, m_serverConfig(config)
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 );
46
bool DBusScreen::setScreenPowerMode(const QString &mode)
48
MirPowerMode newPowerMode;
49
// Note: the "standby" and "suspend" modes are mostly unused
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)
60
qWarning() << "DBusScreen: unknown mode type" << mode;
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();
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,
77
displayConfigOutput.orientation //unchanged
82
if (newPowerMode != MirPowerMode::mir_power_mode_on)
85
display->configure(*displayConfig.get());
87
if (newPowerMode == MirPowerMode::mir_power_mode_on)