CVSROOT: /cvsroot/gnash Module name: gnash Changes by: Udo Giacomozzi <udog> 07/12/06 14:59:46
Modified files: . : ChangeLog gui : fb.cpp fbsup.h Log message: gui/fb.{h,cpp}: switch to graphics mode (and back) to get rid of any text console output and the cursor CVSWeb URLs: http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5099&r2=1.5100 http://cvs.savannah.gnu.org/viewcvs/gnash/gui/fb.cpp?cvsroot=gnash&r1=1.44&r2=1.45 http://cvs.savannah.gnu.org/viewcvs/gnash/gui/fbsup.h?cvsroot=gnash&r1=1.22&r2=1.23 Patches: Index: ChangeLog =================================================================== RCS file: /cvsroot/gnash/gnash/ChangeLog,v retrieving revision 1.5099 retrieving revision 1.5100 diff -u -b -r1.5099 -r1.5100 --- ChangeLog 6 Dec 2007 13:23:35 -0000 1.5099 +++ ChangeLog 6 Dec 2007 14:59:45 -0000 1.5100 @@ -1,3 +1,8 @@ +2007-12-06 Udo Giacomozzi <[EMAIL PROTECTED]> + + * gui/fb.{h,cpp}: switch to graphics mode (and back) to get rid + of any text console output and the cursor + 2007-12-06 Benjamin Wolsey <[EMAIL PROTECTED]> * server/swf/tag_loaders.cpp: revert last change; it stops Index: gui/fb.cpp =================================================================== RCS file: /cvsroot/gnash/gnash/gui/fb.cpp,v retrieving revision 1.44 retrieving revision 1.45 diff -u -b -r1.44 -r1.45 --- gui/fb.cpp 24 Oct 2007 13:16:26 -0000 1.44 +++ gui/fb.cpp 6 Dec 2007 14:59:46 -0000 1.45 @@ -76,6 +76,8 @@ #include <sys/ioctl.h> #include <sys/mman.h> #include <linux/fb.h> +#include <linux/kd.h> +#include <linux/vt.h> #include <unistd.h> #include <signal.h> @@ -501,19 +503,180 @@ } -void FBGui::disable_terminal() +char* FBGui::find_accessible_tty(int no) { + + char* fn; + + fn = find_accessible_tty("/dev/vc/%d", no); if (fn) return fn; + fn = find_accessible_tty("/dev/tty%d", no); if (fn) return fn; + fn = find_accessible_tty("/dev/tty%02x", no); if (fn) return fn; + fn = find_accessible_tty("/dev/tty%x", no); if (fn) return fn; + fn = find_accessible_tty("/dev/tty%02d", no); if (fn) return fn; + + if (no==0) { + fn = find_accessible_tty("/dev/tty", no); // just "/dev/tty" + if (fn) return fn; + } + + return NULL; + +} + +char* FBGui::find_accessible_tty(const char* format, int no) { + + static char fname[1024]; + + snprintf(fname, sizeof fname, format, no); + + if (access(fname, R_OK|W_OK) != -1) { + return fname; + } + + return NULL; +} + +bool FBGui::disable_terminal() { - /* - --> doesn't work as this hides the cursor of the *current* terminal (which - --> doesn't have to be the fb one). Maybe just detach from terminal? - printf("\033[?25l"); - fflush(stdout);*/ + original_kd = -1; + + struct vt_stat vts; + + // Find the TTY device name + + char* tty = find_accessible_tty(0); + + int fd; + + if (!tty) { + log_msg("WARNING: Could not detect controlling TTY"); + return false; + } + + + // Detect the currently active virtual terminal (so we can switch back to + // it later) + + fd = open(tty, O_RDWR); + if (fd<0) { + log_msg("WARNING: Could not open %s", tty); + return false; + } + + if (ioctl(fd, VT_GETSTATE, &vts) == -1) { + log_msg("WARNING: Could not get current VT state"); + close(fd); + return false; + } + + original_vt = vts.v_active; + log_msg("Original TTY NO = %d", original_vt); + +#ifdef REQUEST_NEW_VT + + // Request a new VT number + if (ioctl(fd, VT_OPENQRY, &own_vt) == -1) { + log_msg("WARNING: Could not request a new VT"); + close(fd); + return false; + } + + log_msg("Own TTY NO = %d", own_vt); + + close(fd); + + // Activate our new VT + tty = find_accessible_tty(own_vt); + if (!tty) { + log_msg("WARNING: Could not find device for VT number %d", own_vt); + return false; + } + + fd = open(tty, O_RDWR); + if (fd<0) { + log_msg("WARNING: Could not open %s", tty); + return false; + } + + if (ioctl(fd, VT_ACTIVATE, own_vt)) { + log_msg("WARNING: Could not activate VT number %d", own_vt); + close(fd); + return false; + } + + if (ioctl(fd, VT_WAITACTIVE, own_vt)) { + log_msg("WARNING: Error waiting for VT %d becoming active", own_vt); + //close(tty); + //return false; don't abort + } + +#else + + own_vt = original_vt; // keep on using the original VT + +#endif + + // Disable keyboard cursor + + if (ioctl(fd, KDGETMODE, &original_kd)) { + log_msg("WARNING: Could not query current keyboard mode on VT"); + } + + if (ioctl(fd, KDSETMODE, KD_GRAPHICS)) { + log_msg("WARNING: Could not switch to graphics mode on new VT"); + } + + close(fd); + + log_msg("VT %d ready", own_vt); + + + // NOTE: We could also implement virtual console switching by using + // VT_GETMODE / VT_SETMODE ioctl calls and handling their signals, but + // probably nobody will ever want to switch consoles, so I don't bother... + + return true; } -void FBGui::enable_terminal() +bool FBGui::enable_terminal() { - /*printf("\033[?25h"); - fflush(stdout);*/ + + log_msg("Restoring terminal..."); + + char* tty = find_accessible_tty(own_vt); + if (!tty) { + log_msg("WARNING: Could not find device for VT number %d", own_vt); + return false; + } + + int fd = open(tty, O_RDWR); + if (fd<0) { + log_msg("WARNING: Could not open %s", tty); + return false; + } + + if (ioctl(fd, VT_ACTIVATE, original_vt)) { + log_msg("WARNING: Could not activate VT number %d", original_vt); + close(fd); + return false; + } + + if (ioctl(fd, VT_WAITACTIVE, original_vt)) { + log_msg("WARNING: Error waiting for VT %d becoming active", original_vt); + //close(tty); + //return false; don't abort + } + + + + // Restore keyboard + + if (ioctl(fd, KDSETMODE, original_kd)) { + log_msg("WARNING: Could not restore keyboard mode"); + } + + close(fd); + + return true; } void FBGui::read_mouse_data() Index: gui/fbsup.h =================================================================== RCS file: /cvsroot/gnash/gnash/gui/fbsup.h,v retrieving revision 1.22 retrieving revision 1.23 diff -u -b -r1.22 -r1.23 --- gui/fbsup.h 19 Oct 2007 12:28:25 -0000 1.22 +++ gui/fbsup.h 6 Dec 2007 14:59:46 -0000 1.23 @@ -63,6 +63,11 @@ #endif +// Define this to request a new virtual terminal at startup. This doesn't always +// work and probably is not necessary anyway +//#define REQUEST_NEW_VT + + namespace gnash { @@ -111,6 +116,9 @@ { private: int fd; + int original_vt; // virtual terminal that was active at startup + int original_kd; // keyboard mode at startup + int own_vt; // virtual terminal we are running in unsigned char *fbmem; // framebuffer memory #ifdef DOUBLE_BUFFER unsigned char *buffer; // offscreen buffer @@ -141,11 +149,15 @@ bool initialize_renderer(); + /// Tries to find a accessible tty + char* find_accessible_tty(int no); + char* find_accessible_tty(const char* format, int no); + /// switches from text mode to graphics mode (disables the text terminal) - void disable_terminal(); + bool disable_terminal(); /// reverts disable_terminal() changes - void enable_terminal(); + bool enable_terminal(); #ifdef USE_MOUSE_PS2 /// Sends a command to the mouse and waits for the response _______________________________________________ Gnash-commit mailing list Gnash-commit@gnu.org http://lists.gnu.org/mailman/listinfo/gnash-commit