~ci-train-bot/miral/miral-ubuntu-zesty-2683

« back to all changes in this revision

Viewing changes to include/mir/client/display_config.h

  • Committer: Bileto Bot
  • Date: 2017-03-03 10:18:50 UTC
  • mfrom: (354.2.1 miral-release)
  • Revision ID: ci-train-bot@canonical.com-20170303101850-co4wayjsirso5nmj
* New upstream release 1.3.0 (https://launchpad.net/miral/+milestone/1.3)
  - ABI summary:
    . miral ABI unchanged at 2
  - Enhancements:
    . [libmiral] Support for workspaces
    . [libmiral] Add miral::WindowManagerTools::focus_prev_within_application
                 (LP: #1668562)
    . [libmirclientcpp] A better description of libmirclientcpp-dev
    . [libmirclientcpp] Add RAII wrapper for MirDisplayConfig.
    . [libmirclientcpp] Prevent accidental double-release by deleting release
                        functions for handle classes
    . [miral-shell] Example workspaces implementation
    . [miral-shell] Use background to show keyboard shortcuts
  - Bugs fixed:
    . [libmiral] Join internal client threads before server shutdown
                 (LP: #1668651)
    . [miral-shell] Workaround for crash on exit (LP: #1667645)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
24
#include <mir/client/detail/mir_features.h>
 
25
 
 
26
#include <functional>
 
27
#include <memory>
 
28
 
 
29
namespace mir
 
30
{
 
31
/// Convenient C++ wrappers around the Mir toolkit API.
 
32
///
 
33
/// These wrappers are intentionally inline adapters: the compiled code depend directly on the Mir toolkit API.
 
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