wlr_xdg_output_v1: only send name/description once

The xdg-output protocol states that name and description should only be
sent once per output since they do not change.
This commit is contained in:
Brian Ashworth 2019-01-22 15:44:46 -05:00 committed by emersion
parent 88ee102992
commit f3ff40a0eb
1 changed files with 16 additions and 12 deletions

View File

@ -1,4 +1,5 @@
#include <assert.h> #include <assert.h>
#include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
@ -24,7 +25,7 @@ static void output_handle_resource_destroy(struct wl_resource *resource) {
} }
static void output_send_details(struct wlr_xdg_output_v1 *xdg_output, static void output_send_details(struct wlr_xdg_output_v1 *xdg_output,
struct wl_resource *resource) { struct wl_resource *resource, bool updated) {
struct wlr_output *output = xdg_output->layout_output->output; struct wlr_output *output = xdg_output->layout_output->output;
zxdg_output_v1_send_logical_position(resource, zxdg_output_v1_send_logical_position(resource,
@ -32,15 +33,18 @@ static void output_send_details(struct wlr_xdg_output_v1 *xdg_output,
zxdg_output_v1_send_logical_size(resource, zxdg_output_v1_send_logical_size(resource,
xdg_output->width, xdg_output->height); xdg_output->width, xdg_output->height);
uint32_t version = wl_resource_get_version(resource); if (!updated) {
if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { // Name and description should only be sent once per output
zxdg_output_v1_send_name(resource, output->name); uint32_t version = wl_resource_get_version(resource);
} if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) {
if (version >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION) { zxdg_output_v1_send_name(resource, output->name);
char description[128]; }
snprintf(description, sizeof(description), "%s %s %s (%s)", if (version >= ZXDG_OUTPUT_V1_DESCRIPTION_SINCE_VERSION) {
output->make, output->model, output->serial, output->name); char description[128];
zxdg_output_v1_send_description(resource, description); snprintf(description, sizeof(description), "%s %s %s (%s)",
output->make, output->model, output->serial, output->name);
zxdg_output_v1_send_description(resource, description);
}
} }
zxdg_output_v1_send_done(resource); zxdg_output_v1_send_done(resource);
@ -67,7 +71,7 @@ static void output_update(struct wlr_xdg_output_v1 *xdg_output) {
if (updated) { if (updated) {
struct wl_resource *resource; struct wl_resource *resource;
wl_resource_for_each(resource, &xdg_output->resources) { wl_resource_for_each(resource, &xdg_output->resources) {
output_send_details(xdg_output, resource); output_send_details(xdg_output, resource, true);
} }
} }
} }
@ -128,7 +132,7 @@ static void output_manager_handle_get_xdg_output(struct wl_client *client,
wl_list_insert(&xdg_output->resources, wl_list_insert(&xdg_output->resources,
wl_resource_get_link(xdg_output_resource)); wl_resource_get_link(xdg_output_resource));
output_send_details(xdg_output, xdg_output_resource); output_send_details(xdg_output, xdg_output_resource, false);
} }
static const struct zxdg_output_manager_v1_interface static const struct zxdg_output_manager_v1_interface