Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 0e34208

Browse files
emersionKirill Primak
authored andcommitted
xdg-shell: introduce wlr_xdg_surface.current
This holds the current state, and avoids having ad-hoc fields in wlr_xdg_surface.
1 parent db4afc2 commit 0e34208

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

include/wlr/types/wlr_xdg_shell.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,11 @@ struct wlr_xdg_surface {
191191
struct wl_list popups; // wlr_xdg_popup::link
192192

193193
bool added, configured, mapped;
194-
uint32_t configure_serial;
195194
struct wl_event_source *configure_idle;
196195
uint32_t configure_next_serial;
197196
struct wl_list configure_list;
198197

199-
struct wlr_box geometry;
200-
201-
struct wlr_xdg_surface_state pending;
198+
struct wlr_xdg_surface_state current, pending;
202199

203200
struct wl_listener surface_destroy;
204201
struct wl_listener surface_commit;

types/wlr_layer_shell_v1.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ void wlr_layer_surface_v1_for_each_popup_surface(struct wlr_layer_surface_v1 *su
511511
}
512512

513513
double popup_sx, popup_sy;
514-
popup_sx = popup->popup->geometry.x - popup->geometry.x;
515-
popup_sy = popup->popup->geometry.y - popup->geometry.y;
514+
popup_sx = popup->popup->geometry.x - popup->current.geometry.x;
515+
popup_sy = popup->popup->geometry.y - popup->current.geometry.y;
516516

517517
struct layer_surface_iterator_data data = {
518518
.user_iterator = iterator,
@@ -542,8 +542,8 @@ struct wlr_surface *wlr_layer_surface_v1_popup_surface_at(
542542
wl_list_for_each(popup_state, &surface->popups, link) {
543543
struct wlr_xdg_surface *popup = popup_state->base;
544544

545-
double popup_sx = popup_state->geometry.x - popup->geometry.x;
546-
double popup_sy = popup_state->geometry.y - popup->geometry.y;
545+
double popup_sx = popup_state->geometry.x - popup->current.geometry.x;
546+
double popup_sy = popup_state->geometry.y - popup->current.geometry.y;
547547

548548
struct wlr_surface *sub = wlr_xdg_surface_surface_at(popup,
549549
sx - popup_sx,

types/xdg_shell/wlr_xdg_popup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ void wlr_xdg_popup_get_toplevel_coords(struct wlr_xdg_popup *popup,
408408
popup_sy += xdg_surface->popup->geometry.y;
409409
parent = xdg_surface->popup->parent;
410410
} else {
411-
popup_sx += xdg_surface->geometry.x;
412-
popup_sy += xdg_surface->geometry.y;
411+
popup_sx += xdg_surface->current.geometry.x;
412+
popup_sy += xdg_surface->current.geometry.y;
413413
break;
414414
}
415415
}

types/xdg_shell/wlr_xdg_surface.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ void unmap_xdg_surface(struct wlr_xdg_surface *surface) {
8181
}
8282

8383
surface->configured = surface->mapped = false;
84-
surface->configure_serial = 0;
8584
if (surface->configure_idle) {
8685
wl_event_source_remove(surface->configure_idle);
8786
surface->configure_idle = NULL;
8887
}
8988
surface->configure_next_serial = 0;
9089

91-
memset(&surface->geometry, 0, sizeof(struct wlr_box));
90+
memset(&surface->current, 0, sizeof(struct wlr_xdg_surface_state));
9291
memset(&surface->pending, 0, sizeof(struct wlr_xdg_surface_state));
9392
}
9493

@@ -310,22 +309,14 @@ static void xdg_surface_handle_surface_commit(struct wl_listener *listener,
310309
}
311310
}
312311

313-
static void surface_commit_state(struct wlr_xdg_surface *surface,
314-
struct wlr_xdg_surface_state *state) {
315-
surface->configure_serial = state->configure_serial;
316-
if (!wlr_box_empty(&state->geometry)) {
317-
surface->geometry = state->geometry;
318-
}
319-
}
320-
321312
void handle_xdg_surface_commit(struct wlr_surface *wlr_surface) {
322313
struct wlr_xdg_surface *surface =
323314
wlr_xdg_surface_from_wlr_surface(wlr_surface);
324315
if (surface == NULL) {
325316
return;
326317
}
327318

328-
surface_commit_state(surface, &surface->pending);
319+
surface->current = surface->pending;
329320

330321
switch (surface->role) {
331322
case WLR_XDG_SURFACE_ROLE_NONE:
@@ -540,9 +531,9 @@ void wlr_xdg_popup_get_position(struct wlr_xdg_popup *popup,
540531
struct wlr_box parent_geo;
541532
wlr_xdg_surface_get_geometry(parent, &parent_geo);
542533
*popup_sx = parent_geo.x + popup->geometry.x -
543-
popup->base->geometry.x;
534+
popup->base->current.geometry.x;
544535
*popup_sy = parent_geo.y + popup->geometry.y -
545-
popup->base->geometry.y;
536+
popup->base->current.geometry.y;
546537
}
547538

548539
struct wlr_surface *wlr_xdg_surface_surface_at(
@@ -632,10 +623,11 @@ void wlr_xdg_surface_for_each_popup_surface(struct wlr_xdg_surface *surface,
632623
void wlr_xdg_surface_get_geometry(struct wlr_xdg_surface *surface,
633624
struct wlr_box *box) {
634625
wlr_surface_get_extends(surface->surface, box);
626+
635627
/* The client never set the geometry */
636-
if (!surface->geometry.width) {
628+
if (wlr_box_empty(&surface->current.geometry)) {
637629
return;
638630
}
639631

640-
wlr_box_intersection(box, &surface->geometry, box);
632+
wlr_box_intersection(box, &surface->current.geometry, box);
641633
}

0 commit comments

Comments
 (0)