Configuration of dwm for Mac Computers
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.

152 lines
2.7 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. tag(const char *arg) {
  91. int i;
  92. if(!sel)
  93. return;
  94. for(i = 0; i < ntags; i++)
  95. sel->tags[i] = arg == NULL;
  96. i = arg ? atoi(arg) : 0;
  97. if(i >= 0 && i < ntags)
  98. sel->tags[i] = True;
  99. lt->arrange(NULL);
  100. }
  101. void
  102. toggletag(const char *arg) {
  103. int i, j;
  104. if(!sel)
  105. return;
  106. i = arg ? atoi(arg) : 0;
  107. sel->tags[i] = !sel->tags[i];
  108. for(j = 0; j < ntags && !sel->tags[j]; j++);
  109. if(j == ntags)
  110. sel->tags[i] = True;
  111. lt->arrange(NULL);
  112. }
  113. void
  114. toggleview(const char *arg) {
  115. int i, j;
  116. i = arg ? atoi(arg) : 0;
  117. seltag[i] = !seltag[i];
  118. for(j = 0; j < ntags && !seltag[j]; j++);
  119. if(j == ntags)
  120. seltag[i] = True; /* cannot toggle last view */
  121. lt->arrange(NULL);
  122. }
  123. void
  124. view(const char *arg) {
  125. int i;
  126. for(i = 0; i < ntags; i++)
  127. seltag[i] = arg == NULL;
  128. i = arg ? atoi(arg) : 0;
  129. if(i >= 0 && i < ntags)
  130. seltag[i] = True;
  131. lt->arrange(NULL);
  132. }