mirror of
https://github.com/labwc/labwc.git
synced 2025-11-01 22:58:47 -04:00
view: add view_for_each_reverse() macro
This commit is contained in:
parent
da1f28f3dd
commit
e274c588c0
2 changed files with 47 additions and 3 deletions
|
|
@ -386,6 +386,22 @@ bool view_matches_query(struct view *view, struct view_query *query);
|
|||
view; \
|
||||
view = view_next(head, view, criteria))
|
||||
|
||||
/**
|
||||
* for_each_view_reverse() - iterate over all views which match criteria
|
||||
* @view: Iterator.
|
||||
* @head: Head of list to iterate over.
|
||||
* @criteria: Criteria to match against.
|
||||
* Example:
|
||||
* struct view *view;
|
||||
* for_each_view_reverse(view, &server->views, LAB_VIEW_CRITERIA_NONE) {
|
||||
* printf("%s\n", view_get_string_prop(view, "app_id"));
|
||||
* }
|
||||
*/
|
||||
#define for_each_view_reverse(view, head, criteria) \
|
||||
for (view = view_prev(head, NULL, criteria); \
|
||||
view; \
|
||||
view = view_prev(head, view, criteria))
|
||||
|
||||
/**
|
||||
* view_next() - Get next view which matches criteria.
|
||||
* @head: Head of list to iterate over.
|
||||
|
|
@ -398,6 +414,18 @@ bool view_matches_query(struct view *view, struct view_query *query);
|
|||
struct view *view_next(struct wl_list *head, struct view *view,
|
||||
enum lab_view_criteria criteria);
|
||||
|
||||
/**
|
||||
* view_prev() - Get previous view which matches criteria.
|
||||
* @head: Head of list to iterate over.
|
||||
* @view: Current view from which to find the previous one. If NULL is provided
|
||||
* as the view argument, the end of the list will be used.
|
||||
* @criteria: Criteria to match against.
|
||||
*
|
||||
* Returns NULL if there are no views matching the criteria.
|
||||
*/
|
||||
struct view *view_prev(struct wl_list *head, struct view *view,
|
||||
enum lab_view_criteria criteria);
|
||||
|
||||
/*
|
||||
* Same as `view_next()` except that they iterate one whole cycle rather than
|
||||
* stopping at the list-head
|
||||
|
|
|
|||
16
src/view.c
16
src/view.c
|
|
@ -269,6 +269,22 @@ view_next(struct wl_list *head, struct view *view, enum lab_view_criteria criter
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct view *
|
||||
view_prev(struct wl_list *head, struct view *view, enum lab_view_criteria criteria)
|
||||
{
|
||||
assert(head);
|
||||
|
||||
struct wl_list *elm = view ? &view->link : head;
|
||||
|
||||
for (elm = elm->prev; elm != head; elm = elm->prev) {
|
||||
view = wl_container_of(elm, view, link);
|
||||
if (matches_criteria(view, criteria)) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct view *
|
||||
view_next_no_head_stop(struct wl_list *head, struct view *from,
|
||||
enum lab_view_criteria criteria)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue