📄 libfbx-console.c
字号:
/* * libfbx-console.c -- Console Manipulation Functions * (C)opyright 2000-2001 U4X Labs * * Written by: Paul Mundt <lethal@u4x.org> * * $Id: libfbx-console.c,v 1.9 2001/02/04 20:29:56 lethal Exp $ * * This is where all the console manipulation functions are * kept. (ie, console-switching). * * See ChangeLog for modifications, CREDITS for credits. * * All source herein is copyright U4X Labs and its original author. * Any code modifications or additions are (C)opyright the original * author and U4X Labs respectively. * * libfbx is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * libfbx is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with libfbx; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */#include <libfbx/libfbx.h>#include <libfbx/libfbx-drivers.h>#include <linux/vt.h>#include <linux/kd.h>#include <linux/config.h>#include <sys/ioctl.h>#include <signal.h>#include <string.h>/* * Function: fb_handle_switch_signals() * Arguments: Signal to handle. * Returns: None. * Description: Handles release and acquire signals sent to us * (SIGUSR1 and SIGUSR2). */void fb_handle_switch_signals(int signal){ if (signal == SIGUSR1) fb_screen->switch_state = FB_CONSOLE_REL_REQ; if (signal == SIGUSR2) fb_screen->switch_state = FB_CONSOLE_ACQ_REQ;}/* * Function: fb_switch_release() * Arguments: None. * Returns: None. * Description: Releases current VT. */void fb_switch_release(){ ioctl(tty, VT_RELDISP, 1); fb_screen->switch_state = FB_CONSOLE_INACTIVE;}/* * Function: fb_switch_acquire() * Arguments: None. * Returns: None. * Description: Acquires VT. */void fb_switch_acquire(){ if(ioctl(tty, VT_RELDISP, VT_ACKACQ) < 0) { perror("ioctl VT_RELDISP"); exit(1); } if(ioctl(tty, VT_SETMODE, VT_ACKACQ) < 0) { perror("ioctl VT_SETMODE"); exit(1); } if(ioctl(tty, KDSETMODE, KD_GRAPHICS) < 0) { perror("ioctl KDSETMODE"); exit(1); } fb_screen->switch_state = FB_CONSOLE_ACTIVE;}/* * Function: fb_switch_init() * Arguments: None. * Returns: None. * Description: Initializes console switching support. */void fb_switch_init(){ struct sigaction act, oldact; fb_memset(&act, 0, sizeof(act)); act.sa_handler = fb_handle_switch_signals; sigemptyset(&act.sa_mask); sigaction(SIGUSR1, &act, &oldact); sigaction(SIGUSR2, &act, &oldact); if (ioctl(tty, VT_GETMODE, &vtmode) < 0) { perror("ioctl VT_GETMODE"); exit(1); } vtmode.mode = VT_PROCESS; vtmode.waitv = 0; vtmode.relsig = SIGUSR1; vtmode.acqsig = SIGUSR2; if (ioctl(tty, VT_SETMODE, &vtmode) < 0) { perror("ioctl VT_SETMODE"); exit(1); }}/* * Function: fb_switch_console() * Arguments: None. * Returns: Redraw boolean. * Description: Determines the current switch state and * takes appropriate action. */int fb_switch_console(){ int redraw = 0; switch (fb_screen->switch_state) { case FB_CONSOLE_REL_REQ: fb_switch_release(); case FB_CONSOLE_INACTIVE: break; case FB_CONSOLE_ACQ_REQ: fb_switch_acquire(); case FB_CONSOLE_ACTIVE: fb_memset(fb_screen->mem_pointer, 0, fb_screen->buffer_size); ioctl(fbfd, FBIOPUT_VSCREENINFO, fb_screen->vinfo); redraw = 1; break; default: break; } fb_screen->last_switch = fb_screen->switch_state; return redraw;}int tty_switch = 0;void fb_set_vt(int num){ struct vt_stat vts; char name[12]; if (num < 0) if (ioctl(tty, VT_OPENQRY, &num) < 0) { perror("ioctl VT_OPENQRY"); exit(1); } num &= 0xff;#ifdef CONFIG_DEVFS_FS snprintf(name, sizeof(name), "/dev/vc/%d", num);#else snprintf(name, sizeof(name), "/dev/tty%d", num);#endif /* CONFIG_DEVFS_FS */ chown(name, getuid(), getgid()); if(access(name, R_OK | W_OK) == -1 ) { fprintf(stderr, "access: %s: %s\n", name, strerror(errno)); exit(1); } if((tty_switch = open(name, O_RDWR)) < 0) { perror(name); exit(1); } if (ioctl(tty, KDSETMODE, KD_TEXT)) { perror("ioctl KDSETMODE"); exit(1); } if (ioctl(tty_switch, VT_GETSTATE, &vts) < 0) { perror("ioctl VT_GETSTATE"); exit(1); } if (ioctl(tty_switch, VT_ACTIVATE, num) < 0) { perror("ioctl VT_ACTIVATE"); exit(1); } if (ioctl(tty, VT_RELDISP, 1) < 0) { perror("ioctl VT_RELDISP"); exit(1); } if (ioctl(tty_switch, VT_WAITACTIVE, num) < 0) { perror("ioctl VT_WAITACTIVE"); exit(1); }}/* * Function: fb_blank() * Arguments: * Returns: None. * Description: Blanks the console (if supported, otherwise clears). */inline void fb_blank(int val){ if (fb_screen->driver != NULL && fb_screen->driver->ops->has_blank) { fb_screen->driver->ops->blank(val); return; } fb_cls();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -