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

Commit ca4a97b

Browse files
committed
do not use wl_event_loop for signal handling
ΔSLOC: -4 Fixes: #456 Fixes: #459
1 parent 76ba2cd commit ca4a97b

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

dwl.c

+10-13
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static void focusmon(const Arg *arg);
260260
static void focusstack(const Arg *arg);
261261
static Client *focustop(Monitor *m);
262262
static void fullscreennotify(struct wl_listener *listener, void *data);
263-
static int handlesig(int signo, void *data);
263+
static void handlesig(int signo);
264264
static void incnmaster(const Arg *arg);
265265
static void inputdevice(struct wl_listener *listener, void *data);
266266
static int keybinding(uint32_t mods, xkb_keysym_t sym);
@@ -326,8 +326,6 @@ static pid_t child_pid = -1;
326326
static int locked;
327327
static void *exclusive_focus;
328328
static struct wl_display *dpy;
329-
static struct wl_event_loop *eventloop;
330-
static struct wl_event_source *sighandler[4];
331329
static struct wlr_backend *backend;
332330
static struct wlr_scene *scene;
333331
static struct wlr_scene_tree *layers[NUM_LAYERS];
@@ -654,7 +652,6 @@ checkidleinhibitor(struct wlr_surface *exclude)
654652
void
655653
cleanup(void)
656654
{
657-
int i;
658655
#ifdef XWAYLAND
659656
wlr_xwayland_destroy(xwayland);
660657
#endif
@@ -671,8 +668,6 @@ cleanup(void)
671668
wlr_cursor_destroy(cursor);
672669
wlr_output_layout_destroy(output_layout);
673670
wlr_seat_destroy(seat);
674-
for (i = 0; i < LENGTH(sighandler); i++)
675-
wl_event_source_remove(sighandler[i]);
676671
wl_display_destroy(dpy);
677672
}
678673

@@ -826,7 +821,8 @@ createkeyboard(struct wlr_keyboard *keyboard)
826821

827822
wlr_seat_set_keyboard(seat, keyboard);
828823

829-
kb->key_repeat_source = wl_event_loop_add_timer(eventloop, keyrepeat, kb);
824+
kb->key_repeat_source = wl_event_loop_add_timer(
825+
wl_display_get_event_loop(dpy), keyrepeat, kb);
830826

831827
/* And add the keyboard to our list of keyboards */
832828
wl_list_insert(&keyboards, &kb->link);
@@ -1338,8 +1334,8 @@ fullscreennotify(struct wl_listener *listener, void *data)
13381334
setfullscreen(c, client_wants_fullscreen(c));
13391335
}
13401336

1341-
int
1342-
handlesig(int signo, void *data)
1337+
void
1338+
handlesig(int signo)
13431339
{
13441340
if (signo == SIGCHLD) {
13451341
#ifdef XWAYLAND
@@ -1357,7 +1353,6 @@ handlesig(int signo, void *data)
13571353
} else if (signo == SIGINT || signo == SIGTERM) {
13581354
quit(NULL);
13591355
}
1360-
return 0;
13611356
}
13621357

13631358
void
@@ -2143,13 +2138,15 @@ void
21432138
setup(void)
21442139
{
21452140
int i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE};
2141+
struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = handlesig};
2142+
sigemptyset(&sa.sa_mask);
2143+
2144+
for (i = 0; i < LENGTH(sig); i++)
2145+
sigaction(sig[i], &sa, NULL);
21462146

21472147
/* The Wayland display is managed by libwayland. It handles accepting
21482148
* clients from the Unix socket, manging Wayland globals, and so on. */
21492149
dpy = wl_display_create();
2150-
eventloop = wl_display_get_event_loop(dpy);
2151-
for (i = 0; i < LENGTH(sighandler); i++)
2152-
sighandler[i] = wl_event_loop_add_signal(eventloop, sig[i], handlesig, NULL);
21532150

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

0 commit comments

Comments
 (0)