output: turn make/model/serial into char *

This allows the make/model/serial to be NULL when unset, and allows
them to be longer than the hardcoded array length.

This is a breaking change: compositors need to handle the new NULL
case, and we stop setting make/model to useless "headless" or
"wayland" strings.
Simon Ser 3 years ago committed by Simon Zeni
parent 2e69eb1030
commit be86145322

@ -1,9 +1,11 @@
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
#include <drm_fourcc.h>
#include <drm_mode.h>
#include <drm.h>
#include <libudev.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wlr/util/log.h>
#include "backend/drm/drm.h"
@ -64,34 +66,40 @@ static const char *get_manufacturer(struct udev_hwdb *hwdb, uint16_t code) {
void parse_edid(struct wlr_drm_connector *conn, size_t len, const uint8_t *data) {
struct wlr_output *output = &conn->output;
free(output->make);
free(output->model);
free(output->serial);
output->make = NULL;
output->model = NULL;
output->serial = NULL;
if (!data || len < 128) {
snprintf(output->make, sizeof(output->make), "Unknown");
snprintf(output->model, sizeof(output->model), "Unknown");
return;
}
uint16_t id = (data[8] << 8) | data[9];
snprintf(output->make, sizeof(output->make), "%s",
get_manufacturer(conn->backend->hwdb, id));
output->make = strdup(get_manufacturer(conn->backend->hwdb, id));
uint16_t model = data[10] | (data[11] << 8);
snprintf(output->model, sizeof(output->model), "0x%04X", model);
char model_str[32];
snprintf(model_str, sizeof(model_str), "0x%04" PRIX16, model);
uint32_t serial = data[12] | (data[13] << 8) | (data[14] << 8) | (data[15] << 8);
snprintf(output->serial, sizeof(output->serial), "0x%08X", serial);
char serial_str[32];
snprintf(serial_str, sizeof(serial_str), "0x%08" PRIX32, serial);
for (size_t i = 72; i <= 108; i += 18) {
uint16_t flag = (data[i] << 8) | data[i + 1];
if (flag == 0 && data[i + 3] == 0xFC) {
sprintf(output->model, "%.13s", &data[i + 5]);
snprintf(model_str, sizeof(model_str), "%.13s", &data[i + 5]);
// Monitor names are terminated by newline if they're too short
char *nl = strchr(output->model, '\n');
char *nl = strchr(model_str, '\n');
if (nl) {
*nl = '\0';
}
} else if (flag == 0 && data[i + 3] == 0xFF) {
sprintf(output->serial, "%.13s", &data[i + 5]);
snprintf(serial_str, sizeof(serial_str), "%.13s", &data[i + 5]);
// Monitor serial numbers are terminated by newline if they're too
// short
@ -101,6 +109,9 @@ void parse_edid(struct wlr_drm_connector *conn, size_t len, const uint8_t *data)
}
}
}
output->model = strdup(model_str);
output->serial = strdup(serial_str);
}
const char *conn_get_name(uint32_t type_id) {

@ -115,8 +115,6 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
struct wlr_output *wlr_output = &output->wlr_output;
output_set_custom_mode(output, width, height, 0);
strncpy(wlr_output->make, "headless", sizeof(wlr_output->make));
strncpy(wlr_output->model, "headless", sizeof(wlr_output->model));
char name[64];
snprintf(name, sizeof(name), "HEADLESS-%zu", ++backend->last_output_num);

@ -520,8 +520,6 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) {
struct wlr_output *wlr_output = &output->wlr_output;
wlr_output_update_custom_mode(wlr_output, 1280, 720, 0);
strncpy(wlr_output->make, "wayland", sizeof(wlr_output->make));
strncpy(wlr_output->model, "wayland", sizeof(wlr_output->model));
char name[64];
snprintf(name, sizeof(name), "WL-%zu", ++backend->last_output_num);

@ -33,12 +33,19 @@ static void parse_xcb_setup(struct wlr_output *output,
xcb_connection_t *xcb) {
const xcb_setup_t *xcb_setup = xcb_get_setup(xcb);
snprintf(output->make, sizeof(output->make), "%.*s",
xcb_setup_vendor_length(xcb_setup),
xcb_setup_vendor(xcb_setup));
snprintf(output->model, sizeof(output->model), "%"PRIu16".%"PRIu16,
xcb_setup->protocol_major_version,
xcb_setup->protocol_minor_version);
output->make = calloc(1, xcb_setup_vendor_length(xcb_setup) + 1);
if (output->make == NULL) {
wlr_log_errno(WLR_ERROR, "Allocation failed");
return;
}
memcpy(output->make, xcb_setup_vendor(xcb_setup),
xcb_setup_vendor_length(xcb_setup));
char model[64];
snprintf(model, sizeof(model), "%"PRIu16".%"PRIu16,
xcb_setup->protocol_major_version,
xcb_setup->protocol_minor_version);
output->model = strdup(output->model);
}
static struct wlr_x11_output *get_x11_output_from_output(

@ -122,9 +122,7 @@ struct wlr_output {
char *name;
char *description; // may be NULL
char make[56];
char model[16];
char serial[16];
char *make, *model, *serial; // may be NULL
int32_t phys_width, phys_height; // mm
// Note: some backends may have zero modes

@ -17,9 +17,20 @@
static void send_geometry(struct wl_resource *resource) {
struct wlr_output *output = wlr_output_from_resource(resource);
const char *make = output->make;
if (make == NULL) {
make = "Unknown";
}
const char *model = output->model;
if (model == NULL) {
model = "Unknown";
}
wl_output_send_geometry(resource, 0, 0,
output->phys_width, output->phys_height, output->subpixel,
output->make, output->model, output->transform);
make, model, output->transform);
}
static void send_current_mode(struct wl_resource *resource) {

@ -767,13 +767,13 @@ static void manager_send_head(struct wlr_output_manager_v1 *manager,
output->phys_width, output->phys_height);
}
if (version >= ZWLR_OUTPUT_HEAD_V1_MAKE_SINCE_VERSION && output->make[0] != '\0') {
if (version >= ZWLR_OUTPUT_HEAD_V1_MAKE_SINCE_VERSION && output->make != NULL) {
zwlr_output_head_v1_send_make(head_resource, output->make);
}
if (version >= ZWLR_OUTPUT_HEAD_V1_MODEL_SINCE_VERSION && output->model[0] != '\0') {
if (version >= ZWLR_OUTPUT_HEAD_V1_MODEL_SINCE_VERSION && output->model != NULL) {
zwlr_output_head_v1_send_model(head_resource, output->model);
}
if (version >= ZWLR_OUTPUT_HEAD_V1_SERIAL_NUMBER_SINCE_VERSION && output->serial[0] != '\0') {
if (version >= ZWLR_OUTPUT_HEAD_V1_SERIAL_NUMBER_SINCE_VERSION && output->serial != NULL) {
zwlr_output_head_v1_send_serial_number(head_resource, output->serial);
}

Loading…
Cancel
Save