From f04d5d4b725c0e1254b62139d067add708c218fc Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 11 Oct 2018 22:03:58 -0400 Subject: [PATCH] added logic to warp mouse to cursor location --- TODO.md | 1 - inc/win.h | 1 + src/lib/x11.c | 29 +++++++++++++++++++++++------ src/tide.c | 4 +++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 42567fd..d8c172c 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,6 @@ ## STAGING -* implement mouse warping on search, jump to line, and focus change * implement new version of tfetch (plumb) * implement tide registrar * implement tctl command diff --git a/inc/win.h b/inc/win.h index 342e31a..a939c30 100644 --- a/inc/win.h +++ b/inc/win.h @@ -139,6 +139,7 @@ void win_update(int ms); void win_loop(void); void win_quit(void); void win_togglefocus(void); +void win_syncmouse(void); View* win_view(WinRegion id); Buf* win_buf(WinRegion id); diff --git a/src/lib/x11.c b/src/lib/x11.c index 722629b..85d20a6 100644 --- a/src/lib/x11.c +++ b/src/lib/x11.c @@ -52,6 +52,7 @@ static KeyBinding* Keys = NULL; static int Divider; static Atom SelTarget; static int FontSel; +static bool SyncMouse = false; static struct XSel Selections[] = { { .name = "PRIMARY" }, { .name = "CLIPBOARD" }, @@ -251,6 +252,7 @@ static void mouse_right(WinRegion id, bool pressed, size_t row, size_t col) { free(SearchTerm); SearchTerm = view_fetch(win_view(id), row, col, risfile); view_findstr(win_view(EDIT), SearchDir, SearchTerm); + SyncMouse = true; } else { free(FetchCmd[1]); } @@ -315,6 +317,21 @@ static void draw_statbox(drawcsr* csr) { } } +static bool draw_csr(View* view, size_t fheight, int x, int y, bool csrdrawn) { + if (!csrdrawn && !view_selsize(view)) { + int csrclr = (view == &Regions[TAGS] ? TagsCsr : EditCsr); + draw_rect(csrclr, x-1, y, 3, 3); + draw_rect(csrclr, x, y, 1, fheight); + draw_rect(csrclr, x-1, y+fheight-3, 3, 3); + csrdrawn = true; + } + if (SyncMouse && view == &Regions[EDIT]) { + XWarpPointer(X.display, X.self, X.self, 0, 0, X.width, X.height, x-4, y + fheight/2); + SyncMouse = false; + } + return csrdrawn; +} + static void draw_view(View* view, XftFont* font, size_t nrows, drawcsr* csr, int bg, int fg, int sel) { size_t fheight = font->height; size_t csrx = SIZE_MAX, csry = SIZE_MAX; @@ -333,12 +350,8 @@ static void draw_view(View* view, XftFont* font, size_t nrows, drawcsr* csr, int rune = ' '; if (buf_insel(&(view->buffer), row->cols[i].off)) draw_rect(sel, x, y, row->cols[i].width, fheight); - if (!csr_drawn && !view_selsize(view) && row->cols[i].off == view->buffer.selection.end) { - draw_rect((i == TAGS ? TagsCsr : EditCsr), x-1, y, 3, 3); - draw_rect((i == TAGS ? TagsCsr : EditCsr), x, y, 1, fheight); - draw_rect((i == TAGS ? TagsCsr : EditCsr), x-1, y+fheight-3, 3, 3); - csr_drawn = true; - } + if (row->cols[i].off == view->buffer.selection.end) + csr_drawn = draw_csr(view, fheight, x, y, csr_drawn); specs[i].glyph = XftCharIndex(X.display, font, rune); specs[i].x = x; specs[i].y = y + font->ascent; @@ -680,3 +693,7 @@ bool win_sel_set(int selid, char* str) { return true; } } + +void win_syncmouse(void) { + SyncMouse = true; +} diff --git a/src/tide.c b/src/tide.c index d71d92b..e324ba8 100644 --- a/src/tide.c +++ b/src/tide.c @@ -291,6 +291,7 @@ static void search(char* arg) { view_findstr(win_view(EDIT), SearchDir, str); free(SearchTerm); SearchTerm = str; + win_syncmouse(); } static void execute(char* arg) { @@ -327,7 +328,7 @@ static void jump_to(char* arg) { size_t line = strtoul(arg, NULL, 0); if (line) { view_setln(win_view(EDIT), line); - /* move mouse to edit region */ + win_syncmouse(); } else { pick_symbol(arg); } @@ -338,6 +339,7 @@ static void goto_ctag(char* arg) { char* str = view_getctx(win_view(FOCUSED)); jump_to(str); free(str); + } static void tabs(char* arg) { -- 2.54.0