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

📄 sdl_x11events.c

📁 linux下面的一个开源的多媒体中间件
💻 C
📖 第 1 页 / 共 3 页
字号:
	    }	    break;	    /* Mouse button press? */	    case ButtonPress: {		posted = SDL_PrivateMouseButton(SDL_PRESSED, 					xevent.xbutton.button, 0, 0);	    }	    break;	    /* Mouse button release? */	    case ButtonRelease: {		posted = SDL_PrivateMouseButton(SDL_RELEASED, 					xevent.xbutton.button, 0, 0);	    }	    break;	    /* Key press? */	    case KeyPress: {		static SDL_keysym saved_keysym;		SDL_keysym keysym;		KeyCode keycode = xevent.xkey.keycode;#ifdef DEBUG_XEVENTSprintf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);#endif		/* Get the translated SDL virtual keysym */		if ( keycode ) {			keysym.scancode = keycode;			keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);			keysym.mod = KMOD_NONE;			keysym.unicode = 0;		} else {			keysym = saved_keysym;		}		/* If we're not doing translation, we're done! */		if ( !SDL_TranslateUNICODE ) {			posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);			break;		}		if ( XFilterEvent(&xevent, None) ) {			if ( xevent.xkey.keycode ) {				posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);			} else {				/* Save event to be associated with IM text				   In 1.3 we'll have a text event instead.. */				saved_keysym = keysym;			}			break;		}		/* Look up the translated value for the key event */#ifdef X_HAVE_UTF8_STRING		if ( SDL_IC != NULL ) {			static Status state;			/* A UTF-8 character can be at most 6 bytes */			char keybuf[6];			if ( Xutf8LookupString(SDL_IC, &xevent.xkey,			                        keybuf, sizeof(keybuf),			                        NULL, &state) ) {				keysym.unicode = Utf8ToUcs4((Uint8*)keybuf);			}		}		else#endif		{			static XComposeStatus state;			char keybuf[32];			if ( XLookupString(&xevent.xkey,			                    keybuf, sizeof(keybuf),			                    NULL, &state) ) {				/*				* FIXME: XLookupString() may yield more than one				* character, so we need a mechanism to allow for				* this (perhaps null keypress events with a				* unicode value)				*/				keysym.unicode = (Uint8)keybuf[0];			}		}		posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);	    }	    break;	    /* Key release? */	    case KeyRelease: {		SDL_keysym keysym;		KeyCode keycode = xevent.xkey.keycode;#ifdef DEBUG_XEVENTSprintf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);#endif		/* Check to see if this is a repeated key */		if ( X11_KeyRepeat(SDL_Display, &xevent) ) {			break;		}		/* Get the translated SDL virtual keysym */		keysym.scancode = keycode;		keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);		keysym.mod = KMOD_NONE;		keysym.unicode = 0;		posted = SDL_PrivateKeyboard(SDL_RELEASED, &keysym);	    }	    break;	    /* Have we been iconified? */	    case UnmapNotify: {#ifdef DEBUG_XEVENTSprintf("UnmapNotify!\n");#endif		/* If we're active, make ourselves inactive */		if ( SDL_GetAppState() & SDL_APPACTIVE ) {			/* Swap out the gamma before we go inactive */			X11_SwapVidModeGamma(this);			/* Send an internal deactivate event */			posted = SDL_PrivateAppActive(0,					SDL_APPACTIVE|SDL_APPINPUTFOCUS);		}	    }	    break;	    /* Have we been restored? */	    case MapNotify: {#ifdef DEBUG_XEVENTSprintf("MapNotify!\n");#endif		/* If we're not active, make ourselves active */		if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {			/* Send an internal activate event */			posted = SDL_PrivateAppActive(1, SDL_APPACTIVE);			/* Now that we're active, swap the gamma back */			X11_SwapVidModeGamma(this);		}		if ( SDL_VideoSurface &&		     (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) {			X11_EnterFullScreen(this);		} else {			X11_GrabInputNoLock(this, this->input_grab);		}		X11_CheckMouseModeNoLock(this);		if ( SDL_VideoSurface ) {			X11_RefreshDisplay(this);		}	    }	    break;	    /* Have we been resized or moved? */	    case ConfigureNotify: {#ifdef DEBUG_XEVENTSprintf("ConfigureNotify! (resize: %dx%d)\n", xevent.xconfigure.width, xevent.xconfigure.height);#endif		if ( SDL_VideoSurface ) {		    if ((xevent.xconfigure.width != SDL_VideoSurface->w) ||		        (xevent.xconfigure.height != SDL_VideoSurface->h)) {			/* FIXME: Find a better fix for the bug with KDE 1.2 */			if ( ! ((xevent.xconfigure.width == 32) &&			        (xevent.xconfigure.height == 32)) ) {				SDL_PrivateResize(xevent.xconfigure.width,				                  xevent.xconfigure.height);			}		    } else {			/* OpenGL windows need to know about the change */			if ( SDL_VideoSurface->flags & SDL_OPENGL ) {				SDL_PrivateExpose();			}		    }		}	    }	    break;	    /* Have we been requested to quit (or another client message?) */	    case ClientMessage: {		if ( (xevent.xclient.format == 32) &&		     (xevent.xclient.data.l[0] == WM_DELETE_WINDOW) )		{			posted = SDL_PrivateQuit();		} else		if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {			SDL_SysWMmsg wmmsg;			SDL_VERSION(&wmmsg.version);			wmmsg.subsystem = SDL_SYSWM_X11;			wmmsg.event.xevent = xevent;			posted = SDL_PrivateSysWMEvent(&wmmsg);		}	    }	    break;	    /* Do we need to refresh ourselves? */	    case Expose: {#ifdef DEBUG_XEVENTSprintf("Expose (count = %d)\n", xevent.xexpose.count);#endif		if ( SDL_VideoSurface && (xevent.xexpose.count == 0) ) {			X11_RefreshDisplay(this);		}	    }	    break;	    default: {#ifdef DEBUG_XEVENTSprintf("Unhandled event %d\n", xevent.type);#endif		/* Only post the event if we're watching for it */		if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {			SDL_SysWMmsg wmmsg;			SDL_VERSION(&wmmsg.version);			wmmsg.subsystem = SDL_SYSWM_X11;			wmmsg.event.xevent = xevent;			posted = SDL_PrivateSysWMEvent(&wmmsg);		}	    }	    break;	}	return(posted);}/* Ack!  XPending() actually performs a blocking read if no events available */int X11_Pending(Display *display){	/* Flush the display connection and look to see if events are queued */	XFlush(display);	if ( XEventsQueued(display, QueuedAlready) ) {		return(1);	}	/* More drastic measures are required -- see if X is ready to talk */	{		static struct timeval zero_time;	/* static == 0 */		int x11_fd;		fd_set fdset;		x11_fd = ConnectionNumber(display);		FD_ZERO(&fdset);		FD_SET(x11_fd, &fdset);		if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) {			return(XPending(display));		}	}	/* Oh well, nothing is ready .. */	return(0);}void X11_PumpEvents(_THIS){	int pending;	/* Keep processing pending events */	pending = 0;	while ( X11_Pending(SDL_Display) ) {		X11_DispatchEvent(this);		++pending;	}	if ( switch_waiting ) {		Uint32 now;		now  = SDL_GetTicks();		if ( pending || !SDL_VideoSurface ) {			/* Try again later... */			if ( switch_waiting & SDL_FULLSCREEN ) {				switch_time = now + 1500;			} else {				switch_time = now + 200;			}		} else if ( (int)(switch_time-now) <= 0 ) {			Uint32 go_fullscreen;			go_fullscreen = switch_waiting & SDL_FULLSCREEN;			switch_waiting = 0;			if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {				if ( go_fullscreen ) {					X11_EnterFullScreen(this);				} else {					X11_LeaveFullScreen(this);				}			}			/* Handle focus in/out when grabbed */			if ( go_fullscreen ) {				X11_GrabInputNoLock(this, this->input_grab);			} else {				X11_GrabInputNoLock(this, SDL_GRAB_OFF);			}			X11_CheckMouseModeNoLock(this);		}	}}void X11_InitKeymap(void){	int i;	/* Odd keys used in international keyboards */	for ( i=0; i<SDL_arraysize(ODD_keymap); ++i )		ODD_keymap[i] = SDLK_UNKNOWN; 	/* Some of these might be mappable to an existing SDLK_ code */ 	ODD_keymap[XK_dead_grave&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_acute&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_tilde&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_macron&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_breve&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_abovedot&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_diaeresis&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_abovering&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_doubleacute&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_caron&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_cedilla&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_ogonek&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_iota&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_voiced_sound&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_semivoiced_sound&0xFF] = SDLK_COMPOSE; 	ODD_keymap[XK_dead_belowdot&0xFF] = SDLK_COMPOSE;#ifdef XK_dead_hook 	ODD_keymap[XK_dead_hook&0xFF] = SDLK_COMPOSE;#endif#ifdef XK_dead_horn 	ODD_keymap[XK_dead_horn&0xFF] = SDLK_COMPOSE;#endif#ifdef XK_dead_circumflex	/* These X keysyms have 0xFE as the high byte */	ODD_keymap[XK_dead_circumflex&0xFF] = SDLK_CARET;#endif#ifdef XK_ISO_Level3_Shift	ODD_keymap[XK_ISO_Level3_Shift&0xFF] = SDLK_MODE; /* "Alt Gr" key */#endif	/* Map the miscellaneous keys */	for ( i=0; i<SDL_arraysize(MISC_keymap); ++i )		MISC_keymap[i] = SDLK_UNKNOWN;	/* These X keysyms have 0xFF as the high byte */	MISC_keymap[XK_BackSpace&0xFF] = SDLK_BACKSPACE;	MISC_keymap[XK_Tab&0xFF] = SDLK_TAB;	MISC_keymap[XK_Clear&0xFF] = SDLK_CLEAR;	MISC_keymap[XK_Return&0xFF] = SDLK_RETURN;	MISC_keymap[XK_Pause&0xFF] = SDLK_PAUSE;	MISC_keymap[XK_Escape&0xFF] = SDLK_ESCAPE;	MISC_keymap[XK_Delete&0xFF] = SDLK_DELETE;	MISC_keymap[XK_KP_0&0xFF] = SDLK_KP0;		/* Keypad 0-9 */	MISC_keymap[XK_KP_1&0xFF] = SDLK_KP1;	MISC_keymap[XK_KP_2&0xFF] = SDLK_KP2;	MISC_keymap[XK_KP_3&0xFF] = SDLK_KP3;	MISC_keymap[XK_KP_4&0xFF] = SDLK_KP4;	MISC_keymap[XK_KP_5&0xFF] = SDLK_KP5;	MISC_keymap[XK_KP_6&0xFF] = SDLK_KP6;	MISC_keymap[XK_KP_7&0xFF] = SDLK_KP7;	MISC_keymap[XK_KP_8&0xFF] = SDLK_KP8;	MISC_keymap[XK_KP_9&0xFF] = SDLK_KP9;	MISC_keymap[XK_KP_Insert&0xFF] = SDLK_KP0;	MISC_keymap[XK_KP_End&0xFF] = SDLK_KP1;		MISC_keymap[XK_KP_Down&0xFF] = SDLK_KP2;	MISC_keymap[XK_KP_Page_Down&0xFF] = SDLK_KP3;	MISC_keymap[XK_KP_Left&0xFF] = SDLK_KP4;	MISC_keymap[XK_KP_Begin&0xFF] = SDLK_KP5;	MISC_keymap[XK_KP_Right&0xFF] = SDLK_KP6;	MISC_keymap[XK_KP_Home&0xFF] = SDLK_KP7;	MISC_keymap[XK_KP_Up&0xFF] = SDLK_KP8;	MISC_keymap[XK_KP_Page_Up&0xFF] = SDLK_KP9;	MISC_keymap[XK_KP_Delete&0xFF] = SDLK_KP_PERIOD;	MISC_keymap[XK_KP_Decimal&0xFF] = SDLK_KP_PERIOD;	MISC_keymap[XK_KP_Divide&0xFF] = SDLK_KP_DIVIDE;	MISC_keymap[XK_KP_Multiply&0xFF] = SDLK_KP_MULTIPLY;	MISC_keymap[XK_KP_Subtract&0xFF] = SDLK_KP_MINUS;	MISC_keymap[XK_KP_Add&0xFF] = SDLK_KP_PLUS;	MISC_keymap[XK_KP_Enter&0xFF] = SDLK_KP_ENTER;	MISC_keymap[XK_KP_Equal&0xFF] = SDLK_KP_EQUALS;	MISC_keymap[XK_Up&0xFF] = SDLK_UP;	MISC_keymap[XK_Down&0xFF] = SDLK_DOWN;	MISC_keymap[XK_Right&0xFF] = SDLK_RIGHT;	MISC_keymap[XK_Left&0xFF] = SDLK_LEFT;	MISC_keymap[XK_Insert&0xFF] = SDLK_INSERT;	MISC_keymap[XK_Home&0xFF] = SDLK_HOME;	MISC_keymap[XK_End&0xFF] = SDLK_END;	MISC_keymap[XK_Page_Up&0xFF] = SDLK_PAGEUP;	MISC_keymap[XK_Page_Down&0xFF] = SDLK_PAGEDOWN;	MISC_keymap[XK_F1&0xFF] = SDLK_F1;	MISC_keymap[XK_F2&0xFF] = SDLK_F2;

⌨️ 快捷键说明

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