From 3cf7225cec637c90f4a676aa02dee9ad06dadee9 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Tue, 23 Jan 2018 17:40:12 +0100 Subject: [PATCH 1/2] decouples outputenable state and wl_output global This decouples wlr_output_enable and the wl_global. The previously internal functions wlr_output_(destroy/create)_global are exposed and used automatically in the wlr_output_layout to create/tear down the global. The compositor can handle them itself if it wants to, but I think this is the right moment to create/destroy the wl_output when the wlr_output_layout is used. --- backend/drm/drm.c | 6 +++--- backend/headless/backend.c | 2 +- backend/headless/output.c | 2 +- backend/wayland/output.c | 2 +- backend/x11/backend.c | 2 +- include/wlr/types/wlr_output.h | 2 ++ types/wlr_output.c | 20 ++------------------ types/wlr_output_layout.c | 3 +++ 8 files changed, 14 insertions(+), 25 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 47bd4e3a..fc2721f3 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -267,7 +267,7 @@ static void wlr_drm_connector_enable(struct wlr_output *output, bool enable) { wlr_drm_connector_start_renderer(conn); } - wlr_output_update_enabled(&conn->output, enable); + conn->output.enabled = enable; } static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in, @@ -813,7 +813,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { wl_list_insert(&wlr_conn->output.modes, &mode->wlr_mode.link); } - wlr_output_update_enabled(&wlr_conn->output, true); + wlr_conn->output.enabled = true; wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET; wlr_log(L_INFO, "Sending modesetting signal for '%s'", @@ -823,7 +823,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { drm_conn->connection != DRM_MODE_CONNECTED) { wlr_log(L_INFO, "'%s' disconnected", wlr_conn->output.name); - wlr_output_update_enabled(&wlr_conn->output, false); + wlr_conn->output.enabled = false; wlr_drm_connector_cleanup(wlr_conn); } diff --git a/backend/headless/backend.c b/backend/headless/backend.c index cef8eec4..5438f1f4 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -15,7 +15,7 @@ static bool backend_start(struct wlr_backend *wlr_backend) { struct wlr_headless_output *output; wl_list_for_each(output, &backend->outputs, link) { wl_event_source_timer_update(output->frame_timer, output->frame_delay); - wlr_output_update_enabled(&output->wlr_output, true); + output->wlr_output.enabled = true; wl_signal_emit(&backend->backend.events.output_add, &output->wlr_output); } diff --git a/backend/headless/output.c b/backend/headless/output.c index 9fc92e88..b89d4106 100644 --- a/backend/headless/output.c +++ b/backend/headless/output.c @@ -139,7 +139,7 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend, if (backend->started) { wl_event_source_timer_update(output->frame_timer, output->frame_delay); - wlr_output_update_enabled(wlr_output, true); + wlr_output->enabled = true; wl_signal_emit(&backend->backend.events.output_add, wlr_output); } diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 52791679..7a115264 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -326,7 +326,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { } wl_list_insert(&backend->outputs, &output->link); - wlr_output_update_enabled(wlr_output, true); + wlr_output->enabled = true; wl_signal_emit(&backend->backend.events.output_add, wlr_output); return wlr_output; diff --git a/backend/x11/backend.c b/backend/x11/backend.c index e1622d06..2ee23b4f 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -226,7 +226,7 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { xcb_map_window(x11->xcb_conn, output->win); xcb_flush(x11->xcb_conn); - wlr_output_update_enabled(&output->wlr_output, true); + output->wlr_output.enabled = true; wl_signal_emit(&x11->backend.events.output_add, output); wl_signal_emit(&x11->backend.events.input_add, &x11->keyboard_dev); diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 71463cb5..1f0fc1ec 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -89,6 +89,8 @@ struct wlr_output { struct wlr_surface; void wlr_output_enable(struct wlr_output *output, bool enable); +void wlr_output_create_global(); +void wlr_output_destroy_global(); bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode); bool wlr_output_set_custom_mode(struct wlr_output *output, int32_t width, diff --git a/types/wlr_output.c b/types/wlr_output.c index b47fb3a0..52ac3d22 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -113,7 +113,7 @@ static void wl_output_bind(struct wl_client *wl_client, void *data, wl_output_send_to_resource(wl_resource); } -static void wlr_output_create_global(struct wlr_output *output) { +void wlr_output_create_global(struct wlr_output *output) { if (output->wl_global != NULL) { return; } @@ -122,7 +122,7 @@ static void wlr_output_create_global(struct wlr_output *output) { output->wl_global = wl_global; } -static void wlr_output_destroy_global(struct wlr_output *output) { +void wlr_output_destroy_global(struct wlr_output *output) { if (output->wl_global == NULL) { return; } @@ -134,22 +134,6 @@ static void wlr_output_destroy_global(struct wlr_output *output) { output->wl_global = NULL; } -void wlr_output_update_enabled(struct wlr_output *output, bool enabled) { - if (output->enabled == enabled) { - return; - } - - output->enabled = enabled; - - if (enabled) { - wlr_output_create_global(output); - } else { - wlr_output_destroy_global(output); - } - - wl_signal_emit(&output->events.enable, output); -} - static void wlr_output_update_matrix(struct wlr_output *output) { wlr_matrix_texture(output->transform_matrix, output->width, output->height, output->transform); diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index d1d67e7d..b01fb840 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -203,6 +203,7 @@ void wlr_output_layout_add(struct wlr_output_layout *layout, l_output->y = y; l_output->state->auto_configured = false; wlr_output_layout_reconfigure(layout); + wlr_output_create_global(output); wl_signal_emit(&layout->events.add, l_output); } @@ -289,6 +290,7 @@ void wlr_output_layout_remove(struct wlr_output_layout *layout, wlr_output_layout_output_destroy(l_output); wlr_output_layout_reconfigure(layout); } + wlr_output_destroy_global(output); } void wlr_output_layout_output_coords(struct wlr_output_layout *layout, @@ -394,6 +396,7 @@ void wlr_output_layout_add_auto(struct wlr_output_layout *layout, l_output->state->auto_configured = true; wlr_output_layout_reconfigure(layout); + wlr_output_create_global(output); wl_signal_emit(&layout->events.add, l_output); } From f946c10cb171644e915deeaa40b5e8f8344a808c Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Wed, 24 Jan 2018 10:23:48 +0100 Subject: [PATCH 2/2] re-adds wlr_output_update_enabled Re-add the wlr_output_update_enabled to make sure wlr_output::events.enable is called when the output enabled state changes. --- backend/drm/drm.c | 6 +++--- backend/headless/backend.c | 2 +- backend/headless/output.c | 2 +- backend/wayland/output.c | 2 +- backend/x11/backend.c | 2 +- include/wlr/types/wlr_output.h | 4 ++-- types/wlr_output.c | 9 +++++++++ 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/backend/drm/drm.c b/backend/drm/drm.c index fc2721f3..47bd4e3a 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -267,7 +267,7 @@ static void wlr_drm_connector_enable(struct wlr_output *output, bool enable) { wlr_drm_connector_start_renderer(conn); } - conn->output.enabled = enable; + wlr_output_update_enabled(&conn->output, enable); } static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in, @@ -813,7 +813,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { wl_list_insert(&wlr_conn->output.modes, &mode->wlr_mode.link); } - wlr_conn->output.enabled = true; + wlr_output_update_enabled(&wlr_conn->output, true); wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET; wlr_log(L_INFO, "Sending modesetting signal for '%s'", @@ -823,7 +823,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { drm_conn->connection != DRM_MODE_CONNECTED) { wlr_log(L_INFO, "'%s' disconnected", wlr_conn->output.name); - wlr_conn->output.enabled = false; + wlr_output_update_enabled(&wlr_conn->output, false); wlr_drm_connector_cleanup(wlr_conn); } diff --git a/backend/headless/backend.c b/backend/headless/backend.c index 5438f1f4..cef8eec4 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -15,7 +15,7 @@ static bool backend_start(struct wlr_backend *wlr_backend) { struct wlr_headless_output *output; wl_list_for_each(output, &backend->outputs, link) { wl_event_source_timer_update(output->frame_timer, output->frame_delay); - output->wlr_output.enabled = true; + wlr_output_update_enabled(&output->wlr_output, true); wl_signal_emit(&backend->backend.events.output_add, &output->wlr_output); } diff --git a/backend/headless/output.c b/backend/headless/output.c index b89d4106..9fc92e88 100644 --- a/backend/headless/output.c +++ b/backend/headless/output.c @@ -139,7 +139,7 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend, if (backend->started) { wl_event_source_timer_update(output->frame_timer, output->frame_delay); - wlr_output->enabled = true; + wlr_output_update_enabled(wlr_output, true); wl_signal_emit(&backend->backend.events.output_add, wlr_output); } diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 7a115264..52791679 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -326,7 +326,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { } wl_list_insert(&backend->outputs, &output->link); - wlr_output->enabled = true; + wlr_output_update_enabled(wlr_output, true); wl_signal_emit(&backend->backend.events.output_add, wlr_output); return wlr_output; diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 2ee23b4f..e1622d06 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -226,7 +226,7 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { xcb_map_window(x11->xcb_conn, output->win); xcb_flush(x11->xcb_conn); - output->wlr_output.enabled = true; + wlr_output_update_enabled(&output->wlr_output, true); wl_signal_emit(&x11->backend.events.output_add, output); wl_signal_emit(&x11->backend.events.input_add, &x11->keyboard_dev); diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 1f0fc1ec..55431ab1 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -89,8 +89,8 @@ struct wlr_output { struct wlr_surface; void wlr_output_enable(struct wlr_output *output, bool enable); -void wlr_output_create_global(); -void wlr_output_destroy_global(); +void wlr_output_create_global(struct wlr_output *output); +void wlr_output_destroy_global(struct wlr_output *output); bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode); bool wlr_output_set_custom_mode(struct wlr_output *output, int32_t width, diff --git a/types/wlr_output.c b/types/wlr_output.c index 52ac3d22..426926ac 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -134,6 +134,15 @@ void wlr_output_destroy_global(struct wlr_output *output) { output->wl_global = NULL; } +void wlr_output_update_enabled(struct wlr_output *output, bool enabled) { + if (output->enabled == enabled) { + return; + } + + output->enabled = enabled; + wl_signal_emit(&output->events.enable, output); +} + static void wlr_output_update_matrix(struct wlr_output *output) { wlr_matrix_texture(output->transform_matrix, output->width, output->height, output->transform);