13 #include <wayland-client-protocol-extra.hpp>
14 #include <linux/input.h>
15 #include <wayland-cursor.hpp>
22 using namespace wayland;
45 cursor_image_t cursor_image;
61 std::chrono::time_point<std::chrono::steady_clock> tstart;
63 void draw(uint32_t serial = 0)
67 std::fill_n(static_cast<uint32_t*>(mem)+cur_buf*320*240, 320*240, 0xffffff);
68 surface.
attach(buffer[cur_buf], 0, 0);
69 surface.
damage(0, 0, 320, 240);
74 tstart = std::chrono::steady_clock::now();
79 frame_cb = surface.
frame();
80 frame_cb.
on_done() = [
this] (uint32_t serial) { this->draw(serial); };
84 auto now = std::chrono::steady_clock::now();
85 auto diff = std::chrono::duration_cast<std::chrono::milliseconds>(now - tstart).count();
88 std::cout << count << std::endl;
100 registry.
on_global() = [&] (uint32_t name, std::string interface, uint32_t version)
102 if(interface == compositor_t::interface_name)
103 registry.
bind(name, compositor, version);
104 else if(interface == shell_t::interface_name)
105 registry.
bind(name, shell, version);
106 else if(interface == xdg_wm_base_t::interface_name)
107 registry.
bind(name, xdg_wm_base, version);
108 else if(interface == seat_t::interface_name)
109 registry.
bind(name, seat, version);
110 else if(interface == shm_t::interface_name)
111 registry.
bind(name, shm, version);
127 xdg_wm_base.
on_ping() = [&] (uint32_t serial) { xdg_wm_base.
pong(serial); };
132 xdg_toplevel.
on_close() = [&] () { running =
false; };
137 shell_surface.
on_ping() = [&] (uint32_t serial) { shell_surface.
pong(serial); };
147 throw std::runtime_error(
"No keyboard found.");
149 throw std::runtime_error(
"No pointer found.");
155 std::stringstream ss;
156 std::srand(std::time(0));
157 ss <<
'/' << std::rand();
161 fd = shm_open(name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
163 throw std::runtime_error(
"shm_open failed.");
166 if(ftruncate(fd, 2*320*240*4) < 0)
167 throw std::runtime_error(
"ftruncate failed.");
170 mem = mmap(NULL, 2*320*240*4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
171 if(mem == MAP_FAILED)
172 throw std::runtime_error(
"mmap failed.");
176 for(
unsigned int c = 0; c < 2; c++)
177 buffer[c] = pool.
create_buffer(c*320*240*4, 320, 240, 320*4, shm_format::argb8888);
181 cursor_theme_t cursor_theme = cursor_theme_t(
"default", 16, shm);
182 cursor_t cursor = cursor_theme.get_cursor(
"cross");
183 cursor_image = cursor.image(0);
184 cursor_buffer = cursor_image.get_buffer();
192 cursor_surface.
attach(cursor_buffer, 0, 0);
193 cursor_surface.
damage(0, 0, cursor_image.width(), cursor_image.height());
195 pointer.
set_cursor(serial, cursor_surface, 0, 0);
199 pointer.
on_button() = [&] (uint32_t serial, uint32_t time, uint32_t button, pointer_button_state state)
201 if(button == BTN_LEFT && state == pointer_button_state::pressed)
204 xdg_toplevel.
move(seat, serial);
206 shell_surface.
move(seat, serial);
211 keyboard.
on_key() = [&] (uint32_t, uint32_t, uint32_t key, keyboard_key_state state)
213 if(key == KEY_Q && state == keyboard_key_state::pressed)
224 munmap(mem, 2*320*240*4);
226 shm_unlink(name.c_str());