]> git.mdlowis.com Git - projs/tide.git/commitdiff
Move pointer on search
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 23 Oct 2016 04:03:42 +0000 (00:03 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 23 Oct 2016 04:03:42 +0000 (00:03 -0400)
edit.h
mouse.c
screen.c
tests/tests.c
xedit.c

diff --git a/edit.h b/edit.h
index 96d399eb001346c386384d488f2b15911ba0b7e4..f350b6208a927cec307947868a4664ff77bfd760 100644 (file)
--- a/edit.h
+++ b/edit.h
@@ -206,6 +206,9 @@ typedef struct {
 
 void screen_update(Buf* buf, unsigned crsr, unsigned* csrx, unsigned* csry);
 unsigned screen_getoff(Buf* buf, unsigned pos, unsigned row, unsigned col);
+
+void screen_getcoords(Buf* buf, unsigned pos, unsigned* posx, unsigned* posy);
+
 void screen_setsize(Buf* buf, unsigned nrows, unsigned ncols);
 void screen_getsize(unsigned* nrows, unsigned* ncols);
 Row* screen_getrow(unsigned row);
diff --git a/mouse.c b/mouse.c
index a246c9723dd17a46fadf4602e0557bcfd202356e..37ac1616523758407473670135b36f105afecfdb 100644 (file)
--- a/mouse.c
+++ b/mouse.c
@@ -53,6 +53,11 @@ void search(MouseEvent* mevnt) {
         select(mevnt);
     }
     buf_find(&Buffer, &DotBeg, &DotEnd);
+
+    unsigned x, y;
+    screen_getcoords(&Buffer, DotEnd, &x, &y);
+    extern void move_pointer(unsigned x, unsigned y);
+    move_pointer(x, y);
 }
 
 void scrollup(MouseEvent* mevnt) {
index cb084cbe9df2ae0e0071c3233b5cc978fb90fc7e..799b2db24fc6d93b67d487fb1182d37f975828d2 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -162,6 +162,24 @@ static void sync_view(Buf* buf, unsigned csr) {
     }
 }
 
+void screen_getcoords(Buf* buf, unsigned pos, unsigned* posx, unsigned* posy) {
+    for (unsigned y = 0; y < NumRows; y++) {
+        unsigned start = Rows[y]->off;
+        unsigned end   = Rows[y]->off + Rows[y]->rlen - 1;
+        if (start <= pos && pos <= end) {
+            unsigned off = start;
+            for (unsigned x = 0; x < NumCols;) {
+                if (off == pos) {
+                    *posy = y, *posx = x;
+                    return;
+                }
+                x += runewidth(x, buf_get(buf,off++));
+            }
+            break;
+        }
+    }
+}
+
 void screen_update(Buf* buf, unsigned csr, unsigned* csrx, unsigned* csry) {
     /* scroll the view and reflow the screen lines */
     sync_view(buf, csr);
index fd409e3867a51f977134aeee8ba1fcf43edffdc9..57822ad820c6832f672a5f72086daee27ccad296 100644 (file)
@@ -9,6 +9,8 @@ unsigned DotBeg;
 unsigned DotEnd;
 enum ColorScheme ColorBase;
 
+void move_pointer(unsigned x, unsigned y) { }
+
 int main(int argc, char** argv) {
     atf_init(argc,argv);
     RUN_EXTERN_TEST_SUITE(BufferTests);
diff --git a/xedit.c b/xedit.c
index fa523b6e3843a01e61f777ef3be6a13b1646dd2a..0dda2edd1ade0b1c0d7f031b3d2b3f4382495046 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -428,3 +428,9 @@ int main(int argc, char** argv) {
     }
     return 0;
 }
+
+void move_pointer(unsigned x, unsigned y) {
+    x = (x * Fonts.base.width)  + (Fonts.base.width / 2);
+    y = ((y+1) * Fonts.base.height) + (Fonts.base.height / 2);
+    XWarpPointer(X.display, X.window, X.window, 0, 0, X.width, X.height, x, y);
+}