Configuration file for DWM on MacBook Air
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.

151 lines
2.4 KiB

  1. /*
  2. * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * See LICENSE file for license details.
  4. */
  5. #include "dwm.h"
  6. #include <regex.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <sys/types.h>
  11. #include <X11/Xutil.h>
  12. typedef struct {
  13. const char *clpattern;
  14. const char *tpattern;
  15. Bool isfloat;
  16. } Rule;
  17. typedef struct {
  18. regex_t *clregex;
  19. regex_t *tregex;
  20. } RReg;
  21. /* static */
  22. TAGS
  23. RULES
  24. static RReg *rreg = NULL;
  25. static unsigned int len = 0;
  26. static void
  27. commit()
  28. {
  29. /* asserts sel != NULL */
  30. settitle(sel);
  31. if(!isvisible(sel))
  32. arrange(NULL);
  33. else
  34. drawstatus();
  35. }
  36. /* extern */
  37. Client *
  38. getnext(Client *c)
  39. {
  40. for(; c && !isvisible(c); c = c->next);
  41. return c;
  42. }
  43. Client *
  44. getprev(Client *c)
  45. {
  46. for(; c && !isvisible(c); c = c->prev);
  47. return c;
  48. }
  49. void
  50. initrregs()
  51. {
  52. unsigned int i;
  53. regex_t *reg;
  54. if(rreg)
  55. return;
  56. len = sizeof(rule) / sizeof(rule[0]);
  57. rreg = emallocz(len * sizeof(RReg));
  58. for(i = 0; i < len; i++) {
  59. if(rule[i].clpattern) {
  60. reg = emallocz(sizeof(regex_t));
  61. if(regcomp(reg, rule[i].clpattern, 0))
  62. free(reg);
  63. else
  64. rreg[i].clregex = reg;
  65. }
  66. if(rule[i].tpattern) {
  67. reg = emallocz(sizeof(regex_t));
  68. if(regcomp(reg, rule[i].tpattern, 0))
  69. free(reg);
  70. else
  71. rreg[i].tregex = reg;
  72. }
  73. }
  74. }
  75. void
  76. settags(Client *c)
  77. {
  78. char prop[512];
  79. unsigned int i, j;
  80. regmatch_t tmp;
  81. Bool matched = False;
  82. XClassHint ch;
  83. if(XGetClassHint(dpy, c->win, &ch)) {
  84. snprintf(prop, sizeof(prop), "%s:%s:%s",
  85. ch.res_class ? ch.res_class : "",
  86. ch.res_name ? ch.res_name : "", c->name);
  87. for(i = 0; !matched && i < len; i++)
  88. if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
  89. c->isfloat = rule[i].isfloat;
  90. for(j = 0; rreg[i].tregex && j < ntags; j++) {
  91. if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
  92. matched = True;
  93. c->tags[j] = True;
  94. }
  95. }
  96. }
  97. if(ch.res_class)
  98. XFree(ch.res_class);
  99. if(ch.res_name)
  100. XFree(ch.res_name);
  101. }
  102. if(!matched)
  103. for(i = 0; i < ntags; i++)
  104. c->tags[i] = seltag[i];
  105. for(i = 0; i < ntags && !c->tags[i]; i++);
  106. c->weight = i;
  107. }
  108. void
  109. tag(Arg *arg)
  110. {
  111. unsigned int i;
  112. if(!sel)
  113. return;
  114. for(i = 0; i < ntags; i++)
  115. sel->tags[i] = False;
  116. sel->tags[arg->i] = True;
  117. commit();
  118. }
  119. void
  120. toggletag(Arg *arg)
  121. {
  122. unsigned int i;
  123. if(!sel)
  124. return;
  125. sel->tags[arg->i] = !sel->tags[arg->i];
  126. for(i = 0; i < ntags && !sel->tags[i]; i++);
  127. if(i == ntags)
  128. sel->tags[arg->i] = True;
  129. commit();
  130. }