void getch2_poll(void){ if (!getch2_enabled) return; // check if stdin is in the foreground process group int newstatus = (tcgetpgrp(0) == getpgrp()); // and activate getch2 if it is, deactivate otherwise if (newstatus) do_activate_getch2(); else do_deactivate_getch2(); }
void getch2_enable(void){ if (getch2_enabled) return; // handlers to fix terminal settings setsigaction(SIGCONT, continue_sighandler, 0, true); setsigaction(SIGTSTP, stop_sighandler, SA_RESETHAND, false); setsigaction(SIGINT, quit_request_sighandler, SA_RESETHAND, false); setsigaction(SIGTTIN, SIG_IGN, 0, true); do_activate_getch2(); getch2_enabled = 1; }