[digesting_libdecor] slim down event handlers

main
Allen Webster 2026-03-02 10:56:52 -08:00
parent 1d47997186
commit 458b0bcb55
2 changed files with 45 additions and 75 deletions

View File

@ -235,54 +235,8 @@ const struct wl_registry_listener wl_registry_listener = {
static void
xdg_surface_configure(void *user_data, struct xdg_surface *xdg_surface, uint32_t serial){
struct libdecor_configuration config = {0};
if (ctx.has_pending_config){
ctx.has_pending_config = 0;
config = ctx.pending_config;
}
config.serial = serial;
{
int w = ctx.w;
int h = ctx.h;
bool got_size = false;
if (config.initialized &&
config.window_width != 0 &&
config.window_height != 0){
w = config.window_width;
h = config.window_height;
if (ctx.visible && ctx.decoration_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE){
ctx.frame_window_state = config.window_state;
Sides2D border_size = border_size_from_window_state(config.window_state);
w -= border_size.x[0] + border_size.x[1];
h -= border_size.y[0] + border_size.y[1];
}
if (!(config.window_state & LIBDECOR_WINDOW_STATE_NON_FLOATING)){
if (ctx.size_bounds.x[0] > 0){
w = MAX(ctx.size_bounds.x[0], w);
}
if (ctx.size_bounds.x[1] > 0){
w = MIN(w, ctx.size_bounds.x[1]);
}
if (ctx.size_bounds.y[0] > 0){
h = MAX(ctx.size_bounds.y[0], h);
}
if (ctx.size_bounds.y[1] > 0){
h = MIN(h, ctx.size_bounds.y[1]);
}
}
ctx.w = w;
ctx.h = h;
}
ctx.has_cached_config = 1;
ctx.cached_config = config;
}
ctx.cached_config.serial = serial;
}
const struct xdg_surface_listener xdg_surface_listener = {
@ -319,11 +273,11 @@ xdg_toplevel_configure(void *user_data, struct xdg_toplevel *xdg_toplevel,
}
}
ctx.has_pending_config = true;
ctx.pending_config.initialized = true;
ctx.pending_config.window_width = width;
ctx.pending_config.window_height = height;
ctx.pending_config.window_state = window_state;
ctx.has_cached_config = 1;
ctx.cached_config.initialized = 1;
ctx.cached_config.window_width = width;
ctx.cached_config.window_height = height;
ctx.cached_config.window_state = window_state;
}
static void
@ -357,22 +311,10 @@ xdg_toplevel_wm_capabilities(void *user_data,
wl_array_for_each(wm_cap, capabilities) {
switch (*wm_cap) {
case XDG_TOPLEVEL_WM_CAPABILITIES_WINDOW_MENU: {
ctx.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_WINDOW_MENU;
}break;
case XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE: {
ctx.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_MAXIMIZE;
}break;
case XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN: {
ctx.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_FULLSCREEN;
}break;
case XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE: {
ctx.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_MINIMIZE;
}break;
case XDG_TOPLEVEL_WM_CAPABILITIES_WINDOW_MENU: ctx.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_WINDOW_MENU; break;
case XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE: ctx.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_MAXIMIZE; break;
case XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN: ctx.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_FULLSCREEN; break;
case XDG_TOPLEVEL_WM_CAPABILITIES_MINIMIZE: ctx.wm_capabilities |= LIBDECOR_WM_CAPABILITIES_MINIMIZE; break;
default: break;
}
}
@ -400,9 +342,7 @@ xdg_toplevel_decoration_configure(void *data, struct zxdg_toplevel_decoration_v1
}
const struct zxdg_toplevel_decoration_v1_listener
xdg_toplevel_decoration_listener = {
xdg_toplevel_decoration_configure,
};
xdg_toplevel_decoration_listener = { xdg_toplevel_decoration_configure, };
int main(){
/* get desktop settings */
@ -947,6 +887,39 @@ int main(){
/* apply new surface config */
if (ctx.has_cached_config){
ctx.has_cached_config = 0;
if (ctx.cached_config.initialized &&
ctx.cached_config.window_width != 0 &&
ctx.cached_config.window_height != 0){
int w = ctx.cached_config.window_width;
int h = ctx.cached_config.window_height;
if (ctx.visible && ctx.decoration_mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE){
ctx.frame_window_state = ctx.cached_config.window_state;
Sides2D border_size = border_size_from_window_state(ctx.cached_config.window_state);
w -= border_size.x[0] + border_size.x[1];
h -= border_size.y[0] + border_size.y[1];
}
if (!(ctx.cached_config.window_state & LIBDECOR_WINDOW_STATE_NON_FLOATING)){
if (ctx.size_bounds.x[0] > 0){
w = MAX(ctx.size_bounds.x[0], w);
}
if (ctx.size_bounds.x[1] > 0){
w = MIN(w, ctx.size_bounds.x[1]);
}
if (ctx.size_bounds.y[0] > 0){
h = MAX(ctx.size_bounds.y[0], h);
}
if (ctx.size_bounds.y[1] > 0){
h = MIN(h, ctx.size_bounds.y[1]);
}
}
ctx.w = w;
ctx.h = h;
}
if (ctx.cached_config.initialized){
ctx.frame_window_state = ctx.cached_config.window_state;
}

View File

@ -338,8 +338,6 @@ typedef struct Ctx{
int has_cached_config;
struct libdecor_configuration cached_config;
int has_pending_config;
struct libdecor_configuration pending_config;
/* uncategorized experiments */
struct seat *seat;
@ -356,7 +354,6 @@ typedef struct Ctx{
Sides2D size_bounds;
struct xdg_toplevel *parent;
int frame_content_width;
int frame_content_height;