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.

93 lines
2.1 KiB

  1. diff --git a/dwmblocks.c b/dwmblocks.c
  2. index 88bdfb0..7bd14df 100644
  3. --- a/dwmblocks.c
  4. +++ b/dwmblocks.c
  5. @@ -14,6 +14,7 @@ typedef struct {
  6. unsigned int signal;
  7. } Block;
  8. void sighandler(int num);
  9. +void buttonhandler(int sig, siginfo_t *si, void *ucontext);
  10. void replace(char *str, char old, char new);
  11. void getcmds(int time);
  12. #ifndef __OpenBSD__
  13. @@ -34,6 +35,8 @@ static int screen;
  14. static Window root;
  15. static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
  16. static char statusstr[2][256];
  17. +static char exportstring[CMDLENGTH + 16] = "export BUTTON=-;";
  18. +static int button = 0;
  19. static int statusContinue = 1;
  20. static void (*writestatus) () = setroot;
  21. @@ -48,16 +51,34 @@ void replace(char *str, char old, char new)
  22. //opens process *cmd and stores output in *output
  23. void getcmd(const Block *block, char *output)
  24. {
  25. + if (block->signal)
  26. + {
  27. + output[0] = block->signal;
  28. + output++;
  29. + }
  30. strcpy(output, block->icon);
  31. - char *cmd = block->command;
  32. - FILE *cmdf = popen(cmd,"r");
  33. + char* cmd;
  34. + FILE *cmdf;
  35. + if (button)
  36. + {
  37. + cmd = strcat(exportstring, block->command);
  38. + cmd[14] = '0' + button;
  39. + button = 0;
  40. + cmdf = popen(cmd,"r");
  41. + cmd[16] = '\0';
  42. + }
  43. + else
  44. + {
  45. + cmd = block->command;
  46. + cmdf = popen(cmd,"r");
  47. + }
  48. if (!cmdf)
  49. return;
  50. char c;
  51. int i = strlen(block->icon);
  52. fgets(output+i, CMDLENGTH-i, cmdf);
  53. i = strlen(output);
  54. - if (delim != '\0' && --i)
  55. + if (delim != '\0' && i)
  56. output[i++] = delim;
  57. output[i++] = '\0';
  58. pclose(cmdf);
  59. @@ -88,11 +106,18 @@ void getsigcmds(int signal)
  60. void setupsignals()
  61. {
  62. + struct sigaction sa;
  63. for(int i = 0; i < LENGTH(blocks); i++)
  64. {
  65. if (blocks[i].signal > 0)
  66. + {
  67. signal(SIGRTMIN+blocks[i].signal, sighandler);
  68. + sigaddset(&sa.sa_mask, SIGRTMIN+blocks[i].signal);
  69. + }
  70. }
  71. + sa.sa_sigaction = buttonhandler;
  72. + sa.sa_flags = SA_SIGINFO;
  73. + sigaction(SIGUSR1, &sa, NULL);
  74. }
  75. #endif
  76. @@ -152,6 +177,14 @@ void sighandler(int signum)
  77. getsigcmds(signum-SIGRTMIN);
  78. writestatus();
  79. }
  80. +
  81. +void buttonhandler(int sig, siginfo_t *si, void *ucontext)
  82. +{
  83. + button = si->si_value.sival_int & 0xff;
  84. + getsigcmds(si->si_value.sival_int >> 8);
  85. + writestatus();
  86. +}
  87. +
  88. #endif
  89. void termhandler(int signum)