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.

156 lines
2.9 KiB

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