Skip to content

Commit

Permalink
Adding key and mouse binding option to control whether they apply to …
Browse files Browse the repository at this point in the history
…primary screen, alt screen or both ref. #81
  • Loading branch information
bakkeby committed Sep 1, 2022
1 parent 89ced62 commit 34cd955
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 61 deletions.
39 changes: 12 additions & 27 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,48 +339,33 @@ static uint forcemousemod = ShiftMask;
* Beware that overloading Button1 will disable the selection.
*/
static MouseShortcut mshortcuts[] = {
#if UNIVERSCROLL_PATCH
/* mask button function argument release alt */
#else
/* mask button function argument release */
#endif // UNIVERSCROLL_PATCH
/* mask button function argument release screen */
#if CLIPBOARD_PATCH
{ XK_ANY_MOD, Button2, clippaste, {.i = 0}, 1 },
#else
{ XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
#endif // CLIPBOARD_PATCH
#if SCROLLBACK_MOUSE_PATCH
{ ShiftMask, Button4, kscrollup, {.i = 1} },
{ ShiftMask, Button5, kscrolldown, {.i = 1} },
{ ShiftMask, Button4, kscrollup, {.i = 1}, 0, S_PRI},
{ ShiftMask, Button5, kscrolldown, {.i = 1}, 0, S_PRI},
#elif UNIVERSCROLL_PATCH
{ XK_ANY_MOD, Button4, ttysend, {.s = "\033[5;2~"}, 0, -1 },
{ XK_ANY_MOD, Button5, ttysend, {.s = "\033[6;2~"}, 0, -1 },
{ XK_ANY_MOD, Button4, ttysend, {.s = "\033[5;2~"}, 0, S_PRI },
{ XK_ANY_MOD, Button5, ttysend, {.s = "\033[6;2~"}, 0, S_PRI },
#else
{ ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} },
{ ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} },
#endif // SCROLLBACK_MOUSE_PATCH
#if SCROLLBACK_MOUSE_ALTSCREEN_PATCH
{ XK_NO_MOD, Button4, kscrollup, {.i = 1} },
{ XK_NO_MOD, Button5, kscrolldown, {.i = 1} },
{ XK_NO_MOD, Button4, kscrollup, {.i = 1}, 0, S_PRI },
{ XK_NO_MOD, Button5, kscrolldown, {.i = 1}, 0, S_PRI },
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"}, 0, S_ALT },
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"}, 0, S_ALT },
#else
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
#endif // SCROLLBACK_MOUSE_ALTSCREEN_PATCH
};

#if SCROLLBACK_MOUSE_ALTSCREEN_PATCH
static MouseShortcut maltshortcuts[] = {
/* mask button function argument release */
#if CLIPBOARD_PATCH
{ XK_ANY_MOD, Button2, clippaste, {.i = 0}, 1 },
#else
{ XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
#endif // CLIPBOARD_PATCH
{ XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
{ XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
};
#endif // SCROLLBACK_MOUSE_ALTSCREEN_PATCH

/* Internal keyboard shortcuts. */
#define MODKEY Mod1Mask
#define TERMMOD (ControlMask|ShiftMask)
Expand All @@ -398,7 +383,7 @@ static char *setbgcolorcmd[] = { "/bin/sh", "-c",
#endif // EXTERNALPIPE_PATCH

static Shortcut shortcuts[] = {
/* mask keysym function argument */
/* mask keysym function argument screen */
{ XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} },
{ ControlMask, XK_Print, toggleprinter, {.i = 0} },
{ ShiftMask, XK_Print, printscreen, {.i = 0} },
Expand All @@ -409,8 +394,8 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_C, clipcopy, {.i = 0} },
{ TERMMOD, XK_V, clippaste, {.i = 0} },
#if SCROLLBACK_PATCH
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1} },
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
{ ShiftMask, XK_Page_Up, kscrollup, {.i = -1}, S_PRI },
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1}, S_PRI },
#endif // SCROLLBACK_PATCH
#if CLIPBOARD_PATCH
{ TERMMOD, XK_Y, clippaste, {.i = 0} },
Expand Down
3 changes: 0 additions & 3 deletions patch/st_include.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#if SCROLLBACK_PATCH || SCROLLBACK_MOUSE_PATCH || SCROLLBACK_MOUSE_ALTSCREEN_PATCH
#include "scrollback.c"
#endif
#if UNIVERSCROLL_PATCH || SCROLLBACK_MOUSE_ALTSCREEN_PATCH
#include "universcroll.c"
#endif
#if SIXEL_PATCH
#include "sixel_st.c"
#endif
Expand Down
3 changes: 0 additions & 3 deletions patch/st_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#if SCROLLBACK_PATCH || SCROLLBACK_MOUSE_PATCH || SCROLLBACK_MOUSE_ALTSCREEN_PATCH
#include "scrollback.h"
#endif
#if UNIVERSCROLL_PATCH || SCROLLBACK_MOUSE_ALTSCREEN_PATCH
#include "universcroll.h"
#endif
#if SIXEL_PATCH
#include "sixel_st.h"
#endif
Expand Down
5 changes: 0 additions & 5 deletions patch/universcroll.c

