void (*minimize)(struct view *view, bool minimize);
void (*move_to_front)(struct view *view);
void (*move_to_back)(struct view *view);
+ struct view *(*get_root)(struct view *self);
+ void (*append_children)(struct view *self, struct wl_array *children);
};
struct view {
void view_move_to_front(struct view *view);
void view_move_to_back(struct view *view);
+struct view *view_get_root(struct view *view);
+void view_append_children(struct view *view, struct wl_array *children);
const char *view_get_string_prop(struct view *view, const char *prop);
void view_update_title(struct view *view);
*h = MAX(*h, LAB_MIN_VIEW_HEIGHT);
}
-void
-view_minimize(struct view *view, bool minimized)
+static void
+_minimize(struct view *view, bool minimized)
{
assert(view);
if (view->minimized == minimized) {
}
}
+static void
+minimize_sub_views(struct view *view, bool minimized)
+{
+ struct view **child;
+ struct wl_array children;
+
+ wl_array_init(&children);
+ view_append_children(view, &children);
+ wl_array_for_each(child, &children) {
+ _minimize(*child, minimized);
+ minimize_sub_views(*child, minimized);
+ }
+ wl_array_release(&children);
+}
+
+/*
+ * Minimize the whole view-hierarchy from top to bottom regardless of which one
+ * in the hierarchy requested the minimize. For example, if an 'About' or
+ * 'Open File' dialog is minimized, its toplevel is minimized also. And vice
+ * versa.
+ */
+void
+view_minimize(struct view *view, bool minimized)
+{
+ /*
+ * Minimize the root window first because some xwayland clients send a
+ * request-unmap to sub-windows at this point (for example gimp and its
+ * 'open file' dialog), so it saves trying to unmap them twice
+ */
+ struct view *root = view_get_root(view);
+ _minimize(root, minimized);
+ minimize_sub_views(root, minimized);
+}
+
static bool
view_compute_centered_position(struct view *view, const struct wlr_box *ref,
int w, int h, int *x, int *y)
}
}
+struct view *
+view_get_root(struct view *view)
+{
+ assert(view);
+ if (view->impl->get_root) {
+ return view->impl->get_root(view);
+ }
+ return view;
+}
+
+void
+view_append_children(struct view *view, struct wl_array *children)
+{
+ assert(view);
+ if (view->impl->append_children) {
+ view->impl->append_children(view, children);
+ }
+}
+
const char *
view_get_string_prop(struct view *view, const char *prop)
{
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)
{
/* Return the most senior parent (=root) view */
static struct view *
-root_view_of_view(struct view *view)
+xdg_toplevel_view_get_root(struct view *view)
{
struct wlr_xdg_toplevel *root = top_parent_of(view);
struct wlr_xdg_surface *surface = (struct wlr_xdg_surface *)root->base;
static void
xdg_toplevel_view_move_to_front(struct view *view)
{
- struct view *root = root_view_of_view(view);
+ struct view *root = xdg_toplevel_view_get_root(view);
view_impl_move_to_front(root);
move_sub_views(root, LAB_TO_FRONT);
}
static void
xdg_toplevel_view_move_to_back(struct view *view)
{
- struct view *root = root_view_of_view(view);
+ struct view *root = xdg_toplevel_view_get_root(view);
view_impl_move_to_back(root);
move_sub_views(root, LAB_TO_BACK);
}
+static void
+xdg_toplevel_view_append_children(struct view *self, struct wl_array *children)
+{
+ struct wlr_xdg_toplevel *toplevel = xdg_toplevel_from_view(self);
+ struct view *view;
+
+ wl_list_for_each_reverse(view, &self->server->views, link)
+ {
+ if (view == self) {
+ continue;
+ }
+ if (view->type != LAB_XDG_SHELL_VIEW) {
+ continue;
+ }
+ if (!view->mapped && !view->minimized) {
+ continue;
+ }
+ if (top_parent_of(view) != toplevel) {
+ continue;
+ }
+ struct view **child = wl_array_add(children, sizeof(*child));
+ *child = view;
+ }
+}
+
static void
xdg_toplevel_view_set_activated(struct view *view, bool activated)
{
.minimize = xdg_toplevel_view_minimize,
.move_to_front = xdg_toplevel_view_move_to_front,
.move_to_back = xdg_toplevel_view_move_to_back,
+ .get_root = xdg_toplevel_view_get_root,
+ .append_children = xdg_toplevel_view_append_children,
};
void
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)
{
}
static struct view *
-root_view_of_view(struct view *view)
+xwayland_view_get_root(struct view *view)
{
struct wlr_xwayland_surface *root = top_parent_of(view);
return (struct view *)root->data;
static void
xwayland_view_move_to_front(struct view *view)
{
- struct view *root = root_view_of_view(view);
+ struct view *root = xwayland_view_get_root(view);
view_impl_move_to_front(root);
move_sub_views(root, LAB_TO_FRONT);
}
static void
xwayland_view_move_to_back(struct view *view)
{
- struct view *root = root_view_of_view(view);
+ struct view *root = xwayland_view_get_root(view);
view_impl_move_to_back(root);
move_sub_views(root, LAB_TO_BACK);
}
+static void
+xwayland_view_append_children(struct view *self, struct wl_array *children)
+{
+ struct wlr_xwayland_surface *surface = xwayland_surface_from_view(self);
+ struct view *view;
+
+ wl_list_for_each_reverse(view, &self->server->views, link)
+ {
+ if (view == self) {
+ continue;
+ }
+ if (view->type != LAB_XWAYLAND_VIEW) {
+ continue;
+ }
+ /*
+ * This happens when a view has never been mapped or when a
+ * client has requested a `handle_unmap`.
+ */
+ if (!view->surface) {
+ continue;
+ }
+ if (!view->mapped && !view->minimized) {
+ continue;
+ }
+ if (top_parent_of(view) != surface) {
+ continue;
+ }
+ struct view **child = wl_array_add(children, sizeof(*child));
+ *child = view;
+ }
+}
+
static void
xwayland_view_set_activated(struct view *view, bool activated)
{
.minimize = xwayland_view_minimize,
.move_to_front = xwayland_view_move_to_front,
.move_to_back = xwayland_view_move_to_back,
+ .get_root = xwayland_view_get_root,
+ .append_children = xwayland_view_append_children,
};
void