1 /****************************************************************************
2 * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996-on *
33 * and: Juergen Pfeifer 2009 *
34 ****************************************************************************/
39 ** The routines to handle option setting.
43 #include <curses.priv.h>
47 MODULE_ID("$Id: lib_options.c,v 1.59 2009/02/15 00:48:40 tom Exp $")
49 static int _nc_curs_set(SCREEN *, int);
50 static int _nc_meta(SCREEN *, bool);
53 idlok(WINDOW *win, bool flag)
55 T((T_CALLED("idlok(%p,%d)"), win, flag));
58 _nc_idlok = win->_idlok = (flag && (has_il() || change_scroll_region));
65 idcok(WINDOW *win, bool flag)
67 T((T_CALLED("idcok(%p,%d)"), win, flag));
70 _nc_idcok = win->_idcok = (flag && has_ic());
76 NCURSES_SP_NAME(halfdelay) (NCURSES_SP_DCLx int t)
78 T((T_CALLED("halfdelay(%d)"), t));
80 if (t < 1 || t > 255 || SP_PARM == 0)
84 SP_PARM->_cbreak = t + 1;
92 return NCURSES_SP_NAME(halfdelay) (CURRENT_SCREEN, t);
97 nodelay(WINDOW *win, bool flag)
99 T((T_CALLED("nodelay(%p,%d)"), win, flag));
112 notimeout(WINDOW *win, bool f)
114 T((T_CALLED("notimeout(%p,%d)"), win, f));
124 wtimeout(WINDOW *win, int delay)
126 T((T_CALLED("wtimeout(%p,%d)"), win, delay));
135 keypad(WINDOW *win, bool flag)
137 T((T_CALLED("keypad(%p,%d)"), win, flag));
140 win->_use_keypad = flag;
141 returnCode(_nc_keypad(SP, flag));
147 meta(WINDOW *win GCC_UNUSED, bool flag)
151 /* Ok, we stay relaxed and don't signal an error if win is NULL */
152 T((T_CALLED("meta(%p,%d)"), win, flag));
153 result = _nc_meta(SP, flag);
157 /* curs_set() moved here to narrow the kernel interface */
164 T((T_CALLED("curs_set(%d)"), vis));
165 result = _nc_curs_set(SP, vis);
170 NCURSES_SP_NAME(typeahead) (NCURSES_SP_DCLx int fd)
172 T((T_CALLED("typeahead(%d)"), fd));
174 SP_PARM->_checkfd = fd;
185 return NCURSES_SP_NAME(typeahead) (CURRENT_SCREEN, fd);
192 ** Return TRUE if the current terminal has the given key
196 #if NCURSES_EXT_FUNCS
198 has_key_internal(int keycode, TRIES * tp)
202 else if (tp->value == keycode)
205 return (has_key_internal(keycode, tp->child)
206 || has_key_internal(keycode, tp->sibling));
212 T((T_CALLED("has_key(%d)"), keycode));
213 returnCode(SP != 0 ? has_key_internal(keycode, SP->_keytry) : FALSE);
215 #endif /* NCURSES_EXT_FUNCS */
218 * Internal entrypoints use SCREEN* parameter to obtain capabilities rather
222 #define CUR (sp->_term)->type.
225 _nc_putp(const char *name GCC_UNUSED, const char *value)
237 _nc_putp_flush(const char *name, const char *value)
239 int rc = _nc_putp(name, value);
246 /* Turn the keypad on/off
248 * Note: we flush the output because changing this mode causes some terminals
249 * to emit different escape sequences for cursor and keypad keys. If we don't
250 * flush, then the next wgetch may get the escape sequence that corresponds to
251 * the terminal state _before_ switching modes.
254 _nc_keypad(SCREEN *sp, bool flag)
261 * We might have this situation in a multithreaded application that
262 * has wgetch() reading in more than one thread. putp() and below
263 * may use SP explicitly.
265 if (_nc_use_pthreads && sp != SP) {
268 /* cannot use use_screen(), since that is not in tinfo library */
269 _nc_lock_global(curses);
272 rc = _nc_keypad(sp, flag);
273 _nc_set_screen(save_sp);
274 _nc_unlock_global(curses);
279 (void) _nc_putp_flush("keypad_xmit", keypad_xmit);
280 } else if (!flag && keypad_local) {
281 (void) _nc_putp_flush("keypad_local", keypad_local);
284 if (flag && !sp->_tried) {
288 sp->_keypad_on = flag;
296 _nc_curs_set(SCREEN *sp, int vis)
300 T((T_CALLED("curs_set(%d)"), vis));
301 if (sp != 0 && vis >= 0 && vis <= 2) {
302 int cursor = sp->_cursor;
309 result = _nc_putp_flush("cursor_visible", cursor_visible);
312 result = _nc_putp_flush("cursor_normal", cursor_normal);
315 result = _nc_putp_flush("cursor_invisible", cursor_invisible);
319 result = (cursor == -1 ? 1 : cursor);
327 _nc_meta(SCREEN *sp, bool flag)
331 /* Ok, we stay relaxed and don't signal an error if win is NULL */
334 SP->_use_meta = flag;
337 _nc_putp("meta_on", meta_on);
339 _nc_putp("meta_off", meta_off);