mirror of
https://github.com/VARCem/PDCurses.git
synced 2026-09-24 07:45:21 +00:00
Support for timeout() and wtimeout()
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef PDCDEBUG
|
||||
char *rcsid_getch = "$Id: getch.c,v 1.3 2002/03/22 22:36:08 mark Exp $";
|
||||
char *rcsid_getch = "$Id: getch.c,v 1.4 2003/12/28 08:38:43 mark Exp $";
|
||||
#endif
|
||||
|
||||
/*man-start*********************************************************************
|
||||
@@ -170,7 +170,20 @@ extern WINDOW* _getch_win_;
|
||||
return( ERR );
|
||||
|
||||
if ( SP->delaytenths )
|
||||
waitingtenths = 2*SP->delaytenths; /* changed from 10 to 2 - William McBrine */
|
||||
waitingtenths = 2*SP->delaytenths; /* set the number of 1/20th second napms() calls */
|
||||
else if ( win->_delayms )
|
||||
{
|
||||
/*
|
||||
* As granularity of clocks is not ideal for waiting for individual periods
|
||||
* of 1 millisecond, we need to determine a reasonably accurate mechanism
|
||||
* based on the specified delay period. As delaying by 1/20th of a second
|
||||
* is reasonable, then determine how many 1/20th seconds are in the specified
|
||||
* delay time, and pause that many times.
|
||||
*/
|
||||
waitingtenths = win->_delayms / 50;
|
||||
if (waitingtenths == 0)
|
||||
waitingtenths = 1;
|
||||
}
|
||||
|
||||
/* wrs (7/31/93) -- System V curses refreshes window when wgetch is called */
|
||||
/* if there have been changes to it and it is not a pad */
|
||||
@@ -262,14 +275,14 @@ extern WINDOW* _getch_win_;
|
||||
/*
|
||||
* Order of test for delaytenths and _nodelay reversed - William McBrine
|
||||
*/
|
||||
if (SP->delaytenths)
|
||||
if (SP->delaytenths || w->_delayms)
|
||||
{
|
||||
if (waitingtenths == 0 && key == (-1))
|
||||
return(ERR);
|
||||
if (key == (-1))
|
||||
{
|
||||
waitingtenths--;
|
||||
napms(50); /* changed from 10 to 50 - William McBrine */
|
||||
napms(50); /* sleep for 1/20th second */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef PDCDEBUG
|
||||
char *rcsid_inopts = "$Id: inopts.c,v 1.1 2001/01/10 08:27:09 mark Exp $";
|
||||
char *rcsid_inopts = "$Id: inopts.c,v 1.2 2003/12/28 08:38:59 mark Exp $";
|
||||
#endif
|
||||
|
||||
/*man-start*********************************************************************
|
||||
@@ -77,8 +77,8 @@ char *rcsid_inopts = "$Id: inopts.c,v 1.1 2001/01/10 08:27:09 mark Exp $";
|
||||
int noraw(void);
|
||||
*** void noqiflush(void);
|
||||
*** void qiflush(void);
|
||||
*** int timeout(int delay);
|
||||
*** int wtimeout(WINDOW *win, int delay);
|
||||
int timeout(int delay);
|
||||
int wtimeout(WINDOW *win, int delay);
|
||||
int typeahead(int fildes);
|
||||
|
||||
X/Open Description:
|
||||
@@ -145,6 +145,13 @@ char *rcsid_inopts = "$Id: inopts.c,v 1.1 2001/01/10 08:27:09 mark Exp $";
|
||||
signal. The behaviour of the BREAK key depends on other
|
||||
parameters of the terminal drive that are not set by curses.
|
||||
|
||||
The timeout() and wtimeout() functions set blocking or non-blocking
|
||||
reads for the specified window. "delay" is measured in milliseconds.
|
||||
If "delay" is negative a blocking read is used. If "delay" is zero
|
||||
then non-blocking reads are done. If no input is waiting, ERR is
|
||||
returned immediately. If "delay" is positive, the read blocks for
|
||||
the "delay" period. If the period expires, ERR is returned.
|
||||
|
||||
The curses package does the "line-breakout optimisation" by
|
||||
looking for type-ahead periodically while updating the screen.
|
||||
If input is found, the current update will be postponed until
|
||||
@@ -306,7 +313,7 @@ int tenths;
|
||||
/***********************************************************************/
|
||||
{
|
||||
#ifdef PDCDEBUG
|
||||
if (trace_on) PDC_debug("nodelay() - called\n");
|
||||
if (trace_on) PDC_debug("halfdelay() - called\n");
|
||||
#endif
|
||||
if (tenths < 1 || tenths > 255)
|
||||
return (ERR);
|
||||
@@ -545,21 +552,6 @@ int fildes;
|
||||
}
|
||||
/***********************************************************************/
|
||||
#ifdef HAVE_PROTO
|
||||
int PDC_CDECL timeout( int delay )
|
||||
#else
|
||||
int PDC_CDECL timeout(delay)
|
||||
int delay;
|
||||
#endif
|
||||
/***********************************************************************/
|
||||
{
|
||||
#ifdef PDCDEBUG
|
||||
if (trace_on) PDC_debug("timeout() - called\n");
|
||||
#endif
|
||||
/*************** this does nothing at the moment *************/
|
||||
return(OK);
|
||||
}
|
||||
/***********************************************************************/
|
||||
#ifdef HAVE_PROTO
|
||||
int PDC_CDECL wtimeout( WINDOW *win, int delay )
|
||||
#else
|
||||
int PDC_CDECL wtimeout(win,delay)
|
||||
@@ -571,6 +563,51 @@ int delay;
|
||||
#ifdef PDCDEBUG
|
||||
if (trace_on) PDC_debug("wtimeout() - called\n");
|
||||
#endif
|
||||
/*************** this does nothing at the moment *************/
|
||||
|
||||
if (win == NULL)
|
||||
return ERR;
|
||||
|
||||
if (delay < 0)
|
||||
{
|
||||
/*
|
||||
* This causes a blocking read on the window
|
||||
* so turn on delay mode
|
||||
*/
|
||||
win->_nodelay = FALSE;
|
||||
win->_delayms = 0;
|
||||
}
|
||||
else if (delay == 0)
|
||||
{
|
||||
/*
|
||||
* This causes a non-blocking read on the window
|
||||
* so turn off delay mode
|
||||
*/
|
||||
win->_nodelay = TRUE;
|
||||
win->_delayms = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* This causes the read on the window
|
||||
* to delay for the number of milliseconds.
|
||||
* Also forces the window into non-blocking read mode
|
||||
*/
|
||||
/*win->_nodelay = TRUE;*/
|
||||
win->_delayms = delay;
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
/***********************************************************************/
|
||||
#ifdef HAVE_PROTO
|
||||
int PDC_CDECL timeout( int delay )
|
||||
#else
|
||||
int PDC_CDECL timeout(delay)
|
||||
int delay;
|
||||
#endif
|
||||
/***********************************************************************/
|
||||
{
|
||||
#ifdef PDCDEBUG
|
||||
if (trace_on) PDC_debug("timeout() - called\n");
|
||||
#endif
|
||||
return(wtimeout(stdscr,delay));
|
||||
}
|
||||
|
||||
10
x11/pdckbd.c
10
x11/pdckbd.c
@@ -25,7 +25,7 @@
|
||||
#include <curses.h>
|
||||
|
||||
#ifdef PDCDEBUG
|
||||
char *rcsid_PDCkbd = "$Id: pdckbd.c,v 1.3 2002/06/23 10:52:48 mark Exp $";
|
||||
char *rcsid_PDCkbd = "$Id: pdckbd.c,v 1.4 2003/12/28 08:39:21 mark Exp $";
|
||||
#endif
|
||||
|
||||
/*man-start*********************************************************************
|
||||
@@ -229,6 +229,7 @@ int PDC_rawgetch()
|
||||
extern WINDOW* _getch_win_;
|
||||
|
||||
int c=0;
|
||||
int delay;
|
||||
|
||||
#ifdef PDCDEBUG
|
||||
if (trace_on) PDC_debug("PDC_rawgetch() - called\n");
|
||||
@@ -240,7 +241,12 @@ extern WINDOW* _getch_win_;
|
||||
if (_getch_win_->_nodelay && !PDC_breakout()) /* @@ */
|
||||
return( -1 );
|
||||
|
||||
c = XCurses_rawgetch( SP->delaytenths );
|
||||
if ( SP->delaytenths || _getch_win_->_delayms > 0 )
|
||||
delay = 1;
|
||||
else
|
||||
delay = 0;
|
||||
|
||||
c = XCurses_rawgetch( delay );
|
||||
return(c);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user