/** * <p>Switch the display to a graphics mode.</p> * * <p>It switches VT to graphics mode with keyboard turned off. * Then, it tells kernel to notify Java when VT switch occurs. * Also, framebuffer contents are restored and write access is enabled.</p> * * @throws RuntimeException when the switch fails */ public void switchToGraphicsMode() { LOGGER.trace("Switching console to graphics mode"); try { ttyfd.setKeyboardMode(K_OFF); ttyfd.setConsoleMode(KD_GRAPHICS); NativeTTY.vt_mode vtm = new NativeTTY.vt_mode(); vtm.mode = VT_PROCESS; vtm.relsig = SIGUSR2; vtm.acqsig = SIGUSR2; ttyfd.setVTmode(vtm); } catch (LastErrorException e) { throw new RuntimeException("Switch to graphics mode failed", e); } if (fbInstance != null) { fbInstance.restoreData(); fbInstance.setFlushEnabled(true); } }
/** * Set current TTY mode. TTY mode is mostly about VT switching. * * @param mode TTY mode. * @throws LastErrorException when the operation fails. */ public void setVTmode(@NonNull vt_mode mode) throws LastErrorException { mode.write(); super.ioctl(VT_SETMODE, mode.getPointer()); }
/** * <p>Switch the display to a text mode.</p> * * <p>It stores framebuffer data and disables write access. Then, * it switches VT to text mode and allows kernel to auto-switch it.</p> * * @throws RuntimeException when the switch fails */ public void switchToTextMode() { LOGGER.trace("Switching console to text mode"); if (fbInstance != null) { fbInstance.setFlushEnabled(false); fbInstance.storeData(); } try { ttyfd.setConsoleMode(KD_TEXT); NativeTTY.vt_mode vtm = new NativeTTY.vt_mode(); vtm.mode = VT_AUTO; vtm.relsig = 0; vtm.acqsig = 0; ttyfd.setVTmode(vtm); } catch (LastErrorException e) { throw new RuntimeException("Switch to text mode failed", e); } }
/** * <p>Put the display to a state where it is ready for returning.</p> * * <p>Keyboard mode is restored, text mode is set and VT autoswitch is enabled. * Then, console file descriptor is closed.</p> */ private void deinitialize() { LOGGER.trace("Closing system console"); try { ttyfd.setKeyboardMode(old_kbmode); ttyfd.setConsoleMode(KD_TEXT); NativeTTY.vt_mode vtm = new NativeTTY.vt_mode(); vtm.mode = VT_AUTO; vtm.relsig = 0; vtm.acqsig = 0; ttyfd.setVTmode(vtm); ttyfd.close(); } catch (LastErrorException e) { System.err.println("Error occured during console shutdown: " + e.getMessage()); e.printStackTrace(); } // free objects closeFramebuffer(); ttyfd = null; libc = null; }
/** * Get current TTY mode. TTY mode is mostly about VT switching. * * @return TTY mode. * @throws LastErrorException when the operation fails. */ public vt_mode getVTmode() throws LastErrorException { vt_mode mode = new vt_mode(); super.ioctl(VT_GETMODE, mode.getPointer()); mode.read(); return mode; }