Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

do not use wl_event_loop for signal handling #460

Merged
merged 1 commit into from
Jul 14, 2023
Merged
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
23 changes: 10 additions & 13 deletions dwl.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m);
static void fullscreennotify(struct wl_listener *listener, void *data);
static int handlesig(int signo, void *data);
static void handlesig(int signo);
static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data);
static int keybinding(uint32_t mods, xkb_keysym_t sym);
Expand Down Expand Up @@ -326,8 +326,6 @@ static pid_t child_pid = -1;
static int locked;
static void *exclusive_focus;
static struct wl_display *dpy;
static struct wl_event_loop *eventloop;
static struct wl_event_source *sighandler[4];
static struct wlr_backend *backend;
static struct wlr_scene *scene;
static struct wlr_scene_tree *layers[NUM_LAYERS];
Expand Down Expand Up @@ -653,7 +651,6 @@ checkidleinhibitor(struct wlr_surface *exclude)
void
cleanup(void)
{
int i;
#ifdef XWAYLAND
wlr_xwayland_destroy(xwayland);
#endif
Expand All @@ -670,8 +667,6 @@ cleanup(void)
wlr_cursor_destroy(cursor);
wlr_output_layout_destroy(output_layout);
wlr_seat_destroy(seat);
for (i = 0; i < LENGTH(sighandler); i++)
wl_event_source_remove(sighandler[i]);
wl_display_destroy(dpy);
}

Expand Down Expand Up @@ -825,7 +820,8 @@ createkeyboard(struct wlr_keyboard *keyboard)

wlr_seat_set_keyboard(seat, keyboard);

kb->key_repeat_source = wl_event_loop_add_timer(eventloop, keyrepeat, kb);
kb->key_repeat_source = wl_event_loop_add_timer(
wl_display_get_event_loop(dpy), keyrepeat, kb);

/* And add the keyboard to our list of keyboards */
wl_list_insert(&keyboards, &kb->link);
Expand Down Expand Up @@ -1337,8 +1333,8 @@ fullscreennotify(struct wl_listener *listener, void *data)
setfullscreen(c, client_wants_fullscreen(c));
}

int
handlesig(int signo, void *data)
void
handlesig(int signo)
{
if (signo == SIGCHLD) {
#ifdef XWAYLAND
Expand All @@ -1356,7 +1352,6 @@ handlesig(int signo, void *data)
} else if (signo == SIGINT || signo == SIGTERM) {
quit(NULL);
}
return 0;
}

void
Expand Down Expand Up @@ -2144,13 +2139,15 @@ void
setup(void)
{
int i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE};
struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = handlesig};
sigemptyset(&sa.sa_mask);

for (i = 0; i < LENGTH(sig); i++)
sigaction(sig[i], &sa, NULL);

/* 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();
eventloop = wl_display_get_event_loop(dpy);
for (i = 0; i < LENGTH(sighandler); i++)
sighandler[i] = wl_event_loop_add_signal(eventloop, sig[i], handlesig, NULL);

/* The backend is a wlroots feature which abstracts the underlying input and
* output hardware. The autocreate option will choose the most suitable
Expand Down