Wayland++  0.2.6
C++ Bindings for Wayland
dump.cpp
1 /*
2  * Copyright (c) 2017-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 
31 #include <iostream>
32 
33 #include <wayland-client.hpp>
34 
35 using namespace wayland;
36 
37 // Wayland protocol info dumper
38 class dumper
39 {
40 private:
41  // global objects
42  display_t display;
43  registry_t registry;
44 
45 public:
46  dumper()
47  {
48  }
49 
50  ~dumper()
51  {
52  }
53 
54  void run()
55  {
56  std::vector<output_t> outputs;
57  // retrieve global objects
58  registry = display.get_registry();
59  registry.on_global() = [&] (uint32_t name, std::string interface, uint32_t version)
60  {
61  std::cout << "* Global interface " << interface << " (name " << name << " version " << version << ")" << std::endl;
62  if(interface == output_t::interface_name)
63  {
64  outputs.emplace_back();
65  auto& output = outputs.back();
66  registry.bind(name, output, version);
67  output.on_geometry() = [=](int32_t x, int32_t y, int32_t physw, int32_t physh, output_subpixel subp, std::string make, std::string model, output_transform transform)
68  {
69  std::cout << "* Output geometry for " << output.get_id() << ":" << std::endl
70  << " Maker: " << make << std::endl
71  << " Model: " << model << std::endl
72  << " X: " << x << std::endl
73  << " Y: " << y << std::endl
74  << " PhysW: " << physw << " mm" << std::endl
75  << " PhysH: " << physh << " mm" << std::endl
76  << " Subpix: " << static_cast<unsigned int>(subp) << std::endl
77  << " Transf: " << static_cast<unsigned int>(transform) << std::endl;
78  };
79  output.on_scale() = [=](int32_t scale)
80  {
81  std::cout << "* Output scale for " << output.get_id() << ": " << scale << std::endl;
82  };
83  output.on_mode() = [=](uint32_t flags, int32_t width, int32_t height, int32_t refresh)
84  {
85  std::cout << "* Output mode for " << output.get_id() << ":" << std::endl
86  << " Width: " << width << std::endl
87  << " Height: " << height << std::endl
88  << " Refresh: " << refresh << " mHz" << std::endl
89  << " Flags: " << flags << std::endl;
90  };
91  }
92  };
93  // Print global information
94  display.roundtrip();
95  std::cout << "------" << std::endl;
96  // Print output information
97  display.roundtrip();
98  }
99 };
100 
101 int main()
102 {
103  dumper d;
104  d.run();
105  return 0;
106 }
wayland::display_t
Represents a connection to the compositor and acts as a proxy to the display singleton object.
Definition: wayland-client.hpp:463
wayland::display_t::get_registry
registry_t get_registry()
get global registry object
wayland::proxy_t::get_id
uint32_t get_id() const
Get the id of a proxy object.
wayland::registry_t
global registry object
Definition: wayland-client-protocol.hpp:130
wayland::registry_t::bind
proxy_t bind(uint32_t name, proxy_t &interface, uint32_t version)
bind an object to the display
Definition: wayland-client-protocol.cpp:1560
wayland::output_transform
transform from framebuffer to output
Definition: wayland-client-protocol.hpp:3431
wayland::display_t::roundtrip
int roundtrip()
Block until all pending request are processed by the server.
wayland::registry_t::on_global
std::function< void(uint32_t, std::string, uint32_t)> & on_global()
announce global object
Definition: wayland-client-protocol.cpp:1567
wayland-client.hpp