swaynag: remove xdg-output logic

We can just get the output name from wl_output directly, now that
wl_output version 4 exists.
This commit is contained in:
Simon Ser 2021-12-13 18:33:32 +01:00 committed by Simon Zeni
parent 4732325f59
commit 57a7b3998e
4 changed files with 22 additions and 47 deletions

View file

@ -5,7 +5,6 @@
#include "list.h" #include "list.h"
#include "pool-buffer.h" #include "pool-buffer.h"
#include "swaynag/types.h" #include "swaynag/types.h"
#include "xdg-output-unstable-v1-client-protocol.h"
#define SWAYNAG_MAX_HEIGHT 500 #define SWAYNAG_MAX_HEIGHT 500
@ -75,13 +74,11 @@ struct swaynag_details {
struct swaynag { struct swaynag {
bool run_display; bool run_display;
int querying_outputs;
struct wl_display *display; struct wl_display *display;
struct wl_compositor *compositor; struct wl_compositor *compositor;
struct wl_seat *seat; struct wl_seat *seat;
struct wl_shm *shm; struct wl_shm *shm;
struct zxdg_output_manager_v1 *xdg_output_manager;
struct wl_list outputs; // swaynag_output::link struct wl_list outputs; // swaynag_output::link
struct wl_list seats; // swaynag_seat::link struct wl_list seats; // swaynag_seat::link
struct swaynag_output *output; struct swaynag_output *output;

View file

@ -37,7 +37,7 @@ endif
jsonc = dependency('json-c', version: '>=0.13') jsonc = dependency('json-c', version: '>=0.13')
pcre = dependency('libpcre') pcre = dependency('libpcre')
wayland_server = dependency('wayland-server') wayland_server = dependency('wayland-server', version: '>=1.20.0')
wayland_client = dependency('wayland-client') wayland_client = dependency('wayland-client')
wayland_cursor = dependency('wayland-cursor') wayland_cursor = dependency('wayland-cursor')
wayland_egl = dependency('wayland-egl') wayland_egl = dependency('wayland-egl')

View file

@ -54,7 +54,6 @@ static void swaybar_output_free(struct swaybar_output *output) {
if (output->input_region != NULL) { if (output->input_region != NULL) {
wl_region_destroy(output->input_region); wl_region_destroy(output->input_region);
} }
zxdg_output_v1_destroy(output->xdg_output);
wl_output_destroy(output->output); wl_output_destroy(output->output);
destroy_buffer(&output->buffers[0]); destroy_buffer(&output->buffers[0]);
destroy_buffer(&output->buffers[1]); destroy_buffer(&output->buffers[1]);

View file

@ -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 = { static const struct wl_output_listener output_listener = {
.geometry = nop, .geometry = nop,
.mode = nop, .mode = nop,
.done = nop, .done = nop,
.scale = output_scale, .scale = output_scale,
}; .name = output_name,
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,
.description = nop, .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) { } else if (strcmp(interface, wl_shm_interface.name) == 0) {
swaynag->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); swaynag->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
} else if (strcmp(interface, wl_output_interface.name) == 0) { } else if (strcmp(interface, wl_output_interface.name) == 0) {
if (!swaynag->output && swaynag->xdg_output_manager) { if (!swaynag->output) {
swaynag->querying_outputs++;
struct swaynag_output *output = struct swaynag_output *output =
calloc(1, sizeof(struct swaynag_output)); calloc(1, sizeof(struct swaynag_output));
output->wl_output = wl_registry_bind(registry, name, output->wl_output = wl_registry_bind(registry, name,
&wl_output_interface, 3); &wl_output_interface, 4);
output->wl_name = name; output->wl_name = name;
output->scale = 1; output->scale = 1;
output->swaynag = swaynag; output->swaynag = swaynag;
wl_list_insert(&swaynag->outputs, &output->link); wl_list_insert(&swaynag->outputs, &output->link);
wl_output_add_listener(output->wl_output, wl_output_add_listener(output->wl_output,
&output_listener, 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) { } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
swaynag->layer_shell = wl_registry_bind( swaynag->layer_shell = wl_registry_bind(
registry, name, &zwlr_layer_shell_v1_interface, 1); 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); assert(swaynag->compositor && swaynag->layer_shell && swaynag->shm);
while (swaynag->querying_outputs > 0) { // Second roundtrip to get wl_output properties
if (wl_display_roundtrip(swaynag->display) < 0) { if (wl_display_roundtrip(swaynag->display) < 0) {
sway_log(SWAY_ERROR, "Error during outputs init."); sway_log(SWAY_ERROR, "Error during outputs init.");
swaynag_destroy(swaynag); swaynag_destroy(swaynag);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
} }
if (!swaynag->output && swaynag->type->output) { if (!swaynag->output && swaynag->type->output) {