test/testwm.c
branchSDL-1.2
changeset 4257 14195cfdb66e
parent 1779 67fc81efcfc3
equal deleted inserted replaced
4256:ba587a51f899 4257:14195cfdb66e
   166 	printf("Posting internal quit request\n");
   166 	printf("Posting internal quit request\n");
   167 	event.type = SDL_USEREVENT;
   167 	event.type = SDL_USEREVENT;
   168 	SDL_PushEvent(&event);
   168 	SDL_PushEvent(&event);
   169 }
   169 }
   170 
   170 
       
   171 static void print_modifiers(void)
       
   172 {
       
   173 	int mod;
       
   174 	printf(" modifiers:");
       
   175 	mod = SDL_GetModState();
       
   176 	if(!mod) {
       
   177 		printf(" (none)");
       
   178 		return;
       
   179 	}
       
   180 	if(mod & KMOD_LSHIFT)
       
   181 		printf(" LSHIFT");
       
   182 	if(mod & KMOD_RSHIFT)
       
   183 		printf(" RSHIFT");
       
   184 	if(mod & KMOD_LCTRL)
       
   185 		printf(" LCTRL");
       
   186 	if(mod & KMOD_RCTRL)
       
   187 		printf(" RCTRL");
       
   188 	if(mod & KMOD_LALT)
       
   189 		printf(" LALT");
       
   190 	if(mod & KMOD_RALT)
       
   191 		printf(" RALT");
       
   192 	if(mod & KMOD_LMETA)
       
   193 		printf(" LMETA");
       
   194 	if(mod & KMOD_RMETA)
       
   195 		printf(" RMETA");
       
   196 	if(mod & KMOD_NUM)
       
   197 		printf(" NUM");
       
   198 	if(mod & KMOD_CAPS)
       
   199 		printf(" CAPS");
       
   200 	if(mod & KMOD_MODE)
       
   201 		printf(" MODE");
       
   202 }
       
   203 
       
   204 static void PrintKey(const SDL_keysym *sym, int pressed)
       
   205 {
       
   206 	/* Print the keycode, name and state */
       
   207 	if ( sym->sym ) {
       
   208 		printf("Key %s:  %d-%s ", pressed ?  "pressed" : "released",
       
   209 					sym->sym, SDL_GetKeyName(sym->sym));
       
   210 	} else {
       
   211 		printf("Unknown Key (scancode = %d) %s ", sym->scancode,
       
   212 					pressed ?  "pressed" : "released");
       
   213 	}
       
   214 
       
   215 	/* Print the translated character, if one exists */
       
   216 	if ( sym->unicode ) {
       
   217 		/* Is it a control-character? */
       
   218 		if ( sym->unicode < ' ' ) {
       
   219 			printf(" (^%c)", sym->unicode+'@');
       
   220 		} else {
       
   221 #ifdef UNICODE
       
   222 			printf(" (%c)", sym->unicode);
       
   223 #else
       
   224 			/* This is a Latin-1 program, so only show 8-bits */
       
   225 			if ( !(sym->unicode & 0xFF00) )
       
   226 				printf(" (%c)", sym->unicode);
       
   227 			else
       
   228 				printf(" (0x%X)", sym->unicode);
       
   229 #endif
       
   230 		}
       
   231 	}
       
   232 	print_modifiers();
       
   233 	printf("\n");
       
   234 }
       
   235 
   171 int SDLCALL FilterEvents(const SDL_Event *event)
   236 int SDLCALL FilterEvents(const SDL_Event *event)
   172 {
   237 {
   173 	static int reallyquit = 0;
   238 	static int reallyquit = 0;
   174 
   239 
   175 	switch (event->type) {
   240 	switch (event->type) {
   215 				event->motion.xrel, event->motion.yrel);
   280 				event->motion.xrel, event->motion.yrel);
   216 #endif
   281 #endif
   217 			return(0);
   282 			return(0);
   218 
   283 
   219 		case SDL_KEYDOWN:
   284 		case SDL_KEYDOWN:
       
   285 			PrintKey(&event->key.keysym, 1);
   220 			if ( event->key.keysym.sym == SDLK_ESCAPE ) {
   286 			if ( event->key.keysym.sym == SDLK_ESCAPE ) {
   221 				HotKey_Quit();
   287 				HotKey_Quit();
   222 			}
   288 			}
   223 			if ( (event->key.keysym.sym == SDLK_g) &&
   289 			if ( (event->key.keysym.sym == SDLK_g) &&
   224 			     (event->key.keysym.mod & KMOD_CTRL) ) {
   290 			     (event->key.keysym.mod & KMOD_CTRL) ) {
   230 			}
   296 			}
   231 			if ( (event->key.keysym.sym == SDLK_RETURN) &&
   297 			if ( (event->key.keysym.sym == SDLK_RETURN) &&
   232 			     (event->key.keysym.mod & KMOD_ALT) ) {
   298 			     (event->key.keysym.mod & KMOD_ALT) ) {
   233 				HotKey_ToggleFullScreen();
   299 				HotKey_ToggleFullScreen();
   234 			}
   300 			}
       
   301 			return(0);
       
   302 
       
   303 		case SDL_KEYUP:
       
   304 			PrintKey(&event->key.keysym, 0);
   235 			return(0);
   305 			return(0);
   236 
   306 
   237 		/* Pass the video resize event through .. */
   307 		/* Pass the video resize event through .. */
   238 		case SDL_VIDEORESIZE:
   308 		case SDL_VIDEORESIZE:
   239 			return(1);
   309 			return(1);
   344 	}
   414 	}
   345 
   415 
   346 	/* Set an event filter that discards everything but QUIT */
   416 	/* Set an event filter that discards everything but QUIT */
   347 	SDL_SetEventFilter(FilterEvents);
   417 	SDL_SetEventFilter(FilterEvents);
   348 
   418 
   349 	/* Ignore key up events, they don't even get filtered */
       
   350 	SDL_EventState(SDL_KEYUP, SDL_IGNORE);
       
   351 
       
   352 	/* Loop, waiting for QUIT */
   419 	/* Loop, waiting for QUIT */
   353 	while ( SDL_WaitEvent(&event) ) {
   420 	while ( SDL_WaitEvent(&event) ) {
   354 		switch (event.type) {
   421 		switch (event.type) {
   355 			case SDL_VIDEORESIZE:
   422 			case SDL_VIDEORESIZE:
   356 				printf("Got a resize event: %dx%d\n",
   423 				printf("Got a resize event: %dx%d\n",