⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 native.c

📁 在ecos 下mingui 的移植开发
💻 C
字号:
//// $Id: native.c,v 1.4 2000/11/27 09:42:27 ymwei Exp $//// native.c: native Low Level Input Engine // // Copyright (C) 2000,Song Lixin // Copyright (C) 2000, BluePoint Software.//// Created by Song Lixin, 2000/10/17///***  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Library General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This library 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**  Library General Public License for more details.****  You should have received a copy of the GNU Library General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*///TODO://	Currently tty keyboard driver can not detect function keys such as F1,F2...//#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/ioctl.h>#include <signal.h>#ifndef __ECOS#include <sys/io.h>#include <linux/kd.h># include <syslog.h>#else#include <sys/select.h>#endif#include "common.h"#include "misc.h"#include "ial.h"#include "gal.h"#include "native.h"#include "../../gal/native/native.h"#ifdef HAVE_LINUX_KEYBOARD_H /* For NR_KEYS */#include <linux/keyboard.h>#endif#ifndef NR_KEYS#define NR_KEYS		128#endifstatic int mouse_fd;static int kbd_fd;static int	xpos;		/* current x position of mouse */static int	ypos;		/* current y position of mouse */static int	minx;		/* minimum allowed x position */static int	maxx;		/* maximum allowed x position */static int	miny;		/* minimum allowed y position */static int	maxy;		/* maximum allowed y position */static int	buttons;	/* current state of buttons */static int	scale;		/* acceleration scale factor */static int	thresh;		/* acceleration threshhold */static unsigned char state[NR_KEYS];MOUSEDEVICE * mousedev;/************************  Low Level Input Operations **********************//* * Mouse operations -- Event */static int mouse_update(void){	int	dx,dy,dz;	int	r;	int	sign;		dx = dy = 0;	while (1) {		r = mousedev->Read(&dx, &dy, &dz, &buttons);		if (r < 0 )			return -1;		if (r == 0)			return 0;		sign = 1;		if (dx < 0) {			sign = -1;			dx = -dx;		}		if (dx > thresh)			dx = thresh + (dx - thresh) * scale;		dx *= sign;		xpos += dx;		if( xpos < minx )			xpos = minx;		if( xpos > maxx )			xpos = maxx;		sign = 1;		if (dy < 0) {			sign = -1;			dy = -dy;		}		if (dy > thresh)			dy = thresh + (dy - thresh) * scale;		dy *= sign;		ypos += dy;		if ( ypos < miny )			ypos = miny;		if ( ypos > maxy )			ypos = maxy;	}	return r;}static int mouse_getx(void){	return xpos;}static int mouse_gety(void){	return ypos;}static void mouse_setposition(int newx, int newy){	if (newx < minx)		newx = minx;	if (newx > maxx)		newx = maxx;	if (newy < miny)		newy = miny;	if (newy > maxy)		newy = maxy;	if (newx == xpos && newy == ypos)		return;	xpos = newx;	ypos = newy;}static int mouse_getbutton(void){	return buttons;}static void mouse_setrange(int newminx,int newminy,int newmaxx,int newmaxy){	minx = newminx;	miny = newminy;	maxx = newmaxx;	maxy = newmaxy;	mouse_setposition ((newminx + newmaxx) / 2, (newminy + newmaxy) / 2);}/* * -1: error * 0 : no data * 1 : data */static int keyboard_update(void){	unsigned char buf;	int modifier;	int ch;	int is_pressed;	int retvalue;	retvalue = kbddev.Read(&buf,&modifier); 	if ( (retvalue == -1) || (retvalue ==0) )		return 0;	else { /* retvalue > 0 */		is_pressed = !(buf & 0x80);		ch         = buf & 0x7f;		if(is_pressed) {			if ((ch >= SCANCODE_F1) && (ch <= SCANCODE_F6) && 							(state[SCANCODE_LEFTALT]==1) && (state[SCANCODE_LEFTCONTROL]==1)) 			{#ifndef __ECOS				vtswitch_try(ch - SCANCODE_F1 + 1);#endif				return 0;			}			state[ch] = 1;		}		else 			state[ch] = 0;	}	return 1;}static char * keyboard_getstate(void){	return (char *)state;}static int wait_event (int which, fd_set *in, fd_set *out, fd_set *except,                struct timeval *timeout){	fd_set	rfds;	int	setsize = 0;	int	retvalue = 0;	int	e;	FD_ZERO(&rfds);	if (which | IAL_MOUSEEVENT){		FD_SET(mouse_fd,&rfds);		if(mouse_fd > setsize)			setsize = mouse_fd;	}	if (which | IAL_KEYEVENT){		FD_SET(kbd_fd, &rfds);		if(kbd_fd > setsize)			setsize = kbd_fd;	}	++setsize;	e = select(setsize, &rfds, NULL, NULL, timeout) ;	if(e > 0) { 		/* If data is present on the mouse fd, service it: */		if(mouse_fd >= 0 && FD_ISSET(mouse_fd, &rfds))		{			mouse_update();			retvalue |= IAL_MOUSEEVENT;		}		/* If data is present on the keyboard fd, service it: */		if(kbd_fd >= 0 && FD_ISSET(kbd_fd, &rfds))		{			keyboard_update();			retvalue |= IAL_KEYEVENT;		}	} else if(e < 0) {	//	fprintf(stderr,"Select() call in  wait_event() failed!\n");		return -1;	}	return retvalue;}static void set_leds (unsigned int leds){#ifndef __ECOS    ioctl (0, KDSETLED, leds);#endif    }BOOL InitNativeInput (INPUT* input, const char* mdev, const char* mtype){	PSD psd;	kbd_fd = kbddev.Open();		if (kbd_fd < 0) {		fprintf (stderr, "IAL ENGINE: Can not init keyboard!\n");		return FALSE;	}		if (strncasecmp(mtype, "ps2",3) == 0 )		mousedev = &mousedev_PS2;	else		mousedev = &mousedev_GPM;	mouse_fd = mousedev->Open();	if (mouse_fd <0) {		fprintf (stderr, "IAL ENGINE: Can not init mouse!\n");		kbddev.Close();		return FALSE;	}	xpos = 0;	ypos = 0;	buttons = 0;	minx = 0;	psd = cur_gfx->phygc.psd;	maxx = (psd->xres) - 2;	miny = 0;	maxy = (psd->yres) - 2;	mousedev->GetDefaultAccel (&scale,&thresh);	input->update_mouse = mouse_update;	input->get_mouse_x = mouse_getx;	input->get_mouse_y = mouse_gety;	input->set_mouse_xy = mouse_setposition;	input->get_mouse_button = mouse_getbutton;	input->set_mouse_range = mouse_setrange;	input->update_keyboard = keyboard_update;	input->get_keyboard_state = keyboard_getstate;	input->set_leds = set_leds;	input->wait_event = wait_event;		mouse_update ();	return TRUE;}void TermNativeInput (void){    mousedev->Close();    kbddev.Close();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -