Handle SIGINT through libev
Handle SIGINT using libev's ev_signal handler, instead of using sigaction(). Fixes #64. But compton might miss signals when it's not in the main loop (e.g. when compton is reset), and thus not exit "clearly". It should cause any real problem though, so we don't care. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
df69749804
commit
7a21cef9a4
|
@ -311,6 +311,8 @@ typedef struct session {
|
||||||
ev_prepare event_check;
|
ev_prepare event_check;
|
||||||
/// Signal handler for SIGUSR1
|
/// Signal handler for SIGUSR1
|
||||||
ev_signal usr1_signal;
|
ev_signal usr1_signal;
|
||||||
|
/// Signal handler for SIGINT
|
||||||
|
ev_signal int_signal;
|
||||||
/// backend data
|
/// backend data
|
||||||
void *backend_data;
|
void *backend_data;
|
||||||
/// libev mainloop
|
/// libev mainloop
|
||||||
|
|
|
@ -2436,6 +2436,15 @@ x_event_callback(EV_P_ ev_io *w, int revents) {
|
||||||
static void
|
static void
|
||||||
reset_enable(EV_P_ ev_signal *w, int revents) {
|
reset_enable(EV_P_ ev_signal *w, int revents) {
|
||||||
session_t *ps = session_ptr(w, usr1_signal);
|
session_t *ps = session_ptr(w, usr1_signal);
|
||||||
|
log_info("compton is resetting...");
|
||||||
|
ev_break(ps->loop, EVBREAK_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
exit_enable(EV_P_ ev_signal *w, int revents) {
|
||||||
|
session_t *ps = session_ptr(w, int_signal);
|
||||||
|
log_info("compton is quitting...");
|
||||||
|
ps->quit = true;
|
||||||
ev_break(ps->loop, EVBREAK_ALL);
|
ev_break(ps->loop, EVBREAK_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2916,7 +2925,9 @@ session_init(int argc, char **argv, Display *dpy, const char *config_file,
|
||||||
|
|
||||||
// Set up SIGUSR1 signal handler to reset program
|
// Set up SIGUSR1 signal handler to reset program
|
||||||
ev_signal_init(&ps->usr1_signal, reset_enable, SIGUSR1);
|
ev_signal_init(&ps->usr1_signal, reset_enable, SIGUSR1);
|
||||||
|
ev_signal_init(&ps->int_signal, exit_enable, SIGINT);
|
||||||
ev_signal_start(ps->loop, &ps->usr1_signal);
|
ev_signal_start(ps->loop, &ps->usr1_signal);
|
||||||
|
ev_signal_start(ps->loop, &ps->int_signal);
|
||||||
|
|
||||||
// xcb can read multiple events from the socket when a request with reply is
|
// xcb can read multiple events from the socket when a request with reply is
|
||||||
// made.
|
// made.
|
||||||
|
@ -3136,6 +3147,7 @@ session_destroy(session_t *ps) {
|
||||||
ev_idle_stop(ps->loop, &ps->draw_idle);
|
ev_idle_stop(ps->loop, &ps->draw_idle);
|
||||||
ev_prepare_stop(ps->loop, &ps->event_check);
|
ev_prepare_stop(ps->loop, &ps->event_check);
|
||||||
ev_signal_stop(ps->loop, &ps->usr1_signal);
|
ev_signal_stop(ps->loop, &ps->usr1_signal);
|
||||||
|
ev_signal_stop(ps->loop, &ps->int_signal);
|
||||||
|
|
||||||
if (ps == ps_g)
|
if (ps == ps_g)
|
||||||
ps_g = NULL;
|
ps_g = NULL;
|
||||||
|
@ -3167,11 +3179,6 @@ session_run(session_t *ps) {
|
||||||
ev_run(ps->loop, 0);
|
ev_run(ps->loop, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
sigint_handler(int attr_unused signum) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The function that everybody knows.
|
* The function that everybody knows.
|
||||||
*/
|
*/
|
||||||
|
@ -3218,15 +3225,6 @@ main(int argc, char **argv) {
|
||||||
close(pfds[0]);
|
close(pfds[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
sigset_t sigmask;
|
|
||||||
sigemptyset(&sigmask);
|
|
||||||
const struct sigaction int_action = {
|
|
||||||
.sa_handler = sigint_handler,
|
|
||||||
.sa_mask = sigmask,
|
|
||||||
.sa_flags = 0
|
|
||||||
};
|
|
||||||
sigaction(SIGINT, &int_action, NULL);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
Display *dpy = XOpenDisplay(NULL);
|
Display *dpy = XOpenDisplay(NULL);
|
||||||
|
|
Loading…
Reference in New Issue