aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/drm/util.c29
-rw-r--r--backend/headless/output.c2
-rw-r--r--backend/wayland/output.c2
-rw-r--r--backend/x11/output.c19
-rw-r--r--include/wlr/types/wlr_output.h4
-rw-r--r--types/output/output.c13
-rw-r--r--types/wlr_output_management_v1.c6
7 files changed, 49 insertions, 26 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(
diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h
index 48b6e6f9..13b6797f 100644
--- a/include/wlr/types/wlr_output.h
+++ b/include/wlr/types/wlr_output.h
@@ -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
diff --git a/types/output/output.c b/types/output/output.c
index 68a74b6b..4f725915 100644
--- a/types/output/output.c
+++ b/types/output/output.c
@@ -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) {
diff --git a/types/wlr_output_management_v1.c b/types/wlr_output_management_v1.c
index 7acfe9d9..2c3ae027 100644
--- a/types/wlr_output_management_v1.c
+++ b/types/wlr_output_management_v1.c
@@ -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);
}