]> git.mdlowis.com Git - projs/tide.git/commitdiff
refactor mouse handling and separate common keyboard shortcuts for extraction later
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 9 May 2019 03:08:22 +0000 (23:08 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 9 May 2019 03:08:22 +0000 (23:08 -0400)
src/tide.c

index d0d20b7c8757571264c9fbc7cd04ddbd0a9dc7bd..11cfc8dd62b14a04b86da753caa4b2281786c845 100644 (file)
@@ -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) {