Close previewer when opening file (#1171)

This commit is contained in:
luukvbaal 2021-09-21 06:44:25 +02:00 committed by Arun Prakash Jana
parent 2a6cc41972
commit 532532704e
No known key found for this signature in database
GPG key ID: A75979F35C080412
3 changed files with 27 additions and 7 deletions

View file

@ -133,6 +133,10 @@ previewer_loop () {
continue continue
fi fi
if [ "$FILE" = "close" ] ; then
break
fi
kill_viewer kill_viewer
MIME="$(file -bL --mime-type "$FILE")" MIME="$(file -bL --mime-type "$FILE")"

View file

@ -389,6 +389,7 @@ preview_fifo() {
if [ -n "$selection" ]; then if [ -n "$selection" ]; then
kill "$(cat "$PREVIEWPID")" kill "$(cat "$PREVIEWPID")"
[ -p "$FIFO_UEBERZUG" ] && ueberzug_remove [ -p "$FIFO_UEBERZUG" ] && ueberzug_remove
[ "$selection" = "close" ] && break
preview_file "$selection" preview_file "$selection"
printf "%s" "$selection" > "$CURSEL" printf "%s" "$selection" > "$CURSEL"
fi fi

View file

@ -846,7 +846,7 @@ static char *load_input(int fd, const char *path);
static int set_sort_flags(int r); static int set_sort_flags(int r);
static void statusbar(char *path); static void statusbar(char *path);
#ifndef NOFIFO #ifndef NOFIFO
static void notify_fifo(bool force); static void notify_fifo(bool force, bool closepreview);
#endif #endif
/* Functions */ /* Functions */
@ -3045,7 +3045,7 @@ try_quit:
} else { } else {
#ifndef NOFIFO #ifndef NOFIFO
if (!g_state.fifomode) if (!g_state.fifomode)
notify_fifo(TRUE); /* Send hovered path to NNN_FIFO */ notify_fifo(TRUE, FALSE); /* Send hovered path to NNN_FIFO */
#endif #endif
escaped = TRUE; escaped = TRUE;
settimeout(); settimeout();
@ -5787,7 +5787,7 @@ static void populate(char *path, char *lastname)
} }
#ifndef NOFIFO #ifndef NOFIFO
static void notify_fifo(bool force) static void notify_fifo(bool force, bool closepreview)
{ {
if (!fifopath) if (!fifopath)
return; return;
@ -5803,6 +5803,12 @@ static void notify_fifo(bool force)
} }
} }
if (closepreview) {
if (write(fifofd, "close\n", 6) != 6)
xerror();
return;
}
static struct entry lastentry; static struct entry lastentry;
if (!force && !memcmp(&lastentry, &pdents[cur], sizeof(struct entry))) if (!force && !memcmp(&lastentry, &pdents[cur], sizeof(struct entry)))
@ -5852,7 +5858,7 @@ static void move_cursor(int target, int ignore_scrolloff)
#ifndef NOFIFO #ifndef NOFIFO
if (!g_state.fifomode) if (!g_state.fifomode)
notify_fifo(FALSE); /* Send hovered path to NNN_FIFO */ notify_fifo(FALSE, FALSE); /* Send hovered path to NNN_FIFO */
#endif #endif
} }
@ -6735,7 +6741,7 @@ nochange:
move_cursor(r, 1); move_cursor(r, 1);
#ifndef NOFIFO #ifndef NOFIFO
else if ((event.bstate == BUTTON1_PRESSED) && !g_state.fifomode) else if ((event.bstate == BUTTON1_PRESSED) && !g_state.fifomode)
notify_fifo(TRUE); /* Send clicked path to NNN_FIFO */ notify_fifo(TRUE, FALSE); /* Send clicked path to NNN_FIFO */
#endif #endif
/* Handle right click selection */ /* Handle right click selection */
if (event.bstate == BUTTON3_PRESSED) { if (event.bstate == BUTTON3_PRESSED) {
@ -6808,7 +6814,7 @@ nochange:
} }
#ifndef NOFIFO #ifndef NOFIFO
if (g_state.fifomode && (sel == SEL_OPEN)) { if (g_state.fifomode && (sel == SEL_OPEN)) {
notify_fifo(TRUE); /* Send opened path to NNN_FIFO */ notify_fifo(TRUE, FALSE); /* Send opened path to NNN_FIFO */
goto nochange; goto nochange;
} }
#endif #endif
@ -6890,6 +6896,9 @@ nochange:
&& strstr(g_buf, "text") && strstr(g_buf, "text")
#endif #endif
) { ) {
#ifndef NOFIFO
notify_fifo(FALSE, TRUE);
#endif
spawn(editor, newpath, NULL, NULL, F_CLI); spawn(editor, newpath, NULL, NULL, F_CLI);
if (cfg.filtermode) { if (cfg.filtermode) {
presel = FILTER; presel = FILTER;
@ -6942,6 +6951,9 @@ nochange:
} }
/* Invoke desktop opener as last resort */ /* Invoke desktop opener as last resort */
#ifndef NOFIFO
notify_fifo(FALSE, TRUE);
#endif
spawn(opener, newpath, NULL, NULL, opener_flags); spawn(opener, newpath, NULL, NULL, opener_flags);
/* Move cursor to the next entry if not the last entry */ /* Move cursor to the next entry if not the last entry */
@ -7198,6 +7210,9 @@ nochange:
copycurname(); copycurname();
goto nochange; goto nochange;
case SEL_EDIT: case SEL_EDIT:
#ifndef NOFIFO
notify_fifo(FALSE, TRUE);
#endif
spawn(editor, newpath, NULL, NULL, F_CLI); spawn(editor, newpath, NULL, NULL, F_CLI);
continue; continue;
default: /* SEL_LOCK */ default: /* SEL_LOCK */
@ -8681,7 +8696,7 @@ int main(int argc, char *argv[])
#ifndef NOFIFO #ifndef NOFIFO
if (!g_state.fifomode) if (!g_state.fifomode)
notify_fifo(FALSE); notify_fifo(FALSE, FALSE);
if (fifofd != -1) if (fifofd != -1)
close(fifofd); close(fifofd);
#endif #endif