From 097ea84cda70a71ad8ea5940b3b3d277167424e5 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Tue, 30 Aug 2022 19:05:38 +0300 Subject: output-layout: improve API - wlr_output_layout_add{,_auto}() now return a bool indicating whether the function has succeeded. - wlr_output_layout_move() is removed. Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/1083 --- include/wlr/types/wlr_output_layout.h | 37 +++++++++------- types/wlr_output_layout.c | 83 +++++++++++++---------------------- 2 files changed, 51 insertions(+), 69 deletions(-) diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index 89066ae8..7d567579 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -28,7 +28,7 @@ struct wlr_output_layout { struct wl_list outputs; struct { - struct wl_signal add; + struct wl_signal add; // struct wlr_output_layout_output * struct wl_signal change; struct wl_signal destroy; } events; @@ -77,14 +77,30 @@ struct wlr_output *wlr_output_layout_output_at( /** * Add the output to the layout at the specified coordinates. If the output is - * already part of the output layout, this moves the output. + * already a part of the output layout, it will become manually configured and + * will be moved to the specified coordinates. + * + * Returns true on success, false on a memory allocation error. */ -void wlr_output_layout_add(struct wlr_output_layout *layout, +bool wlr_output_layout_add(struct wlr_output_layout *layout, struct wlr_output *output, int lx, int ly); -void wlr_output_layout_move(struct wlr_output_layout *layout, - struct wlr_output *output, int lx, int ly); +/** + * Add the output to the layout as automatically configured. This will place + * the output in a sensible location in the layout. The coordinates of + * the output in the layout will be adjusted dynamically when the layout + * changes. If the output is already a part of the layout, it will become + * automatically configured. + * + * Returns true on success, false on a memory allocation error. + */ +bool wlr_output_layout_add_auto(struct wlr_output_layout *layout, + struct wlr_output *output); +/** + * Remove the output from the layout. If the output is already not a part of + * the layout, this function is a no-op. + */ void wlr_output_layout_remove(struct wlr_output_layout *layout, struct wlr_output *output); @@ -117,17 +133,6 @@ void wlr_output_layout_closest_point(struct wlr_output_layout *layout, void wlr_output_layout_get_box(struct wlr_output_layout *layout, struct wlr_output *reference, struct wlr_box *dest_box); -/** -* Add an auto configured output to the layout. This will place the output in a -* sensible location in the layout. The coordinates of the output in the layout -* may adjust dynamically when the layout changes. If the output is already in -* the layout, it will become auto configured. If the position of the output is -* set such as with wlr_output_layout_move(), the output will become manually -* configured. -*/ -void wlr_output_layout_add_auto(struct wlr_output_layout *layout, - struct wlr_output *output); - /** * Get the output closest to the center of the layout extents. */ diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 475ce911..83be909c 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -165,28 +165,51 @@ static struct wlr_output_layout_output *output_layout_output_create( return l_output; } -void wlr_output_layout_add(struct wlr_output_layout *layout, - struct wlr_output *output, int lx, int ly) { +static bool output_layout_add(struct wlr_output_layout *layout, + struct wlr_output *output, int lx, int ly, + bool auto_configured) { struct wlr_output_layout_output *l_output = wlr_output_layout_get(layout, output); bool is_new = l_output == NULL; - if (!l_output) { + if (is_new) { l_output = output_layout_output_create(layout, output); - if (!l_output) { - wlr_log(WLR_ERROR, "Failed to create wlr_output_layout_output"); - return; + if (l_output == NULL) { + return false; } } l_output->x = lx; l_output->y = ly; - l_output->auto_configured = false; + l_output->auto_configured = auto_configured; + output_layout_reconfigure(layout); output_update_global(output); if (is_new) { wl_signal_emit_mutable(&layout->events.add, l_output); } + + return true; +} + +bool wlr_output_layout_add(struct wlr_output_layout *layout, + struct wlr_output *output, int lx, int ly) { + return output_layout_add(layout, output, lx, ly, false); +} + +bool wlr_output_layout_add_auto(struct wlr_output_layout *layout, + struct wlr_output *output) { + return output_layout_add(layout, output, 0, 0, true); +} + +void wlr_output_layout_remove(struct wlr_output_layout *layout, + struct wlr_output *output) { + struct wlr_output_layout_output *l_output = + wlr_output_layout_get(layout, output); + if (l_output != NULL) { + output_layout_output_destroy(l_output); + output_layout_reconfigure(layout); + } } struct wlr_output_layout_output *wlr_output_layout_get( @@ -256,30 +279,6 @@ struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout, return NULL; } -void wlr_output_layout_move(struct wlr_output_layout *layout, - struct wlr_output *output, int lx, int ly) { - struct wlr_output_layout_output *l_output = - wlr_output_layout_get(layout, output); - if (l_output) { - l_output->x = lx; - l_output->y = ly; - l_output->auto_configured = false; - output_layout_reconfigure(layout); - } else { - wlr_log(WLR_ERROR, "output not found in this layout: %s", output->name); - } -} - -void wlr_output_layout_remove(struct wlr_output_layout *layout, - struct wlr_output *output) { - struct wlr_output_layout_output *l_output = - wlr_output_layout_get(layout, output); - if (l_output) { - output_layout_output_destroy(l_output); - output_layout_reconfigure(layout); - } -} - void wlr_output_layout_output_coords(struct wlr_output_layout *layout, struct wlr_output *reference, double *lx, double *ly) { assert(layout && reference); @@ -381,28 +380,6 @@ void wlr_output_layout_get_box(struct wlr_output_layout *layout, } } -void wlr_output_layout_add_auto(struct wlr_output_layout *layout, - struct wlr_output *output) { - struct wlr_output_layout_output *l_output = - wlr_output_layout_get(layout, output); - bool is_new = l_output == NULL; - if (!l_output) { - l_output = output_layout_output_create(layout, output); - if (!l_output) { - wlr_log(WLR_ERROR, "Failed to create wlr_output_layout_output"); - return; - } - } - - l_output->auto_configured = true; - output_layout_reconfigure(layout); - output_update_global(output); - - if (is_new) { - wl_signal_emit_mutable(&layout->events.add, l_output); - } -} - struct wlr_output *wlr_output_layout_get_center_output( struct wlr_output_layout *layout) { if (wl_list_empty(&layout->outputs)) { -- cgit v1.2.3