This file was deleted.

1 change: 0 additions & 1 deletion patch/universcroll.h

This file was deleted.

6 changes: 6 additions & 0 deletions st.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,12 @@ tattrset(int attr)
return 0;
}

int
tisaltscr(void)
{
return IS_SET(MODE_ALTSCREEN);
}

void
tsetdirt(int top, int bot)
{
Expand Down
15 changes: 11 additions & 4 deletions st.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ enum drawing_mode {
};
#endif // WIDE_GLYPHS_PATCH

/* Used to control which screen(s) keybindings and mouse shortcuts apply to. */
enum screen {
S_PRI = -1, /* primary screen */
S_ALL = 0, /* both primary and alt screen */
S_ALT = 1 /* alternate screen */
};

enum selection_mode {
SEL_IDLE = 0,
SEL_EMPTY = 1,
Expand Down Expand Up @@ -251,17 +258,16 @@ typedef struct {
KeySym keysym;
void (*func)(const Arg *);
const Arg arg;
int screen;
} Shortcut;

typedef struct {
uint mod;
uint button;
void (*func)(const Arg *);
const Arg arg;
uint release;
#if UNIVERSCROLL_PATCH
int altscrn; /* 0: don't care, -1: not alt screen, 1: alt screen */
#endif // UNIVERSCROLL_PATCH
uint release;
int screen;
} MouseShortcut;

typedef struct {
Expand Down Expand Up @@ -309,6 +315,7 @@ void sendbreak(const Arg *);
void toggleprinter(const Arg *);

int tattrset(int);
int tisaltscr(void);
void tnew(int, int);
void tresize(int, int);
#if VIM_BROWSE_PATCH
Expand Down
25 changes: 7 additions & 18 deletions x.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,29 +345,15 @@ int
mouseaction(XEvent *e, uint release)
{
MouseShortcut *ms;
int screen = tisaltscr() ? S_ALT : S_PRI;

/* ignore Button<N>mask for Button<N> - it's set on release */
uint state = e->xbutton.state & ~buttonmask(e->xbutton.button);

#if SCROLLBACK_MOUSE_ALTSCREEN_PATCH
if (tisaltscr())
for (ms = maltshortcuts; ms < maltshortcuts + LEN(maltshortcuts); ms++) {
if (ms->release == release &&
ms->button == e->xbutton.button &&
(match(ms->mod, state) || /* exact or forced */
match(ms->mod, state & ~forcemousemod))) {
ms->func(&(ms->arg));
return 1;
}
}
else
#endif // SCROLLBACK_MOUSE_ALTSCREEN_PATCH
for (ms = mshortcuts; ms < mshortcuts + LEN(mshortcuts); ms++) {
if (ms->release == release &&
ms->button == e->xbutton.button &&
#if UNIVERSCROLL_PATCH
(!ms->altscrn || (ms->altscrn == (tisaltscr() ? 1 : -1))) &&
#endif // UNIVERSCROLL_PATCH
(!ms->screen || (ms->screen == screen)) &&
(match(ms->mod, state) || /* exact or forced */
match(ms->mod, state & ~forcemousemod))) {
ms->func(&(ms->arg));
Expand Down Expand Up @@ -3112,7 +3098,7 @@ kpress(XEvent *ev)
XKeyEvent *e = &ev->xkey;
KeySym ksym;
char buf[64], *customkey;
int len;
int len, screen;
Rune c;
Status status;
Shortcut *bp;
Expand Down Expand Up @@ -3165,9 +3151,12 @@ kpress(XEvent *ev)
}
#endif // VIM_BROWSE_PATCH

screen = tisaltscr() ? S_ALT : S_PRI;

/* 1. shortcuts */
for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
if (ksym == bp->keysym && match(bp->mod, e->state)) {
if (ksym == bp->keysym && match(bp->mod, e->state) &&
(!bp->screen || bp->screen == screen)) {
bp->func(&(bp->arg));
return;
}
Expand Down

0 comments on commit 34cd955

Please sign in to comment.