From 012a0e6670533911d70f47533e064969c7fc3b65 Mon Sep 17 00:00:00 2001
From: Lars Henriksen <LarsHenriksen@get2net.dk>
Date: Fri, 27 Oct 2017 08:17:57 +0200
Subject: Fix multiple popup windows

The window was not deleted if an "already in use"-key was detected,
and a new one was created as the loop was reentered.

Create/delete of the popup are moved outside the loop.
A redrawwin() call is needed to have the window displayed again.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
---
 src/calcurse.h |  1 +
 src/custom.c   | 18 +++++++-----------
 src/wins.c     | 11 +++++++++++
 3 files changed, 19 insertions(+), 11 deletions(-)

(limited to 'src')

diff --git a/src/calcurse.h b/src/calcurse.h
index 2124bb2..85e36b2 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -1216,6 +1216,7 @@ void wins_calendar_cleanup(void *);
 int wins_refresh(void);
 int wins_wrefresh(WINDOW *);
 int wins_doupdate(void);
+int wins_redrawwin(WINDOW *);
 int wins_layout(void);
 void wins_set_layout(int);
 unsigned wins_sbar_width(void);
diff --git a/src/custom.c b/src/custom.c
index 3da9da4..52bdd5b 100644
--- a/src/custom.c
+++ b/src/custom.c
@@ -988,21 +988,16 @@ void custom_keys_config(void)
 		case KEY_ADD_ITEM:
 #define WINROW 10
 #define WINCOL 50
+			grabwin = popup(WINROW, WINCOL,
+					(row - WINROW) / 2, (col - WINCOL) / 2,
+					_("Press the key you want to assign to:"),
+					keys_get_label(selrow), 0);
 			for (;;) {
-				grabwin =
-				    popup(WINROW, WINCOL,
-					  (row - WINROW) / 2,
-					  (col - WINCOL) / 2,
-					  _("Press the key you want to assign to:"),
-					  keys_get_label(selrow), 0);
-
 				ch = keys_wgetch(grabwin);
 				enum key action = keys_get_action(ch);
 				/* Is the key already used by this action? */
-				if (action == selrow) {
-					delwin(grabwin);
+				if (action == selrow)
 					break;
-				}
 				/* Is the key used by another action? */
 				if (keys_assign_binding(ch, selrow)) {
 					char *keystr = keys_int2str(ch);
@@ -1018,13 +1013,14 @@ void custom_keys_config(void)
 								selelm,
 								LINESPERKEY);
 					wins_scrollwin_display(&kwin);
+					wins_redrawwin(grabwin);
 					continue;
 				}
 				nbrowelm++;
 				selelm = nbrowelm - 1;
-				delwin(grabwin);
 				break;
 			}
+			delwin(grabwin);
 #undef WINROW
 #undef WINCOL
 			break;
diff --git a/src/wins.c b/src/wins.c
index d86b168..5a28dc7 100644
--- a/src/wins.c
+++ b/src/wins.c
@@ -163,6 +163,17 @@ int wins_doupdate(void)
 	return rc;
 }
 
+int wins_redrawwin(WINDOW *win)
+{
+	int rc;
+
+	SCREEN_ACQUIRE;
+	rc = redrawwin(win);
+	SCREEN_RELEASE;
+
+	return rc;
+}
+
 /* Get the current layout. */
 int wins_layout(void)
 {
-- 
cgit v1.2.3-70-g09d2