From: Michael D. Lowis Date: Thu, 9 May 2019 02:39:13 +0000 (-0400) Subject: pass modifiers to subfunctions instead of relying on global X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=91575a470ac49f978f80afc8fbc5c9af5e562ac2;p=projs%2Ftide.git pass modifiers to subfunctions instead of relying on global --- diff --git a/src/tide.c b/src/tide.c index 60b9ffa..a64a197 100644 --- a/src/tide.c +++ b/src/tide.c @@ -46,8 +46,8 @@ static int SearchDir = DOWN; static char* SearchTerm = NULL; static int ExecRequest = 0; -#define PRESSED(btn) \ - ((KeyBtnState & (1 << (btn + 7))) == (1 << (btn + 7))) +#define PRESSED(mods, btn) \ + ((mods & (1 << (btn + 7))) == (1 << (btn + 7))) /* X11 Window Code ******************************************************************************/ @@ -85,15 +85,15 @@ static void tide_send(char* type) { } } -static void mouse_left(WinRegion id, bool pressed, size_t row, size_t col) { +static void mouse_left(WinRegion id, int state, bool pressed, size_t row, size_t col) { static int count = 0; static Time before = 0; if (!pressed) return; count = ((X.now - before) <= (uint64_t)ClickTime ? count+1 : 1); before = X.now; - if (PRESSED(MouseRight)) { + if (PRESSED(state, MouseRight)) { puts("fetch tag"); - } else if (PRESSED(MouseMiddle)) { + } else if (PRESSED(state, MouseMiddle)) { /* if we didnt get an arg, find one in the selection */ char* arg = NULL; if (!arg || !*arg) arg = view_getstr(win_view(EDIT)); @@ -113,9 +113,9 @@ static void mouse_left(WinRegion id, bool pressed, size_t row, size_t col) { } } -static void mouse_middle(WinRegion id, bool pressed, size_t row, size_t col) { +static void mouse_middle(WinRegion id, int state, bool pressed, size_t row, size_t col) { if (pressed) { ExecRequest = 1; return; } - if (PRESSED(MouseLeft)) { + if (PRESSED(state, MouseLeft)) { cut(NULL); } else if (ExecRequest) { char* str = view_fetch(win_view(id), row, col, riscmd); @@ -124,9 +124,9 @@ static void mouse_middle(WinRegion id, bool pressed, size_t row, size_t col) { } } -static void mouse_right(WinRegion id, bool pressed, size_t row, size_t col) { +static void mouse_right(WinRegion id, int state, bool pressed, size_t row, size_t col) { if (pressed) return; - if (PRESSED(MouseLeft)) { + if (PRESSED(state, MouseLeft)) { paste(NULL); } else { FetchCmd[2] = view_fetch(win_view(id), row, col, risfile); @@ -146,14 +146,14 @@ static void mouse_scroll(WinRegion id, bool pressed, int amount) { view_scroll(win_view(id), amount); } -static void mouse_click(int btn, bool pressed, int x, int y) { +static void mouse_click(int btn, int mods, bool pressed, int x, int y) { size_t row, col; Focused = (y <= Divider ? TAGS : EDIT); get_position(Focused, x, y, &row, &col); switch(btn) { - case MouseLeft: mouse_left(Focused, pressed, row, col); break; - case MouseMiddle: mouse_middle(Focused, pressed, row, col); break; - case MouseRight: mouse_right(Focused, pressed, row, col); break; + case MouseLeft: mouse_left(Focused, mods, pressed, row, col); break; + case MouseMiddle: mouse_middle(Focused, mods, pressed, row, col); break; + case MouseRight: mouse_right(Focused, mods, pressed, row, col); break; case MouseWheelUp: mouse_scroll(Focused, pressed, -ScrollBy); break; case MouseWheelDn: mouse_scroll(Focused, pressed, +ScrollBy); break; } @@ -181,13 +181,13 @@ static void xkeypress(XConf* x, XEvent* e) { static void xbtnpress(XConf* x, XEvent* e) { (void)x; KeyBtnState = (e->xbutton.state | (1 << (e->xbutton.button + 7))); - mouse_click(e->xbutton.button, true, e->xbutton.x, e->xbutton.y); + mouse_click(e->xbutton.button, e->xbutton.state, true, e->xbutton.x, e->xbutton.y); } static void xbtnrelease(XConf* x, XEvent* e) { (void)x; KeyBtnState = (KeyBtnState & ~(1 << (e->xbutton.button + 7))); - mouse_click(e->xbutton.button, false, e->xbutton.x, e->xbutton.y); + mouse_click(e->xbutton.button, e->xbutton.state, false, e->xbutton.x, e->xbutton.y); } static void xbtnmotion(XConf* x, XEvent* e) { @@ -196,7 +196,7 @@ static void xbtnmotion(XConf* x, XEvent* e) { KeyBtnState = e->xbutton.state; int xpos = e->xbutton.x, ypos = e->xbutton.y; get_position(Focused, xpos, ypos, &row, &col); - if (PRESSED(MouseLeft)) + if (PRESSED(e->xbutton.state, MouseLeft)) view_setcursor(win_view(Focused), row, col, true); }