Add output_cycle to get next/prev outputs

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
pull/175/head
Jim Ramsay 2022-10-08 14:45:14 -04:00 committed by Andri Yngvason
parent a1aa69625c
commit 4018c698c2
2 changed files with 25 additions and 0 deletions

View File

@ -60,6 +60,14 @@ struct output* output_find_by_id(struct wl_list* list, uint32_t id);
struct output* output_find_by_name(struct wl_list* list, const char* name);
struct output* output_first(struct wl_list* list);
enum output_cycle_direction {
OUTPUT_CYCLE_FORWARD,
OUTPUT_CYCLE_REVERSE,
};
struct output* output_cycle(const struct wl_list* list,
const struct output* current,
enum output_cycle_direction);
uint32_t output_get_transformed_width(const struct output* self);
uint32_t output_get_transformed_height(const struct output* self);

View File

@ -285,3 +285,20 @@ struct output* output_first(struct wl_list* list)
return output;
}
struct output* output_cycle(const struct wl_list* list,
const struct output* current,
enum output_cycle_direction direction)
{
const struct wl_list* iter = current ? &current->link : list;
iter = (direction == OUTPUT_CYCLE_FORWARD) ?
iter->next : iter->prev;
if (iter == list) {
if (wl_list_empty(list))
return NULL;
iter = (direction == OUTPUT_CYCLE_FORWARD) ?
iter->next : iter->prev;
}
struct output* output;
return wl_container_of(iter, output, link);
}