Skip to content

Commit

Permalink
Fix GNOME breaking when setting window geometry
Browse files Browse the repository at this point in the history
The current version of GNOME has a regression that causes the compositor
to send incorrect geometry with the next configure event if the CSD
buffers are created after a call to set_window_geometry.

So call set_window_geometry last. And shake head sadly.
  • Loading branch information
kovidgoyal committed Apr 7, 2021
1 parent 82a5733 commit 4e6d5d3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
14 changes: 5 additions & 9 deletions glfw/wl_client_side_decorations.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string.h>
#include <stdlib.h>

#define debug(...) if (_glfw.hints.init.debugRendering) fprintf(stderr, __VA_ARGS__);
#define decs window->wl.decorations

#define ARGB(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
Expand Down Expand Up @@ -273,6 +274,7 @@ create_shm_buffers(_GLFWwindow* window) {
create_shadow_tile(window);
render_title_bar(window, true);
render_edges(window);
debug("Created decoration buffers at scale: %u vertical_height: %zu horizontal_width: %zu\n", scale, vertical_height, horizontal_width);
return true;
}

Expand Down Expand Up @@ -375,12 +377,6 @@ free_all_csd_resources(_GLFWwindow *window) {
decs.shadow_tile.data = NULL;
}

void
resize_csd(_GLFWwindow *window) {
if (!window->decorated || window->wl.decorations.serverSide) return;
ensure_csd_resources(window);
}

void
change_csd_title(_GLFWwindow *window) {
if (!window->decorated || window->wl.decorations.serverSide) return;
Expand All @@ -400,10 +396,10 @@ set_csd_window_geometry(_GLFWwindow *window, int32_t *width, int32_t *height) {
*height = window->wl.user_requested_content_size.height;
if (has_csd) *height += decs.metrics.visible_titlebar_height;
}
struct { int32_t x, y, width, height; } geometry = {.x = 0, .y = 0, .width = *width, .height = *height};
decs.geometry.x = 0; decs.geometry.y = 0;
decs.geometry.width = *width; decs.geometry.height = *height;
if (has_csd) {
geometry.y = -decs.metrics.visible_titlebar_height;
decs.geometry.y = -decs.metrics.visible_titlebar_height;
*height -= decs.metrics.visible_titlebar_height;
}
xdg_surface_set_window_geometry(window->wl.xdg.surface, geometry.x, geometry.y, geometry.width, geometry.height);
}
1 change: 0 additions & 1 deletion glfw/wl_client_side_decorations.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

void free_all_csd_resources(_GLFWwindow *window);
void free_csd_surfaces(_GLFWwindow *window);
void resize_csd(_GLFWwindow *window);
void change_csd_title(_GLFWwindow *window);
bool ensure_csd_resources(_GLFWwindow *window);
void set_csd_window_geometry(_GLFWwindow *window, int32_t *width, int32_t *height);
4 changes: 4 additions & 0 deletions glfw/wl_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ typedef struct _GLFWwindowWayland
unsigned int width, top, horizontal, vertical, visible_titlebar_height;
} metrics;

struct {
int32_t x, y, width, height;
} geometry;

struct {
uint32_t *data;
size_t for_decoration_size, stride, segments, corner_size;
Expand Down
29 changes: 15 additions & 14 deletions glfw/wl_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <fcntl.h>
#include <sys/mman.h>

#define debug(...) if (_glfw.hints.init.debugRendering) printf(__VA_ARGS__);
#define debug(...) if (_glfw.hints.init.debugRendering) fprintf(stderr, __VA_ARGS__);

static struct wl_buffer* createShmBuffer(const GLFWimage* image, bool is_opaque, bool init_data)
{
Expand Down Expand Up @@ -213,18 +213,15 @@ static void setOpaqueRegion(_GLFWwindow* window)
}


static void resizeFramebuffer(_GLFWwindow* window)
{
static void
resizeFramebuffer(_GLFWwindow* window) {
int scale = window->wl.scale;
int scaledWidth = window->wl.width * scale;
int scaledHeight = window->wl.height * scale;
debug("Resizing framebuffer to: %dx%d at scale: %d\n", window->wl.width, window->wl.height, scale);
wl_egl_window_resize(window->wl.native, scaledWidth, scaledHeight, 0, 0);
if (!window->wl.transparent)
setOpaqueRegion(window);
if (!window->wl.transparent) setOpaqueRegion(window);
_glfwInputFramebufferSize(window, scaledWidth, scaledHeight);

if (window->wl.decorations.mapping.data) resize_csd(window);

}


Expand Down Expand Up @@ -265,8 +262,7 @@ static void xdgDecorationHandleConfigure(void* data,
_GLFWwindow* window = data;

window->wl.decorations.serverSide = (mode == ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);

if (!window->wl.decorations.serverSide) ensure_csd_resources(window);
ensure_csd_resources(window);
}

static const struct zxdg_toplevel_decoration_v1_listener xdgDecorationListener = {
Expand All @@ -293,6 +289,7 @@ static void surfaceHandleEnter(void *data,
if (checkScaleChange(window)) {
resizeFramebuffer(window);
_glfwInputWindowContentScale(window, window->wl.scale, window->wl.scale);
ensure_csd_resources(window);
}
}

Expand All @@ -317,6 +314,7 @@ static void surfaceHandleLeave(void *data,
if (checkScaleChange(window)) {
resizeFramebuffer(window);
_glfwInputWindowContentScale(window, window->wl.scale, window->wl.scale);
ensure_csd_resources(window);
}
}

Expand Down Expand Up @@ -385,8 +383,7 @@ static void setFullscreen(_GLFWwindow* window, _GLFWmonitor* monitor, bool on)
if (!window->wl.decorations.serverSide) free_csd_surfaces(window);
} else {
xdg_toplevel_unset_fullscreen(window->wl.xdg.toplevel);
if (!_glfw.wl.decorationManager)
ensure_csd_resources(window);
ensure_csd_resources(window);
}
}
setIdleInhibitor(window, on);
Expand Down Expand Up @@ -450,11 +447,15 @@ static void xdgToplevelHandleConfigure(void* data,
bool live_resize_done = !(new_states & TOPLEVEL_STATE_RESIZING) && (window->wl.toplevel_states & TOPLEVEL_STATE_RESIZING);
window->wl.toplevel_states = new_states;
set_csd_window_geometry(window, &width, &height);
wl_surface_commit(window->wl.surface);
dispatchChangesAfterConfigure(window, width, height);
debug("final window content size: %dx%d\n", window->wl.width, window->wl.height);
_glfwInputWindowFocus(window, window->wl.toplevel_states & TOPLEVEL_STATE_ACTIVATED);
ensure_csd_resources(window);
#define geometry window->wl.decorations.geometry
debug("Setting window geometry: x=%d y=%d %dx%d\n", geometry.x, geometry.y, geometry.width, geometry.height);
xdg_surface_set_window_geometry(window->wl.xdg.surface, geometry.x, geometry.y, geometry.width, geometry.height);
#undef geometry
wl_surface_commit(window->wl.surface);
if (live_resize_done) _glfwInputLiveResize(window, false);
}

Expand Down Expand Up @@ -872,8 +873,8 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
set_csd_window_geometry(window, &width, &height);
window->wl.width = width; window->wl.height = height;
resizeFramebuffer(window);
wl_surface_commit(window->wl.surface);
ensure_csd_resources(window);
wl_surface_commit(window->wl.surface);
}
}

Expand Down

0 comments on commit 4e6d5d3

Please sign in to comment.