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

📄 sdl_fbevents.c

📁 linux下面的一个开源的多媒体中间件
💻 C
📖 第 1 页 / 共 3 页
字号:
					if ( SDL_strncmp(arg, "-R", 2) == 0 ) {						char *t, *s;						available = 1;						t = arg + 2;						s = SDL_strchr(t, ' ');						if (s) *s = 0;						SDL_strlcpy(repeat_proto, t, SDL_arraysize(repeat_proto));						if (s) *s = ' ';					}					len -= arglen;					arg += arglen;				}				close(cmdline);			}		}		closedir(proc);		if ( available ) {			if ( SDL_strcmp(repeat_proto, "raw") == 0 ) {				SDL_strlcpy(proto, raw_proto, protolen);			} else if ( *repeat_proto ) {				SDL_strlcpy(proto, repeat_proto, protolen);			} else {				SDL_strlcpy(proto, "msc", protolen);			}		}	}	return available;}/* rcg06112001 Set up IMPS/2 mode, if possible. This gives *  us access to the mousewheel, etc. Returns zero if *  writes to device failed, but you still need to query the *  device to see which mode it's actually in. */static int set_imps2_mode(int fd){	/* If you wanted to control the mouse mode (and we do :)  ) ...		Set IMPS/2 protocol:			{0xf3,200,0xf3,100,0xf3,80}		Reset mouse device:			{0xFF}	*/	Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80};	/*Uint8 reset = 0xff;*/	fd_set fdset;	struct timeval tv;	int retval = 0;	if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) {		/* Don't reset it, that'll clear IMPS/2 mode on some mice		if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) {			retval = 1;		}		*/	}	/* Get rid of any chatter from the above */	FD_ZERO(&fdset);	FD_SET(fd, &fdset);	tv.tv_sec = 0;	tv.tv_usec = 0;	while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {		char temp[32];		read(fd, temp, sizeof(temp));	}	return retval;}/* Returns true if the mouse uses the IMPS/2 protocol */static int detect_imps2(int fd){	int imps2;	imps2 = 0;	if ( SDL_getenv("SDL_MOUSEDEV_IMPS2") ) {		imps2 = 1;	}	if ( ! imps2 ) {		Uint8 query_ps2 = 0xF2;		fd_set fdset;		struct timeval tv;		/* Get rid of any mouse motion noise */		FD_ZERO(&fdset);		FD_SET(fd, &fdset);		tv.tv_sec = 0;		tv.tv_usec = 0;		while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {			char temp[32];			read(fd, temp, sizeof(temp));		}   		/* Query for the type of mouse protocol */   		if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) {   			Uint8 ch = 0;			/* Get the mouse protocol response */			do {				FD_ZERO(&fdset);				FD_SET(fd, &fdset);				tv.tv_sec = 1;				tv.tv_usec = 0;				if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) {					break;				}			} while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) &&			          ((ch == 0xFA) || (ch == 0xAA)) );			/* Experimental values (Logitech wheelmouse) */#ifdef DEBUG_MOUSEfprintf(stderr, "Last mouse mode: 0x%x\n", ch);#endif			if ( (ch == 3) || (ch == 4) ) {				imps2 = 1;			}		}	}	return imps2;}int FB_OpenMouse(_THIS){	int i;	const char *mousedev;	const char *mousedrv;	mousedrv = SDL_getenv("SDL_MOUSEDRV");	mousedev = SDL_getenv("SDL_MOUSEDEV");	mouse_fd = -1;#if SDL_INPUT_TSLIB	if ( mousedrv && (SDL_strcmp(mousedrv, "TSLIB") == 0) ) {		if (mousedev == NULL) mousedev = SDL_getenv("TSLIB_TSDEVICE");		if (mousedev != NULL) {			ts_dev = ts_open(mousedev, 1);			if ((ts_dev != NULL) && (ts_config(ts_dev) >= 0)) {#ifdef DEBUG_MOUSE				fprintf(stderr, "Using tslib touchscreen\n");#endif				mouse_drv = MOUSE_TSLIB;				mouse_fd = ts_fd(ts_dev);				return mouse_fd;			}		}		mouse_drv = MOUSE_NONE;		return mouse_fd;	}#endif /* SDL_INPUT_TSLIB */	/* ELO TOUCHSCREEN SUPPORT */	if ( mousedrv && (SDL_strcmp(mousedrv, "ELO") == 0) ) {		mouse_fd = open(mousedev, O_RDWR);		if ( mouse_fd >= 0 ) {			if(eloInitController(mouse_fd)) {#ifdef DEBUG_MOUSEfprintf(stderr, "Using ELO touchscreen\n");#endif   				mouse_drv = MOUSE_ELO;			}		}		else if ( mouse_fd < 0 ) {			mouse_drv = MOUSE_NONE;		}		return(mouse_fd);	}	/* STD MICE */	if ( mousedev == NULL ) {		/* FIXME someday... allow multiple mice in this driver */		static const char *ps2mice[] = {		    "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL		};		/* First try to use GPM in repeater mode */		if ( mouse_fd < 0 ) {			char proto[10];			if ( gpm_available(proto, SDL_arraysize(proto)) ) {				mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0);				if ( mouse_fd >= 0 ) {					if ( SDL_strcmp(proto, "msc") == 0 ) {						mouse_drv = MOUSE_MSC;					} else if ( SDL_strcmp(proto, "ps2") == 0 ) {						mouse_drv = MOUSE_PS2;					} else if ( SDL_strcmp(proto, "imps2") == 0 ) {						mouse_drv = MOUSE_IMPS2;					} else if ( SDL_strcmp(proto, "ms") == 0 ||					            SDL_strcmp(proto, "bare") == 0 ) {						mouse_drv = MOUSE_MS;					} else if ( SDL_strcmp(proto, "bm") == 0 ) {						mouse_drv = MOUSE_BM;					} else {						/* Unknown protocol... */#ifdef DEBUG_MOUSE						fprintf(stderr, "GPM mouse using unknown protocol = %s\n", proto);#endif						close(mouse_fd);						mouse_fd = -1;					}				}#ifdef DEBUG_MOUSE				if ( mouse_fd >= 0 ) {					fprintf(stderr, "Using GPM mouse, protocol = %s\n", proto);				}#endif /* DEBUG_MOUSE */			}		}		/* Now try to use a modern PS/2 mouse */		for ( i=0; (mouse_fd < 0) && ps2mice[i]; ++i ) {			mouse_fd = open(ps2mice[i], O_RDWR, 0);			if (mouse_fd < 0) {				mouse_fd = open(ps2mice[i], O_RDONLY, 0);			}			if (mouse_fd >= 0) {				/* rcg06112001 Attempt to set IMPS/2 mode */				set_imps2_mode(mouse_fd);				if (detect_imps2(mouse_fd)) {#ifdef DEBUG_MOUSEfprintf(stderr, "Using IMPS2 mouse\n");#endif					mouse_drv = MOUSE_IMPS2;				} else {#ifdef DEBUG_MOUSEfprintf(stderr, "Using PS2 mouse\n");#endif					mouse_drv = MOUSE_PS2;				}			}		}		/* Next try to use a PPC ADB port mouse */		if ( mouse_fd < 0 ) {			mouse_fd = open("/dev/adbmouse", O_RDONLY, 0);			if ( mouse_fd >= 0 ) {#ifdef DEBUG_MOUSEfprintf(stderr, "Using ADB mouse\n");#endif				mouse_drv = MOUSE_BM;			}		}	}	/* Default to a serial Microsoft mouse */	if ( mouse_fd < 0 ) {		if ( mousedev == NULL ) {			mousedev = "/dev/mouse";		}		mouse_fd = open(mousedev, O_RDONLY, 0);		if ( mouse_fd >= 0 ) {			struct termios mouse_termios;			/* Set the sampling speed to 1200 baud */			tcgetattr(mouse_fd, &mouse_termios);			mouse_termios.c_iflag = IGNBRK | IGNPAR;			mouse_termios.c_oflag = 0;			mouse_termios.c_lflag = 0;			mouse_termios.c_line = 0;			mouse_termios.c_cc[VTIME] = 0;			mouse_termios.c_cc[VMIN] = 1;			mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL;			mouse_termios.c_cflag |= CS8;			mouse_termios.c_cflag |= B1200;			tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios);			if ( mousedrv && (SDL_strcmp(mousedrv, "PS2") == 0) ) {#ifdef DEBUG_MOUSEfprintf(stderr, "Using (user specified) PS2 mouse on %s\n", mousedev);#endif				mouse_drv = MOUSE_PS2;			} else {#ifdef DEBUG_MOUSEfprintf(stderr, "Using (default) MS mouse on %s\n", mousedev);#endif				mouse_drv = MOUSE_MS;			}		}	}	if ( mouse_fd < 0 ) {		mouse_drv = MOUSE_NONE;	}	return(mouse_fd);}static int posted = 0;void FB_vgamousecallback(int button, int relative, int dx, int dy){	int button_1, button_3;	int button_state;	int state_changed;	int i;	Uint8 state;	if ( dx || dy ) {		posted += SDL_PrivateMouseMotion(0, relative, dx, dy);	}	/* Swap button 1 and 3 */	button_1 = (button & 0x04) >> 2;	button_3 = (button & 0x01) << 2;	button &= ~0x05;	button |= (button_1|button_3);	/* See what changed */	button_state = SDL_GetMouseState(NULL, NULL);	state_changed = button_state ^ button;	for ( i=0; i<8; ++i ) {		if ( state_changed & (1<<i) ) {			if ( button & (1<<i) ) {				state = SDL_PRESSED;			} else {				state = SDL_RELEASED;			}			posted += SDL_PrivateMouseButton(state, i+1, 0, 0);		}	}}/* Handle input from tslib */#if SDL_INPUT_TSLIBstatic void handle_tslib(_THIS){	struct ts_sample sample;	int button;	while (ts_read(ts_dev, &sample, 1) > 0) {		button = (sample.pressure > 0) ? 1 : 0;		button <<= 2;	/* must report it as button 3 */		FB_vgamousecallback(button, 0, sample.x, sample.y);	}	return;}#endif /* SDL_INPUT_TSLIB *//* For now, use MSC, PS/2, and MS protocols   Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.) */static void handle_mouse(_THIS){	static int start = 0;	static unsigned char mousebuf[BUFSIZ];	static int relative = 1;	int i, nread;	int button = 0;	int dx = 0, dy = 0;	int packetsize = 0;	int realx, realy;		/* Figure out the mouse packet size */	switch (mouse_drv) {		case MOUSE_NONE:			/* Ack! */			read(mouse_fd, mousebuf, BUFSIZ);			return;		case MOUSE_MSC:			packetsize = 5;			break;		case MOUSE_IMPS2:			packetsize = 4;			break;		case MOUSE_PS2:		case MOUSE_MS:		case MOUSE_BM:			packetsize = 3;			break;		case MOUSE_ELO:			/* try to read the next packet */			if(eloReadPosition(this, mouse_fd, &dx, &dy, &button, &realx, &realy)) {				button = (button & 0x01) << 2;				FB_vgamousecallback(button, 0, dx, dy);			}			return; /* nothing left to do */		case MOUSE_TSLIB:#if SDL_INPUT_TSLIB			handle_tslib(this);#endif			return; /* nothing left to do */		default:			/* Uh oh.. */			packetsize = 0;			break;	}	/* Special handling for the quite sensitive ELO controller */	if (mouse_drv == MOUSE_ELO) {		}		/* Read as many packets as possible */	nread = read(mouse_fd, &mousebuf[start], BUFSIZ-start);	if ( nread < 0 ) {		return;	}	nread += start;#ifdef DEBUG_MOUSE	fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start);#endif	for ( i=0; i<(nread-(packetsize-1)); i += packetsize ) {		switch (mouse_drv) {			case MOUSE_NONE:				break;			case MOUSE_MSC:				/* MSC protocol has 0x80 in high byte */				if ( (mousebuf[i] & 0xF8) != 0x80 ) {					/* Go to next byte */					i -= (packetsize-1);					continue;				}				/* Get current mouse state */				button = (~mousebuf[i]) & 0x07;				dx =   (signed char)(mousebuf[i+1]) +

⌨️ 快捷键说明

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