]> Sergey Matveev's repositories - nnn.git/commitdiff
Termux improvement: remap visit parent click
authorArun Prakash Jana <engineerarun@gmail.com>
Fri, 12 Jul 2019 15:36:37 +0000 (21:06 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 12 Jul 2019 16:28:18 +0000 (21:58 +0530)
Visit parent is now left single click outside context nums on top row.

README.md
src/nnn.c

index 23ed3b0fa8ac4ac98069c40c7ec051479ae8707e..cfb7ab91679fcccb316bde503afa8198974a3c49 100644 (file)
--- a/README.md
+++ b/README.md
@@ -264,10 +264,11 @@ Press <kbd>?</kbd> in `nnn` to see the list anytime.
 Note: Help & settings, file details, media info and archive listing are shown in the PAGER. Use the PAGER-specific keys in these screens.
 
 | Mouse click | Function |
-|:---:| --- |
+|---| --- |
+| Left single on context number | Visit context |
+| Left single on top row after context numbers | Visit parent |
 | Left single | Select context or entry |
 | Left double | Select context or open file/directory |
-| Middle single | Visit parent directory |
 
 ##### Leader key
 
index 8e841c132b7b9d034af75b6a897280e02c496997..b4ccbf09809da76bf1ccce81c5b93d4b231b0c5a 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -912,10 +912,9 @@ static bool initcurses(void)
        //intrflush(stdscr, FALSE);
        keypad(stdscr, TRUE);
 #if NCURSES_MOUSE_VERSION <= 1
-       mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON2_CLICKED, NULL);
+       mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED, NULL);
 #else
-       mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON2_CLICKED
-                 | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL);
+       mousemask(BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL);
 #endif
        mouseinterval(400);
        curs_set(FALSE); /* Hide cursor */
@@ -3341,9 +3340,28 @@ nochange:
                        if (getmouse(&event) != OK)
                                goto nochange; // fallthrough
                case SEL_BACK:
-                       // Handle right click to go to parent
-                       if ((sel == SEL_BACK)
-                           || (sel == SEL_CLICK && event.bstate == BUTTON2_CLICKED)) {
+                       /* Handle clicking on a context at the top */
+                       if (sel == SEL_CLICK && event.bstate == BUTTON1_CLICKED && event.y == 0) {
+                               /* Get context from: "[1 2 3 4]..." */
+                               r = event.x >> 1;
+
+                               /* If clicked after contexts, go to parent */
+                               if (r >= CTX_MAX)
+                                       sel = SEL_BACK;
+                               else if (0 <= r && r < CTX_MAX && r != cfg.curctx) {
+                                       savecurctx(&cfg, path, dents[cur].name, r);
+
+                                       /* Reset the pointers */
+                                       path = g_ctx[r].c_path;
+                                       lastdir = g_ctx[r].c_last;
+                                       lastname = g_ctx[r].c_name;
+
+                                       setdirwatch();
+                                       goto begin;
+                               }
+                       }
+
+                       if (sel == SEL_BACK) {
                                dir = visit_parent(path, newpath, &presel);
                                if (!dir)
                                        goto nochange;
@@ -3361,45 +3379,20 @@ nochange:
                        }
 
 #if NCURSES_MOUSE_VERSION > 1
-                       if (event.bstate == BUTTON4_PRESSED || event.bstate == BUTTON5_PRESSED)
-                       {
-                               /* Scroll up */
-                               if (event.bstate == BUTTON4_PRESSED && ndents) {
-                                       move_cursor((cur + ndents - 1) % ndents, 0);
-                                       break;
-                               }
-
-                               /* Scroll down */
-                               if (event.bstate == BUTTON5_PRESSED && ndents) {
-                                       move_cursor((cur + 1) % ndents, 0);
-                                       break;
-                               }
+                       /* Scroll up */
+                       if (event.bstate == BUTTON4_PRESSED && ndents) {
+                               move_cursor((cur + ndents - 1) % ndents, 0);
+                               break;
                        }
-#endif
-
-                       // Handle clicking on a context at the top:
-                       if (event.y == 0) {
-                               // Get context from: "[1 2 3 4]..."
-                               r = event.x >> 1;
-
-                               if (event.x != 1 + (r << 1))
-                                       goto nochange; // The character after the context number
-
-                               if (0 <= r && r < CTX_MAX && r != cfg.curctx) {
-                                       savecurctx(&cfg, path, dents[cur].name, r);
-
-                                       /* Reset the pointers */
-                                       path = g_ctx[r].c_path;
-                                       lastdir = g_ctx[r].c_last;
-                                       lastname = g_ctx[r].c_name;
 
-                                       setdirwatch();
-                                       goto begin;
-                               }
-                               goto nochange;
+                       /* Scroll down */
+                       if (event.bstate == BUTTON5_PRESSED && ndents) {
+                               move_cursor((cur + 1) % ndents, 0);
+                               break;
                        }
+#endif
 
-                       // Handle clicking on a file:
+                       /* Handle clicking on a file */
                        if (2 <= event.y && event.y < xlines - 2) {
                                r = curscroll + (event.y - 2);
 
@@ -3408,7 +3401,7 @@ nochange:
 
                                move_cursor(r, 1);
 
-                               // Single click just selects, double click also opens
+                               /*Single click just selects, double click also opens */
                                if (event.bstate != BUTTON1_DOUBLE_CLICKED)
                                        break;
                        } else