struct wl_list link;
struct output *output;
struct workspace *workspace;
-
- union {
- struct wlr_xdg_surface *xdg_surface;
-#if HAVE_XWAYLAND
- struct wlr_xwayland_surface *xwayland_surface;
-#endif
- };
struct wlr_surface *surface;
struct wlr_scene_tree *scene_tree;
struct wlr_scene_node *scene_node;
struct xdg_toplevel_view {
struct view base;
+ struct wlr_xdg_surface *xdg_surface;
/* Events unique to xdg-toplevel views */
struct wl_listener set_app_id;
#if HAVE_XWAYLAND
struct xwayland_view {
struct view base;
+ struct wlr_xwayland_surface *xwayland_surface;
/* Events unique to XWayland views */
struct wl_listener request_configure;
void view_on_output_destroy(struct view *view);
void view_destroy(struct view *view);
+/* xdg.c */
+struct wlr_xdg_surface *xdg_surface_from_view(struct view *view);
+
+/* xwayland.c */
+#if HAVE_XWAYLAND
+struct wlr_xwayland_surface *xwayland_surface_from_view(struct view *view);
+#endif
+
#endif /* __LABWC_VIEW_H */
double sx = server->seat.cursor->x - lx;
double sy = server->seat.cursor->y - ly;
/* Take into account invisible xdg-shell CSD borders */
- if (view && view->type == LAB_XDG_SHELL_VIEW && view->xdg_surface) {
+ if (view && view->type == LAB_XDG_SHELL_VIEW) {
struct wlr_box geo;
- wlr_xdg_surface_get_geometry(view->xdg_surface, &geo);
+ wlr_xdg_surface_get_geometry(xdg_surface_from_view(view), &geo);
sx += geo.x;
sy += geo.y;
}
static struct wlr_xwayland_surface *
top_parent_of(struct view *view)
{
- struct wlr_xwayland_surface *s = view->xwayland_surface;
+ struct wlr_xwayland_surface *s = xwayland_surface_from_view(view);
while (s->parent) {
s = s->parent;
}
if (!parent || 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)
{
if (!view->mapped && !view->minimized) {
continue;
}
- if (top_parent_of(view) != parent->xwayland_surface) {
+ if (top_parent_of(view) != parent_xwayland_surface) {
continue;
}
move_to_front(view);
#if HAVE_XWAYLAND
case LAB_XWAYLAND_VIEW:
return g_strcmp0(view_get_string_prop(view, "title"),
- view->xwayland_surface->class);
+ view_get_string_prop(view, "class"));
#endif
}
return 1;
int min_height = MIN_VIEW_HEIGHT;
#if HAVE_XWAYLAND
if (view->type == LAB_XWAYLAND_VIEW) {
- xcb_size_hints_t *hints = view->xwayland_surface->size_hints;
+ xcb_size_hints_t *hints =
+ xwayland_surface_from_view(view)->size_hints;
/*
* Honor size increments from WM_SIZE_HINTS. Typically, X11
#include "view.h"
#include "workspaces.h"
+struct wlr_xdg_surface *
+xdg_surface_from_view(struct view *view)
+{
+ assert(view->type == LAB_XDG_SHELL_VIEW);
+ struct xdg_toplevel_view *xdg_toplevel_view =
+ (struct xdg_toplevel_view *)view;
+ assert(xdg_toplevel_view->xdg_surface);
+ return xdg_toplevel_view->xdg_surface;
+}
+
+static struct wlr_xdg_toplevel *
+xdg_toplevel_from_view(struct view *view)
+{
+ struct wlr_xdg_surface *xdg_surface = xdg_surface_from_view(view);
+ assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL);
+ assert(xdg_surface->toplevel);
+ return xdg_surface->toplevel;
+}
+
static void
handle_new_xdg_popup(struct wl_listener *listener, void *data)
{
* geometry.{x,y} seems to be greater than zero. We filter on that
* on the assumption that this will remain true.
*/
- struct wlr_xdg_surface_state *current = &view->xdg_surface->current;
+ struct wlr_xdg_surface_state *current =
+ &xdg_surface_from_view(view)->current;
if (current->geometry.x || current->geometry.y) {
return false;
}
handle_commit(struct wl_listener *listener, void *data)
{
struct view *view = wl_container_of(listener, view, commit);
+ struct wlr_xdg_surface *xdg_surface = xdg_surface_from_view(view);
assert(view->surface);
+
struct wlr_box size;
- wlr_xdg_surface_get_geometry(view->xdg_surface, &size);
+ wlr_xdg_surface_get_geometry(xdg_surface, &size);
bool update_required = false;
}
uint32_t serial = view->pending_move_resize.configure_serial;
- if (serial > 0 && serial >= view->xdg_surface->current.configure_serial) {
+ if (serial > 0 && serial >= xdg_surface->current.configure_serial) {
if (view->pending_move_resize.update_x) {
update_required = true;
view->x = view->pending_move_resize.x +
view->y = view->pending_move_resize.y +
view->pending_move_resize.height - size.height;
}
- if (serial == view->xdg_surface->current.configure_serial) {
+ if (serial == xdg_surface->current.configure_serial) {
view->pending_move_resize.configure_serial = 0;
}
}
assert(view->type == LAB_XDG_SHELL_VIEW);
/* Reset XDG specific surface for good measure */
- view->xdg_surface = NULL;
+ ((struct xdg_toplevel_view *)view)->xdg_surface = NULL;
/* Remove XDG specific handlers */
wl_list_remove(&view->destroy.link);
handle_request_minimize(struct wl_listener *listener, void *data)
{
struct view *view = wl_container_of(listener, view, request_minimize);
- view_minimize(view, view->xdg_surface->toplevel->requested.minimized);
+ view_minimize(view, xdg_toplevel_from_view(view)->requested.minimized);
}
static void
handle_request_maximize(struct wl_listener *listener, void *data)
{
struct view *view = wl_container_of(listener, view, request_maximize);
- view_maximize(view, view->xdg_surface->toplevel->requested.maximized,
+ view_maximize(view, xdg_toplevel_from_view(view)->requested.maximized,
/*store_natural_geometry*/ true);
}
handle_request_fullscreen(struct wl_listener *listener, void *data)
{
struct view *view = wl_container_of(listener, view, request_fullscreen);
- view_set_fullscreen(view,
- view->xdg_surface->toplevel->requested.fullscreen,
- view->xdg_surface->toplevel->requested.fullscreen_output);
+ struct wlr_xdg_toplevel *xdg_toplevel = xdg_toplevel_from_view(view);
+ view_set_fullscreen(view, xdg_toplevel->requested.fullscreen,
+ xdg_toplevel->requested.fullscreen_output);
}
static void
view->pending_move_resize.width = geo.width;
view->pending_move_resize.height = geo.height;
- uint32_t serial = wlr_xdg_toplevel_set_size(view->xdg_surface->toplevel,
+ struct wlr_xdg_toplevel *xdg_toplevel = xdg_toplevel_from_view(view);
+ uint32_t serial = wlr_xdg_toplevel_set_size(xdg_toplevel,
(uint32_t)geo.width, (uint32_t)geo.height);
if (serial > 0) {
view->pending_move_resize.configure_serial = serial;
static void
xdg_toplevel_view_close(struct view *view)
{
- wlr_xdg_toplevel_send_close(view->xdg_surface->toplevel);
+ wlr_xdg_toplevel_send_close(xdg_toplevel_from_view(view));
}
static void
xdg_toplevel_view_maximize(struct view *view, bool maximized)
{
- wlr_xdg_toplevel_set_maximized(view->xdg_surface->toplevel, maximized);
+ wlr_xdg_toplevel_set_maximized(xdg_toplevel_from_view(view), maximized);
}
static void
xdg_toplevel_view_set_activated(struct view *view, bool activated)
{
- struct wlr_xdg_surface *surface = view->xdg_surface;
- if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
- wlr_xdg_toplevel_set_activated(surface->toplevel, activated);
- }
+ wlr_xdg_toplevel_set_activated(xdg_toplevel_from_view(view), activated);
}
static void
xdg_toplevel_view_set_fullscreen(struct view *view, bool fullscreen)
{
- wlr_xdg_toplevel_set_fullscreen(view->xdg_surface->toplevel, fullscreen);
-}
-
-static bool
-istopmost(struct view *view)
-{
- return !view->xdg_surface->toplevel->parent;
+ wlr_xdg_toplevel_set_fullscreen(xdg_toplevel_from_view(view),
+ fullscreen);
}
static struct view *
-parent_of(struct view *view)
+lookup_view_by_xdg_toplevel(struct server *server,
+ struct wlr_xdg_toplevel *xdg_toplevel)
{
- struct view *p;
- wl_list_for_each(p, &view->server->views, link) {
- if (p->xdg_surface->toplevel
- == view->xdg_surface->toplevel->parent) {
- return p;
+ struct view *view;
+ wl_list_for_each(view, &server->views, link) {
+ if (view->type != LAB_XDG_SHELL_VIEW) {
+ continue;
+ }
+ if (xdg_toplevel_from_view(view) == xdg_toplevel) {
+ return view;
}
}
return NULL;
static void
position_xdg_toplevel_view(struct view *view)
{
- if (istopmost(view)) {
+ struct wlr_xdg_surface *xdg_surface = xdg_surface_from_view(view);
+ struct wlr_xdg_toplevel *parent_xdg_toplevel =
+ xdg_toplevel_from_view(view)->parent;
+
+ if (!parent_xdg_toplevel) {
struct wlr_box box =
output_usable_area_from_cursor_coords(view->server);
view->x = box.x;
view->y = box.y;
- view->w = view->xdg_surface->current.geometry.width;
- view->h = view->xdg_surface->current.geometry.height;
+ view->w = xdg_surface->current.geometry.width;
+ view->h = xdg_surface->current.geometry.height;
if (view->w && view->h) {
view_center(view);
}
* If child-toplevel-views, we center-align relative to their
* parents
*/
- struct view *parent = parent_of(view);
+ struct view *parent = lookup_view_by_xdg_toplevel(
+ view->server, parent_xdg_toplevel);
assert(parent);
int center_x = parent->x + parent->w / 2;
int center_y = parent->y + parent->h / 2;
- view->x = center_x - view->xdg_surface->current.geometry.width / 2;
- view->y = center_y - view->xdg_surface->current.geometry.height / 2;
+ view->x = center_x - xdg_surface->current.geometry.width / 2;
+ view->y = center_y - xdg_surface->current.geometry.height / 2;
}
view->x += view->ssd.margin.left;
view->y += view->ssd.margin.top;
static const char *
xdg_toplevel_view_get_string_prop(struct view *view, const char *prop)
{
+ struct wlr_xdg_toplevel *xdg_toplevel = xdg_toplevel_from_view(view);
if (!strcmp(prop, "title")) {
- return view->xdg_surface->toplevel->title;
+ return xdg_toplevel->title;
}
if (!strcmp(prop, "app_id")) {
- return view->xdg_surface->toplevel->app_id;
+ return xdg_toplevel->app_id;
}
return "";
}
return;
}
view->mapped = true;
- view->surface = view->xdg_surface->surface;
+ struct wlr_xdg_surface *xdg_surface = xdg_surface_from_view(view);
+ view->surface = xdg_surface->surface;
wlr_scene_node_set_enabled(&view->scene_tree->node, true);
if (!view->been_mapped) {
struct wlr_xdg_toplevel_requested *requested =
- &view->xdg_surface->toplevel->requested;
+ &xdg_toplevel_from_view(view)->requested;
foreign_toplevel_handle_create(view);
view_set_decorations(view, has_ssd(view));
}
view->commit.notify = handle_commit;
- wl_signal_add(&view->xdg_surface->surface->events.commit,
- &view->commit);
+ wl_signal_add(&xdg_surface->surface->events.commit, &view->commit);
view_impl_map(view);
}
view->server = server;
view->type = LAB_XDG_SHELL_VIEW;
view->impl = &xdg_toplevel_view_impl;
- view->xdg_surface = xdg_surface;
+ xdg_toplevel_view->xdg_surface = xdg_surface;
view->workspace = server->workspace_current;
view->scene_tree = wlr_scene_tree_create(view->workspace->tree);
wlr_scene_node_set_enabled(&view->scene_tree->node, false);
struct wlr_scene_tree *tree = wlr_scene_xdg_surface_create(
- view->scene_tree, view->xdg_surface);
+ view->scene_tree, xdg_surface);
if (!tree) {
/* TODO: might need further clean up */
wl_resource_post_no_memory(view->surface->resource);
return (struct xwayland_view *)view;
}
+struct wlr_xwayland_surface *
+xwayland_surface_from_view(struct view *view)
+{
+ struct xwayland_view *xwayland_view = xwayland_view_from_view(view);
+ assert(xwayland_view->xwayland_surface);
+ return xwayland_view->xwayland_surface;
+}
+
static void
handle_commit(struct wl_listener *listener, void *data)
{
handle_map(struct wl_listener *listener, void *data)
{
struct view *view = wl_container_of(listener, view, map);
- assert(data && data == view->xwayland_surface);
-
view->impl->map(view);
}
handle_unmap(struct wl_listener *listener, void *data)
{
struct view *view = wl_container_of(listener, view, unmap);
- assert(data && data == view->xwayland_surface);
-
view->impl->unmap(view);
/*
handle_destroy(struct wl_listener *listener, void *data)
{
struct view *view = wl_container_of(listener, view, destroy);
- assert(data && data == view->xwayland_surface);
- assert(view->xwayland_surface->data == view);
+ struct xwayland_view *xwayland_view = xwayland_view_from_view(view);
+ assert(data && data == xwayland_view->xwayland_surface);
+ assert(xwayland_view->xwayland_surface->data == view);
if (view->surface) {
/*
* may not actually be destroyed at this point; it may become an
* "unmanaged" surface instead.
*/
- view->xwayland_surface->data = NULL;
- view->xwayland_surface = NULL;
+ xwayland_view->xwayland_surface->data = NULL;
+ xwayland_view->xwayland_surface = NULL;
/* Remove XWayland specific handlers */
wl_list_remove(&view->map.link);
wl_list_remove(&view->request_fullscreen.link);
wl_list_remove(&view->set_title.link);
- struct xwayland_view *xwayland_view = xwayland_view_from_view(view);
wl_list_remove(&xwayland_view->request_configure.link);
wl_list_remove(&xwayland_view->set_app_id.link);
wl_list_remove(&xwayland_view->set_decorations.link);
static void
configure(struct view *view, struct wlr_box geo)
{
- assert(view->xwayland_surface);
-
view->pending_move_resize.x = geo.x;
view->pending_move_resize.y = geo.y;
view->pending_move_resize.width = geo.width;
view->pending_move_resize.height = geo.height;
- wlr_xwayland_surface_configure(view->xwayland_surface, geo.x, geo.y,
- geo.width, geo.height);
+ wlr_xwayland_surface_configure(xwayland_surface_from_view(view),
+ geo.x, geo.y, geo.width, geo.height);
/* If not resizing, process the move immediately */
if (view->w == geo.width && view->h == geo.height) {
handle_request_fullscreen(struct wl_listener *listener, void *data)
{
struct view *view = wl_container_of(listener, view, request_fullscreen);
- bool fullscreen = view->xwayland_surface->fullscreen;
+ bool fullscreen = xwayland_surface_from_view(view)->fullscreen;
view_set_fullscreen(view, fullscreen, NULL);
}
static void
move(struct view *view, int x, int y)
{
- assert(view->xwayland_surface);
-
view->x = x;
view->y = y;
view->pending_move_resize.x = x;
view->pending_move_resize.y = y;
- struct wlr_xwayland_surface *s = view->xwayland_surface;
+ struct wlr_xwayland_surface *s = xwayland_surface_from_view(view);
wlr_xwayland_surface_configure(s, (int16_t)x, (int16_t)y,
(uint16_t)s->width, (uint16_t)s->height);
view_moved(view);
static void
_close(struct view *view)
{
- wlr_xwayland_surface_close(view->xwayland_surface);
+ wlr_xwayland_surface_close(xwayland_surface_from_view(view));
}
static const char *
get_string_prop(struct view *view, const char *prop)
{
+ struct wlr_xwayland_surface *xwayland_surface =
+ xwayland_surface_from_view(view);
if (!strcmp(prop, "title")) {
- return view->xwayland_surface->title;
+ return xwayland_surface->title;
}
if (!strcmp(prop, "class")) {
- return view->xwayland_surface->class;
+ return xwayland_surface->class;
}
/* We give 'class' for wlr_foreign_toplevel_handle_v1_set_app_id() */
if (!strcmp(prop, "app_id")) {
- return view->xwayland_surface->class;
+ return xwayland_surface->class;
}
return "";
}
static bool
-want_deco(struct view *view)
+want_deco(struct wlr_xwayland_surface *xwayland_surface)
{
- return view->xwayland_surface->decorations ==
+ return xwayland_surface->decorations ==
WLR_XWAYLAND_SURFACE_DECORATIONS_ALL;
}
struct xwayland_view *xwayland_view =
wl_container_of(listener, xwayland_view, set_decorations);
struct view *view = &xwayland_view->base;
- view_set_decorations(view, want_deco(view));
+ assert(data && data == xwayland_view->xwayland_surface);
+
+ view_set_decorations(view, want_deco(xwayland_view->xwayland_surface));
}
static void
wl_container_of(listener, xwayland_view, override_redirect);
struct view *view = &xwayland_view->base;
struct wlr_xwayland_surface *xsurface = data;
- assert(xsurface && xsurface == view->xwayland_surface);
+ assert(xsurface && xsurface == xwayland_view->xwayland_surface);
+
struct server *server = view->server;
bool mapped = xsurface->mapped;
if (mapped) {
}
static void
-set_initial_position(struct view *view)
+set_initial_position(struct view *view,
+ struct wlr_xwayland_surface *xwayland_surface)
{
/* Don't center views with position explicitly specified */
- bool has_position = view->xwayland_surface->size_hints &&
- (view->xwayland_surface->size_hints->flags &
+ bool has_position = xwayland_surface->size_hints &&
+ (xwayland_surface->size_hints->flags &
(XCB_ICCCM_SIZE_HINT_US_POSITION |
XCB_ICCCM_SIZE_HINT_P_POSITION));
}
view->mapped = true;
wlr_scene_node_set_enabled(&view->scene_tree->node, true);
- if (!view->fullscreen && view->xwayland_surface->fullscreen) {
+ struct wlr_xwayland_surface *xwayland_surface =
+ xwayland_surface_from_view(view);
+ if (!view->fullscreen && xwayland_surface->fullscreen) {
view_set_fullscreen(view, true, NULL);
}
if (!view->maximized && !view->fullscreen) {
- view->x = view->xwayland_surface->x;
- view->y = view->xwayland_surface->y;
- view->w = view->xwayland_surface->width;
- view->h = view->xwayland_surface->height;
+ view->x = xwayland_surface->x;
+ view->y = xwayland_surface->y;
+ view->w = xwayland_surface->width;
+ view->h = xwayland_surface->height;
}
- if (view->surface != view->xwayland_surface->surface) {
+ if (view->surface != xwayland_surface->surface) {
if (view->surface) {
wl_list_remove(&view->surface_destroy.link);
}
- view->surface = view->xwayland_surface->surface;
+ view->surface = xwayland_surface->surface;
/* Required to set the surface to NULL when destroyed by the client */
view->surface_destroy.notify = handle_surface_destroy;
}
if (!view->been_mapped) {
- view_set_decorations(view, want_deco(view));
+ view_set_decorations(view, want_deco(xwayland_surface));
if (!view->maximized && !view->fullscreen) {
- set_initial_position(view);
+ set_initial_position(view, xwayland_surface);
}
view_moved(view);
}
/* Add commit here, as xwayland map/unmap can change the wlr_surface */
- wl_signal_add(&view->xwayland_surface->surface->events.commit,
- &view->commit);
+ wl_signal_add(&xwayland_surface->surface->events.commit, &view->commit);
view->commit.notify = handle_commit;
view_impl_map(view);
static void
maximize(struct view *view, bool maximized)
{
- wlr_xwayland_surface_set_maximized(view->xwayland_surface, maximized);
+ wlr_xwayland_surface_set_maximized(xwayland_surface_from_view(view),
+ maximized);
}
static void
set_activated(struct view *view, bool activated)
{
- struct wlr_xwayland_surface *surface = view->xwayland_surface;
+ struct wlr_xwayland_surface *xwayland_surface =
+ xwayland_surface_from_view(view);
- if (activated && surface->minimized) {
- wlr_xwayland_surface_set_minimized(surface, false);
+ if (activated && xwayland_surface->minimized) {
+ wlr_xwayland_surface_set_minimized(xwayland_surface, false);
}
- wlr_xwayland_surface_activate(surface, activated);
+ wlr_xwayland_surface_activate(xwayland_surface, activated);
if (activated) {
- wlr_xwayland_surface_restack(surface, NULL, XCB_STACK_MODE_ABOVE);
+ wlr_xwayland_surface_restack(xwayland_surface,
+ NULL, XCB_STACK_MODE_ABOVE);
/* Restack unmanaged surfaces on top */
struct xwayland_unmanaged *u;
struct wl_list *list = &view->server->unmanaged_surfaces;
wl_list_for_each(u, list, link) {
- wlr_xwayland_surface_restack(u->xwayland_surface, NULL,
- XCB_STACK_MODE_ABOVE);
+ wlr_xwayland_surface_restack(u->xwayland_surface,
+ NULL, XCB_STACK_MODE_ABOVE);
}
}
}
static void
set_fullscreen(struct view *view, bool fullscreen)
{
- wlr_xwayland_surface_set_fullscreen(view->xwayland_surface, fullscreen);
+ wlr_xwayland_surface_set_fullscreen(xwayland_surface_from_view(view),
+ fullscreen);
}
static const struct view_impl xwl_view_impl = {
* from the view (destroying the view) and makes it an
* "unmanaged" surface.
*/
- view->xwayland_surface = xsurface;
+ xwayland_view->xwayland_surface = xsurface;
xsurface->data = view;
view->workspace = server->workspace_current;