/* Timer handler used to do the VT switch at a time when not drawing */ static void vt_do_switch(void *arg) { static unsigned short r[16], g[16], b[16]; /* * If a drawing function is in progress then we cannot mode * switch right now because the drawing function would continue to * scribble on the screen after the switch. So disable further * drawing and schedule an alarm to try again in .1 second. */ if(mwdrawing) { draw_disable (); GdAddTimer(100, vt_do_switch, NULL); return; } if(visible) { draw_disable (); ioctl_getpalette(0, 16, r, g, b); if(ioctl (ttyfd, VT_RELDISP, 1) == -1) EPRINTF("Error can't switch away from VT: %m\n"); } else { ioctl_setpalette(0, 16, r, g, b); draw_enable (); if(ioctl (ttyfd, VT_RELDISP, VT_ACKACQ) == -1) EPRINTF("Error can't acknowledge VT switch: %m\n"); } }
/* Signal handler called whenever the kernel wants to switch to or from our tty. */ static void vt_switch (int sig unused) { signal (SIGUSR2, vt_switch); /* If a BOGL drawing function is in progress then we cannot mode switch right now because the drawing function would continue to scribble on the screen after the switch. So disable further drawing and schedule an alarm to try again in .1 second. */ if (bogl_drawing) { draw_disable (); signal (SIGALRM, vt_switch); { struct itimerval duration; duration.it_interval.tv_sec = 0; duration.it_interval.tv_usec = 0; duration.it_value.tv_sec = 0; duration.it_value.tv_usec = 100000; if (-1 == setitimer (ITIMER_REAL, &duration, NULL)) bogl_fail ("can't set timer: %s", strerror (errno)); } return; } if (visible) { visible = 0; draw_disable (); if (-1 == ioctl (tty, VT_RELDISP, 1)) bogl_fail ("can't switch away from VT: %s", strerror (errno)); } else { visible = 1; draw_enable (); if (-1 == ioctl (tty, VT_RELDISP, VT_ACKACQ)) bogl_fail ("can't acknowledge VT switch: %s", strerror (errno)); if (bogl_reinit != NULL) bogl_reinit (); bogl_refresh = 2; } }