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.
 
 
 
 
 

103 lines
2.8 KiB

  1. diff --git a/lisgd.c b/lisgd.c
  2. index 9d3442b..af49a80 100644
  3. --- a/lisgd.c
  4. +++ b/lisgd.c
  5. @@ -1,3 +1,4 @@
  6. +#include <stdbool.h>
  7. #include <errno.h>
  8. #include <fcntl.h>
  9. #include <libinput.h>
  10. @@ -86,6 +87,51 @@ touchmotion(struct libinput_event *e)
  11. yend[slot] = libinput_event_touch_get_y(tevent);
  12. }
  13. +bool display_rotation_matches(char* transform) {
  14. + char cmd[256];
  15. + snprintf(cmd, sizeof(cmd),
  16. + "swaymsg -t get_outputs | grep DSI-1 -A 50 | grep transform | grep %s",
  17. + transform);
  18. + return system(cmd) == 0;
  19. +}
  20. +
  21. +enum rotation{normal, left, right, invert};
  22. +enum rotation get_display_rotation()
  23. +{
  24. + if (display_rotation_matches("normal"))
  25. + return normal;
  26. + if (display_rotation_matches("90"))
  27. + return left;
  28. + if (display_rotation_matches("180"))
  29. + return invert;
  30. + if (display_rotation_matches("270"))
  31. + return right;
  32. + return normal;
  33. +}
  34. +
  35. +void rotate_move_based_on_display(int* move_x, int* move_y)
  36. +{
  37. + enum rotation rot = get_display_rotation();
  38. + int t;
  39. + switch (get_display_rotation()) {
  40. + case normal:
  41. + break;
  42. + case left:
  43. + t = *move_x;
  44. + (*move_x) = (*move_y);
  45. + (*move_y) = -t;
  46. + break;
  47. + case right:
  48. + t = *move_x;
  49. + (*move_x) = -(*move_y);
  50. + (*move_y) = t;
  51. + break;
  52. + case invert:
  53. + (*move_y) = -(*move_y);
  54. + break;
  55. + }
  56. +}
  57. +
  58. void
  59. touchup(struct libinput_event *e)
  60. {
  61. @@ -109,19 +155,27 @@ touchup(struct libinput_event *e)
  62. );
  63. }
  64. - if (xend[slot] > xstart[slot] && fabs(xend[slot] - xstart[slot]) > threshold) {
  65. - start = Left;
  66. - end = Right;
  67. - } else if (xend[slot] < xstart[slot] && fabs(xend[slot] - xstart[slot]) > threshold) {
  68. - start = Right;
  69. - end = Left;
  70. - } else if (yend[slot] > ystart[slot] && fabs(yend[slot] - ystart[slot]) > threshold) {
  71. - start = Up;
  72. - end = Down;
  73. - } else if (yend[slot] < ystart[slot] && fabs(yend[slot] - ystart[slot]) > threshold) {
  74. - start = Down;
  75. - end = Up;
  76. - } else {
  77. + int move_x = fabs(xend[slot] - xstart[slot]) > threshold
  78. + ? (xend[slot] > xstart[slot] ? 1 : -1) : 0;
  79. + int move_y = fabs(yend[slot] - ystart[slot]) > threshold
  80. + ? (yend[slot] > ystart[slot] ? 1 : -1) : 0;
  81. +
  82. + rotate_move_based_on_display(&move_x, &move_y);
  83. +
  84. +#define X_DIR 4
  85. +#define Y_DIR 1
  86. +#define NODIR 0
  87. + switch (move_x * X_DIR + move_y * Y_DIR) {
  88. + case -X_DIR -Y_DIR: start = Right; end = Up; break;
  89. + case -X_DIR +NODIR: start = Right; end = Left; break;
  90. + case -X_DIR +Y_DIR: start = Right; end = Down; break;
  91. + case +NODIR -Y_DIR: start = Down; end = Up; break;
  92. + case +NODIR +Y_DIR: start = Up; end = Down; break;
  93. + case +X_DIR -Y_DIR: start = Left; end = Up; break;
  94. + case +X_DIR +NODIR: start = Left; end = Right; break;
  95. + case +X_DIR +Y_DIR: start = Left; end = Down; break;
  96. + case +NODIR +NODIR:
  97. + default:
  98. if (verbose) {
  99. fprintf(stderr, "Input didn't match a known gesture\n");
  100. }