From 620da43933f2b192735d8e71196f89271007ce60 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Wed, 19 Aug 2020 00:32:57 -0500 Subject: cleanup function to match dwm --- dwl.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'dwl.c') diff --git a/dwl.c b/dwl.c index fa0a193..11ea951 100644 --- a/dwl.c +++ b/dwl.c @@ -179,6 +179,7 @@ static void arrange(Monitor *m); static void axisnotify(struct wl_listener *listener, void *data); static void buttonpress(struct wl_listener *listener, void *data); static void chvt(const Arg *arg); +static void cleanup(void); static void cleanupkeyboard(struct wl_listener *listener, void *data); static void cleanupmon(struct wl_listener *listener, void *data); static void commitnotify(struct wl_listener *listener, void *data); @@ -434,6 +435,20 @@ chvt(const Arg *arg) wlr_session_change_vt(wlr_backend_get_session(backend), arg->ui); } +void +cleanup(void) +{ +#ifdef XWAYLAND + wlr_xwayland_destroy(xwayland); +#endif + wl_display_destroy_clients(dpy); + wl_display_destroy(dpy); + + wlr_xcursor_manager_destroy(cursor_mgr); + wlr_cursor_destroy(cursor); + wlr_output_layout_destroy(output_layout); +} + void cleanupkeyboard(struct wl_listener *listener, void *data) { @@ -1447,6 +1462,10 @@ setsel(struct wl_listener *listener, void *data) void setup(void) { + /* The Wayland display is managed by libwayland. It handles accepting + * clients from the Unix socket, manging Wayland globals, and so on. */ + dpy = wl_display_create(); + /* clean up child processes immediately */ sigchld(0); @@ -1912,25 +1931,9 @@ main(int argc, char *argv[]) // socket if (!getenv("XDG_RUNTIME_DIR")) BARF("XDG_RUNTIME_DIR must be set"); - - /* The Wayland display is managed by libwayland. It handles accepting - * clients from the Unix socket, manging Wayland globals, and so on. */ - dpy = wl_display_create(); - setup(); run(startup_cmd); - - /* Once wl_display_run returns, we shut down the server. */ -#ifdef XWAYLAND - wlr_xwayland_destroy(xwayland); -#endif - wl_display_destroy_clients(dpy); - wl_display_destroy(dpy); - - wlr_xcursor_manager_destroy(cursor_mgr); - wlr_cursor_destroy(cursor); - wlr_output_layout_destroy(output_layout); - + cleanup(); return EXIT_SUCCESS; usage: -- cgit v1.2.3