From 537b2859f249c4f6953049ee4c4e8829bbdeff0a Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <lfleischer@calcurse.org>
Date: Sun, 7 Feb 2016 13:47:02 +0100
Subject: hooks.c: Fix window preparation in interactive mode

In commit 2857bac (Fix segfault when running hooks in non-interactive
mode, 2016-01-16), we added checks to fix a segmentation fault in
non-interactive mode. However, at the same time, that commit broke
window preparation in interactive mode.

When wins_prepare_external() is called, the UI mode is changed to
command line, such that we cannot determine whether we need to call
wins_unprepare_external() when returning from the hook. As a workaround,
we now store the mode in a temporary variable.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
---
 src/hooks.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

(limited to 'src')

diff --git a/src/hooks.c b/src/hooks.c
index a2bc8b2..b025f47 100644
--- a/src/hooks.c
+++ b/src/hooks.c
@@ -43,6 +43,7 @@ int run_hook(const char *name)
 	char *hook_path;
 	char const *arg[2];
 	int pid, ret = -127;
+	int prepare_wins = (ui_mode == UI_CURSES);
 
 	asprintf(&hook_path, "%s/%s", path_hooks, name);
 	arg[0] = hook_path;
@@ -51,7 +52,7 @@ int run_hook(const char *name)
 	if (!io_file_exists(hook_path))
 		return 0;
 
-	if (ui_mode == UI_CURSES)
+	if (prepare_wins)
 		wins_prepare_external();
 
 	if ((pid = shell_exec(NULL, NULL, *arg, arg))) {
@@ -60,7 +61,7 @@ int run_hook(const char *name)
 			press_any_key();
 	}
 
-	if (ui_mode == UI_CURSES)
+	if (prepare_wins)
 		wins_unprepare_external();
 
 	return ret;
-- 
cgit v1.2.3-70-g09d2