Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Headers/wayland/WaylandServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ struct window
CairoSurface *wcs;
};

/* get_window_with_id returns the known window with the passed ID, or NULL.
*
* NULL is returned when the passed window is not known; for example, the
* window has been '->terminated' and was removed from the window_list already,
* but something has referred to its ID. It is the responsibility of the caller
* to handle the case where NULL is used.
*/
struct window *get_window_with_id(WaylandConfig *wlconfig, int winid);

@interface WaylandServer : GSDisplayServer
Expand Down
16 changes: 16 additions & 0 deletions Source/wayland/WaylandServer+Xdgshell.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@

if (window->terminated == YES)
{
// 'struct window' is defined in Headers/wayland/WaylandServer.
//
// window->terminated should only be true after
// -[WaylandServer(WindowOps) termwindow:(int)win] sets this to true
// after invoking -[WaylandServer destroyWindowShell:window] and
// using wl_list_remove(&window->link);.
//
// We do not expect 'window' to be referenced again, since
// -destroyWindowShell: invokes wl_display_dispatch_pending(...) and
// wl_display_flush(...);. On the off chance it does, first, we may want
// to patch every single invocation of get_window_with_id() that may
// currently be ignoring the case where NULL may be returned, and
// possibly crashing for that reason.
//
// But, a free here should on its own be fine as long as everyone
// passes around the window ID and does not store a ptr to window itself.
NSDebugLog(@"deleting window win=%d", window->window_id);
free(window);
return;
Expand Down
2 changes: 2 additions & 0 deletions Source/wayland/WaylandServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ static void handle_global_remove(void *data, struct wl_registry *registry,
handle_global, handle_global_remove};

struct window *get_window_with_id(WaylandConfig *wlconfig, int winid) {
/* This can return NULL. A relevant note has been added to the docstring
* in the header. Callers should be handling this. */
struct window *window;

wl_list_for_each(window, &wlconfig->window_list, link) {
Expand Down