Another copy of my dotfiles. Because I don't completely trust GitHub.
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.

100 lines
2.2 KiB

  1. void
  2. setlayoutex(const Arg *arg)
  3. {
  4. setlayout(&((Arg) { .v = &layouts[arg->i] }));
  5. }
  6. void
  7. viewex(const Arg *arg)
  8. {
  9. view(&((Arg) { .ui = 1 << arg->ui }));
  10. }
  11. void
  12. viewallex(const Arg *arg)
  13. {
  14. #if SCRATCHPADS_PATCH
  15. view(&((Arg){.ui = ~SPTAGMASK}));
  16. #else
  17. view(&((Arg){.ui = ~0}));
  18. #endif // SCRATCHPADS_PATCH
  19. }
  20. void
  21. toggleviewex(const Arg *arg)
  22. {
  23. toggleview(&((Arg) { .ui = 1 << arg->ui }));
  24. }
  25. void
  26. tagex(const Arg *arg)
  27. {
  28. tag(&((Arg) { .ui = 1 << arg->ui }));
  29. }
  30. void
  31. toggletagex(const Arg *arg)
  32. {
  33. toggletag(&((Arg) { .ui = 1 << arg->ui }));
  34. }
  35. void
  36. tagallex(const Arg *arg)
  37. {
  38. #if SCRATCHPADS_PATCH
  39. tag(&((Arg){.ui = ~SPTAGMASK}));
  40. #else
  41. tag(&((Arg){.ui = ~0}));
  42. #endif // SCRATCHPADS_PATCH
  43. }
  44. int
  45. fake_signal(void)
  46. {
  47. char fsignal[256];
  48. char indicator[9] = "fsignal:";
  49. char str_sig[50];
  50. char param[16];
  51. int i, len_str_sig, n, paramn;
  52. size_t len_fsignal, len_indicator = strlen(indicator);
  53. Arg arg;
  54. // Get root name property
  55. if (gettextprop(root, XA_WM_NAME, fsignal, sizeof(fsignal))) {
  56. len_fsignal = strlen(fsignal);
  57. // Check if this is indeed a fake signal
  58. if (len_indicator > len_fsignal ? 0 : strncmp(indicator, fsignal, len_indicator) == 0) {
  59. paramn = sscanf(fsignal+len_indicator, "%s%n%s%n", str_sig, &len_str_sig, param, &n);
  60. if (paramn == 1) arg = (Arg) {0};
  61. else if (paramn > 2) return 1;
  62. else if (strncmp(param, "i", n - len_str_sig) == 0)
  63. #if IPC_PATCH
  64. sscanf(fsignal + len_indicator + n, "%li", &(arg.i));
  65. #else
  66. sscanf(fsignal + len_indicator + n, "%i", &(arg.i));
  67. #endif // IPC_PATCH
  68. else if (strncmp(param, "ui", n - len_str_sig) == 0)
  69. #if IPC_PATCH
  70. sscanf(fsignal + len_indicator + n, "%lu", &(arg.ui));
  71. #else
  72. sscanf(fsignal + len_indicator + n, "%u", &(arg.ui));
  73. #endif // IPC_PATCH
  74. else if (strncmp(param, "f", n - len_str_sig) == 0)
  75. sscanf(fsignal + len_indicator + n, "%f", &(arg.f));
  76. else return 1;
  77. // Check if a signal was found, and if so handle it
  78. for (i = 0; i < LENGTH(signals); i++)
  79. if (strncmp(str_sig, signals[i].sig, len_str_sig) == 0 && signals[i].func)
  80. signals[i].func(&(arg));
  81. // A fake signal was sent
  82. return 1;
  83. }
  84. }
  85. // No fake signal was sent, so proceed with update
  86. return 0;
  87. }