mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-23 12:35:41 +02:00
main: drop xcb dependency
Handle program termination by a) using a signal handler to detect e.g. ctrl-c, and b) listening on the abort_fd to detect when the bar aborts (e.g. due to XCB disconnect, i.e. when the X server dies).
This commit is contained in:
parent
404a7a7dcd
commit
9239d4298c
1 changed files with 9 additions and 26 deletions
33
main.c
33
main.c
|
@ -121,15 +121,6 @@ main(int argc, const char *const *argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Connect to XCB, to be able to detect a disconnect (allowing us
|
|
||||||
* to exit) */
|
|
||||||
xcb_connection_t *xcb = xcb_connect(NULL, NULL);
|
|
||||||
if (xcb_connection_has_error(xcb) > 0) {
|
|
||||||
LOG_ERR("failed to connect to X");
|
|
||||||
xcb_disconnect(xcb);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
xcb_init();
|
xcb_init();
|
||||||
|
|
||||||
bar->abort_fd = abort_fd;
|
bar->abort_fd = abort_fd;
|
||||||
|
@ -140,26 +131,18 @@ main(int argc, const char *const *argv)
|
||||||
/* Now unblock. We should be only thread receiving SIGINT */
|
/* Now unblock. We should be only thread receiving SIGINT */
|
||||||
pthread_sigmask(SIG_UNBLOCK, &signal_mask, NULL);
|
pthread_sigmask(SIG_UNBLOCK, &signal_mask, NULL);
|
||||||
|
|
||||||
/* Wait for SIGINT, or XCB disconnect */
|
|
||||||
while (!aborted) {
|
while (!aborted) {
|
||||||
struct pollfd fds[] = {
|
struct pollfd fds[] = {{.fd = abort_fd, .events = POLLIN}};
|
||||||
{.fd = xcb_get_file_descriptor(xcb), .events = POLLPRI}
|
int r = poll(fds, 1, -1);
|
||||||
};
|
|
||||||
|
|
||||||
poll(fds, 1, -1);
|
/*
|
||||||
|
* Either the bar aborted (triggering the abort_fd), or user
|
||||||
if (aborted)
|
* killed us (triggering the signal handler which sets
|
||||||
break;
|
* 'aborted')
|
||||||
|
*/
|
||||||
LOG_INFO("XCB poll data");
|
assert(aborted || r == 1);
|
||||||
|
|
||||||
if (fds[0].revents & POLLHUP) {
|
|
||||||
LOG_INFO("disconnected from XCB, exiting");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
xcb_disconnect(xcb);
|
|
||||||
|
|
||||||
if (aborted)
|
if (aborted)
|
||||||
LOG_INFO("aborted: %s (%d)", strsignal(aborted), aborted);
|
LOG_INFO("aborted: %s (%d)", strsignal(aborted), aborted);
|
||||||
|
|
Loading…
Add table
Reference in a new issue