xdg-shell: add support for v7

This commit is contained in:
Kirill Primak 2024-05-09 00:22:15 +03:00 committed by Simon Ser
parent a08acfcee0
commit afe427d149
3 changed files with 39 additions and 3 deletions

View file

@ -141,6 +141,7 @@ enum wlr_xdg_surface_role {
struct wlr_xdg_toplevel_state {
bool maximized, fullscreen, resizing, activated, suspended;
uint32_t tiled; // enum wlr_edges
uint32_t constrained; // enum wlr_edges
int32_t width, height;
int32_t max_width, max_height;
int32_t min_width, min_height;
@ -168,6 +169,7 @@ struct wlr_xdg_toplevel_configure {
// The following fields must always be set to reflect the current state
bool maximized, fullscreen, resizing, activated, suspended;
uint32_t tiled; // enum wlr_edges
uint32_t constrained; // enum wlr_edges
int32_t width, height;
// Only for WLR_XDG_TOPLEVEL_CONFIGURE_BOUNDS
@ -454,6 +456,14 @@ uint32_t wlr_xdg_toplevel_set_wm_capabilities(struct wlr_xdg_toplevel *toplevel,
uint32_t wlr_xdg_toplevel_set_suspended(struct wlr_xdg_toplevel *toplevel,
bool suspended);
/**
* Request that this toplevel consider itself constrained and doesn't attempt to
* resize from some edges. `constrained_edges` is a bitfield of enum wlr_edges.
* Returns the associated configure serial.
*/
uint32_t wlr_xdg_toplevel_set_constrained(struct wlr_xdg_toplevel *toplevel,
uint32_t constrained_edges);
/**
* Request that this toplevel closes.
*/

View file

@ -2,7 +2,7 @@
#include <stdlib.h>
#include "types/wlr_xdg_shell.h"
#define WM_BASE_VERSION 6
#define WM_BASE_VERSION 7
static const struct xdg_wm_base_interface xdg_shell_impl;

View file

@ -15,6 +15,7 @@ void handle_xdg_toplevel_ack_configure(
toplevel->pending.resizing = configure->resizing;
toplevel->pending.activated = configure->activated;
toplevel->pending.tiled = configure->tiled;
toplevel->pending.constrained = configure->constrained;
toplevel->pending.suspended = configure->suspended;
toplevel->pending.width = configure->width;
@ -80,7 +81,7 @@ struct wlr_xdg_toplevel_configure *send_xdg_toplevel_configure(
states[nstates++] = XDG_TOPLEVEL_STATE_ACTIVATED;
}
if (configure->tiled && version >= XDG_TOPLEVEL_STATE_TILED_LEFT_SINCE_VERSION) {
const struct {
static const struct {
enum wlr_edges edge;
enum xdg_toplevel_state state;
} tiled[] = {
@ -90,7 +91,7 @@ struct wlr_xdg_toplevel_configure *send_xdg_toplevel_configure(
{ WLR_EDGE_BOTTOM, XDG_TOPLEVEL_STATE_TILED_BOTTOM },
};
for (size_t i = 0; i < sizeof(tiled)/sizeof(tiled[0]); ++i) {
for (size_t i = 0; i < sizeof(tiled) / sizeof(tiled[0]); ++i) {
if ((configure->tiled & tiled[i].edge) == 0) {
continue;
}
@ -100,6 +101,24 @@ struct wlr_xdg_toplevel_configure *send_xdg_toplevel_configure(
if (configure->suspended && version >= XDG_TOPLEVEL_STATE_SUSPENDED_SINCE_VERSION) {
states[nstates++] = XDG_TOPLEVEL_STATE_SUSPENDED;
}
if (configure->constrained && version >= XDG_TOPLEVEL_STATE_CONSTRAINED_LEFT_SINCE_VERSION) {
static const struct {
enum wlr_edges edge;
enum xdg_toplevel_state state;
} constrained[] = {
{ WLR_EDGE_LEFT, XDG_TOPLEVEL_STATE_CONSTRAINED_LEFT },
{ WLR_EDGE_RIGHT, XDG_TOPLEVEL_STATE_CONSTRAINED_RIGHT },
{ WLR_EDGE_TOP, XDG_TOPLEVEL_STATE_CONSTRAINED_TOP },
{ WLR_EDGE_BOTTOM, XDG_TOPLEVEL_STATE_CONSTRAINED_BOTTOM },
};
for (size_t i = 0; i < sizeof(constrained) / sizeof(constrained[0]); ++i) {
if ((configure->constrained & constrained[i].edge) == 0) {
continue;
}
states[nstates++] = constrained[i].state;
}
}
assert(nstates <= sizeof(states) / sizeof(states[0]));
int32_t width = configure->width;
@ -638,3 +657,10 @@ uint32_t wlr_xdg_toplevel_set_suspended(struct wlr_xdg_toplevel *toplevel,
toplevel->scheduled.suspended = suspended;
return wlr_xdg_surface_schedule_configure(toplevel->base);
}
uint32_t wlr_xdg_toplevel_set_constrained(struct wlr_xdg_toplevel *toplevel, uint32_t constrained) {
assert(toplevel->base->client->shell->version >=
XDG_TOPLEVEL_STATE_CONSTRAINED_LEFT_SINCE_VERSION);
toplevel->scheduled.constrained = constrained;
return wlr_xdg_surface_schedule_configure(toplevel->base);
}