bspwm/main.c

54 lines
1.2 KiB
C
Raw Normal View History

2012-07-30 12:21:22 +02:00
#include <sys/select.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
2012-07-29 22:46:12 +02:00
#include <xcb/xcb.h>
2012-07-30 12:21:22 +02:00
#include <xcb/xcb_event.h>
2012-07-29 22:46:12 +02:00
#include "main.h"
2012-07-30 12:21:22 +02:00
#include "types.h"
#include "utils.h"
2012-07-29 22:46:12 +02:00
int main(void)
{
2012-07-30 12:21:22 +02:00
fd_set descriptors;
int fifo, xfd, nbr;
char message[MSG_BUF_SIZE];
struct timeval timeout;
xcb_generic_event_t *event;
dpy = xcb_connect(NULL, &default_screen);
if (xcb_connection_has_error(dpy))
die("error: cannot open display\n");
xfd = xcb_get_file_descriptor(dpy);
timeout.tv_sec = SELECT_TIMEOUT;
/* O_RDWR is needed, see http://bit.ly/T0C5Mh */
fifo = open(INPUT_FIFO, O_RDWR | O_NONBLOCK);
FD_ZERO(&descriptors);
FD_SET(xfd, &descriptors);
FD_SET(fifo, &descriptors);
while (true) {
if (select(fifo + 1, &descriptors, 0, 0, &timeout)) {
nbr = read(fifo, message, sizeof(message));
if (nbr > 0) {
message[nbr] = '\0';
/* process_msg(message); */
}
event = xcb_poll_for_event(dpy);
if (event != NULL) {
/* handle_event(event); */
}
}
}
close(fifo);
xcb_disconnect(dpy);
2012-07-29 22:46:12 +02:00
return 0;
}