Make wlr_wl_shell_create work like xdg
Also: - rename wlr_xdg_shell_v6_init to create as that is what it does - free wlr_xdg_shell on failure to create wl_global, the struct is not initialized enough to call destroy at that point
This commit is contained in:
parent
d49edc8243
commit
f9b55dfa95
|
@ -22,7 +22,7 @@
|
||||||
struct sample_state {
|
struct sample_state {
|
||||||
struct wlr_renderer *renderer;
|
struct wlr_renderer *renderer;
|
||||||
struct wl_compositor_state compositor;
|
struct wl_compositor_state compositor;
|
||||||
struct wlr_wl_shell wl_shell;
|
struct wlr_wl_shell *wl_shell;
|
||||||
struct wlr_xdg_shell_v6 *xdg_shell;
|
struct wlr_xdg_shell_v6 *xdg_shell;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ void handle_output_frame(struct output_state *output, struct timespec *ts) {
|
||||||
wlr_renderer_begin(sample->renderer, wlr_output);
|
wlr_renderer_begin(sample->renderer, wlr_output);
|
||||||
|
|
||||||
struct wlr_wl_shell_surface *wl_shell_surface;
|
struct wlr_wl_shell_surface *wl_shell_surface;
|
||||||
wl_list_for_each(wl_shell_surface, &sample->wl_shell.surfaces, link) {
|
wl_list_for_each(wl_shell_surface, &sample->wl_shell->surfaces, link) {
|
||||||
output_frame_handle_surface(sample, wlr_output, ts, wl_shell_surface->surface);
|
output_frame_handle_surface(sample, wlr_output, ts, wl_shell_surface->surface);
|
||||||
}
|
}
|
||||||
struct wlr_xdg_surface_v6 *xdg_surface;
|
struct wlr_xdg_surface_v6 *xdg_surface;
|
||||||
|
@ -85,8 +85,11 @@ int main() {
|
||||||
state.renderer = wlr_gles2_renderer_init(compositor.backend);
|
state.renderer = wlr_gles2_renderer_init(compositor.backend);
|
||||||
wl_display_init_shm(compositor.display);
|
wl_display_init_shm(compositor.display);
|
||||||
wl_compositor_init(compositor.display, &state.compositor, state.renderer);
|
wl_compositor_init(compositor.display, &state.compositor, state.renderer);
|
||||||
wlr_wl_shell_init(&state.wl_shell, compositor.display);
|
state.wl_shell = wlr_wl_shell_create(compositor.display);
|
||||||
state.xdg_shell = wlr_xdg_shell_v6_init(compositor.display);
|
state.xdg_shell = wlr_xdg_shell_v6_create(compositor.display);
|
||||||
|
|
||||||
compositor_run(&compositor);
|
compositor_run(&compositor);
|
||||||
|
|
||||||
|
wlr_wl_shell_destroy(state.wl_shell);
|
||||||
|
wlr_xdg_shell_v6_destroy(state.xdg_shell);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@ struct wlr_wl_shell_surface {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void wlr_wl_shell_init(struct wlr_wl_shell *wlr_wl_shell,
|
struct wlr_wl_shell *wlr_wl_shell_create(struct wl_display *display);
|
||||||
struct wl_display *display);
|
|
||||||
void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell);
|
void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,7 +18,7 @@ struct wlr_xdg_surface_v6 {
|
||||||
void *data;
|
void *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_init(struct wl_display *display);
|
struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display);
|
||||||
void wlr_xdg_shell_v6_destroy(struct wlr_xdg_shell_v6 *xdg_shell);
|
void wlr_xdg_shell_v6_destroy(struct wlr_xdg_shell_v6 *xdg_shell);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -117,17 +117,22 @@ static void wl_shell_bind(struct wl_client *wl_client, void *_wl_shell,
|
||||||
wl_list_insert(&wl_shell->wl_resources, wl_resource_get_link(wl_resource));
|
wl_list_insert(&wl_shell->wl_resources, wl_resource_get_link(wl_resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_wl_shell_init(struct wlr_wl_shell *wlr_wl_shell,
|
struct wlr_wl_shell *wlr_wl_shell_create(struct wl_display *display) {
|
||||||
struct wl_display *display) {
|
struct wlr_wl_shell *wlr_wl_shell =
|
||||||
|
calloc(1, sizeof(struct wlr_wl_shell));
|
||||||
|
if (!wlr_wl_shell) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
struct wl_global *wl_global = wl_global_create(display,
|
struct wl_global *wl_global = wl_global_create(display,
|
||||||
&wl_shell_interface, 1, wlr_wl_shell, wl_shell_bind);
|
&wl_shell_interface, 1, wlr_wl_shell, wl_shell_bind);
|
||||||
if (!wl_global) {
|
if (!wl_global) {
|
||||||
// TODO: return failure somehow
|
free(wlr_wl_shell);
|
||||||
return;
|
return NULL;
|
||||||
}
|
}
|
||||||
wlr_wl_shell->wl_global = wl_global;
|
wlr_wl_shell->wl_global = wl_global;
|
||||||
wl_list_init(&wlr_wl_shell->wl_resources);
|
wl_list_init(&wlr_wl_shell->wl_resources);
|
||||||
wl_list_init(&wlr_wl_shell->surfaces);
|
wl_list_init(&wlr_wl_shell->surfaces);
|
||||||
|
return wlr_wl_shell;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell) {
|
void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell) {
|
||||||
|
@ -141,4 +146,5 @@ void wlr_wl_shell_destroy(struct wlr_wl_shell *wlr_wl_shell) {
|
||||||
}
|
}
|
||||||
// TODO: destroy surfaces
|
// TODO: destroy surfaces
|
||||||
wl_global_destroy(wlr_wl_shell->wl_global);
|
wl_global_destroy(wlr_wl_shell->wl_global);
|
||||||
|
free(wlr_wl_shell);
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ static void xdg_shell_bind(struct wl_client *wl_client, void *_xdg_shell,
|
||||||
wl_list_insert(&xdg_shell->wl_resources, wl_resource_get_link(wl_resource));
|
wl_list_insert(&xdg_shell->wl_resources, wl_resource_get_link(wl_resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_init(struct wl_display *display) {
|
struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_create(struct wl_display *display) {
|
||||||
struct wlr_xdg_shell_v6 *xdg_shell =
|
struct wlr_xdg_shell_v6 *xdg_shell =
|
||||||
calloc(1, sizeof(struct wlr_xdg_shell_v6));
|
calloc(1, sizeof(struct wlr_xdg_shell_v6));
|
||||||
if (!xdg_shell) {
|
if (!xdg_shell) {
|
||||||
|
@ -188,7 +188,7 @@ struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_init(struct wl_display *display) {
|
||||||
struct wl_global *wl_global = wl_global_create(display,
|
struct wl_global *wl_global = wl_global_create(display,
|
||||||
&zxdg_shell_v6_interface, 1, xdg_shell, xdg_shell_bind);
|
&zxdg_shell_v6_interface, 1, xdg_shell, xdg_shell_bind);
|
||||||
if (!wl_global) {
|
if (!wl_global) {
|
||||||
wlr_xdg_shell_v6_destroy(xdg_shell);
|
free(xdg_shell);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
xdg_shell->wl_global = wl_global;
|
xdg_shell->wl_global = wl_global;
|
||||||
|
|
Loading…
Reference in New Issue