diff options
author | Simon Ser <contact@emersion.fr> | 2022-05-23 10:32:26 +0200 |
---|---|---|
committer | Simon Zeni <simon@bl4ckb0ne.ca> | 2022-05-26 13:36:06 +0000 |
commit | be86145322e6157994b348711b7bedd209b565ea (patch) | |
tree | 6bb25298bff2a0b6be3db64769b9f103d789cd64 /backend | |
parent | 2e69eb10303f3074d6cafef30e7e1ce49cb7a1ac (diff) |
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.
Diffstat (limited to 'backend')
-rw-r--r-- | backend/drm/util.c | 29 | ||||
-rw-r--r-- | backend/headless/output.c | 2 | ||||
-rw-r--r-- | backend/wayland/output.c | 2 | ||||
-rw-r--r-- | backend/x11/output.c | 19 |
4 files changed, 33 insertions, 19 deletions
diff --git a/backend/drm/util.c b/backend/drm/util.c index 33446fd7..8588fa86 100644 --- a/backend/drm/util.c +++ b/backend/drm/util.c @@ -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) { diff --git a/backend/headless/output.c b/backend/headless/output.c index 10de845f..824a265e 100644 --- a/backend/headless/output.c +++ b/backend/headless/output.c @@ -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); diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 65084b7a..87b8ca1f 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -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); diff --git a/backend/x11/output.c b/backend/x11/output.c index 86e1dfd8..38310374 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -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( |