2020-12-25 15:33:55 +09:00
|
|
|
/*
|
|
|
|
* Attempt to consolidate unavoidable suck into one file, away from dwl.c. This
|
|
|
|
* file is not meant to be pretty. We use a .h file with static inline
|
|
|
|
* functions instead of a separate .c module, or function pointers like sway, so
|
|
|
|
* that they will simply compile out if the chosen #defines leave them unused.
|
|
|
|
*/
|
|
|
|
|
2021-09-06 01:41:23 +09:00
|
|
|
/* Leave these functions first; they're used in the others */
|
2020-12-25 15:33:55 +09:00
|
|
|
static inline int
|
|
|
|
client_is_x11(Client *c)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
return c->type == X11Managed || c->type == X11Unmanaged;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-07-20 10:13:56 +09:00
|
|
|
static inline Client *
|
|
|
|
client_from_wlr_surface(struct wlr_surface *s)
|
|
|
|
{
|
|
|
|
struct wlr_xdg_surface *surface;
|
|
|
|
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
struct wlr_xwayland_surface *xsurface;
|
|
|
|
if (s && wlr_surface_is_xwayland_surface(s)
|
|
|
|
&& (xsurface = wlr_xwayland_surface_from_wlr_surface(s)))
|
|
|
|
return xsurface->data;
|
|
|
|
#endif
|
|
|
|
if (s && wlr_surface_is_xdg_surface(s)
|
|
|
|
&& (surface = wlr_xdg_surface_from_wlr_surface(s))
|
|
|
|
&& surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL)
|
|
|
|
return surface->data;
|
|
|
|
|
2022-08-13 13:58:11 +09:00
|
|
|
if (s && wlr_surface_is_subsurface(s))
|
|
|
|
return client_from_wlr_surface(wlr_surface_get_root_surface(s));
|
2022-07-20 10:13:56 +09:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-08-28 06:29:23 +09:00
|
|
|
static inline Client *
|
|
|
|
client_get_parent(Client *c)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c) && c->surface.xwayland->parent)
|
|
|
|
return client_from_wlr_surface(c->surface.xwayland->parent->surface);
|
|
|
|
#endif
|
|
|
|
if (c->surface.xdg->toplevel->parent)
|
2022-10-02 13:30:47 +09:00
|
|
|
return client_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface);
|
2022-08-28 06:29:23 +09:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)) {
|
2022-10-02 13:30:47 +09:00
|
|
|
xcb_size_hints_t *size_hints = c->surface.xwayland->size_hints;
|
2022-08-28 06:29:23 +09:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct wlr_surface *
|
|
|
|
client_surface(Client *c)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c))
|
|
|
|
return c->surface.xwayland->surface;
|
|
|
|
#endif
|
|
|
|
return c->surface.xdg->surface;
|
|
|
|
}
|
|
|
|
|
2020-12-25 15:33:55 +09:00
|
|
|
/* The others */
|
|
|
|
static inline void
|
|
|
|
client_activate_surface(struct wlr_surface *s, int activated)
|
|
|
|
{
|
2022-05-14 14:24:06 +09:00
|
|
|
struct wlr_xdg_surface *surface;
|
2020-12-25 15:33:55 +09:00
|
|
|
#ifdef XWAYLAND
|
2022-05-14 14:24:06 +09:00
|
|
|
struct wlr_xwayland_surface *xsurface;
|
|
|
|
if (wlr_surface_is_xwayland_surface(s)
|
|
|
|
&& (xsurface = wlr_xwayland_surface_from_wlr_surface(s))) {
|
|
|
|
wlr_xwayland_surface_activate(xsurface, activated);
|
2020-12-25 15:33:55 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2022-05-14 14:24:06 +09:00
|
|
|
if (wlr_surface_is_xdg_surface(s)
|
|
|
|
&& (surface = wlr_xdg_surface_from_wlr_surface(s))
|
|
|
|
&& surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL)
|
2022-05-18 05:31:31 +09:00
|
|
|
wlr_xdg_toplevel_set_activated(surface->toplevel, activated);
|
2020-12-25 15:33:55 +09:00
|
|
|
}
|
|
|
|
|
2022-06-10 02:45:42 +09:00
|
|
|
static inline uint32_t
|
|
|
|
client_set_bounds(Client *c, int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c))
|
|
|
|
return 0;
|
|
|
|
#endif
|
2022-07-15 14:27:31 +09:00
|
|
|
if (c->surface.xdg->client->shell->version >=
|
|
|
|
XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION)
|
|
|
|
return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height);
|
|
|
|
return 0;
|
2022-06-10 02:45:42 +09:00
|
|
|
}
|
|
|
|
|
2020-12-25 15:33:55 +09:00
|
|
|
static inline void
|
|
|
|
client_for_each_surface(Client *c, wlr_surface_iterator_func_t fn, void *data)
|
|
|
|
{
|
2021-09-06 01:41:23 +09:00
|
|
|
wlr_surface_for_each_surface(client_surface(c), fn, data);
|
2020-12-25 15:33:55 +09:00
|
|
|
#ifdef XWAYLAND
|
2021-09-06 01:41:23 +09:00
|
|
|
if (client_is_x11(c))
|
2020-12-25 15:33:55 +09:00
|
|
|
return;
|
|
|
|
#endif
|
2021-09-06 01:41:23 +09:00
|
|
|
wlr_xdg_surface_for_each_popup_surface(c->surface.xdg, fn, data);
|
2020-12-25 15:33:55 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline const char *
|
|
|
|
client_get_appid(Client *c)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c))
|
|
|
|
return c->surface.xwayland->class;
|
|
|
|
#endif
|
|
|
|
return c->surface.xdg->toplevel->app_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
client_get_geometry(Client *c, struct wlr_box *geom)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c)) {
|
|
|
|
geom->x = c->surface.xwayland->x;
|
|
|
|
geom->y = c->surface.xwayland->y;
|
|
|
|
geom->width = c->surface.xwayland->width;
|
|
|
|
geom->height = c->surface.xwayland->height;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
wlr_xdg_surface_get_geometry(c->surface.xdg, geom);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const char *
|
|
|
|
client_get_title(Client *c)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c))
|
|
|
|
return c->surface.xwayland->title;
|
|
|
|
#endif
|
|
|
|
return c->surface.xdg->toplevel->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
client_is_float_type(Client *c)
|
|
|
|
{
|
2022-06-25 09:15:24 +09:00
|
|
|
struct wlr_box min = {0}, max = {0};
|
|
|
|
client_get_size_hints(c, &max, &min);
|
2022-03-22 04:52:33 +09:00
|
|
|
|
2020-12-25 15:33:55 +09:00
|
|
|
#ifdef XWAYLAND
|
2022-03-22 04:52:33 +09:00
|
|
|
if (client_is_x11(c)) {
|
|
|
|
struct wlr_xwayland_surface *surface = c->surface.xwayland;
|
|
|
|
if (surface->modal)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < surface->window_type_len; i++)
|
2022-06-25 09:15:24 +09:00
|
|
|
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])
|
2020-12-25 15:33:55 +09:00
|
|
|
return 1;
|
2022-03-22 04:52:33 +09:00
|
|
|
}
|
2020-12-25 15:33:55 +09:00
|
|
|
#endif
|
2022-06-25 09:15:24 +09:00
|
|
|
return ((min.width > 0 || min.height > 0 || max.width > 0 || max.height > 0)
|
|
|
|
&& (min.width == max.width || min.height == max.height))
|
2022-08-28 06:29:23 +09:00
|
|
|
|| client_get_parent(c);
|
2020-12-25 15:33:55 +09:00
|
|
|
}
|
|
|
|
|
2022-08-19 06:59:38 +09:00
|
|
|
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;
|
2020-12-25 15:33:55 +09:00
|
|
|
}
|
|
|
|
|
2022-03-14 11:54:44 +09:00
|
|
|
static inline int
|
2022-08-28 06:29:23 +09:00
|
|
|
client_is_unmanaged(Client *c)
|
2022-03-14 11:54:44 +09:00
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
2022-08-28 06:29:23 +09:00
|
|
|
return c->type == X11Unmanaged;
|
2022-03-14 11:54:44 +09:00
|
|
|
#endif
|
2022-08-28 06:29:23 +09:00
|
|
|
return 0;
|
2022-03-14 11:54:44 +09:00
|
|
|
}
|
|
|
|
|
2022-08-28 06:05:12 +09:00
|
|
|
static inline void
|
|
|
|
client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb)
|
|
|
|
{
|
|
|
|
if (kb)
|
|
|
|
wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes,
|
|
|
|
kb->num_keycodes, &kb->modifiers);
|
|
|
|
else
|
|
|
|
wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL);
|
|
|
|
}
|
|
|
|
|
2022-08-28 06:29:23 +09:00
|
|
|
static inline void
|
|
|
|
client_restack_surface(Client *c)
|
2020-12-25 15:33:55 +09:00
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
2022-08-28 06:29:23 +09:00
|
|
|
if (client_is_x11(c))
|
|
|
|
wlr_xwayland_surface_restack(c->surface.xwayland, NULL,
|
|
|
|
XCB_STACK_MODE_ABOVE);
|
2020-12-25 15:33:55 +09:00
|
|
|
#endif
|
2022-08-28 06:29:23 +09:00
|
|
|
return;
|
2020-12-25 15:33:55 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
client_send_close(Client *c)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c)) {
|
|
|
|
wlr_xwayland_surface_close(c->surface.xwayland);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2022-02-04 12:54:44 +09:00
|
|
|
wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel);
|
2020-12-25 15:33:55 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
client_set_fullscreen(Client *c, int fullscreen)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c)) {
|
|
|
|
wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2022-02-04 12:54:44 +09:00
|
|
|
wlr_xdg_toplevel_set_fullscreen(c->surface.xdg->toplevel, fullscreen);
|
2020-12-25 15:33:55 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
client_set_size(Client *c, uint32_t width, uint32_t height)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c)) {
|
|
|
|
wlr_xwayland_surface_configure(c->surface.xwayland,
|
|
|
|
c->geom.x, c->geom.y, width, height);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2022-02-04 12:54:44 +09:00
|
|
|
return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, width, height);
|
2020-12-25 15:33:55 +09:00
|
|
|
}
|
|
|
|
|
2021-05-24 08:28:13 +09:00
|
|
|
static inline void
|
|
|
|
client_set_tiled(Client *c, uint32_t edges)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c))
|
|
|
|
return;
|
|
|
|
#endif
|
2022-03-11 01:34:43 +09:00
|
|
|
wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges);
|
2021-05-24 08:28:13 +09:00
|
|
|
}
|
|
|
|
|
2020-12-25 15:33:55 +09:00
|
|
|
static inline struct wlr_surface *
|
|
|
|
client_surface_at(Client *c, double cx, double cy, double *sx, double *sy)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
if (client_is_x11(c))
|
|
|
|
return wlr_surface_surface_at(c->surface.xwayland->surface,
|
|
|
|
cx, cy, sx, sy);
|
|
|
|
#endif
|
|
|
|
return wlr_xdg_surface_surface_at(c->surface.xdg, cx, cy, sx, sy);
|
|
|
|
}
|
2022-03-18 16:25:53 +09:00
|
|
|
|
2022-06-17 06:05:07 +09:00
|
|
|
static inline int
|
|
|
|
client_wants_focus(Client *c)
|
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
|
|
|
return client_is_unmanaged(c)
|
|
|
|
&& wlr_xwayland_or_surface_wants_focus(c->surface.xwayland)
|
|
|
|
&& wlr_xwayland_icccm_input_model(c->surface.xwayland) != WLR_ICCCM_INPUT_MODEL_NONE;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-28 06:29:23 +09:00
|
|
|
static inline int
|
|
|
|
client_wants_fullscreen(Client *c)
|
2022-03-18 16:25:53 +09:00
|
|
|
{
|
|
|
|
#ifdef XWAYLAND
|
2022-06-17 05:54:13 +09:00
|
|
|
if (client_is_x11(c))
|
2022-08-28 06:29:23 +09:00
|
|
|
return c->surface.xwayland->fullscreen;
|
2022-03-18 16:25:53 +09:00
|
|
|
#endif
|
2022-08-28 06:29:23 +09:00
|
|
|
return c->surface.xdg->toplevel->requested.fullscreen;
|
2022-03-18 16:25:53 +09:00
|
|
|
}
|
2022-03-18 16:31:28 +09:00
|
|
|
|
2022-06-21 13:46:11 +09:00
|
|
|
static inline void *
|
|
|
|
toplevel_from_popup(struct wlr_xdg_popup *popup)
|
2022-03-17 14:08:17 +09:00
|
|
|
{
|
|
|
|
struct wlr_xdg_surface *surface = popup->base;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
switch (surface->role) {
|
|
|
|
case WLR_XDG_SURFACE_ROLE_POPUP:
|
2022-11-09 15:01:50 +09:00
|
|
|
if (!surface->popup->parent)
|
|
|
|
return NULL;
|
|
|
|
else if (wlr_surface_is_layer_surface(surface->popup->parent))
|
2022-06-21 13:46:11 +09:00
|
|
|
return wlr_layer_surface_v1_from_wlr_surface(surface->popup->parent)->data;
|
|
|
|
else if (!wlr_surface_is_xdg_surface(surface->popup->parent))
|
2022-03-17 14:08:17 +09:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
surface = wlr_xdg_surface_from_wlr_surface(surface->popup->parent);
|
|
|
|
break;
|
|
|
|
case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
|
|
|
|
return surface->data;
|
|
|
|
case WLR_XDG_SURFACE_ROLE_NONE:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-09 03:00:03 +09:00
|
|
|
|
|
|
|
static inline void *
|
|
|
|
toplevel_from_wlr_layer_surface(struct wlr_surface *s)
|
|
|
|
{
|
|
|
|
Client *c;
|
|
|
|
struct wlr_layer_surface_v1 *wlr_layer_surface;
|
|
|
|
|
|
|
|
if ((c = client_from_wlr_surface(s)))
|
|
|
|
return c;
|
|
|
|
else if (s && wlr_surface_is_layer_surface(s)
|
|
|
|
&& (wlr_layer_surface = wlr_layer_surface_v1_from_wlr_surface(s)))
|
|
|
|
return wlr_layer_surface->data;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|