MirAL
display_config.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2017 Canonical Ltd.
3  *
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.
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  * Authored by: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIR_CLIENT_DISPLAY_CONFIG_H
20 #define MIR_CLIENT_DISPLAY_CONFIG_H
21 
22 #include <mir_toolkit/mir_connection.h>
23 #include <mir_toolkit/mir_display_configuration.h>
25 
26 #include <functional>
27 #include <memory>
28 
29 namespace mir
30 {
34 namespace client
35 {
36 class DisplayConfig
37 {
38 public:
39  DisplayConfig() = default;
40 
41  explicit DisplayConfig(MirDisplayConfig* config) : self{config, deleter} {}
42 
43  explicit DisplayConfig(MirConnection* connection) :
44  self{mir_connection_create_display_configuration(connection), deleter} {}
45 
46  operator MirDisplayConfig*() { return self.get(); }
47 
48  operator MirDisplayConfig const*() const { return self.get(); }
49 
50  void reset() { self.reset(); }
51 
52  void for_each_output(std::function<void(MirOutput const*)> const& enumerator) const
53  {
54  auto const count = mir_display_config_get_num_outputs(*this);
55 
56  for (int i = 0; i != count; ++i)
57  enumerator(mir_display_config_get_output(*this, i));
58  }
59 
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)
64  {
65  auto const count = mir_display_config_get_num_outputs(*this);
66 
67  for (int i = 0; i != count; ++i)
68  enumerator(mir_display_config_get_mutable_output(*this, i));
69  }
70 #endif
71 
72 private:
73  static void deleter(MirDisplayConfig* config) { mir_display_config_release(config); }
74 
75  std::shared_ptr <MirDisplayConfig> self;
76 };
77 
78 // Provide a deleted overload to avoid double release "accidents".
79 void mir_display_config_release(DisplayConfig const& config) = delete;
80 }
81 }
82 
83 #endif //MIR_CLIENT_DISPLAY_CONFIG_H
Definition: connection.h:26

Copyright © 2016 Canonical Ltd.
Generated on Fri Mar 3 10:22:14 UTC 2017