]> git.mdlowis.com Git - projs/tide.git/commitdiff
added logic to warp mouse to cursor location
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 12 Oct 2018 02:03:58 +0000 (22:03 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 12 Oct 2018 02:03:58 +0000 (22:03 -0400)
TODO.md
inc/win.h
src/lib/x11.c
src/tide.c

diff --git a/TODO.md b/TODO.md
index 42567fd25bd98b5b355df25128ecd7e06971d4fc..d8c172cd25bd3258361c0bd3706b11b8af4d055f 100644 (file)
--- 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
index 342e31ac6206b2eb898ff84150e3c49c0dc14cc3..a939c3098b94ebb00c9d61c53b11b992a93a05c4 100644 (file)
--- 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);
index 722629b2978ddff74a14343a96874ec4a747bd92..85d20a6b7fd9e9679376abce1c736c1295ded16c 100644 (file)
@@ -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;
+}
index d71d92bc5bc9545ec666d8c050fc07319b4a2bfe..e324ba8b28a047ce4a464cf57f6338710da789a9 100644 (file)
@@ -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) {