- if (flag && keypad_xmit) {
- TPUTS_TRACE("keypad_xmit");
- putp(keypad_xmit);
- _nc_flush();
- } else if (!flag && keypad_local) {
- TPUTS_TRACE("keypad_local");
- putp(keypad_local);
- _nc_flush();
- }
+ int rc = ERR;
+
+ if (sp != 0) {
+#ifdef USE_PTHREADS
+ /*
+ * We might have this situation in a multithreaded application that
+ * has wgetch() reading in more than one thread. putp() and below
+ * may use SP explicitly.
+ */
+ if (_nc_use_pthreads && sp != CURRENT_SCREEN) {
+ SCREEN *save_sp;
+
+ /* cannot use use_screen(), since that is not in tinfo library */
+ _nc_lock_global(curses);
+ save_sp = CURRENT_SCREEN;
+ _nc_set_screen(sp);
+ rc = _nc_keypad(sp, flag);
+ _nc_set_screen(save_sp);
+ _nc_unlock_global(curses);
+ } else
+#endif
+ {
+#ifdef USE_TERM_DRIVER
+ rc = CallDriver_1(sp, td_kpad, flag);
+ if (rc == OK)
+ sp->_keypad_on = flag;
+#else
+ if (flag) {
+ (void) NCURSES_PUTP2_FLUSH("keypad_xmit", keypad_xmit);
+ } else if (!flag && keypad_local) {
+ (void) NCURSES_PUTP2_FLUSH("keypad_local", keypad_local);
+ }