NCURSES_SP_NAME(baudrate) (NCURSES_SP_DCL0) { int result; T((T_CALLED("baudrate(%p)"), (void *) SP_PARM)); /* * In debugging, allow the environment symbol to override when we're * redirecting to a file, so we can construct repeatable test-cases * that take into account costs that depend on baudrate. */ #ifdef TRACE if (IsValidTIScreen(SP_PARM) && !NC_ISATTY(fileno(SP_PARM ? SP_PARM->_ofp : stdout)) && getenv("BAUDRATE") != 0) { int ret; if ((ret = _nc_getenv_num("BAUDRATE")) <= 0) ret = 9600; ospeed = (NCURSES_OSPEED) _nc_ospeed(ret); returnCode(ret); } #endif if (IsValidTIScreen(SP_PARM)) { #ifdef USE_OLD_TTY result = (int) cfgetospeed(&(TerminalOf(SP_PARM)->Nttyb)); ospeed = (NCURSES_OSPEED) _nc_ospeed(result); #else /* !USE_OLD_TTY */ #ifdef TERMIOS ospeed = (NCURSES_OSPEED) cfgetospeed(&(TerminalOf(SP_PARM)->Nttyb)); #else ospeed = (NCURSES_OSPEED) TerminalOf(SP_PARM)->Nttyb.sg_ospeed; #endif result = _nc_baudrate(ospeed); #endif TerminalOf(SP_PARM)->_baudrate = result; } else { result = ERR; } returnCode(result); }
static bool allow_gpm_mouse(SCREEN *sp) { bool result = FALSE; #if USE_WEAK_SYMBOLS /* Danger Robinson: do not use dlopen for libgpm if already loaded */ if ((Gpm_Wgetch)) { if (!sp->_mouse_gpm_loaded) { T(("GPM library was already dlopen'd, not by us")); } } else #endif /* GPM does printf's without checking if stdout is a terminal */ if (NC_ISATTY(fileno(stdout))) { char *list = getenv("NCURSES_GPM_TERMS"); char *env = getenv("TERM"); if (list != 0) { if (env != 0) { result = _nc_name_match(list, env, "|:"); } } else { /* GPM checks the beginning of the $TERM variable to decide if it * should pass xterm events through. There is no real advantage in * allowing GPM to do this. Recent versions relax that check, and * pretend that GPM can work with any terminal having the kmous * capability. Perhaps that works for someone. If so, they can * set the environment variable (above). */ if (env != 0 && strstr(env, "linux") != 0) { result = TRUE; } } } return result; }
static void initialize_mousetype(SCREEN *sp) { T((T_CALLED("initialize_mousetype()"))); /* Try gpm first, because gpm may be configured to run in xterm */ #if USE_GPM_SUPPORT if (allow_gpm_mouse(sp)) { if (!sp->_mouse_gpm_loaded) { #ifdef HAVE_LIBDL load_gpm_library(sp); #else /* !HAVE_LIBDL */ sp->_mouse_gpm_found = TRUE; sp->_mouse_gpm_loaded = TRUE; #endif } /* * The gpm_fd file-descriptor may be negative (xterm). So we have to * maintain our notion of whether the mouse connection is active * without testing the file-descriptor. */ if (sp->_mouse_gpm_found && enable_gpm_mouse(sp, TRUE)) { sp->_mouse_type = M_GPM; sp->_mouse_fd = *(my_gpm_fd); T(("GPM mouse_fd %d", sp->_mouse_fd)); returnVoid; } } #endif /* USE_GPM_SUPPORT */ /* OS/2 VIO */ #if USE_EMX_MOUSE if (!sp->_emxmouse_thread && strstr(TerminalOf(sp)->type.term_names, "xterm") == 0 && key_mouse) { int handles[2]; if (pipe(handles) < 0) { perror("mouse pipe error"); returnVoid; } else { int rc; if (!sp->_emxmouse_buttons[0]) { char *s = getenv("MOUSE_BUTTONS_123"); sp->_emxmouse_buttons[0] = 1; if (s && strlen(s) >= 3) { sp->_emxmouse_buttons[1] = s[0] - '0'; sp->_emxmouse_buttons[2] = s[1] - '0'; sp->_emxmouse_buttons[3] = s[2] - '0'; } else { sp->_emxmouse_buttons[1] = 1; sp->_emxmouse_buttons[2] = 3; sp->_emxmouse_buttons[3] = 2; } } sp->_emxmouse_wfd = handles[1]; M_FD(sp) = handles[0]; /* Needed? */ setmode(handles[0], O_BINARY); setmode(handles[1], O_BINARY); /* Do not use CRT functions, we may single-threaded. */ rc = DosCreateThread((unsigned long *) &sp->_emxmouse_thread, mouse_server, (long) sp, 0, 8192); if (rc) { printf("mouse thread error %d=%#x", rc, rc); } else { sp->_mouse_type = M_XTERM; } returnVoid; } } #endif /* USE_EMX_MOUSE */ #if USE_SYSMOUSE { struct mouse_info the_mouse; char *the_device = 0; if (NC_ISATTY(sp->_ifd)) the_device = ttyname(sp->_ifd); if (the_device == 0) the_device = "/dev/tty"; sp->_mouse_fd = open(the_device, O_RDWR); if (sp->_mouse_fd >= 0) { /* * sysmouse does not have a usable user interface for obtaining * mouse events. The logical way to proceed (reading data on a * stream) only works if one opens the device as root. Even in * that mode, careful examination shows we lose events * occasionally. The interface provided for user programs is to * establish a signal handler. really. * * Take over SIGUSR2 for this purpose since SIGUSR1 is more * likely to be used by an application. getch() will have to * handle the misleading EINTR's. */ signal(SIGUSR2, SIG_IGN); the_mouse.operation = MOUSE_MODE; the_mouse.u.mode.mode = 0; the_mouse.u.mode.signal = SIGUSR2; if (ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse) != -1) { signal(SIGUSR2, handle_sysmouse); the_mouse.operation = MOUSE_SHOW; ioctl(sp->_mouse_fd, CONS_MOUSECTL, &the_mouse); #if defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) /* FreeBSD > 2.x */ { #ifndef FBIO_GETMODE /* FreeBSD 3.x */ #define FBIO_GETMODE CONS_GET #define FBIO_MODEINFO CONS_MODEINFO #endif /* FBIO_GETMODE */ video_info_t the_video; if (ioctl(sp->_mouse_fd, FBIO_GETMODE, &the_video.vi_mode) != -1 && ioctl(sp->_mouse_fd, FBIO_MODEINFO, &the_video) != -1) { sp->_sysmouse_char_width = the_video.vi_cwidth; sp->_sysmouse_char_height = the_video.vi_cheight; } } #endif /* defined(FBIO_MODEINFO) || defined(CONS_MODEINFO) */ if (sp->_sysmouse_char_width <= 0) sp->_sysmouse_char_width = 8; if (sp->_sysmouse_char_height <= 0) sp->_sysmouse_char_height = 16; sp->_mouse_type = M_SYSMOUSE; returnVoid; } } } #endif /* USE_SYSMOUSE */ #ifdef USE_TERM_DRIVER CallDriver(sp, td_initmouse); #else /* we know how to recognize mouse events under "xterm" */ if (key_mouse != 0) { if (!strcmp(key_mouse, xterm_kmous) || strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) { init_xterm_mouse(sp); } } else if (strstr(TerminalOf(sp)->type.term_names, "xterm") != 0) { if (_nc_add_to_try(&(sp->_keytry), xterm_kmous, KEY_MOUSE) == OK) init_xterm_mouse(sp); } #endif returnVoid; }