+ SCREEN *sp = _nc_screen_of(win);
+ return (sp ? sp->_use_meta : 0);
+}
+
+#ifdef NCURSES_WGETCH_EVENTS
+#define TWAIT_MASK (TW_ANY | TW_EVENT)
+#else
+#define TWAIT_MASK TW_ANY
+#endif
+
+/*
+ * Check for mouse activity, returning nonzero if we find any.
+ */
+static int
+check_mouse_activity(SCREEN *sp, int delay EVENTLIST_2nd(_nc_eventlist * evl))
+{
+ int rc;
+
+#if USE_SYSMOUSE
+ if ((sp->_mouse_type == M_SYSMOUSE)
+ && (sp->_sysmouse_head < sp->_sysmouse_tail)) {
+ return TW_MOUSE;
+ }
+#endif
+#ifdef USE_TERM_DRIVER
+ rc = TCBOf(sp)->drv->twait(TCBOf(sp),
+ TWAIT_MASK,
+ delay,
+ (int *) 0
+ EVENTLIST_2nd(evl));
+#else
+ rc = _nc_timed_wait(sp,
+ TWAIT_MASK,
+ delay,
+ (int *) 0
+ EVENTLIST_2nd(evl));
+#endif
+#if USE_SYSMOUSE
+ if ((sp->_mouse_type == M_SYSMOUSE)
+ && (sp->_sysmouse_head < sp->_sysmouse_tail)
+ && (rc == 0)
+ && (errno == EINTR)) {
+ rc |= TW_MOUSE;
+ }
+#endif
+ return rc;
+}
+
+static NCURSES_INLINE int
+fifo_peek(SCREEN *sp)
+{
+ int ch = sp->_fifo[peek];