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.

133 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. else {
  72. XGetClassHint(dpy, c->win, &ch);
  73. snprintf(prop, sizeof prop, "%s:%s:%s",
  74. ch.res_class ? ch.res_class : "",
  75. ch.res_name ? ch.res_name : "", c->name);
  76. for(i = 0; i < len; i++)
  77. if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
  78. c->isfloat = rule[i].isfloat;
  79. for(j = 0; rreg[i].tregex && j < ntags; j++) {
  80. if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
  81. matched = True;
  82. c->tags[j] = True;
  83. }
  84. }
  85. }
  86. if(ch.res_class)
  87. XFree(ch.res_class);
  88. if(ch.res_name)
  89. XFree(ch.res_name);
  90. }
  91. if(!matched)
  92. for(i = 0; i < ntags; i++)
  93. c->tags[i] = seltag[i];
  94. }
  95. void
  96. tag(Arg *arg) {
  97. unsigned int i;
  98. if(!sel)
  99. return;
  100. for(i = 0; i < ntags; i++)
  101. sel->tags[i] = (arg->i == -1) ? True : False;
  102. if(arg->i >= 0 && arg->i < ntags)
  103. sel->tags[arg->i] = True;
  104. arrange();
  105. }
  106. void
  107. toggletag(Arg *arg) {
  108. unsigned int i;
  109. if(!sel)
  110. return;
  111. sel->tags[arg->i] = !sel->tags[arg->i];
  112. for(i = 0; i < ntags && !sel->tags[i]; i++);
  113. if(i == ntags)
  114. sel->tags[arg->i] = True;
  115. arrange();
  116. }