[PATCH weston 01/10] desktop-shell: Simplify popup_end_grab popup_done sending loop
Jonas Ådahl
jadahl at gmail.com
Thu Feb 12 22:01:53 PST 2015
Can just use wl_list_for_each_safe instead of dealing with pointers
ourself.
Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
desktop-shell/shell.c | 36 +++++++++++++++---------------------
1 file changed, 15 insertions(+), 21 deletions(-)
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index f28fc10..db0c5a9 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -3059,20 +3059,18 @@ destroy_shell_seat(struct wl_listener *listener, void *data)
struct shell_seat *shseat =
container_of(listener,
struct shell_seat, seat_destroy_listener);
- struct shell_surface *shsurf, *prev = NULL;
+ struct shell_surface *shsurf, *next;
if (shseat->popup_grab.grab.interface == &popup_grab_interface) {
weston_pointer_end_grab(shseat->popup_grab.grab.pointer);
shseat->popup_grab.client = NULL;
- wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
+ wl_list_for_each_safe(shsurf, next,
+ &shseat->popup_grab.surfaces_list,
+ popup.grab_link) {
shsurf->popup.shseat = NULL;
- if (prev) {
- wl_list_init(&prev->popup.grab_link);
- }
- prev = shsurf;
+ wl_list_init(&shsurf->popup.grab_link);
}
- wl_list_init(&prev->popup.grab_link);
}
wl_list_remove(&shseat->seat_destroy_listener.link);
@@ -3328,7 +3326,7 @@ popup_grab_end(struct weston_pointer *pointer)
struct shell_seat *shseat =
container_of(grab, struct shell_seat, popup_grab.grab);
struct shell_surface *shsurf;
- struct shell_surface *prev = NULL;
+ struct shell_surface *next;
if (pointer->grab->interface == &popup_grab_interface) {
weston_pointer_end_grab(grab->pointer);
@@ -3336,15 +3334,13 @@ popup_grab_end(struct weston_pointer *pointer)
shseat->popup_grab.grab.interface = NULL;
assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
/* Send the popup_done event to all the popups open */
- wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
+ wl_list_for_each_safe(shsurf, next,
+ &shseat->popup_grab.surfaces_list,
+ popup.grab_link) {
shell_surface_send_popup_done(shsurf);
shsurf->popup.shseat = NULL;
- if (prev) {
- wl_list_init(&prev->popup.grab_link);
- }
- prev = shsurf;
+ wl_list_init(&shsurf->popup.grab_link);
}
- wl_list_init(&prev->popup.grab_link);
wl_list_init(&shseat->popup_grab.surfaces_list);
}
}
@@ -3356,7 +3352,7 @@ touch_popup_grab_end(struct weston_touch *touch)
struct shell_seat *shseat =
container_of(grab, struct shell_seat, popup_grab.touch_grab);
struct shell_surface *shsurf;
- struct shell_surface *prev = NULL;
+ struct shell_surface *next;
if (touch->grab->interface == &touch_popup_grab_interface) {
weston_touch_end_grab(grab->touch);
@@ -3364,15 +3360,13 @@ touch_popup_grab_end(struct weston_touch *touch)
shseat->popup_grab.touch_grab.interface = NULL;
assert(!wl_list_empty(&shseat->popup_grab.surfaces_list));
/* Send the popup_done event to all the popups open */
- wl_list_for_each(shsurf, &shseat->popup_grab.surfaces_list, popup.grab_link) {
+ wl_list_for_each_safe(shsurf, next,
+ &shseat->popup_grab.surfaces_list,
+ popup.grab_link) {
shell_surface_send_popup_done(shsurf);
shsurf->popup.shseat = NULL;
- if (prev) {
- wl_list_init(&prev->popup.grab_link);
- }
- prev = shsurf;
+ wl_list_init(&shsurf->popup.grab_link);
}
- wl_list_init(&prev->popup.grab_link);
wl_list_init(&shseat->popup_grab.surfaces_list);
}
}
--
2.1.0
More information about the wayland-devel
mailing list