aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/drm/drm.c65
-rw-r--r--backend/drm/properties.c1
-rw-r--r--include/backend/drm/properties.h1
-rw-r--r--include/wlr/types/wlr_gtk_primary_selection.h1
-rw-r--r--types/wlr_gtk_primary_selection.c15
5 files changed, 55 insertions, 28 deletions
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 97028dc7..0acb0324 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -991,36 +991,43 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, bool *changed_outputs) {
}
}
-static uint32_t get_possible_crtcs(int fd, uint32_t conn_id) {
- drmModeConnector *conn = drmModeGetConnector(fd, conn_id);
- if (!conn) {
- wlr_log_errno(WLR_ERROR, "Failed to get DRM connector");
- return 0;
- }
+static uint32_t get_possible_crtcs(int fd, drmModeRes *res,
+ drmModeConnector *conn, bool is_mst) {
+ uint32_t ret = 0;
- if (conn->connection != DRM_MODE_CONNECTED || conn->count_modes == 0) {
- wlr_log(WLR_ERROR, "Output is not connected");
- goto error_conn;
+ for (int i = 0; i < conn->count_encoders; ++i) {
+ drmModeEncoder *enc = drmModeGetEncoder(fd, conn->encoders[i]);
+ if (!enc) {
+ continue;
+ }
+
+ ret |= enc->possible_crtcs;
+
+ drmModeFreeEncoder(enc);
}
- drmModeEncoder *enc = NULL;
- for (int i = 0; !enc && i < conn->count_encoders; ++i) {
- enc = drmModeGetEncoder(fd, conn->encoders[i]);
+ // Sometimes DP MST connectors report no encoders, so we'll loop though
+ // all of the encoders of the MST type instead.
+ // TODO: See if there is a better solution.
+
+ if (!is_mst || ret) {
+ return ret;
}
- if (!enc) {
- wlr_log(WLR_ERROR, "Failed to get DRM encoder");
- goto error_conn;
+ for (int i = 0; i < res->count_encoders; ++i) {
+ drmModeEncoder *enc = drmModeGetEncoder(fd, res->encoders[i]);
+ if (!enc) {
+ continue;
+ }
+
+ if (enc->encoder_type == DRM_MODE_ENCODER_DPMST) {
+ ret |= enc->possible_crtcs;
+ }
+
+ drmModeFreeEncoder(enc);
}
- uint32_t ret = enc->possible_crtcs;
- drmModeFreeEncoder(enc);
- drmModeFreeConnector(conn);
return ret;
-
-error_conn:
- drmModeFreeConnector(conn);
- return 0;
}
void scan_drm_connectors(struct wlr_drm_backend *drm) {
@@ -1050,7 +1057,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
drmModeEncoder *curr_enc = drmModeGetEncoder(drm->fd,
drm_conn->encoder_id);
- int index = -1;
+ ssize_t index = -1;
struct wlr_drm_connector *c, *wlr_conn = NULL;
wl_list_for_each(c, &drm->outputs, link) {
index++;
@@ -1086,7 +1093,7 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
wlr_conn->old_crtc = drmModeGetCrtc(drm->fd, curr_enc->crtc_id);
}
- wl_list_insert(&drm->outputs, &wlr_conn->link);
+ wl_list_insert(drm->outputs.prev, &wlr_conn->link);
wlr_log(WLR_INFO, "Found connector '%s'", wlr_conn->output.name);
} else {
seen[index] = true;
@@ -1167,7 +1174,8 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
wl_list_insert(&wlr_conn->output.modes, &mode->wlr_mode.link);
}
- wlr_conn->possible_crtc = get_possible_crtcs(drm->fd, wlr_conn->id);
+ wlr_conn->possible_crtc = get_possible_crtcs(drm->fd, res, drm_conn,
+ wlr_conn->props.path != 0);
if (wlr_conn->possible_crtc == 0) {
wlr_log(WLR_ERROR, "No CRTC possible for connector '%s'",
wlr_conn->output.name);
@@ -1178,7 +1186,8 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET;
new_outputs[new_outputs_len++] = wlr_conn;
- } else if (wlr_conn->state == WLR_DRM_CONN_CONNECTED &&
+ } 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);
@@ -1191,9 +1200,11 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
drmModeFreeResources(res);
+ // Iterate in reverse order because we'll remove items from the list and
+ // still want indices to remain correct.
struct wlr_drm_connector *conn, *tmp_conn;
size_t index = wl_list_length(&drm->outputs);
- wl_list_for_each_safe(conn, tmp_conn, &drm->outputs, link) {
+ wl_list_for_each_reverse_safe(conn, tmp_conn, &drm->outputs, link) {
index--;
if (index >= seen_len || seen[index]) {
continue;
diff --git a/backend/drm/properties.c b/backend/drm/properties.c
index 5ca4c8ac..5541d1be 100644
--- a/backend/drm/properties.c
+++ b/backend/drm/properties.c
@@ -22,6 +22,7 @@ static const struct prop_info connector_info[] = {
{ "CRTC_ID", INDEX(crtc_id) },
{ "DPMS", INDEX(dpms) },
{ "EDID", INDEX(edid) },
+ { "PATH", INDEX(path) },
{ "link-status", INDEX(link_status) },
#undef INDEX
};
diff --git a/include/backend/drm/properties.h b/include/backend/drm/properties.h
index 321b4492..b4d43bdd 100644
--- a/include/backend/drm/properties.h
+++ b/include/backend/drm/properties.h
@@ -15,6 +15,7 @@ union wlr_drm_connector_props {
uint32_t edid;
uint32_t dpms;
uint32_t link_status; // not guaranteed to exist
+ uint32_t path;
// atomic-modesetting only
diff --git a/include/wlr/types/wlr_gtk_primary_selection.h b/include/wlr/types/wlr_gtk_primary_selection.h
index 7cf34201..436a50d2 100644
--- a/include/wlr/types/wlr_gtk_primary_selection.h
+++ b/include/wlr/types/wlr_gtk_primary_selection.h
@@ -36,6 +36,7 @@ struct wlr_gtk_primary_selection_device {
struct wl_list resources; // wl_resource_get_link
struct wl_list offers; // wl_resource_get_link
+ uint32_t selection_serial;
struct wl_listener seat_destroy;
struct wl_listener seat_focus_change;
diff --git a/types/wlr_gtk_primary_selection.c b/types/wlr_gtk_primary_selection.c
index 5f349154..18bc624a 100644
--- a/types/wlr_gtk_primary_selection.c
+++ b/types/wlr_gtk_primary_selection.c
@@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#include <assert.h>
+#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -97,6 +98,7 @@ static void destroy_offer(struct wl_resource *resource) {
struct client_data_source {
struct wlr_primary_selection_source source;
struct wl_resource *resource;
+ bool finalized;
};
static void client_source_send(
@@ -137,6 +139,9 @@ static void source_handle_offer(struct wl_client *client,
if (source == NULL) {
return;
}
+ if (source->finalized) {
+ wlr_log(WLR_DEBUG, "Offering additional MIME type after set_selection");
+ }
char *dup_mime_type = strdup(mime_type);
if (dup_mime_type == NULL) {
@@ -199,10 +204,18 @@ static void device_handle_set_selection(struct wl_client *client,
struct wlr_primary_selection_source *source = NULL;
if (client_source != NULL) {
+ client_source->finalized = true;
source = &client_source->source;
}
- // TODO: serial checking
+ // TODO: improve serial validation
+ if (device->seat->primary_selection_source != NULL &&
+ device->selection_serial - serial < UINT32_MAX / 2) {
+ wlr_log(WLR_DEBUG, "Rejecting set_selection request, invalid serial "
+ "(%"PRIu32" <= %"PRIu32")", serial, device->selection_serial);
+ return;
+ }
+ device->selection_serial = serial;
wlr_seat_set_primary_selection(device->seat, source);
}