]> git.mdlowis.com Git - projs/tide.git/commitdiff
move mouse handling to x11.c. need to move cut and paste functionality to buffer...
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 29 Mar 2018 02:27:23 +0000 (22:27 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 29 Mar 2018 02:27:23 +0000 (22:27 -0400)
inc/win.h
lib/x11.c
tide.c

index 89e2213c5a91eeef49c636f119d1ad99e919c977..fe2968f4075b69397bb2c051ae51a3558e758b3e 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -28,14 +28,6 @@ typedef struct {
     View view;
 } Region;
 
-typedef void (*MouseFunc)(WinRegion id, size_t count, size_t row, size_t col);
-
-typedef struct {
-    MouseFunc left;
-    MouseFunc middle;
-    MouseFunc right;
-} MouseConfig;
-
 void win_init(KeyBinding* bindings, void (*errfn)(char*));
 void win_save(char* path);
 void win_loop(void);
@@ -53,3 +45,10 @@ void onupdate(void);
 void onmouseleft(WinRegion id, bool pressed, size_t row, size_t col);
 void onmousemiddle(WinRegion id, bool pressed, size_t row, size_t col);
 void onmouseright(WinRegion id, bool pressed, size_t row, size_t col);
+
+/* move these to x11.c when possible */
+extern int SearchDir;
+extern char* SearchTerm;
+void exec(char* cmd);
+void cut(char* arg);
+void paste(char* arg);
index 85966ca2bbddcb667486fb711076bb86cec835ec..4581839efe44f54512972b4fa53e264530cbe9eb 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -23,6 +23,9 @@
 static uint32_t special_keys(uint32_t key);
 static uint32_t getkey(XEvent* e);
 static void mouse_click(int btn, bool pressed, int x, int y);
+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_right(WinRegion id, bool pressed, size_t row, size_t col);
 
 static void xupdate(Job* job);
 static void xfocus(XEvent* e);
@@ -120,6 +123,9 @@ static Region Regions[NREGIONS] = {0};
 static Rune LastKey;
 static KeyBinding* Keys = NULL;
 
+int SearchDir = DOWN;
+char* SearchTerm = NULL;
+
 void x11_init(XConfig* cfg) {
     signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal
     setlocale(LC_CTYPE, "");
@@ -778,10 +784,49 @@ static void mouse_click(int btn, bool pressed, int x, int y) {
     size_t row = (y-Regions[id].y) / x11_font_height(CurrFont);
     size_t col = (x-Regions[id].x) / x11_font_width(CurrFont);
     switch(btn) {
-        case MouseLeft:    onmouseleft(id, pressed, row, col);   break;
-        case MouseMiddle:  onmousemiddle(id, pressed, row, col); break;
-        case MouseRight:   onmouseright(id, pressed, row, col);  break;
+        case MouseLeft:    mouse_left(id, pressed, row, col);    break;
+        case MouseMiddle:  mouse_middle(id, pressed, row, col);  break;
+        case MouseRight:   mouse_right(id, pressed, row, col);   break;
         case MouseWheelUp: view_scroll(win_view(id), -ScrollBy); break;
         case MouseWheelDn: view_scroll(win_view(id), +ScrollBy); break;
     }
 }
+
+static void mouse_left(WinRegion id, bool pressed, size_t row, size_t col) {
+    static int count = 0;
+    static uint64_t before = 0;
+    if (!pressed) return;
+    uint64_t now = getmillis();
+    count = ((now-before) <= (uint64_t)ClickTime ? count+1 : 1);
+    before = now;
+
+    if (count == 1) {
+        view_setcursor(win_view(id)i, row, col, x11_keymodsset(ModShift));
+    } else if (count == 2) {
+        view_select(win_view(id), row, col);
+    } else if (count == 3) {
+        view_selword(win_view(id), row, col);
+    }
+}
+
+static void mouse_middle(WinRegion id, bool pressed, size_t row, size_t col) {
+    if (pressed) return;
+    if (win_btnpressed(MouseLeft)) {
+        cut(NULL);
+    } else {
+        char* str = view_fetch(win_view(id), row, col, riscmd);
+        if (str) exec(str);
+        free(str);
+    }
+}
+
+static void mouse_right(WinRegion id, bool pressed, size_t row, size_t col) {
+    if (pressed) return;
+    if (win_btnpressed(MouseLeft)) {
+        paste(NULL);
+    } else {
+        SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1);
+        free(SearchTerm);
+        SearchTerm = view_fetch(win_view(id), row, col, risfile);
+    }
+}
diff --git a/tide.c b/tide.c
index 096c305c4dfb77b20c2526b6b5ea7f2cad4284ea..7aab3c34210f8b668280c94e25bd2ba99f02e289 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -12,8 +12,6 @@ typedef struct {
 } Tag;
 
 static Tag Builtins[];
-static int SearchDir = DOWN;
-static char* SearchTerm = NULL;
 static size_t Marks[10] = {0};
 
 /* The shell: Filled in with $SHELL. Used to execute commands */
@@ -67,7 +65,7 @@ static void onpaste(char* text) {
     view_putstr(win_view(FOCUSED), text);
 }
 
-static void cut(char* arg) {
+void cut(char* arg) {
     View* view = win_view(FOCUSED);
     /* select the current line if no selection */
     if (!view_selsize(view))
@@ -82,7 +80,7 @@ static void cut(char* arg) {
     }
 }
 
-static void paste(char* arg) {
+void paste(char* arg) {
     assert(x11_sel_get(CLIPBOARD, onpaste));
 }
 
@@ -270,7 +268,7 @@ static void cmd_execwitharg(char* cmd, char* arg) {
     free(cmd);
 }
 
-static void exec(char* cmd) {
+void exec(char* cmd) {
     /* skip leading space */
     for (; *cmd && isspace(*cmd); cmd++);
     if (!*cmd) return;
@@ -341,47 +339,6 @@ static void get(char* arg) {
         view_reload(win_view(EDIT));
 }
 
-/* Mouse Handling
- ******************************************************************************/
-void onmouseleft(WinRegion id, bool pressed, size_t row, size_t col) {
-    static int count = 0;
-    static uint64_t before = 0;
-    if (!pressed) return;
-    uint64_t now = getmillis();
-    count = ((now-before) <= (uint64_t)ClickTime ? count+1 : 1);
-    before = now;
-
-    if (count == 1) {
-        view_setcursor(win_view(id), row, col, x11_keymodsset(ModShift));
-    } else if (count == 2) {
-        view_select(win_view(id), row, col);
-    } else if (count == 3) {
-        view_selword(win_view(id), row, col);
-    }
-}
-
-void onmousemiddle(WinRegion id, bool pressed, size_t row, size_t col) {
-    if (pressed) return;
-    if (win_btnpressed(MouseLeft)) {
-        cut(NULL);
-    } else {
-        char* str = view_fetch(win_view(id), row, col, riscmd);
-        if (str) exec(str);
-        free(str);
-    }
-}
-
-void onmouseright(WinRegion id, bool pressed, size_t row, size_t col) {
-    if (pressed) return;
-    if (win_btnpressed(MouseLeft)) {
-        paste(NULL);
-    } else {
-        SearchDir *= (x11_keymodsset(ModShift) ? -1 : +1);
-        free(SearchTerm);
-        SearchTerm = view_fetch(win_view(id), row, col, risfile);
-    }
-}
-
 /* Keyboard Handling
  ******************************************************************************/
 static void tag_undo(char* arg) {