diff --git a/src/dulcepan.h b/src/dulcepan.h index 671a4de..bc97c0a 100644 --- a/src/dulcepan.h +++ b/src/dulcepan.h @@ -31,6 +31,8 @@ struct dp_output { uint32_t global_name; struct wl_output *wl_output; + char *name; + struct wl_surface *main_surface; struct zwlr_layer_surface_v1 *main_layer_surface; struct wp_viewport *main_viewport; @@ -198,6 +200,7 @@ void dp_log_error(const char *fmt, ...); void dp_log_fatal(const char *fmt, ...); void *dp_zalloc(size_t size); +char *dp_strdup(const char *str); const char *dp_ext_from_path(const char *path); enum dp_file_format dp_ext_to_format(const char *ext); diff --git a/src/main.c b/src/main.c index 8f82326..6ce771f 100644 --- a/src/main.c +++ b/src/main.c @@ -35,10 +35,10 @@ static void registry_handle_global(void *data, struct wl_registry *registry, uin } else if (strcmp(interface, wl_output_interface.name) == 0) { if (state->initialized) { dp_log_fatal("An output was added after initialization"); - } else if (version < 2) { + } else if (version < 4) { dp_log_fatal("An output has too low version (%d)", version); } - struct wl_output *global = wl_registry_bind(registry, name, &wl_output_interface, 2); + struct wl_output *global = wl_registry_bind(registry, name, &wl_output_interface, 4); dp_output_create(state, name, global); } else if (strcmp(interface, wl_seat_interface.name) == 0) { struct wl_seat *global = wl_registry_bind(registry, name, &wl_seat_interface, 1); diff --git a/src/output.c b/src/output.c index 12c69f1..91132b1 100644 --- a/src/output.c +++ b/src/output.c @@ -32,8 +32,8 @@ static void layer_surface_handle_configure(void *data, struct zwlr_layer_surface if (output->initialized) { if (i_width != output->effective_width || i_height != output->effective_height) { - dp_log_fatal("Layer surface size has changed: %dx%d => %dx%d", output->effective_width, - output->effective_height, i_width, i_height); + dp_log_fatal("Output %s: layer surface size has changed: %dx%d => %dx%d", output->name, + output->effective_width, output->effective_height, i_width, i_height); } wl_surface_commit(output->main_surface); @@ -61,7 +61,8 @@ static void layer_surface_handle_configure(void *data, struct zwlr_layer_surface } static void layer_surface_handle_closed(void *data, struct zwlr_layer_surface_v1 *layer_surface) { - dp_log_fatal("A layer surface was closed"); + struct dp_output *output = data; + dp_log_fatal("Output %s: a layer surface was closed", output->name); } static const struct zwlr_layer_surface_v1_listener layer_surface_listener = { @@ -104,7 +105,8 @@ static void frame_handle_ready(void *data, struct zwlr_screencopy_frame_v1 *fram } static void frame_handle_failed(void *data, struct zwlr_screencopy_frame_v1 *frame) { - dp_log_fatal("Failed to copy a frame"); + struct dp_output *output = data; + dp_log_fatal("Output %s: failed to copy a frame", output->name); } static const struct zwlr_screencopy_frame_v1_listener frame_listener = { @@ -130,8 +132,8 @@ static void output_handle_geometry(void *data, struct wl_output *wl_output, int3 if (output->has_geom) { if (transform != output->transform) { - dp_log_fatal("Output transform has changed: %d (%#x) => %d (%#x)", output->transform, - output->transform, transform, transform); + dp_log_fatal("Output %s: transform has changed: %d (%#x) => %d (%#x)", output->name, + output->transform, output->transform, transform, transform); } } @@ -144,8 +146,8 @@ static void output_handle_mode(void *data, struct wl_output *wl_output, uint32_t if (output->has_geom) { if (width != output->width || height != output->height) { - dp_log_fatal("Output mode has changed: %dx%d => %dx%d", output->width, output->height, - width, height); + dp_log_fatal("Output %s: mode has changed: %dx%d => %dx%d", output->name, output->width, + output->height, width, height); } } @@ -160,6 +162,8 @@ static void output_handle_done(void *data, struct wl_output *wl_output) { return; } + assert(output->name != NULL); + if ((output->transform & WL_OUTPUT_TRANSFORM_90) != 0) { output->transformed_width = output->height; output->transformed_height = output->width; @@ -222,11 +226,23 @@ static void output_handle_scale(void *data, struct wl_output *wl_output, int32_t // Ignored } +static void output_handle_name(void *data, struct wl_output *wl_output, const char *name) { + struct dp_output *output = data; + assert(output->name == NULL); + output->name = dp_strdup(name); +} + +static void output_handle_description(void *data, struct wl_output *wl_output, const char *name) { + // Ignored +} + static const struct wl_output_listener output_listener = { .geometry = output_handle_geometry, .mode = output_handle_mode, .done = output_handle_done, .scale = output_handle_scale, + .name = output_handle_name, + .description = output_handle_description, }; static void redraw(struct dp_output *output); @@ -261,7 +277,7 @@ static void redraw(struct dp_output *output) { } } if (buffer == NULL) { - dp_log_error("No free buffers in a swapchain\n"); + dp_log_error("Output %s: no free buffers in a swapchain\n", output->name); return; } buffer->used = true; @@ -331,6 +347,8 @@ void dp_output_create(struct dp_state *state, uint32_t name, struct wl_output *w void dp_output_destroy(struct dp_output *output) { wl_output_release(output->wl_output); + free(output->name); + assert(output->frame == NULL); wl_buffer_destroy(output->frame_buffer); munmap(output->frame_data, output->frame_size); diff --git a/src/util.c b/src/util.c index a99efe7..94790e9 100644 --- a/src/util.c +++ b/src/util.c @@ -35,6 +35,14 @@ void *dp_zalloc(size_t size) { return ptr; } +char *dp_strdup(const char *str) { + char *ptr = strdup(str); + if (ptr == NULL) { + dp_log_fatal("Failed to duplicate %s", str); + } + return ptr; +} + const char *dp_ext_from_path(const char *path) { size_t len = strlen(path); for (size_t i = len; i-- > 0;) {