2
* Copyright © 2017 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as published by the Free Software Foundation.
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.
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/>.
16
* Authored by: Alan Griffiths <alan@octopull.co.uk>
19
#ifndef MIR_CLIENT_DISPLAY_CONFIG_H
20
#define MIR_CLIENT_DISPLAY_CONFIG_H
22
#include <mir_toolkit/mir_connection.h>
23
#include <mir_toolkit/mir_display_configuration.h>
24
#include <mir/client/detail/mir_features.h>
31
/// Convenient C++ wrappers around the Mir toolkit API.
33
/// These wrappers are intentionally inline adapters: the compiled code depend directly on the Mir toolkit API.
39
DisplayConfig() = default;
41
explicit DisplayConfig(MirDisplayConfig* config) : self{config, deleter} {}
43
explicit DisplayConfig(MirConnection* connection) :
44
self{mir_connection_create_display_configuration(connection), deleter} {}
46
operator MirDisplayConfig*() { return self.get(); }
48
operator MirDisplayConfig const*() const { return self.get(); }
50
void reset() { self.reset(); }
52
void for_each_output(std::function<void(MirOutput const*)> const& enumerator) const
54
auto const count = mir_display_config_get_num_outputs(*this);
56
for (int i = 0; i != count; ++i)
57
enumerator(mir_display_config_get_output(*this, i));
60
#if MIR_DEFINES_DISPLAY_CONFIG_GET_MUTABLE_OUTPUT
61
// Is it worthwhile to emulate this functionality for Mir 0.21?
62
// Too many API gaps I think.
63
void for_each_output(std::function<void(MirOutput*)> const& enumerator)
65
auto const count = mir_display_config_get_num_outputs(*this);
67
for (int i = 0; i != count; ++i)
68
enumerator(mir_display_config_get_mutable_output(*this, i));
73
static void deleter(MirDisplayConfig* config) { mir_display_config_release(config); }
75
std::shared_ptr <MirDisplayConfig> self;
78
// Provide a deleted overload to avoid double release "accidents".
79
void mir_display_config_release(DisplayConfig const& config) = delete;
83
#endif //MIR_CLIENT_DISPLAY_CONFIG_H