From d0a7effcd3e8df6faafadeb8b79f2e17ba42d326 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 8 May 2019 23:08:22 -0400 Subject: [PATCH] refactor mouse handling and separate common keyboard shortcuts for extraction later --- src/tide.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/tide.c b/src/tide.c index d0d20b7..11cfc8d 100644 --- a/src/tide.c +++ b/src/tide.c @@ -84,15 +84,15 @@ static void tide_send(char* type) { } } -static void mouse_left(WinRegion id, int state, bool pressed, size_t row, size_t col) { +static void mouse_left(WinRegion id, 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(state, MouseRight)) { + if (PRESSED(X.mods, MouseRight)) { puts("fetch tag"); - } else if (PRESSED(state, MouseMiddle)) { + } else if (PRESSED(X.mods, MouseMiddle)) { /* if we didnt get an arg, find one in the selection */ char* arg = NULL; if (!arg || !*arg) arg = view_getstr(win_view(EDIT)); @@ -112,9 +112,9 @@ static void mouse_left(WinRegion id, int state, bool pressed, size_t row, size_t } } -static void mouse_middle(WinRegion id, int state, bool pressed, size_t row, size_t col) { +static void mouse_middle(WinRegion id, bool pressed, size_t row, size_t col) { if (pressed) { ExecRequest = 1; return; } - if (PRESSED(state, MouseLeft)) { + if (PRESSED(X.mods, MouseLeft)) { cut(NULL); } else if (ExecRequest) { char* str = view_fetch(win_view(id), row, col, riscmd); @@ -123,9 +123,9 @@ static void mouse_middle(WinRegion id, int state, bool pressed, size_t row, size } } -static void mouse_right(WinRegion id, int state, bool pressed, size_t row, size_t col) { +static void mouse_right(WinRegion id, bool pressed, size_t row, size_t col) { if (pressed) return; - if (PRESSED(state, MouseLeft)) { + if (PRESSED(X.mods, MouseLeft)) { paste(NULL); } else { FetchCmd[2] = view_fetch(win_view(id), row, col, risfile); @@ -145,14 +145,14 @@ static void mouse_scroll(WinRegion id, bool pressed, int amount) { view_scroll(win_view(id), amount); } -static void mouse_click(int btn, int mods, bool pressed, int x, int y) { +static void mouse_click(int btn, 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, 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 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 MouseWheelUp: mouse_scroll(Focused, pressed, -ScrollBy); break; case MouseWheelDn: mouse_scroll(Focused, pressed, +ScrollBy); break; } @@ -178,12 +178,12 @@ static void xkeypress(XConf* x, XEvent* e) { static void xbtnpress(XConf* x, XEvent* e) { (void)x; - mouse_click(e->xbutton.button, e->xbutton.state, true, e->xbutton.x, e->xbutton.y); + mouse_click(e->xbutton.button, true, e->xbutton.x, e->xbutton.y); } static void xbtnrelease(XConf* x, XEvent* e) { (void)x; - mouse_click(e->xbutton.button, e->xbutton.state, false, e->xbutton.x, e->xbutton.y); + mouse_click(e->xbutton.button, false, e->xbutton.x, e->xbutton.y); } static void xbtnmotion(XConf* x, XEvent* e) { @@ -397,7 +397,7 @@ static void exec(char* cmd, char* arg) { } } -/* Keyboard and Tag Handlers +/* Keyboard Editing Handlers ******************************************************************************/ static void select_line(char* arg) { (void)arg; @@ -579,6 +579,9 @@ static void quit(char* arg) { win_quit(); } +/* Keyboard and Tag Handlers + ******************************************************************************/ + static void put(char* arg) { Buf* buf = win_buf(EDIT); if (buf_save(buf, arg) == NORMAL) { -- 2.51.0