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.

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