|
|
|
@ -39,10 +39,10 @@ void handle_global(void* data, struct wl_registry* registry, uint32_t name, cons
|
|
|
|
|
if(strcmp(interface, wl_shm_interface.name) == 0) {
|
|
|
|
|
wl_shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
|
|
|
|
} else if(strcmp(interface, wl_output_interface.name) == 0) {
|
|
|
|
|
wl_output = wl_registry_bind(registry, name, &wl_output_interface, 3);
|
|
|
|
|
} else if(strcmp(interface, zwlr_screencopy_manager_v1_interface.name) == 0) {
|
|
|
|
|
wl_output = wl_registry_bind(registry, name, &wl_output_interface, 3);
|
|
|
|
|
} else if(strcmp(interface, zwlr_screencopy_manager_v1_interface.name) == 0) {
|
|
|
|
|
zwlr_manager = wl_registry_bind(registry, name, &zwlr_screencopy_manager_v1_interface, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) {
|
|
|
|
@ -50,11 +50,11 @@ void handle_global_remove(void* data, struct wl_registry* registry, uint32_t nam
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const struct wl_registry_listener reg_callbacks = {
|
|
|
|
|
.global = handle_global,
|
|
|
|
|
.global_remove = handle_global_remove,
|
|
|
|
|
.global = handle_global,
|
|
|
|
|
.global_remove = handle_global_remove,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void frame_handle_buffer(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
|
|
|
|
|
void frame_handle_buffer(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
|
|
|
|
|
printf("Handling buffer.\n");
|
|
|
|
|
image_width = width;
|
|
|
|
|
image_height = height;
|
|
|
|
@ -75,10 +75,10 @@ void frame_handle_buffer(void* data, struct zwlr_screencopy_frame_v1* frame, uin
|
|
|
|
|
struct wl_shm_pool* pool = wl_shm_create_pool(wl_shm, shm_fd, buf_size);
|
|
|
|
|
ASSERT(pool != NULL, "Failed to create the wl_shm_pool.");
|
|
|
|
|
|
|
|
|
|
struct wl_buffer* buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, format);
|
|
|
|
|
struct wl_buffer* buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, format);
|
|
|
|
|
ASSERT(buffer != NULL, "Failed to create the wl_buffer.");
|
|
|
|
|
|
|
|
|
|
zwlr_screencopy_frame_v1_copy(frame, buffer);
|
|
|
|
|
zwlr_screencopy_frame_v1_copy(frame, buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void frame_handle_flags(void* data, struct zwlr_screencopy_frame_v1* frame, uint32_t flags) {
|
|
|
|
@ -91,15 +91,15 @@ void frame_handle_ready(void *data, struct zwlr_screencopy_frame_v1 *frame, uint
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void frame_handle_failed(void* data, struct zwlr_screencopy_frame_v1* frame) {
|
|
|
|
|
fprintf(stderr, "Failed to copy output\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
fprintf(stderr, "Failed to copy output\n");
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct zwlr_screencopy_frame_v1_listener frame_listener = {
|
|
|
|
|
.buffer = frame_handle_buffer,
|
|
|
|
|
.flags = frame_handle_flags,
|
|
|
|
|
.ready = frame_handle_ready,
|
|
|
|
|
.failed = frame_handle_failed,
|
|
|
|
|
.buffer = frame_handle_buffer,
|
|
|
|
|
.flags = frame_handle_flags,
|
|
|
|
|
.ready = frame_handle_ready,
|
|
|
|
|
.failed = frame_handle_failed,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
@ -107,8 +107,8 @@ int main() {
|
|
|
|
|
ASSERT(dpy != NULL, "Unable to connect to Wayland");
|
|
|
|
|
|
|
|
|
|
struct wl_registry* registry = wl_display_get_registry(dpy);
|
|
|
|
|
wl_registry_add_listener(registry, ®_callbacks, NULL);
|
|
|
|
|
wl_display_roundtrip(dpy);
|
|
|
|
|
wl_registry_add_listener(registry, ®_callbacks, NULL);
|
|
|
|
|
wl_display_roundtrip(dpy);
|
|
|
|
|
|
|
|
|
|
ASSERT(wl_shm != NULL, "core.wl_shm not supported.");
|
|
|
|
|
|
|
|
|
@ -121,7 +121,7 @@ int main() {
|
|
|
|
|
ASSERT(frame != NULL, "wlr-screencopy-unstable-v1.zwlr_screencopy_manager_v1::capture_output has failed");
|
|
|
|
|
|
|
|
|
|
zwlr_screencopy_frame_v1_add_listener(frame, &frame_listener, wl_output);
|
|
|
|
|
wl_display_roundtrip(dpy);
|
|
|
|
|
wl_display_roundtrip(dpy);
|
|
|
|
|
|
|
|
|
|
while(ready == 0 && wl_display_dispatch(dpy) != -1) {
|
|
|
|
|
// Empty
|
|
|
|
|