dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

ipc.c (2531B)


      1 static int epoll_fd;
      2 static int dpy_fd;
      3 static Monitor *lastselmon;
      4 
      5 int
      6 handlexevent(struct epoll_event *ev)
      7 {
      8 	if (ev->events & EPOLLIN) {
      9 		XEvent ev;
     10 		while (running && XPending(dpy)) {
     11 			XNextEvent(dpy, &ev);
     12 			#if XKB_PATCH
     13 			/* Unfortunately the xkbEventType is not constant hence it can't be part of the
     14 			 * normal event handler below */
     15 			if (ev.type == xkbEventType) {
     16 				xkbeventnotify(&ev);
     17 				continue;
     18 			}
     19 			#endif // XKB_PATCH
     20 
     21 			if (handler[ev.type]) {
     22 				handler[ev.type](&ev); /* call handler */
     23 				ipc_send_events(mons, &lastselmon, selmon);
     24 			}
     25 		}
     26 	} else if (ev-> events & EPOLLHUP)
     27 		return -1;
     28 
     29 	return 0;
     30 }
     31 
     32 void
     33 setlayoutsafe(const Arg *arg)
     34 {
     35 	const Layout *ltptr = (Layout *)arg->v;
     36 	if (ltptr == 0)
     37 		setlayout(arg);
     38 	for (int i = 0; i < LENGTH(layouts); i++) {
     39 		if (ltptr == &layouts[i])
     40 			setlayout(arg);
     41 	}
     42 }
     43 
     44 void
     45 setupepoll(void)
     46 {
     47 	epoll_fd = epoll_create1(0);
     48 	dpy_fd = ConnectionNumber(dpy);
     49 	struct epoll_event dpy_event;
     50 
     51 	// Initialize struct to 0
     52 	memset(&dpy_event, 0, sizeof(dpy_event));
     53 
     54 	DEBUG("Display socket is fd %d\n", dpy_fd);
     55 
     56 	if (epoll_fd == -1)
     57 		fputs("Failed to create epoll file descriptor", stderr);
     58 
     59 	dpy_event.events = EPOLLIN;
     60 	dpy_event.data.fd = dpy_fd;
     61 	if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, dpy_fd, &dpy_event)) {
     62 		fputs("Failed to add display file descriptor to epoll", stderr);
     63 		close(epoll_fd);
     64 		exit(1);
     65 	}
     66 
     67 	if (ipc_init(ipcsockpath, epoll_fd, ipccommands, LENGTH(ipccommands)) < 0)
     68 		fputs("Failed to initialize IPC\n", stderr);
     69 }
     70 
     71 void
     72 setstatus(const Arg *arg)
     73 {
     74 	Monitor *m;
     75 	#if BAR_EXTRASTATUS_PATCH
     76 	if (arg->v == NULL) {
     77 		strcpy(stext, "dwm-"VERSION);
     78 		estext[0] = '\0';
     79 	} else {
     80 		strcpy(rawstext, arg->v);
     81 		char *e = strchr(rawstext, statussep);
     82 		if (e) {
     83 			*e = '\0'; e++;
     84 			#if BAR_STATUSCMD_PATCH
     85 			strncpy(rawestext, e, sizeof(estext) - 1);
     86 			copyvalidchars(estext, rawestext);
     87 			#else
     88 			strncpy(estext, e, sizeof(estext) - 1);
     89 			#endif // BAR_STATUSCMD_PATCH
     90 		} else {
     91 			estext[0] = '\0';
     92 		}
     93 		#if BAR_STATUSCMD_PATCH
     94 		copyvalidchars(stext, rawstext);
     95 		#else
     96 		strncpy(stext, rawstext, sizeof(stext) - 1);
     97 		#endif // BAR_STATUSCMD_PATCH
     98 	}
     99 	#elif BAR_STATUSCMD_PATCH
    100 	if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext)))
    101 		strcpy(stext, "dwm-"VERSION);
    102 	else
    103 		copyvalidchars(stext, rawstext);
    104 	#else
    105 	if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
    106 		strcpy(stext, "dwm-"VERSION);
    107 	#endif // BAR_EXTRASTATUS_PATCH | BAR_STATUSCMD_PATCH
    108 	for (m = mons; m; m = m->next)
    109 		drawbar(m);
    110 }
    111