mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	view: make move_sub_views() use append_children method
...to share common code with minimize_sub_views() Also, fix a bug in the move-to-back functions to move the window hierarchy in the right order. Helped-by: @Consolatis
This commit is contained in:
		
							parent
							
								
									e991eae103
								
							
						
					
					
						commit
						2c14a5a406
					
				
					 4 changed files with 35 additions and 91 deletions
				
			
		| 
						 | 
				
			
			@ -7,10 +7,17 @@
 | 
			
		|||
 * Please note: only xdg-shell-toplevel-view and xwayland-view view_impl
 | 
			
		||||
 * functions should call these functions.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
enum z_direction {
 | 
			
		||||
	LAB_TO_FRONT,
 | 
			
		||||
	LAB_TO_BACK,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct view;
 | 
			
		||||
 | 
			
		||||
void view_impl_move_to_front(struct view *view);
 | 
			
		||||
void view_impl_move_to_back(struct view *view);
 | 
			
		||||
void view_impl_move_sub_views(struct view *parent, enum z_direction z_direction);
 | 
			
		||||
void view_impl_map(struct view *view);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
// SPDX-License-Identifier: GPL-2.0-only
 | 
			
		||||
/* view-impl-common.c: common code for shell view->impl functions */
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <strings.h>
 | 
			
		||||
#include "common/list.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -24,6 +25,29 @@ view_impl_move_to_back(struct view *view)
 | 
			
		|||
	wlr_scene_node_lower_to_bottom(&view->scene_tree->node);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
view_impl_move_sub_views(struct view *parent, enum z_direction z_direction)
 | 
			
		||||
{
 | 
			
		||||
	assert(parent);
 | 
			
		||||
	if (!parent->impl->append_children) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	struct wl_array subviews;
 | 
			
		||||
	wl_array_init(&subviews);
 | 
			
		||||
	parent->impl->append_children(parent, &subviews);
 | 
			
		||||
 | 
			
		||||
	struct view **view;
 | 
			
		||||
	wl_array_for_each(view, &subviews) {
 | 
			
		||||
		if (z_direction == LAB_TO_FRONT) {
 | 
			
		||||
			view_impl_move_to_front(*view);
 | 
			
		||||
		} else if (z_direction == LAB_TO_BACK) {
 | 
			
		||||
			view_impl_move_to_back(*view);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	wl_array_release(&subviews);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
view_impl_map(struct view *view)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										47
									
								
								src/xdg.c
									
										
									
									
									
								
							
							
						
						
									
										47
									
								
								src/xdg.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -330,49 +330,6 @@ top_parent_of(struct view *view)
 | 
			
		|||
	return toplevel;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
enum z_direction {
 | 
			
		||||
	LAB_TO_FRONT,
 | 
			
		||||
	LAB_TO_BACK,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * TODO: Combine append_children() and move_sub_views() as much as possible.
 | 
			
		||||
 * https://github.com/labwc/labwc/pull/998#discussion_r1284085575
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
move_sub_views(struct view *parent, enum z_direction z_direction)
 | 
			
		||||
{
 | 
			
		||||
	assert(parent);
 | 
			
		||||
 | 
			
		||||
	if (parent->type != LAB_XDG_SHELL_VIEW) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	struct wlr_xdg_toplevel *parent_toplevel = xdg_toplevel_from_view(parent);
 | 
			
		||||
	struct view *view, *next;
 | 
			
		||||
	wl_list_for_each_reverse_safe(view, next, &parent->server->views, link)
 | 
			
		||||
	{
 | 
			
		||||
		/* need to stop here, otherwise loops keeps going forever */
 | 
			
		||||
		if (view == parent) {
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
		if (view->type != LAB_XDG_SHELL_VIEW) {
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (!view->mapped && !view->minimized) {
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (top_parent_of(view) != parent_toplevel) {
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (z_direction == LAB_TO_FRONT) {
 | 
			
		||||
			view_impl_move_to_front(view);
 | 
			
		||||
		} else if (z_direction == LAB_TO_BACK) {
 | 
			
		||||
			view_impl_move_to_back(view);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Return the most senior parent (=root) view */
 | 
			
		||||
static struct view *
 | 
			
		||||
xdg_toplevel_view_get_root(struct view *view)
 | 
			
		||||
| 
						 | 
				
			
			@ -393,15 +350,15 @@ xdg_toplevel_view_move_to_front(struct view *view)
 | 
			
		|||
{
 | 
			
		||||
	struct view *root = xdg_toplevel_view_get_root(view);
 | 
			
		||||
	view_impl_move_to_front(root);
 | 
			
		||||
	move_sub_views(root, LAB_TO_FRONT);
 | 
			
		||||
	view_impl_move_sub_views(root, LAB_TO_FRONT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
xdg_toplevel_view_move_to_back(struct view *view)
 | 
			
		||||
{
 | 
			
		||||
	struct view *root = xdg_toplevel_view_get_root(view);
 | 
			
		||||
	view_impl_move_sub_views(root, LAB_TO_BACK);
 | 
			
		||||
	view_impl_move_to_back(root);
 | 
			
		||||
	move_sub_views(root, LAB_TO_BACK);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -522,50 +522,6 @@ xwayland_view_minimize(struct view *view, bool minimized)
 | 
			
		|||
		minimized);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
enum z_direction {
 | 
			
		||||
	LAB_TO_FRONT,
 | 
			
		||||
	LAB_TO_BACK,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * TODO: Combine append_children() and move_sub_views() as much as possible.
 | 
			
		||||
 * https://github.com/labwc/labwc/pull/998#discussion_r1284085575
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
move_sub_views(struct view *parent, enum z_direction z_direction)
 | 
			
		||||
{
 | 
			
		||||
	assert(parent);
 | 
			
		||||
 | 
			
		||||
	if (parent->type != LAB_XWAYLAND_VIEW) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	struct wlr_xwayland_surface *parent_xwayland_surface =
 | 
			
		||||
		xwayland_surface_from_view(parent);
 | 
			
		||||
	struct view *view, *next;
 | 
			
		||||
	wl_list_for_each_reverse_safe(view, next, &parent->server->views, link)
 | 
			
		||||
	{
 | 
			
		||||
		/* need to stop here, otherwise loops keeps going forever */
 | 
			
		||||
		if (view == parent) {
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
		if (view->type != LAB_XWAYLAND_VIEW) {
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (!view->mapped && !view->minimized) {
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (top_parent_of(view) != parent_xwayland_surface) {
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
		if (z_direction == LAB_TO_FRONT) {
 | 
			
		||||
			view_impl_move_to_front(view);
 | 
			
		||||
		} else if (z_direction == LAB_TO_BACK) {
 | 
			
		||||
			view_impl_move_to_back(view);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct view *
 | 
			
		||||
xwayland_view_get_root(struct view *view)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -578,15 +534,15 @@ xwayland_view_move_to_front(struct view *view)
 | 
			
		|||
{
 | 
			
		||||
	struct view *root = xwayland_view_get_root(view);
 | 
			
		||||
	view_impl_move_to_front(root);
 | 
			
		||||
	move_sub_views(root, LAB_TO_FRONT);
 | 
			
		||||
	view_impl_move_sub_views(root, LAB_TO_FRONT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
xwayland_view_move_to_back(struct view *view)
 | 
			
		||||
{
 | 
			
		||||
	struct view *root = xwayland_view_get_root(view);
 | 
			
		||||
	view_impl_move_sub_views(root, LAB_TO_BACK);
 | 
			
		||||
	view_impl_move_to_back(root);
 | 
			
		||||
	move_sub_views(root, LAB_TO_BACK);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue