From 019ffe8a5ba7f97181c56ad2b9a772c717391feb Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 9 Dec 2020 15:11:06 +0100 Subject: backend/drm: introduce wlr_drm_connector.name The DRM backend is a little special when it comes to wlr_outputs: the wlr_drm_connectors are long-lived and are created even when no screen is connected. A wlr_drm_connector only advertises a wlr_output to the compositor when a screen is connected. As such, most of wlr_output's state is invalid when the connector is disconnected. We want to stop using wlr_output state on disconnected connectors. Introduce wlr_drm_connector.name which is always valid regardless of the connector status to avoid reading wlr_output.name when disconnected. --- backend/drm/atomic.c | 2 +- backend/drm/drm.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'backend/drm') diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c index f230419f..fe67244f 100644 --- a/backend/drm/atomic.c +++ b/backend/drm/atomic.c @@ -33,7 +33,7 @@ static bool atomic_commit(struct atomic *atom, int ret = drmModeAtomicCommit(drm->fd, atom->req, flags, drm); if (ret) { wlr_log_errno(WLR_ERROR, "%s: Atomic %s failed (%s)", - conn->output.name, + conn->name, (flags & DRM_MODE_ATOMIC_TEST_ONLY) ? "test" : "commit", (flags & DRM_MODE_ATOMIC_ALLOW_MODESET) ? "modeset" : "pageflip"); return false; diff --git a/backend/drm/drm.c b/backend/drm/drm.c index d64b8cca..82b928b3 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -1087,8 +1087,7 @@ static void realloc_crtcs(struct wlr_drm_backend *drm) { connectors[i] = conn; wlr_log(WLR_DEBUG, " '%s' crtc=%d state=%d desired_enabled=%d", - conn->output.name, - conn->crtc ? (int)(conn->crtc - drm->crtcs) : -1, + conn->name, conn->crtc ? (int)(conn->crtc - drm->crtcs) : -1, conn->state, conn->desired_enabled); if (conn->crtc) { @@ -1146,9 +1145,7 @@ static void realloc_crtcs(struct wlr_drm_backend *drm) { bool prev_enabled = conn->crtc; wlr_log(WLR_DEBUG, " '%s' crtc=%zd state=%d desired_enabled=%d", - conn->output.name, - connector_match[i], - conn->state, conn->desired_enabled); + conn->name, connector_match[i], conn->state, conn->desired_enabled); // We don't need to change anything. if (prev_enabled && connector_match[i] == conn->crtc - drm->crtcs) { @@ -1265,7 +1262,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) { wlr_conn->state = WLR_DRM_CONN_DISCONNECTED; wlr_conn->id = drm_conn->connector_id; - snprintf(wlr_conn->output.name, sizeof(wlr_conn->output.name), + snprintf(wlr_conn->name, sizeof(wlr_conn->name), "%s-%"PRIu32, conn_get_name(drm_conn->connector_type), drm_conn->connector_type_id); @@ -1274,7 +1271,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) { } wl_list_insert(drm->outputs.prev, &wlr_conn->link); - wlr_log(WLR_INFO, "Found connector '%s'", wlr_conn->output.name); + wlr_log(WLR_INFO, "Found connector '%s'", wlr_conn->name); } else { seen[index] = true; } @@ -1310,10 +1307,13 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) { if (wlr_conn->state == WLR_DRM_CONN_DISCONNECTED && drm_conn->connection == DRM_MODE_CONNECTED) { - wlr_log(WLR_INFO, "'%s' connected", wlr_conn->output.name); + wlr_log(WLR_INFO, "'%s' connected", wlr_conn->name); wlr_log(WLR_DEBUG, "Current CRTC: %d", wlr_conn->crtc ? (int)wlr_conn->crtc->id : -1); + strncpy(wlr_conn->output.name, wlr_conn->name, + sizeof(wlr_conn->output.name) - 1); + wlr_conn->output.phys_width = drm_conn->mmWidth; wlr_conn->output.phys_height = drm_conn->mmHeight; wlr_log(WLR_INFO, "Physical size: %"PRId32"x%"PRId32, @@ -1379,7 +1379,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) { } else if ((wlr_conn->state == WLR_DRM_CONN_CONNECTED || wlr_conn->state == WLR_DRM_CONN_NEEDS_MODESET) && drm_conn->connection != DRM_MODE_CONNECTED) { - wlr_log(WLR_INFO, "'%s' disconnected", wlr_conn->output.name); + wlr_log(WLR_INFO, "'%s' disconnected", wlr_conn->name); drm_connector_cleanup(wlr_conn); } @@ -1400,7 +1400,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) { continue; } - wlr_log(WLR_INFO, "'%s' disappeared", conn->output.name); + wlr_log(WLR_INFO, "'%s' disappeared", conn->name); drm_connector_cleanup(conn); wlr_output_destroy(&conn->output); -- cgit v1.2.3