Wayland++
1.0.1
C++ Bindings for Wayland
Toggle main menu visibility
Loading...
Searching...
No Matches
foreign_display.cpp
1
/*
2
* Copyright (c) 2018-2019, Philipp Kerling
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* 1. Redistributions of source code must retain the above copyright notice, this
9
* list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
13
*
14
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
*/
25
29
30
#include <iostream>
31
#include <memory>
32
33
#include <
wayland-client.hpp
>
34
35
using namespace
wayland;
36
37
class
foreign_display
38
{
39
private
:
40
// global objects
41
wl_display* c_display =
nullptr
;
42
std::unique_ptr<display_t> display;
43
registry_t registry;
44
45
public
:
46
foreign_display() =
default
;
47
foreign_display(
const
foreign_display&) =
delete
;
48
foreign_display(foreign_display&&) noexcept = delete;
49
foreign_display& operator=(const foreign_display&) = delete;
50
foreign_display& operator=(foreign_display&&) noexcept = delete;
51
52
53
~foreign_display() noexcept
54
{
55
// wl_display_disconnect destroys all remaining proxy instances implicitly,
56
// so we have to make sure this is already gone in order to not run into a
57
// double-free
58
registry.proxy_release();
59
// This is not called by the display_t destructor for foreign instances!
60
wl_display_disconnect(c_display);
61
}
62
63
void
run()
64
{
65
c_display = wl_display_connect(
nullptr
);
66
if
(!c_display)
67
{
68
std::cerr <<
"Cannot connect to Wayland display"
;
69
return
;
70
}
71
72
display.reset(
new
display_t(c_display));
73
registry = display->get_registry();
74
registry.on_global() = [&] (uint32_t name,
const
std::string& interface, uint32_t version)
75
{
76
std::cout <<
"* Global interface "
<<
interface
<< " (name
" << name << "
version
" << version << "
)
" << std::endl;
77
};
78
display->roundtrip();
79
}
80
};
81
82
int main()
83
{
84
foreign_display d;
85
d.run();
86
return 0;
87
}
wayland-client.hpp
example
foreign_display.cpp
Generated on
for Wayland++ by
1.17.0