From 769e4376c6c5af7a330d0bd0c0c846dffdc63e3a Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Mon, 20 Jun 2022 12:26:29 -0500 Subject: [PATCH] shared/frame: Provide a function to get decoration sizes and use it We need these values to calculate frame extents to properly set _NET_FRAME_EXTENTS, but we don't want to calculate them twice. Break out these bits from frame_resize_inside, and update it to use the new function. Signed-off-by: Derek Foreman --- shared/cairo-util.h | 4 ++++ shared/frame.c | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/shared/cairo-util.h b/shared/cairo-util.h index 6fd11f6b..17f7b4f3 100644 --- a/shared/cairo-util.h +++ b/shared/cairo-util.h @@ -161,6 +161,10 @@ frame_width(struct frame *frame); int32_t frame_height(struct frame *frame); +void +frame_decoration_sizes(struct frame *frame, int32_t *top, int32_t *bottom, + int32_t *left, int32_t *right); + void frame_interior(struct frame *frame, int32_t *x, int32_t *y, int32_t *width, int32_t *height); diff --git a/shared/frame.c b/shared/frame.c index e8a5cad6..cf58d66b 100644 --- a/shared/frame.c +++ b/shared/frame.c @@ -493,27 +493,40 @@ frame_resize(struct frame *frame, int32_t width, int32_t height) } void -frame_resize_inside(struct frame *frame, int32_t width, int32_t height) +frame_decoration_sizes(struct frame *frame, int32_t *top, int32_t *bottom, + int32_t *left, int32_t *right) { struct theme *t = frame->theme; - int decoration_width, decoration_height, titlebar_height; + /* Top may have a titlebar */ if (frame->title || !wl_list_empty(&frame->buttons)) - titlebar_height = t->titlebar_height; + *top = t->titlebar_height; else - titlebar_height = t->width; + *top = t->width; - if (frame->flags & FRAME_FLAG_MAXIMIZED) { - decoration_width = t->width * 2; - decoration_height = t->width + titlebar_height; - } else { - decoration_width = (t->width + t->margin) * 2; - decoration_height = t->width + - titlebar_height + t->margin * 2; - } + /* All other sides have the basic frame thickness */ + *bottom = t->width; + *right = t->width; + *left = t->width; + + if (frame->flags & FRAME_FLAG_MAXIMIZED) + return; + + /* Not maximized, add shadows */ + *top += t->margin; + *bottom += t->margin; + *left += t->margin; + *right += t->margin; +} + +void +frame_resize_inside(struct frame *frame, int32_t width, int32_t height) +{ + int32_t top, bottom, left, right; - frame_resize(frame, width + decoration_width, - height + decoration_height); + frame_decoration_sizes(frame, &top, &bottom, &left, &right); + frame_resize(frame, width + left + right, + height + top + bottom); } int32_t