static int slang_getchar(aa_context * c1, int wait) { int c; volatile int flag = 0; #ifdef GPM_MOUSEDRIVER static Gpm_Event ev; #endif struct timeval tv; fd_set readfds; if (wait) { setjmp(buf); iswaiting = 1; } else iswaiting = 0; if (__resized_slang == 2) { iswaiting = 0; __resized_slang = 1; return (AA_RESIZE); } /*non-gpm way */ if (!wait) { #ifdef GPM_MOUSEDRIVER if (gpm_fd == -1) { #endif if (!SLang_input_pending(0)) return AA_NONE; #ifdef GPM_MOUSEDRIVER } else { GPM_DRAWPOINTER(&ev); tv.tv_sec = 0; tv.tv_usec = 0; FD_ZERO(&readfds); if (gpm_fd != -2) FD_SET(gpm_fd, &readfds); FD_SET(STDIN_FILENO, &readfds); if (!(flag = select( ((gpm_fd == -2)?STDIN_FILENO:gpm_fd) + 1, &readfds, NULL, NULL, &tv))) return AA_NONE; } #endif } #ifdef GPM_MOUSEDRIVER if (gpm_fd != -1) { GPM_DRAWPOINTER(&ev); while (!flag) { FD_ZERO(&readfds); if (gpm_fd != -2) FD_SET(gpm_fd, &readfds); FD_SET(STDIN_FILENO, &readfds); tv.tv_sec = 60; flag = select( ((gpm_fd == -2)?STDIN_FILENO:gpm_fd) + 1, &readfds, NULL, NULL, &tv); } if (flag == -1) { printf("error!\n"); return (AA_NONE); } if ((gpm_fd > -1) && (FD_ISSET(gpm_fd, &readfds))) { if (Gpm_GetEvent(&ev) && gpm_handler && ((*gpm_handler) (&ev, gpm_data))) { gpm_hflag = 1; return AA_MOUSE; } } } if (gpm_fd == -2) c = Gpm_Getchar(); else #endif c = SLkp_getkey(); iswaiting = 0; if (__resized_slang == 2) { __resized_slang = 1; return (AA_RESIZE); } if (c == 27) return (AA_ESC); if (c > 0 && c < 128 && c != 127) return (c); switch (c) { case SL_KEY_ERR: return (AA_NONE); case SL_KEY_LEFT: return (AA_LEFT); case SL_KEY_RIGHT: return (AA_RIGHT); case SL_KEY_UP: return (AA_UP); case SL_KEY_DOWN: return (AA_DOWN); case SL_KEY_BACKSPACE: case 127: return (AA_BACKSPACE); } return (AA_UNKNOWN); }
int mouse_wgetch(WINDOW *win) { int key; #if defined(NCURSES_MOUSE_VERSION) /* before calling this you have to put (only the first time) a "wtimeout(dialog, WTIMEOUT_VAL);" */ do { key = dlg_getc(win); if (key == KEY_MOUSE) { MEVENT event; mseRegion *p; if (getmouse(&event) != ERR && (p = mouse_region(event.y, event.x)) != 0) { key = M_EVENT + p->code; } else { (void) beep(); key = ERR; } } } while (key == ERR); #elif defined(HAVE_LIBGPM) fd_set selSet; int flag, result; int fd = STDIN_FILENO; static Gpm_Event ev; key = 0; if (!gpm_flag || gpm_fd <= -1) return dlg_getc(win); if (gpm_morekeys) return (*gpm_handler) (&ev, gpm_data); gpm_hflag = 0; while (1) { if (gpm_visiblepointer) GPM_DRAWPOINTER(&ev); do { FD_ZERO(&selSet); FD_SET(fd, &selSet); FD_SET(gpm_fd, &selSet); gpm_timeout.tv_usec = WTIMEOUT_VAL * 10000; gpm_timeout.tv_sec = 0; flag = select(5, &selSet, (fd_set *) 0, (fd_set *) 0, &gpm_timeout); /* fprintf(stderr, "X"); */ } while (!flag); if (FD_ISSET(fd, &selSet)) return dlg_getc(win); if (flag == -1) continue; if (Gpm_GetEvent(&ev) && gpm_handler && (result = (*gpm_handler) (&ev, gpm_data))) { gpm_hflag = 1; return result; } } #else /* before calling this you have to put (only the first time) a "wtimeout(dialog, WTIMEOUT_VAL);" */ do { key = dlg_getc(win); } while (key == ERR); #endif return key; }
static int linux_getchar(aa_context * c1, int wait) { #ifdef GPM_MOUSEDRIVER static Gpm_Event e; #endif int c; int key; struct timeval tv; do { fd_set readfds; tv.tv_sec = 0; tv.tv_usec = 0; FD_ZERO(&readfds); FD_SET(tty_fd, &readfds); #ifdef GPM_MOUSEDRIVER if (gpm_visiblepointer) GPM_DRAWPOINTER(&e); if (__curses_usegpm) { FD_SET(gpm_fd, &readfds); } #endif #ifdef GPM_MOUSEDRIVER select((__curses_usegpm ? gpm_fd : 0) + 1, &readfds, NULL, NULL, wait ? NULL : &tv); if (__curses_usegpm && FD_ISSET(gpm_fd, &readfds)) { if (Gpm_GetEvent(&e) == 1) { __gpm_user_handler(&e, NULL); return AA_MOUSE; } } #else select(tty_fd, &readfds, NULL, NULL, wait ? NULL : &tv); #endif c = scan_keyboard(); if (c != -1) { switch (c) { case ESCAPE_KEY: key = AA_ESC; break; case ENTER_KEY: key = 13; break; case BACKSPACE: key = AA_BACKSPACE; break; case CURSOR_LEFT: key = AA_LEFT; break; case CURSOR_RIGHT: key = AA_RIGHT; break; case CURSOR_UP: key = AA_UP; break; case CURSOR_DOWN: key = AA_DOWN; break; case CURSORBLOCK_LEFT: key = AA_LEFT; break; case CURSORBLOCK_RIGHT: key = AA_RIGHT; break; case CURSORBLOCK_UP: key = AA_UP; break; case CURSORBLOCK_DOWN: key = AA_DOWN; break; default: key = keymap_trans(c) & 255; } if (!key_down[c]) key |= AA_RELEASE; return key; } else key = AA_NONE; } while (wait); return AA_NONE; }