2
* Copyright (C) 2016 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/>.
17
#include "screenscontroller.h"
19
#include "screensmodel.h"
22
#include <mir/graphics/display.h>
23
#include <mir/shell/display_configuration_controller.h>
24
#include <mir/geometry/point.h>
26
namespace mg = mir::graphics;
28
ScreensController::ScreensController(const QSharedPointer<ScreensModel> &model,
29
const std::shared_ptr<mir::graphics::Display> &display,
30
const std::shared_ptr<mir::shell::DisplayConfigurationController> &controller,
33
, m_screensModel(model)
35
, m_displayConfigurationController(controller)
39
CustomScreenConfigurationList ScreensController::configuration()
41
CustomScreenConfigurationList list;
43
Q_FOREACH(auto screen, m_screensModel->screens()) {
45
CustomScreenConfiguration {
47
screen->geometry().topLeft(),
48
screen->currentModeIndex(),
50
mir_orientation_normal, //screen->orientation(), disable for now
58
bool ScreensController::setConfiguration(const CustomScreenConfigurationList &newConfig)
60
using namespace mir::geometry;
62
auto displayConfiguration = m_display->configuration();
64
Q_FOREACH (const auto &config, newConfig) {
65
displayConfiguration->for_each_output(
66
[&config](mg::UserDisplayConfigurationOutput &outputConfig)
68
if (config.id == outputConfig.id) {
69
outputConfig.current_mode_index = config.currentModeIndex;
70
outputConfig.top_left = Point{ X{config.topLeft.x()}, Y{config.topLeft.y()}};
71
outputConfig.power_mode = config.powerMode;
72
// outputConfig.orientation = config.orientation; // disabling for now
73
outputConfig.scale = config.scale;
74
outputConfig.form_factor = config.formFactor;
79
if (!displayConfiguration->valid()) {
83
m_displayConfigurationController->set_base_configuration(std::move(displayConfiguration));