Skip to content

Commit 85525d7

Browse files
authored
Merge pull request #201 from Ferdi265/fix-xdg-geometry
xdg-popup-surface: avoid setting window_geometry with no buffer attached
2 parents 1dde35e + 9e9c60f commit 85525d7

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/xdg-popup-surface.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ xdg_popup_surface_map (CustomShellSurface *super, struct wl_surface *wl_surface)
162162
g_return_if_fail (xdg_wm_base_global);
163163
struct xdg_positioner *positioner = xdg_wm_base_create_positioner (xdg_wm_base_global);
164164
self->geom = gtk_window_get_priv_logical_geom (gtk_window);
165+
self->cached_allocation = (GdkRectangle){0};
165166
enum xdg_positioner_anchor anchor = gdk_gravity_get_xdg_positioner_anchor(self->position.rect_anchor);
166167
enum xdg_positioner_gravity gravity = gdk_gravity_get_xdg_positioner_gravity(self->position.window_anchor);
167168
enum xdg_positioner_constraint_adjustment constraint_adjustment =
@@ -188,11 +189,6 @@ xdg_popup_surface_map (CustomShellSurface *super, struct wl_surface *wl_surface)
188189
xdg_positioner_destroy (positioner);
189190

190191
xdg_popup_surface_maybe_grab (self, gdk_window);
191-
xdg_surface_set_window_geometry (self->xdg_surface,
192-
self->geom.x,
193-
self->geom.y,
194-
self->geom.width,
195-
self->geom.height);
196192
}
197193

198194
static void
@@ -277,12 +273,7 @@ xdg_popup_surface_new (GtkWindow *gtk_window, XdgPopupPosition const* position)
277273
custom_shell_surface_init ((CustomShellSurface *)self, gtk_window);
278274

279275
self->position = *position;
280-
self->cached_allocation = (GdkRectangle) {
281-
.x = 0,
282-
.y = 0,
283-
.width = 0,
284-
.height = 0,
285-
};
276+
self->cached_allocation = (GdkRectangle){0};
286277
self->xdg_surface = NULL;
287278
self->xdg_popup = NULL;
288279

test/mock-server/mock-server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ void* alloc_zeroed(size_t size);
3434
#define NEW_ID_ARG(name, index) ASSERT(type_code_at_index(message, index) == 'n'); uint32_t name = args[index].n;
3535
#define RESOURCE_ARG(type, name, index) ASSERT(type_code_at_index(message, index) == 'o'); ASSERT(message->types[index] == &type##_interface); struct wl_resource* name = (struct wl_resource*)args[index].o;
3636
#define UINT_ARG(name, index) ASSERT(type_code_at_index(message, index) == 'u'); uint32_t name = args[index].u;
37+
#define INT_ARG(name, index) ASSERT(type_code_at_index(message, index) == 'i'); int32_t name = args[index].i;
3738

3839
typedef void (*RequestOverrideFunction)(struct wl_resource* resource, const struct wl_message* message, union wl_argument* args);
3940
void install_request_override(const struct wl_interface* interface, const char* name, RequestOverrideFunction function);

test/mock-server/overrides.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct SurfaceData
2929
struct wl_resource* pending_frame;
3030
struct wl_resource* pending_buffer; // The attached but not committed buffer
3131
char buffer_cleared; // If the buffer has been explicitly cleared since the last commit
32+
char pending_window_geom; // If the window geom has been set since last commit
3233
struct wl_resource* xdg_toplevel;
3334
struct wl_resource* xdg_popup;
3435
struct wl_resource* xdg_surface;
@@ -123,6 +124,11 @@ static void wl_surface_commit(struct wl_resource *resource, const struct wl_mess
123124
data->pending_buffer = NULL;
124125
}
125126

127+
if (data->pending_window_geom) {
128+
ASSERT(data->has_committed_buffer);
129+
data->pending_window_geom = 0;
130+
}
131+
126132
if (data->pending_frame)
127133
{
128134
wl_callback_send_done(data->pending_frame, 0);
@@ -255,6 +261,18 @@ static void xdg_surface_destroy(struct wl_resource *resource, const struct wl_me
255261
data->xdg_surface = NULL;
256262
}
257263

264+
static void xdg_surface_set_window_geometry(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args)
265+
{
266+
//INT_ARG(x, 0);
267+
//INT_ARG(y, 1);
268+
INT_ARG(width, 2);
269+
INT_ARG(height, 3);
270+
SurfaceData* data = wl_resource_get_user_data(resource);
271+
ASSERT(width > 0);
272+
ASSERT(height > 0);
273+
data->pending_window_geom = 1;
274+
}
275+
258276
static void xdg_surface_get_toplevel(struct wl_resource *resource, const struct wl_message* message, union wl_argument* args)
259277
{
260278
NEW_ID_ARG(id, 0);
@@ -385,6 +403,7 @@ void init()
385403
OVERRIDE_REQUEST(wl_seat, get_pointer);
386404
OVERRIDE_REQUEST(xdg_wm_base, get_xdg_surface);
387405
OVERRIDE_REQUEST(xdg_surface, destroy);
406+
OVERRIDE_REQUEST(xdg_surface, set_window_geometry);
388407
OVERRIDE_REQUEST(xdg_surface, get_toplevel);
389408
OVERRIDE_REQUEST(xdg_toplevel, destroy);
390409
OVERRIDE_REQUEST(xdg_surface, get_popup);

0 commit comments

Comments
 (0)