From 57a7b3998ea62616223000eb6369c999b4cd1a94 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 13 Dec 2021 18:33:32 +0100 Subject: [PATCH] swaynag: remove xdg-output logic We can just get the output name from wl_output directly, now that wl_output version 4 exists. --- include/swaynag/swaynag.h | 3 -- meson.build | 2 +- swaybar/bar.c | 1 - swaynag/swaynag.c | 63 +++++++++++++-------------------------- 4 files changed, 22 insertions(+), 47 deletions(-) diff --git a/include/swaynag/swaynag.h b/include/swaynag/swaynag.h index 9e39e7162..baa6ee8ba 100644 --- a/include/swaynag/swaynag.h +++ b/include/swaynag/swaynag.h @@ -5,7 +5,6 @@ #include "list.h" #include "pool-buffer.h" #include "swaynag/types.h" -#include "xdg-output-unstable-v1-client-protocol.h" #define SWAYNAG_MAX_HEIGHT 500 @@ -75,13 +74,11 @@ struct swaynag_details { struct swaynag { bool run_display; - int querying_outputs; struct wl_display *display; struct wl_compositor *compositor; struct wl_seat *seat; struct wl_shm *shm; - struct zxdg_output_manager_v1 *xdg_output_manager; struct wl_list outputs; // swaynag_output::link struct wl_list seats; // swaynag_seat::link struct swaynag_output *output; diff --git a/meson.build b/meson.build index 72bce0eee..be1af04ab 100644 --- a/meson.build +++ b/meson.build @@ -37,7 +37,7 @@ endif jsonc = dependency('json-c', version: '>=0.13') pcre = dependency('libpcre') -wayland_server = dependency('wayland-server') +wayland_server = dependency('wayland-server', version: '>=1.20.0') wayland_client = dependency('wayland-client') wayland_cursor = dependency('wayland-cursor') wayland_egl = dependency('wayland-egl') diff --git a/swaybar/bar.c b/swaybar/bar.c index 18b87e6d5..6ffdc9b41 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -54,7 +54,6 @@ static void swaybar_output_free(struct swaybar_output *output) { if (output->input_region != NULL) { wl_region_destroy(output->input_region); } - zxdg_output_v1_destroy(output->xdg_output); wl_output_destroy(output->output); destroy_buffer(&output->buffers[0]); destroy_buffer(&output->buffers[1]); diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index 6d4a7a58d..9b57d5785 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c @@ -307,33 +307,25 @@ static void output_scale(void *data, struct wl_output *output, } } +static void output_name(void *data, struct wl_output *output, + const char *name) { + struct swaynag_output *swaynag_output = data; + swaynag_output->name = strdup(name); + + const char *outname = swaynag_output->swaynag->type->output; + if (!swaynag_output->swaynag->output && outname && + strcmp(outname, name) == 0) { + sway_log(SWAY_DEBUG, "Using output %s", name); + swaynag_output->swaynag->output = swaynag_output; + } +} + static const struct wl_output_listener output_listener = { .geometry = nop, .mode = nop, .done = nop, .scale = output_scale, -}; - -static void xdg_output_handle_name(void *data, - struct zxdg_output_v1 *xdg_output, const char *name) { - struct swaynag_output *swaynag_output = data; - char *outname = swaynag_output->swaynag->type->output; - sway_log(SWAY_DEBUG, "Checking against output %s for %s", name, outname); - if (!swaynag_output->swaynag->output && outname && name - && strcmp(outname, name) == 0) { - sway_log(SWAY_DEBUG, "Using output %s", name); - swaynag_output->swaynag->output = swaynag_output; - } - swaynag_output->name = strdup(name); - zxdg_output_v1_destroy(xdg_output); - swaynag_output->swaynag->querying_outputs--; -} - -static const struct zxdg_output_v1_listener xdg_output_listener = { - .logical_position = nop, - .logical_size = nop, - .done = nop, - .name = xdg_output_handle_name, + .name = output_name, .description = nop, }; @@ -361,33 +353,21 @@ static void handle_global(void *data, struct wl_registry *registry, } else if (strcmp(interface, wl_shm_interface.name) == 0) { swaynag->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); } else if (strcmp(interface, wl_output_interface.name) == 0) { - if (!swaynag->output && swaynag->xdg_output_manager) { - swaynag->querying_outputs++; + if (!swaynag->output) { struct swaynag_output *output = calloc(1, sizeof(struct swaynag_output)); output->wl_output = wl_registry_bind(registry, name, - &wl_output_interface, 3); + &wl_output_interface, 4); output->wl_name = name; output->scale = 1; output->swaynag = swaynag; wl_list_insert(&swaynag->outputs, &output->link); wl_output_add_listener(output->wl_output, &output_listener, output); - - struct zxdg_output_v1 *xdg_output; - xdg_output = zxdg_output_manager_v1_get_xdg_output( - swaynag->xdg_output_manager, output->wl_output); - zxdg_output_v1_add_listener(xdg_output, - &xdg_output_listener, output); } } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { swaynag->layer_shell = wl_registry_bind( registry, name, &zwlr_layer_shell_v1_interface, 1); - } else if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0 - && version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { - swaynag->xdg_output_manager = wl_registry_bind(registry, name, - &zxdg_output_manager_v1_interface, - ZXDG_OUTPUT_V1_NAME_SINCE_VERSION); } } @@ -453,12 +433,11 @@ void swaynag_setup(struct swaynag *swaynag) { assert(swaynag->compositor && swaynag->layer_shell && swaynag->shm); - while (swaynag->querying_outputs > 0) { - if (wl_display_roundtrip(swaynag->display) < 0) { - sway_log(SWAY_ERROR, "Error during outputs init."); - swaynag_destroy(swaynag); - exit(EXIT_FAILURE); - } + // Second roundtrip to get wl_output properties + if (wl_display_roundtrip(swaynag->display) < 0) { + sway_log(SWAY_ERROR, "Error during outputs init."); + swaynag_destroy(swaynag); + exit(EXIT_FAILURE); } if (!swaynag->output && swaynag->type->output) {