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.

149 lines
2.7 KiB

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