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.

153 lines
2.8 KiB

18 years ago
18 years ago
18 years ago
  1. /* © 2004-2007 Anselm R. Garbe <garbeam at gmail dot com>
  2. * See LICENSE file for license details. */
  3. #include "dwm.h"
  4. #include <regex.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <X11/Xutil.h>
  8. /* static */
  9. typedef struct {
  10. const char *prop;
  11. const char *tags;
  12. Bool isfloating;
  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->isfloating = rule[i].isfloating;
  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(const char *arg) {
  92. int i;
  93. if(!sel)
  94. return;
  95. for(i = 0; i < ntags; i++)
  96. sel->tags[i] = arg == NULL;
  97. i = arg ? atoi(arg) : 0;
  98. if(i >= 0 && i < ntags)
  99. sel->tags[i] = True;
  100. lt->arrange();
  101. }
  102. void
  103. toggletag(const char *arg) {
  104. int i, j;
  105. if(!sel)
  106. return;
  107. i = arg ? atoi(arg) : 0;
  108. sel->tags[i] = !sel->tags[i];
  109. for(j = 0; j < ntags && !sel->tags[j]; j++);
  110. if(j == ntags)
  111. sel->tags[i] = True;
  112. lt->arrange();
  113. }
  114. void
  115. toggleview(const char *arg) {
  116. int i, j;
  117. i = arg ? atoi(arg) : 0;
  118. seltag[i] = !seltag[i];
  119. for(j = 0; j < ntags && !seltag[j]; j++);
  120. if(j == ntags)
  121. seltag[i] = True; /* cannot toggle last view */
  122. lt->arrange();
  123. }
  124. void
  125. view(const char *arg) {
  126. int i;
  127. for(i = 0; i < ntags; i++)
  128. seltag[i] = arg == NULL;
  129. i = arg ? atoi(arg) : 0;
  130. if(i >= 0 && i < ntags)
  131. seltag[i] = True;
  132. lt->arrange();
  133. }