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.

135 lines
2.5 KiB

  1. /* (C)opyright MMVI 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, 0))
  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, 0))
  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;
  68. if(matched) {
  69. for(i = 0; i < ntags; i++)
  70. c->tags[i] = trans->tags[i];
  71. }
  72. else if(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; !matched && 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. for(c->weight = 0; c->weight < ntags && !c->tags[c->weight]; c->weight++);
  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] = False;
  103. sel->tags[arg->i] = True;
  104. sel->weight = arg->i;
  105. arrange(NULL);
  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. sel->weight = (i == ntags) ? arg->i : i;
  117. arrange(NULL);
  118. }