ui/sdl: Fix handling of caps lock and num lock keys
Starting with SDL version 1.2.14, caps lock and num lock keys will send a SDL_KEYUP when SDL_DISABLE_LOCK_KEYS=1 is set in the environment. The new code sets the environment unconditionally (it won't harm old versions which do not know it). The workaround for SDL_KEYUP is only compiled with old SDL versions. A similar patch without handling of old SDL versions was already published by Benjamin Drung for Ubuntu. Cc: Anthony Liguori <aliguori@us.ibm.com> Cc: Kevin Wolf <kwolf@redhat.com> Cc: Benjamin Drung <benjamin.drung@gmail.com> Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									4c3d45eb69
								
							
						
					
					
						commit
						4e79bcbb96
					
				
							
								
								
									
										8
									
								
								ui/sdl.c
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								ui/sdl.c
									
									
									
									
									
								
							@ -388,12 +388,16 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
 | 
				
			|||||||
        else
 | 
					        else
 | 
				
			||||||
            modifiers_state[keycode] = 1;
 | 
					            modifiers_state[keycode] = 1;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
 | 
					#define QEMU_SDL_VERSION ((SDL_MAJOR_VERSION << 8) + SDL_MINOR_VERSION)
 | 
				
			||||||
 | 
					#if QEMU_SDL_VERSION < 0x102 || QEMU_SDL_VERSION == 0x102 && SDL_PATCHLEVEL < 14
 | 
				
			||||||
 | 
					        /* SDL versions before 1.2.14 don't support key up for caps/num lock. */
 | 
				
			||||||
    case 0x45: /* num lock */
 | 
					    case 0x45: /* num lock */
 | 
				
			||||||
    case 0x3a: /* caps lock */
 | 
					    case 0x3a: /* caps lock */
 | 
				
			||||||
        /* SDL does not send the key up event, so we generate it */
 | 
					        /* SDL does not send the key up event, so we generate it */
 | 
				
			||||||
        kbd_put_keycode(keycode);
 | 
					        kbd_put_keycode(keycode);
 | 
				
			||||||
        kbd_put_keycode(keycode | SCANCODE_UP);
 | 
					        kbd_put_keycode(keycode | SCANCODE_UP);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* now send the key code */
 | 
					    /* now send the key code */
 | 
				
			||||||
@ -831,6 +835,10 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
 | 
				
			|||||||
        setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 0);
 | 
					        setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Enable normal up/down events for Caps-Lock and Num-Lock keys.
 | 
				
			||||||
 | 
					     * This requires SDL >= 1.2.14. */
 | 
				
			||||||
 | 
					    setenv("SDL_DISABLE_LOCK_KEYS", "1", 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
 | 
					    flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
 | 
				
			||||||
    if (SDL_Init (flags)) {
 | 
					    if (SDL_Init (flags)) {
 | 
				
			||||||
        fprintf(stderr, "Could not initialize SDL(%s) - exiting\n",
 | 
					        fprintf(stderr, "Could not initialize SDL(%s) - exiting\n",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user