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.

121 lines
2.3 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. void
  27. initrregs(void) {
  28. unsigned int i;
  29. regex_t *reg;
  30. if(rreg)
  31. return;
  32. len = sizeof rule / sizeof rule[0];
  33. rreg = emallocz(len * sizeof(RReg));
  34. for(i = 0; i < len; i++) {
  35. if(rule[i].clpattern) {
  36. reg = emallocz(sizeof(regex_t));
  37. if(regcomp(reg, rule[i].clpattern, REG_EXTENDED))
  38. free(reg);
  39. else
  40. rreg[i].clregex = reg;
  41. }
  42. if(rule[i].tpattern) {
  43. reg = emallocz(sizeof(regex_t));
  44. if(regcomp(reg, rule[i].tpattern, REG_EXTENDED))
  45. free(reg);
  46. else
  47. rreg[i].tregex = reg;
  48. }
  49. }
  50. }
  51. void
  52. settags(Client *c, Client *trans) {
  53. char prop[512];
  54. unsigned int i, j;
  55. regmatch_t tmp;
  56. Bool matched = trans != NULL;
  57. XClassHint ch = { 0 };
  58. if(matched)
  59. for(i = 0; i < ntags; i++)
  60. c->tags[i] = trans->tags[i];
  61. else {
  62. XGetClassHint(dpy, c->win, &ch);
  63. snprintf(prop, sizeof prop, "%s:%s:%s",
  64. ch.res_class ? ch.res_class : "",
  65. ch.res_name ? ch.res_name : "", c->name);
  66. for(i = 0; i < len; i++)
  67. if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
  68. c->isfloat = rule[i].isfloat;
  69. for(j = 0; rreg[i].tregex && j < ntags; j++) {
  70. if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
  71. matched = True;
  72. c->tags[j] = True;
  73. }
  74. }
  75. }
  76. if(ch.res_class)
  77. XFree(ch.res_class);
  78. if(ch.res_name)
  79. XFree(ch.res_name);
  80. }
  81. if(!matched)
  82. for(i = 0; i < ntags; i++)
  83. c->tags[i] = seltag[i];
  84. }
  85. void
  86. tag(Arg *arg) {
  87. unsigned int i;
  88. if(!sel)
  89. return;
  90. for(i = 0; i < ntags; i++)
  91. sel->tags[i] = (arg->i == -1) ? True : False;
  92. if(arg->i >= 0 && arg->i < ntags)
  93. sel->tags[arg->i] = True;
  94. arrange();
  95. }
  96. void
  97. toggletag(Arg *arg) {
  98. unsigned int i;
  99. if(!sel)
  100. return;
  101. sel->tags[arg->i] = !sel->tags[arg->i];
  102. for(i = 0; i < ntags && !sel->tags[i]; i++);
  103. if(i == ntags)
  104. sel->tags[arg->i] = True;
  105. arrange();
  106. }