📄 qvfb.c
字号:
/*** $Id: qvfb.c,v 1.8 2003/09/04 03:38:26 weiym Exp $**** qvfb.c: Input Engine for Qt Virtual FrameBuffer** ** Copyright (C) 2003 Feynman Software** Copyright (C) 2001 ~ 2002 Wei Yongming**** Created by Wei Yongming, 2001/11/26*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program 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 General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <sys/ioctl.h>#include <sys/poll.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include "common.h"#include "minigui.h"#include "misc.h"#include "ial.h"#ifdef _QVFB_IAL#include "qvfb.h"#define NOBUTTON 0x0000#define LEFTBUTTON 0x0001#define RIGHTBUTTON 0x0002#define MIDBUTTON 0x0004#define MOUSEBUTTONMASK 0x00FF#define SHIFTBUTTON 0x0100#define CONTROLBUTTON 0x0200#define ALTBUTTON 0x0400#define METABUTTON 0x0800#define KEYBUTTONMASK 0x0FFF#define KEYPAD 0x4000static int mouse_fd = -1;static int kbd_fd = -1;static POINT mouse_pt;static int mouse_buttons;static struct QVFbKeyData kbd_data;static unsigned char kbd_state [NR_KEYS];static unsigned char keycode_scancode [256];static void init_code_map (void){ keycode_scancode [0x00] = SCANCODE_ESCAPE; keycode_scancode [0x30] = SCANCODE_0; keycode_scancode [0x31] = SCANCODE_1; keycode_scancode [0x32] = SCANCODE_2; keycode_scancode [0x33] = SCANCODE_3; keycode_scancode [0x34] = SCANCODE_4; keycode_scancode [0x35] = SCANCODE_5; keycode_scancode [0x36] = SCANCODE_6; keycode_scancode [0x37] = SCANCODE_7; keycode_scancode [0x38] = SCANCODE_8; keycode_scancode [0x39] = SCANCODE_9;/* keycode_scancode [0x30] = SCANCODE_F1; keycode_scancode [0x31] = SCANCODE_F2; keycode_scancode [0x32] = SCANCODE_F3; keycode_scancode [0x33] = SCANCODE_F4; keycode_scancode [0x34] = SCANCODE_F5; keycode_scancode [0x35] = SCANCODE_F6; keycode_scancode [0x36] = SCANCODE_F7; keycode_scancode [0x37] = SCANCODE_F8; keycode_scancode [0x38] = SCANCODE_F9; keycode_scancode [0x39] = SCANCODE_F10;*/ keycode_scancode [0x2D] = SCANCODE_MINUS; keycode_scancode [0x3D] = SCANCODE_EQUAL; keycode_scancode [0x03] = SCANCODE_BACKSPACE; keycode_scancode [0x01] = SCANCODE_TAB; keycode_scancode [0x51] = SCANCODE_Q; keycode_scancode [0x57] = SCANCODE_W; keycode_scancode [0x45] = SCANCODE_E; keycode_scancode [0x52] = SCANCODE_R; keycode_scancode [0x54] = SCANCODE_T; keycode_scancode [0x59] = SCANCODE_Y; keycode_scancode [0x55] = SCANCODE_U; keycode_scancode [0x49] = SCANCODE_I; keycode_scancode [0x4F] = SCANCODE_O; keycode_scancode [0x50] = SCANCODE_P; keycode_scancode [0x5B] = SCANCODE_BRACKET_LEFT; keycode_scancode [0x5D] = SCANCODE_BRACKET_RIGHT; keycode_scancode [0x04] = SCANCODE_ENTER; keycode_scancode [0x21] = SCANCODE_LEFTCONTROL; keycode_scancode [0x41] = SCANCODE_A; keycode_scancode [0x53] = SCANCODE_S; keycode_scancode [0x44] = SCANCODE_D; keycode_scancode [0x46] = SCANCODE_F; keycode_scancode [0x47] = SCANCODE_G; keycode_scancode [0x48] = SCANCODE_H; keycode_scancode [0x4A] = SCANCODE_J; keycode_scancode [0x4B] = SCANCODE_K; keycode_scancode [0x4C] = SCANCODE_L; keycode_scancode [0x3B] = SCANCODE_SEMICOLON;/* keycode_scancode [0x3B] = SCANCODE_F12;*/ keycode_scancode [0x3A] = SCANCODE_F11; keycode_scancode [0x27] = SCANCODE_APOSTROPHE; keycode_scancode [0x60] = SCANCODE_GRAVE; keycode_scancode [0x20] = SCANCODE_SPACE;/* keycode_scancode [0x20] = SCANCODE_LEFTSHIFT;*/ keycode_scancode [0x5C] = SCANCODE_BACKSLASH; keycode_scancode [0x5A] = SCANCODE_Z; keycode_scancode [0x58] = SCANCODE_X; keycode_scancode [0x43] = SCANCODE_C; keycode_scancode [0x56] = SCANCODE_V; keycode_scancode [0x42] = SCANCODE_B; keycode_scancode [0x4E] = SCANCODE_N; keycode_scancode [0x4D] = SCANCODE_M; keycode_scancode [0x2C] = SCANCODE_COMMA; keycode_scancode [0x2E] = SCANCODE_PERIOD; keycode_scancode [0x2F] = SCANCODE_SLASH; keycode_scancode [0x2A] = SCANCODE_KEYPADMULTIPLY; keycode_scancode [0x23] = SCANCODE_LEFTALT; keycode_scancode [0x24] = SCANCODE_CAPSLOCK; keycode_scancode [0x25] = SCANCODE_NUMLOCK; keycode_scancode [0x26] = SCANCODE_SCROLLLOCK; keycode_scancode [0x09] = SCANCODE_PRINTSCREEN; keycode_scancode [0x08] = SCANCODE_BREAK; keycode_scancode [0x06] = SCANCODE_INSERT; keycode_scancode [0x07] = SCANCODE_REMOVE; keycode_scancode [0x10] = SCANCODE_HOME; keycode_scancode [0x11] = SCANCODE_END; keycode_scancode [0x16] = SCANCODE_PAGEUP; keycode_scancode [0x17] = SCANCODE_PAGEDOWN; keycode_scancode [0x13] = SCANCODE_CURSORBLOCKUP; keycode_scancode [0x12] = SCANCODE_CURSORBLOCKLEFT; keycode_scancode [0x14] = SCANCODE_CURSORBLOCKRIGHT; keycode_scancode [0x15] = SCANCODE_CURSORBLOCKDOWN;/* keycode_scancode [0x23] = SCANCODE_RIGHTALT; keycode_scancode [0x2F] = SCANCODE_KEYPADDIVIDE; keycode_scancode [0x20] = SCANCODE_RIGHTSHIFT; keycode_scancode [0x21] = SCANCODE_RIGHTCONTROL; keycode_scancode [0x37] = SCANCODE_KEYPAD7; keycode_scancode [0x38] = SCANCODE_KEYPAD8; keycode_scancode [0x39] = SCANCODE_KEYPAD9; keycode_scancode [0x2D] = SCANCODE_KEYPADMINUS; keycode_scancode [0x34] = SCANCODE_KEYPAD4; keycode_scancode [0x35] = SCANCODE_KEYPAD5; keycode_scancode [0x36] = SCANCODE_KEYPAD6; keycode_scancode [0x2B] = SCANCODE_KEYPADPLUS; keycode_scancode [0x31] = SCANCODE_KEYPAD1; keycode_scancode [0x32] = SCANCODE_KEYPAD2; keycode_scancode [0x33] = SCANCODE_KEYPAD3; keycode_scancode [0x30] = SCANCODE_KEYPAD0; keycode_scancode [0x2E] = SCANCODE_KEYPADPERIOD; keycode_scancode [] = SCANCODE_LESS; keycode_scancode [] = SCANCODE_KEYPADENTER; keycode_scancode [] = SCANCODE_PAUSE; keycode_scancode [] = SCANCODE_LEFTWIN; keycode_scancode [] = SCANCODE_RIGHTWIN; keycode_scancode [] = SCANCODE_MENU;*/}static unsigned char keycode_to_scancode (unsigned char keycode, BOOL asscii){ switch (keycode) { case 0x30 ... 0x39: if (!asscii) return SCANCODE_F1 + keycode - 0x30; break; case 0x3B: if (!asscii) return SCANCODE_F12; break; case 0x20: if (!asscii) return SCANCODE_LEFTSHIFT; break; } return keycode_scancode [keycode];}/************************ Low Level Input Operations **********************//* * Mouse operations -- Event */static int mouse_update (void){ int ret; POINT l_mouse_pt; int l_mouse_buttons; do { ret = read (mouse_fd, &l_mouse_pt, sizeof (POINT)); } while (ret < sizeof (POINT) && errno == EINTR); if (ret == sizeof (POINT)) mouse_pt = l_mouse_pt; do { ret = read (mouse_fd, &l_mouse_buttons, sizeof (int)); } while (ret < sizeof (int) && errno == EINTR); if (ret == sizeof (int)) mouse_buttons = l_mouse_buttons; return 1;}static void mouse_getxy (int *x, int* y){ *x = mouse_pt.x; *y = mouse_pt.y;}static int mouse_getbutton (void){ int buttons = 0; if (mouse_buttons & LEFTBUTTON) buttons |= IAL_MOUSE_LEFTBUTTON; if (mouse_buttons & RIGHTBUTTON) buttons |= IAL_MOUSE_RIGHTBUTTON; if (mouse_buttons & MIDBUTTON) buttons |= IAL_MOUSE_MIDDLEBUTTON; return buttons;}static int keyboard_update (void){ int ret; unsigned char scancode; static unsigned char last = 0; do { ret = read (kbd_fd, &kbd_data, sizeof (struct QVFbKeyData)); } while (ret < sizeof (struct QVFbKeyData) && errno == EINTR);#if 0 printf ("key info: (0x%x(0x%x), %x, %s, %s)\n", kbd_data.unicode, HIWORD(kbd_data.unicode) & 0x00FF, kbd_data.modifiers, kbd_data.press?"Pressed":"Released", kbd_data.repeat?"repeat":"no repete");#endif if (kbd_data.repeat) return 0; if (kbd_data.unicode == 0 && !kbd_data.press) { kbd_state [last] = 0; } else { scancode = keycode_to_scancode (HIWORD (kbd_data.unicode) & 0x00FF, LOWORD (kbd_data.unicode)); kbd_state [scancode] = kbd_data.press; if (kbd_data.press) last = scancode; } return NR_KEYS;}static const char* keyboard_getstate (void){ return kbd_state;}/* NOTE by weiym: Do not ignore the fd_set in, out, and except */#ifdef _LITE_VERSIONstatic int wait_event (int which, int maxfd, fd_set *in, fd_set *out, fd_set *except, struct timeval *timeout)#elsestatic int wait_event (int which, fd_set *in, fd_set *out, fd_set *except, struct timeval *timeout)#endif{ fd_set rfds; int retvalue = 0; int fd, e; if (!in) { in = &rfds; FD_ZERO (in); } if (which & IAL_MOUSEEVENT && mouse_fd >= 0) { fd = mouse_fd; FD_SET (fd, in);#ifdef _LITE_VERSION if (fd > maxfd) maxfd = fd;#endif } if (which & IAL_KEYEVENT){ fd = kbd_fd; FD_SET (kbd_fd, in);#ifdef _LITE_VERSION if (fd > maxfd) maxfd = fd;#endif } /* FIXME: pass the real set size */#ifdef _LITE_VERSION e = select (maxfd + 1, in, out, except, timeout) ;#else e = select (FD_SETSIZE, in, out, except, timeout) ;#endif if (e > 0) { fd = mouse_fd; /* If data is present on the mouse fd, service it: */ if (fd >= 0 && FD_ISSET (fd, in)) { FD_CLR (fd, in); retvalue |= IAL_MOUSEEVENT; } fd = kbd_fd; /* If data is present on the keyboard fd, service it: */ if (fd >= 0 && FD_ISSET (fd, in)) { FD_CLR (fd, in); retvalue |= IAL_KEYEVENT; } } else if (e < 0) { return -1; } return retvalue;}BOOL InitQVFBInput (INPUT* input, const char* mdev, const char* mtype){ char file [50]; int display;#ifdef _INCORE_RES display = 0;#else /* get display number */ if (GetIntValueFromEtcFile (ETCFILEPATH, "qvfb", "display", &display) < 0) return FALSE;#endif /* open mouse pipe */ sprintf (file, QT_VFB_MOUSE_PIPE, display); if ((mouse_fd = open (file, O_RDWR | O_NONBLOCK)) < 0) { fprintf (stderr, "QVFB IAL engine: can not open mouse pipe.\n"); return FALSE; } else { char buf[2]; /* clear pending input */ while (read (mouse_fd, buf, 1) > 0) { } /* clear O_NDELAY flag */ fcntl (mouse_fd, F_SETFL, 0); } /* open keyboard pipe */ sprintf (file, QT_VFB_KEYBOARD_PIPE, display); if ((kbd_fd = open (file, O_RDWR | O_NONBLOCK)) < 0) { fprintf (stderr, "QVFB IAL engine: can not open keyboard pipe.\n"); return FALSE; } else { char buf[2]; /* clear pending input */ while (read (kbd_fd, buf, 1) > 0) { } /* clear O_NDELAY flag */ fcntl (kbd_fd, F_SETFL, 0); } input->update_mouse = mouse_update; input->get_mouse_xy = mouse_getxy; input->set_mouse_xy = NULL; input->get_mouse_button = mouse_getbutton; input->set_mouse_range = NULL; input->suspend_mouse= NULL; input->resume_mouse = NULL; input->update_keyboard = keyboard_update; input->get_keyboard_state = keyboard_getstate; input->suspend_keyboard = NULL; input->resume_keyboard = NULL; input->set_leds = NULL; input->wait_event = wait_event; init_code_map (); return TRUE;}void TermQVFBInput (void){ if (mouse_fd >= 0) close (mouse_fd); if (kbd_fd >= 0) close (kbd_fd);}#endif /* _QVFB_IAL */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -