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.

170 lines
3.0 KiB

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