aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/drm/drm.c7
-rw-r--r--examples/screenshot.c4
-rw-r--r--include/wlr/interfaces/wlr_output.h5
-rw-r--r--types/wlr_output.c31
4 files changed, 31 insertions, 16 deletions
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 51a5f636..8f80e65c 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -748,7 +748,6 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
free(edid);
wl_list_insert(&drm->outputs, &wlr_conn->link);
- wlr_output_create_global(&wlr_conn->output, drm->display);
wlr_log(L_INFO, "Found display '%s'", wlr_conn->output.name);
} else {
seen[index] = true;
@@ -756,7 +755,6 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
if (wlr_conn->state == WLR_DRM_CONN_DISCONNECTED &&
drm_conn->connection == DRM_MODE_CONNECTED) {
-
wlr_log(L_INFO, "'%s' connected", wlr_conn->output.name);
wlr_log(L_INFO, "Detected modes:");
@@ -778,14 +776,17 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
wl_list_insert(&wlr_conn->output.modes, &mode->wlr_mode.link);
}
+ wlr_output_create_global(&wlr_conn->output, drm->display);
+
wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET;
wlr_log(L_INFO, "Sending modesetting signal for '%s'",
wlr_conn->output.name);
wl_signal_emit(&drm->backend.events.output_add, &wlr_conn->output);
} else if (wlr_conn->state == WLR_DRM_CONN_CONNECTED &&
drm_conn->connection != DRM_MODE_CONNECTED) {
-
wlr_log(L_INFO, "'%s' disconnected", wlr_conn->output.name);
+
+ wlr_output_destroy_global(&wlr_conn->output);
wlr_drm_connector_cleanup(wlr_conn);
}
diff --git a/examples/screenshot.c b/examples/screenshot.c
index 95af49ca..2a3b74aa 100644
--- a/examples/screenshot.c
+++ b/examples/screenshot.c
@@ -267,10 +267,6 @@ int main(int argc, char *argv[]) {
struct screenshooter_output *output;
wl_list_for_each(output, &output_list, link) {
- if (output->width == 0 || output->height == 0) {
- continue;
- }
-
output->buffer = create_shm_buffer(output->width, output->height, &output->data);
if (output->buffer == NULL) {
return -1;
diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h
index 17dd5538..338d3375 100644
--- a/include/wlr/interfaces/wlr_output.h
+++ b/include/wlr/interfaces/wlr_output.h
@@ -26,7 +26,8 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
const struct wlr_output_impl *impl);
void wlr_output_free(struct wlr_output *output);
void wlr_output_update_matrix(struct wlr_output *output);
-struct wl_global *wlr_output_create_global(
- struct wlr_output *wlr_output, struct wl_display *display);
+struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output,
+ struct wl_display *display);
+void wlr_output_destroy_global(struct wlr_output *wlr_output);
#endif
diff --git a/types/wlr_output.c b/types/wlr_output.c
index 611d4ad1..eb5bdd26 100644
--- a/types/wlr_output.c
+++ b/types/wlr_output.c
@@ -76,16 +76,20 @@ static void wl_output_bind(struct wl_client *wl_client, void *_wlr_output,
struct wlr_output *wlr_output = _wlr_output;
assert(wl_client && wlr_output);
- struct wl_resource *wl_resource = wl_resource_create(
- wl_client, &wl_output_interface, version, id);
- wl_resource_set_implementation(wl_resource, &wl_output_impl,
- wlr_output, wl_output_destroy);
- wl_list_insert(&wlr_output->wl_resources, wl_resource_get_link(wl_resource));
+ struct wl_resource *wl_resource = wl_resource_create(wl_client,
+ &wl_output_interface, version, id);
+ wl_resource_set_implementation(wl_resource, &wl_output_impl, wlr_output,
+ wl_output_destroy);
+ wl_list_insert(&wlr_output->wl_resources,
+ wl_resource_get_link(wl_resource));
wl_output_send_to_resource(wl_resource);
}
-struct wl_global *wlr_output_create_global(
- struct wlr_output *wlr_output, struct wl_display *display) {
+struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output,
+ struct wl_display *display) {
+ if (wlr_output->wl_global != NULL) {
+ return wlr_output->wl_global;
+ }
struct wl_global *wl_global = wl_global_create(display,
&wl_output_interface, 3, wlr_output, wl_output_bind);
wlr_output->wl_global = wl_global;
@@ -93,6 +97,19 @@ struct wl_global *wlr_output_create_global(
return wl_global;
}
+void wlr_output_destroy_global(struct wlr_output *wlr_output) {
+ if (wlr_output->wl_global == NULL) {
+ return;
+ }
+ struct wl_resource *resource, *tmp;
+ wl_resource_for_each_safe(resource, tmp, &wlr_output->wl_resources) {
+ struct wl_list *link = wl_resource_get_link(resource);
+ wl_list_remove(link);
+ }
+ wl_global_destroy(wlr_output->wl_global);
+ wlr_output->wl_global = NULL;
+}
+
void wlr_output_update_matrix(struct wlr_output *output) {
wlr_matrix_texture(output->transform_matrix, output->width, output->height, output->transform);
}