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.

134 lines
2.4 KiB

18 years ago
  1. /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
  2. * See LICENSE file for license details.
  3. */
  4. #include "dwm.h"
  5. #include <regex.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <sys/types.h>
  10. #include <X11/Xutil.h>
  11. typedef struct {
  12. const char *clpattern;
  13. const char *tpattern;
  14. Bool isfloat;
  15. } Rule;
  16. typedef struct {
  17. regex_t *clregex;
  18. regex_t *tregex;
  19. } RReg;
  20. /* static */
  21. TAGS
  22. RULES
  23. static RReg *rreg = NULL;
  24. static unsigned int len = 0;
  25. /* extern */
  26. Client *
  27. getnext(Client *c) {
  28. for(; c && !isvisible(c); c = c->next);
  29. return c;
  30. }
  31. Client *
  32. getprev(Client *c) {
  33. for(; c && !isvisible(c); c = c->prev);
  34. return c;
  35. }
  36. void
  37. initrregs(void) {
  38. unsigned int i;
  39. regex_t *reg;
  40. if(rreg)
  41. return;
  42. len = sizeof rule / sizeof rule[0];
  43. rreg = emallocz(len * sizeof(RReg));
  44. for(i = 0; i < len; i++) {
  45. if(rule[i].clpattern) {
  46. reg = emallocz(sizeof(regex_t));
  47. if(regcomp(reg, rule[i].clpattern, REG_EXTENDED))
  48. free(reg);
  49. else
  50. rreg[i].clregex = reg;
  51. }
  52. if(rule[i].tpattern) {
  53. reg = emallocz(sizeof(regex_t));
  54. if(regcomp(reg, rule[i].tpattern, REG_EXTENDED))
  55. free(reg);
  56. else
  57. rreg[i].tregex = reg;
  58. }
  59. }
  60. }
  61. void
  62. settags(Client *c, Client *trans) {
  63. char prop[512];
  64. unsigned int i, j;
  65. regmatch_t tmp;
  66. Bool matched = trans != NULL;
  67. XClassHint ch = { 0 };
  68. if(matched) {
  69. for(i = 0; i < ntags; i++)
  70. c->tags[i] = trans->tags[i];
  71. }
  72. else {
  73. XGetClassHint(dpy, c->win, &ch);
  74. snprintf(prop, sizeof prop, "%s:%s:%s",
  75. ch.res_class ? ch.res_class : "",
  76. ch.res_name ? ch.res_name : "", c->name);
  77. for(i = 0; i < len; i++)
  78. if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
  79. c->isfloat = rule[i].isfloat;
  80. for(j = 0; rreg[i].tregex && j < ntags; j++) {
  81. if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
  82. matched = True;
  83. c->tags[j] = True;
  84. }
  85. }
  86. }
  87. if(ch.res_class)
  88. XFree(ch.res_class);
  89. if(ch.res_name)
  90. XFree(ch.res_name);
  91. }
  92. if(!matched)
  93. for(i = 0; i < ntags; i++)
  94. c->tags[i] = seltag[i];
  95. }
  96. void
  97. tag(Arg *arg) {
  98. unsigned int i;
  99. if(!sel)
  100. return;
  101. for(i = 0; i < ntags; i++)
  102. sel->tags[i] = (arg->i == -1) ? True : False;
  103. if(arg->i >= 0 && arg->i < ntags)
  104. sel->tags[arg->i] = True;
  105. arrange();
  106. }
  107. void
  108. toggletag(Arg *arg) {
  109. unsigned int i;
  110. if(!sel)
  111. return;
  112. sel->tags[arg->i] = !sel->tags[arg->i];
  113. for(i = 0; i < ntags && !sel->tags[i]; i++);
  114. if(i == ntags)
  115. sel->tags[arg->i] = True;
  116. arrange();
  117. }