Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.2 KiB

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