st-scrollback-mouse-0.8.2.diff 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. From 315f69069017122ca69d0319d0ad9481113fe5c8 Mon Sep 17 00:00:00 2001
  2. From: Jacob Prosser <jacoblouisprosser@protonmail.com>
  3. Date: Fri, 26 Apr 2019 17:23:27 +1000
  4. Subject: [PATCH] Scrollback-Mouse for 0.8.2
  5. ---
  6. config.def.h | 10 ++++++++--
  7. st.h | 8 ++++++++
  8. x.c | 9 +++++++++
  9. 3 files changed, 25 insertions(+), 2 deletions(-)
  10. diff --git a/config.def.h b/config.def.h
  11. index 7326a74..ad20c4c 100644
  12. --- a/config.def.h
  13. +++ b/config.def.h
  14. @@ -156,8 +156,14 @@ static unsigned int defaultattr = 11;
  15. */
  16. static MouseShortcut mshortcuts[] = {
  17. /* button mask string */
  18. - { Button4, XK_ANY_MOD, "\031" },
  19. - { Button5, XK_ANY_MOD, "\005" },
  20. + { Button4, XK_NO_MOD, "\031" },
  21. + { Button5, XK_NO_MOD, "\005" },
  22. +};
  23. +
  24. +MouseKey mkeys[] = {
  25. + /* button mask function argument */
  26. + { Button4, ShiftMask, kscrollup, {.i = 1} },
  27. + { Button5, ShiftMask, kscrolldown, {.i = 1} },
  28. };
  29. /* Internal keyboard shortcuts. */
  30. diff --git a/st.h b/st.h
  31. index 17a79e0..3ac7f57 100644
  32. --- a/st.h
  33. +++ b/st.h
  34. @@ -76,6 +76,13 @@ typedef union {
  35. const void *v;
  36. } Arg;
  37. +typedef struct {
  38. + uint b;
  39. + uint mask;
  40. + void (*func)(const Arg *);
  41. + const Arg arg;
  42. +} MouseKey;
  43. +
  44. void die(const char *, ...);
  45. void redraw(void);
  46. void draw(void);
  47. @@ -122,3 +129,4 @@ extern char *termname;
  48. extern unsigned int tabspaces;
  49. extern unsigned int defaultfg;
  50. extern unsigned int defaultbg;
  51. +extern MouseKey mkeys[];
  52. diff --git a/x.c b/x.c
  53. index 0422421..e9fd6e9 100644
  54. --- a/x.c
  55. +++ b/x.c
  56. @@ -409,6 +409,7 @@ bpress(XEvent *e)
  57. {
  58. struct timespec now;
  59. MouseShortcut *ms;
  60. + MouseKey *mk;
  61. int snap;
  62. if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
  63. @@ -424,6 +425,14 @@ bpress(XEvent *e)
  64. }
  65. }
  66. + for (mk = mkeys; mk < mkeys + LEN(mkeys); mk++) {
  67. + if (e->xbutton.button == mk->b
  68. + && match(mk->mask, e->xbutton.state)) {
  69. + mk->func(&mk->arg);
  70. + return;
  71. + }
  72. + }
  73. +
  74. if (e->xbutton.button == Button1) {
  75. /*
  76. * If the user clicks below predefined timeouts specific
  77. --
  78. 2.21.0