aboutsummaryrefslogtreecommitdiff
path: root/dwl.c
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2020-08-19 00:32:57 -0500
committerDevin J. Pohly <djpohly@gmail.com>2020-08-19 00:32:57 -0500
commit620da43933f2b192735d8e71196f89271007ce60 (patch)
tree80f5218dabace949ee7994d3f86e93932524ac4a /dwl.c
parent8eb6fe8e9e9e72801e149ef497c68f1df33f9e36 (diff)
cleanup function to match dwm
Diffstat (limited to 'dwl.c')
-rw-r--r--dwl.c37
1 files changed, 20 insertions, 17 deletions
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);
@@ -435,6 +436,20 @@ chvt(const Arg *arg)
}
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)
{
struct wlr_input_device *device = 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: