patch 8.1.1399: popup windows not adjusted when switching tabs

Problem:    Popup windows not adjusted when switching tabs.
Solution:   Save and restore first_tab_popupwin. Fix closing a tabpage.
diff --git a/src/testdir/dumps/Test_popupwin_02.dump b/src/testdir/dumps/Test_popupwin_02.dump
new file mode 100644
index 0000000..c2aa7a2
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_02.dump
@@ -0,0 +1,10 @@
+| +8#0000001#e0e0e08|+| |[|N|o| |N|a|m|e|]| | +2#0000000#ffffff0|[|N|o| |N|a|m|e|]| | +1&&@49|X+8#0000001#e0e0e08
+> +0#0000000#ffffff0@74
+|~+0#4040ff13&| @73
+|~| @6|o+0#0000001#ffd7ff255|t|h|e|r| |t|a|b| @10| +0#4040ff13#ffffff0@46
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|:+0#0000000&|c|a|l@1| |p|o|p|u|p|_|c|r|e|a|t|e|(|'|o|t|h|e|r| |t|a|b|'|,| |{|'|l|i|n|e|'|:| |4|,| |'|c|o|l|'|:| |9|}|)| @2|0|,|0|-|1| @8|A|l@1| 
diff --git a/src/testdir/dumps/Test_popupwin_03.dump b/src/testdir/dumps/Test_popupwin_03.dump
new file mode 100644
index 0000000..7436a01
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_03.dump
@@ -0,0 +1,10 @@
+| +2&#ffffff0|+| |[|N|o| |N|a|m|e|]| | +8#0000001#e0e0e08|[|N|o| |N|a|m|e|]| | +1#0000000#ffffff0@49|X+8#0000001#e0e0e08
+>1+0#0000000#ffffff0| @73
+|2| @8|h+0&#5fd7ff255|e|l@1|o| |t|h|e|r|e| @8|r+0#0000001#ffd7ff255| |o|n|e| @8| +0#0000000#ffffff0@30
+|3| @22|a+0#0000001#ffd7ff255|n|o|t|h|e|r| |t|w|o| @8| +0#0000000#ffffff0@30
+|4| @22|a+0#0000001#ffd7ff255|n|o|t|h|e|r| |t|h|r|e@1| @6| +0#0000000#ffffff0@30
+|5| @73
+|6| @73
+|7| @73
+|8| @73
+|:|c|a|l@1| |p|o|p|u|p|_|c|r|e|a|t|e|(|'|o|t|h|e|r| |t|a|b|'|,| |{|'|l|i|n|e|'|:| |4|,| |'|c|o| @9|1|,|1| @10|T|o|p| 
diff --git a/src/testdir/dumps/Test_popupwin_04.dump b/src/testdir/dumps/Test_popupwin_04.dump
new file mode 100644
index 0000000..a642455
--- /dev/null
+++ b/src/testdir/dumps/Test_popupwin_04.dump
@@ -0,0 +1,10 @@
+> +0&#ffffff0@74
+|~+0#4040ff13&| @73
+|~| @73
+|~| @6|o+0#0000001#ffd7ff255|t|h|e|r| |t|a|b| @10| +0#4040ff13#ffffff0@46
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|:+0#0000000&|q|u|i|t|!| @50|0|,|0|-|1| @8|A|l@1| 
diff --git a/src/testdir/test_popupwin.vim b/src/testdir/test_popupwin.vim
index 7bae0b5..e79c03d 100644
--- a/src/testdir/test_popupwin.vim
+++ b/src/testdir/test_popupwin.vim
@@ -20,6 +20,19 @@
   let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
   call VerifyScreenDump(buf, 'Test_popupwin_01', {})
 
+  " Add a tabpage
+  call term_sendkeys(buf, ":tabnew\<CR>")
+  call term_sendkeys(buf, ":call popup_create('other tab', {'line': 4, 'col': 9})\<CR>")
+  call VerifyScreenDump(buf, 'Test_popupwin_02', {})
+
+  " switch back to first tabpage
+  call term_sendkeys(buf, "gt")
+  call VerifyScreenDump(buf, 'Test_popupwin_03', {})
+
+  " close that tabpage
+  call term_sendkeys(buf, ":quit!\<CR>")
+  call VerifyScreenDump(buf, 'Test_popupwin_04', {})
+
   " clean up
   call StopVimInTerminal(buf)
   call delete('XtestPopup')