summaryrefslogtreecommitdiff
path: root/client.h
diff options
context:
space:
mode:
Diffstat (limited to 'client.h')
-rw-r--r--client.h176
1 files changed, 84 insertions, 92 deletions
diff --git a/client.h b/client.h
index cf1ed85..71c7d76 100644
--- a/client.h
+++ b/client.h
@@ -11,34 +11,8 @@ client_is_x11(Client *c)
{
#ifdef XWAYLAND
return c->type == X11Managed || c->type == X11Unmanaged;
-#else
- return 0;
#endif
-}
-
-static inline void
-client_get_size_hints(Client *c, struct wlr_box *max, struct wlr_box *min)
-{
- struct wlr_xdg_toplevel *toplevel;
- struct wlr_xdg_toplevel_state *state;
-#ifdef XWAYLAND
- if (client_is_x11(c)) {
- xcb_size_hints_t *size_hints = c->surface.xwayland->size_hints;
- if (size_hints) {
- max->width = size_hints->max_width;
- max->height = size_hints->max_height;
- min->width = size_hints->min_width;
- min->height = size_hints->min_height;
- }
- return;
- }
-#endif
- toplevel = c->surface.xdg->toplevel;
- state = &toplevel->current;
- max->width = state->max_width;
- max->height = state->max_height;
- min->width = state->min_width;
- min->height = state->min_height;
+ return 0;
}
static inline struct wlr_surface *
@@ -54,7 +28,7 @@ client_surface(Client *c)
static inline int
toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
{
- struct wlr_xdg_surface *xdg_surface;
+ struct wlr_xdg_surface *xdg_surface, *tmp_xdg_surface;
struct wlr_surface *root_surface;
struct wlr_layer_surface_v1 *layer_surface;
Client *c = NULL;
@@ -65,44 +39,44 @@ toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
#endif
if (!s)
- return type;
+ return -1;
root_surface = wlr_surface_get_root_surface(s);
#ifdef XWAYLAND
- if (wlr_surface_is_xwayland_surface(root_surface)
- && (xsurface = wlr_xwayland_surface_from_wlr_surface(root_surface))) {
+ if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(root_surface))) {
c = xsurface->data;
type = c->type;
goto end;
}
#endif
- if (wlr_surface_is_layer_surface(root_surface)
- && (layer_surface = wlr_layer_surface_v1_from_wlr_surface(root_surface))) {
+ if ((layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
l = layer_surface->data;
type = LayerShell;
goto end;
}
- if (wlr_surface_is_xdg_surface(root_surface)
- && (xdg_surface = wlr_xdg_surface_from_wlr_surface(root_surface))) {
- while (1) {
- switch (xdg_surface->role) {
- case WLR_XDG_SURFACE_ROLE_POPUP:
- if (!xdg_surface->popup->parent)
- return -1;
- else if (!wlr_surface_is_xdg_surface(xdg_surface->popup->parent))
- return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc, pl);
-
- xdg_surface = wlr_xdg_surface_from_wlr_surface(xdg_surface->popup->parent);
- break;
- case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
- c = xdg_surface->data;
- type = c->type;
- goto end;
- case WLR_XDG_SURFACE_ROLE_NONE:
+ xdg_surface = wlr_xdg_surface_try_from_wlr_surface(root_surface);
+ while (xdg_surface) {
+ tmp_xdg_surface = NULL;
+ switch (xdg_surface->role) {
+ case WLR_XDG_SURFACE_ROLE_POPUP:
+ if (!xdg_surface->popup || !xdg_surface->popup->parent)
return -1;
- }
+
+ tmp_xdg_surface = wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent);
+
+ if (!tmp_xdg_surface)
+ return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc, pl);
+
+ xdg_surface = tmp_xdg_surface;
+ break;
+ case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
+ c = xdg_surface->data;
+ type = c->type;
+ goto end;
+ case WLR_XDG_SURFACE_ROLE_NONE:
+ return -1;
}
}
@@ -118,19 +92,16 @@ end:
static inline void
client_activate_surface(struct wlr_surface *s, int activated)
{
- struct wlr_xdg_surface *surface;
+ struct wlr_xdg_toplevel *toplevel;
#ifdef XWAYLAND
struct wlr_xwayland_surface *xsurface;
- if (wlr_surface_is_xwayland_surface(s)
- && (xsurface = wlr_xwayland_surface_from_wlr_surface(s))) {
+ if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(s))) {
wlr_xwayland_surface_activate(xsurface, activated);
return;
}
#endif
- if (wlr_surface_is_xdg_surface(s)
- && (surface = wlr_xdg_surface_from_wlr_surface(s))
- && surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL)
- wlr_xdg_toplevel_set_activated(surface->toplevel, activated);
+ if ((toplevel = wlr_xdg_toplevel_try_from_wlr_surface(s)))
+ wlr_xdg_toplevel_set_activated(toplevel, activated);
}
static inline uint32_t
@@ -140,31 +111,45 @@ client_set_bounds(Client *c, int32_t width, int32_t height)
if (client_is_x11(c))
return 0;
#endif
- if (c->surface.xdg->client->shell->version >=
- XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION && width >= 0 && height >= 0)
+ if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
+ XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION && width >= 0 && height >= 0
+ && (c->bounds.width != width || c->bounds.height != height)) {
+ c->bounds.width = width;
+ c->bounds.height = height;
return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height);
+ }
return 0;
}
-static inline void
-client_for_each_surface(Client *c, wlr_surface_iterator_func_t fn, void *data)
+static inline const char *
+client_get_appid(Client *c)
{
- wlr_surface_for_each_surface(client_surface(c), fn, data);
#ifdef XWAYLAND
if (client_is_x11(c))
- return;
+ return c->surface.xwayland->class;
#endif
- wlr_xdg_surface_for_each_popup_surface(c->surface.xdg, fn, data);
+ return c->surface.xdg->toplevel->app_id;
}
-static inline const char *
-client_get_appid(Client *c)
+static inline void
+client_get_clip(Client *c, struct wlr_box *clip)
{
+ struct wlr_box xdg_geom = {0};
+ *clip = (struct wlr_box){
+ .x = 0,
+ .y = 0,
+ .width = c->geom.width - c->bw,
+ .height = c->geom.height - c->bw,
+ };
+
#ifdef XWAYLAND
if (client_is_x11(c))
- return c->surface.xwayland->class;
+ return;
#endif
- return c->surface.xdg->toplevel->app_id;
+
+ wlr_xdg_surface_get_geometry(c->surface.xdg, &xdg_geom);
+ clip->x = xdg_geom.x;
+ clip->y = xdg_geom.y;
}
static inline void
@@ -192,7 +177,6 @@ client_get_parent(Client *c)
#endif
if (c->surface.xdg->toplevel->parent)
toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface, &p, NULL);
-
return p;
}
@@ -209,35 +193,35 @@ client_get_title(Client *c)
static inline int
client_is_float_type(Client *c)
{
- struct wlr_box min = {0}, max = {0};
- client_get_size_hints(c, &max, &min);
+ struct wlr_xdg_toplevel *toplevel;
+ struct wlr_xdg_toplevel_state state;
#ifdef XWAYLAND
if (client_is_x11(c)) {
struct wlr_xwayland_surface *surface = c->surface.xwayland;
+ xcb_size_hints_t *size_hints = surface->size_hints;
+ size_t i;
if (surface->modal)
return 1;
- for (size_t i = 0; i < surface->window_type_len; i++)
+ for (i = 0; i < surface->window_type_len; i++)
if (surface->window_type[i] == netatom[NetWMWindowTypeDialog]
|| surface->window_type[i] == netatom[NetWMWindowTypeSplash]
|| surface->window_type[i] == netatom[NetWMWindowTypeToolbar]
|| surface->window_type[i] == netatom[NetWMWindowTypeUtility])
return 1;
+
+ return size_hints && size_hints->min_width > 0 && size_hints->min_height > 0
+ && (size_hints->max_width == size_hints->min_width
+ || size_hints->max_height == size_hints->min_height);
}
#endif
- return ((min.width > 0 || min.height > 0 || max.width > 0 || max.height > 0)
- && (min.width == max.width || min.height == max.height));
-}
-static inline int
-client_is_mapped(Client *c)
-{
-#ifdef XWAYLAND
- if (client_is_x11(c))
- return c->surface.xwayland->mapped;
-#endif
- return c->surface.xdg->mapped;
+ toplevel = c->surface.xdg->toplevel;
+ state = toplevel->current;
+ return toplevel->parent || (state.min_width != 0 && state.min_height != 0
+ && (state.min_width == state.max_width
+ || state.min_height == state.max_height));
}
static inline int
@@ -247,7 +231,8 @@ client_is_rendered_on_mon(Client *c, Monitor *m)
* but rather actual displaying of the pixels.
* Usually VISIBLEON suffices and is also faster. */
struct wlr_surface_output *s;
- if (!c->scene->node.enabled)
+ int unused_lx, unused_ly;
+ if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly))
return 0;
wl_list_for_each(s, &client_surface(c)->current_outputs, link)
if (s->output == m->wlr_output)
@@ -366,18 +351,25 @@ client_set_tiled(Client *c, uint32_t edges)
if (client_is_x11(c))
return;
#endif
- wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges);
+ if (wl_resource_get_version(c->surface.xdg->resource)
+ >= XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) {
+ wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges);
+ } else {
+ wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel, edges != WLR_EDGE_NONE);
+ }
}
-static inline struct wlr_surface *
-client_surface_at(Client *c, double cx, double cy, double *sx, double *sy)
+static inline void
+client_set_suspended(Client *c, int suspended)
{
#ifdef XWAYLAND
- if (client_is_x11(c))
- return wlr_surface_surface_at(c->surface.xwayland->surface,
- cx, cy, sx, sy);
+ if (client_is_x11(c)) {
+ wlr_xwayland_surface_set_withdrawn(c->surface.xwayland, suspended);
+ return;
+ }
#endif
- return wlr_xdg_surface_surface_at(c->surface.xdg, cx, cy, sx, sy);
+
+ wlr_xdg_toplevel_set_suspended(c->surface.xdg->toplevel, suspended);
}
static inline int