mirror of
https://github.com/labwc/labwc.git
synced 2026-03-09 05:33:53 -04:00
view: commonize sub-view logic in view_move_to_front/back()
The logic was the same for xdg-shell and xwayland views, so move it from the view->impl layer out to the view_move_to_front/back() functions. view->impl->move_to_front/back() still exist for now, in case we want to add xdg/xwayland-specific logic in future, but they now move only one view and not sub-views.
This commit is contained in:
parent
048d22d473
commit
47e80a488e
5 changed files with 57 additions and 90 deletions
|
|
@ -8,16 +8,10 @@
|
||||||
* functions should call these functions.
|
* functions should call these functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum z_direction {
|
|
||||||
LAB_TO_FRONT,
|
|
||||||
LAB_TO_BACK,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct view;
|
struct view;
|
||||||
|
|
||||||
void view_impl_move_to_front(struct view *view);
|
void view_impl_move_to_front(struct view *view);
|
||||||
void view_impl_move_to_back(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);
|
void view_impl_map(struct view *view);
|
||||||
void view_impl_unmap(struct view *view);
|
void view_impl_unmap(struct view *view);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,29 +25,6 @@ view_impl_move_to_back(struct view *view)
|
||||||
wlr_scene_node_lower_to_bottom(&view->scene_tree->node);
|
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
|
void
|
||||||
view_impl_map(struct view *view)
|
view_impl_map(struct view *view)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
60
src/view.c
60
src/view.c
|
|
@ -1325,24 +1325,70 @@ view_snap_to_region(struct view *view, struct region *region,
|
||||||
view_apply_region_geometry(view);
|
view_apply_region_geometry(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
for_each_subview(struct view *view, void (*action)(struct view *))
|
||||||
|
{
|
||||||
|
struct wl_array subviews;
|
||||||
|
struct view **subview;
|
||||||
|
|
||||||
|
wl_array_init(&subviews);
|
||||||
|
view_append_children(view, &subviews);
|
||||||
|
wl_array_for_each(subview, &subviews) {
|
||||||
|
action(*subview);
|
||||||
|
}
|
||||||
|
wl_array_release(&subviews);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
move_to_front(struct view *view)
|
||||||
|
{
|
||||||
|
if (view->impl->move_to_front) {
|
||||||
|
view->impl->move_to_front(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
move_to_back(struct view *view)
|
||||||
|
{
|
||||||
|
if (view->impl->move_to_back) {
|
||||||
|
view->impl->move_to_back(view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In the view_move_to_{front,back} functions, a modal dialog is always
|
||||||
|
* shown above its parent window, and the two always move together, so
|
||||||
|
* other windows cannot come between them.
|
||||||
|
* This is consistent with GTK3/Qt5 applications on mutter and openbox.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
view_move_to_front(struct view *view)
|
view_move_to_front(struct view *view)
|
||||||
{
|
{
|
||||||
assert(view);
|
assert(view);
|
||||||
if (view->impl->move_to_front) {
|
struct view *root = view_get_root(view);
|
||||||
view->impl->move_to_front(view);
|
assert(root);
|
||||||
cursor_update_focus(view->server);
|
|
||||||
|
move_to_front(root);
|
||||||
|
for_each_subview(root, move_to_front);
|
||||||
|
/* make sure view is in front of other sub-views */
|
||||||
|
if (view != root) {
|
||||||
|
move_to_front(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cursor_update_focus(view->server);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
view_move_to_back(struct view *view)
|
view_move_to_back(struct view *view)
|
||||||
{
|
{
|
||||||
assert(view);
|
assert(view);
|
||||||
if (view->impl->move_to_back) {
|
struct view *root = view_get_root(view);
|
||||||
view->impl->move_to_back(view);
|
assert(root);
|
||||||
cursor_update_focus(view->server);
|
|
||||||
}
|
for_each_subview(root, move_to_back);
|
||||||
|
move_to_back(root);
|
||||||
|
|
||||||
|
cursor_update_focus(view->server);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct view *
|
struct view *
|
||||||
|
|
|
||||||
32
src/xdg.c
32
src/xdg.c
|
|
@ -341,34 +341,6 @@ xdg_toplevel_view_get_root(struct view *view)
|
||||||
return (struct view *)surface->data;
|
return (struct view *)surface->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* In the view_move_to_{front,back} functions, a modal dialog is always shown
|
|
||||||
* above its parent window, and the two always move together, so other window
|
|
||||||
* cannot come between them.
|
|
||||||
* This is consistent with GTK3/Qt5 applications on mutter and openbox.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
xdg_toplevel_view_move_to_front(struct view *view)
|
|
||||||
{
|
|
||||||
struct view *root = xdg_toplevel_view_get_root(view);
|
|
||||||
/* FIXME: this exact code is repeated in xwayland.c */
|
|
||||||
view_impl_move_to_front(root);
|
|
||||||
view_impl_move_sub_views(root, LAB_TO_FRONT);
|
|
||||||
/* make sure view is in front of other sub-views */
|
|
||||||
if (view != root) {
|
|
||||||
view_impl_move_to_front(view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
xdg_toplevel_view_move_to_back(struct view *view)
|
|
||||||
{
|
|
||||||
struct view *root = xdg_toplevel_view_get_root(view);
|
|
||||||
/* FIXME: this exact code is repeated in xwayland.c */
|
|
||||||
view_impl_move_sub_views(root, LAB_TO_BACK);
|
|
||||||
view_impl_move_to_back(root);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xdg_toplevel_view_append_children(struct view *self, struct wl_array *children)
|
xdg_toplevel_view_append_children(struct view *self, struct wl_array *children)
|
||||||
{
|
{
|
||||||
|
|
@ -576,8 +548,8 @@ static const struct view_impl xdg_toplevel_view_impl = {
|
||||||
.unmap = xdg_toplevel_view_unmap,
|
.unmap = xdg_toplevel_view_unmap,
|
||||||
.maximize = xdg_toplevel_view_maximize,
|
.maximize = xdg_toplevel_view_maximize,
|
||||||
.minimize = xdg_toplevel_view_minimize,
|
.minimize = xdg_toplevel_view_minimize,
|
||||||
.move_to_front = xdg_toplevel_view_move_to_front,
|
.move_to_front = view_impl_move_to_front,
|
||||||
.move_to_back = xdg_toplevel_view_move_to_back,
|
.move_to_back = view_impl_move_to_back,
|
||||||
.get_root = xdg_toplevel_view_get_root,
|
.get_root = xdg_toplevel_view_get_root,
|
||||||
.append_children = xdg_toplevel_view_append_children,
|
.append_children = xdg_toplevel_view_append_children,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -642,28 +642,6 @@ xwayland_view_get_root(struct view *view)
|
||||||
return (struct view *)root->data;
|
return (struct view *)root->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
xwayland_view_move_to_front(struct view *view)
|
|
||||||
{
|
|
||||||
struct view *root = xwayland_view_get_root(view);
|
|
||||||
/* FIXME: this exact code is repeated in xdg.c */
|
|
||||||
view_impl_move_to_front(root);
|
|
||||||
view_impl_move_sub_views(root, LAB_TO_FRONT);
|
|
||||||
/* make sure view is in front of other sub-views */
|
|
||||||
if (view != root) {
|
|
||||||
view_impl_move_to_front(view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
xwayland_view_move_to_back(struct view *view)
|
|
||||||
{
|
|
||||||
struct view *root = xwayland_view_get_root(view);
|
|
||||||
/* FIXME: this exact code is repeated in xdg.c */
|
|
||||||
view_impl_move_sub_views(root, LAB_TO_BACK);
|
|
||||||
view_impl_move_to_back(root);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xwayland_view_append_children(struct view *self, struct wl_array *children)
|
xwayland_view_append_children(struct view *self, struct wl_array *children)
|
||||||
{
|
{
|
||||||
|
|
@ -749,8 +727,8 @@ static const struct view_impl xwayland_view_impl = {
|
||||||
.unmap = xwayland_view_unmap,
|
.unmap = xwayland_view_unmap,
|
||||||
.maximize = xwayland_view_maximize,
|
.maximize = xwayland_view_maximize,
|
||||||
.minimize = xwayland_view_minimize,
|
.minimize = xwayland_view_minimize,
|
||||||
.move_to_front = xwayland_view_move_to_front,
|
.move_to_front = view_impl_move_to_front,
|
||||||
.move_to_back = xwayland_view_move_to_back,
|
.move_to_back = view_impl_move_to_back,
|
||||||
.get_root = xwayland_view_get_root,
|
.get_root = xwayland_view_get_root,
|
||||||
.append_children = xwayland_view_append_children,
|
.append_children = xwayland_view_append_children,
|
||||||
.is_related = xwayland_view_is_related,
|
.is_related = xwayland_view_is_related,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue