Applied custom mouse scrolling with altscreen

This commit is contained in:
Ashish Kumar Yadav 2021-07-23 02:24:04 +05:30
parent 7672445bab
commit a930f17091
4 changed files with 16 additions and 1 deletions

View file

@ -176,9 +176,13 @@ static uint forcemousemod = ShiftMask;
/*
* Internal mouse shortcuts.
* Beware that overloading Button1 will disable the selection.
* If altsreen is 1, shortcut will only work when altscreen is active and if -1,
* only when altscreen is not active.
*/
static MouseShortcut mshortcuts[] = {
/* mask button function argument release */
/* mask button function argument release altscreen */
{ XK_ANY_MOD, Button4, kscrollup, {.i = 1}, 0, -1 },
{ XK_ANY_MOD, Button5, kscrolldown, {.i = 1}, 0, -1 },
{ XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
{ ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} },
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
@ -201,6 +205,8 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ ShiftMask, XK_Up, kscrollup, {.i = +1} },
{ ShiftMask, XK_Down, kscrolldown, {.i = +1} },
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
{ TERMMOD, XK_T, newterm, {.i = 0} },

View file

@ -1056,6 +1056,12 @@ treset(void)
}
}
int
tisaltscreen(void)
{
return IS_SET(MODE_ALTSCREEN);
}
void
tnew(int col, int row)
{

View file

@ -91,6 +91,7 @@ void sendbreak(const Arg *);
void toggleprinter(const Arg *);
int tattrset(int);
int tisaltscreen(void);
void tnew(int, int);
void tresize(int, int);
void tsetdirtattr(int);

View file

@ -34,6 +34,7 @@ typedef struct {
void (*func)(const Arg *);
const Arg arg;
uint release;
int altscreen;
} MouseShortcut;
typedef struct {
@ -452,6 +453,7 @@ mouseaction(XEvent *e, uint release)
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
if (ms->release == release &&
ms->button == e->xbutton.button &&
(!ms->altscreen || ms->altscreen == (tisaltscreen() ? 1 : -1)) &&
(match(ms->mod, state) || /* exact or forced */
match(ms->mod, state & ~forcemousemod))) {
ms->func(&(ms->arg));