Commit 32ff25bf68e687a6c15bfef2d855faccb2740472

Authored by bellard
1 parent f9859310

ctrl-alt is the default grab key - reset modifiers when toggling grab state


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1094 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 32 additions and 20 deletions
@@ -41,6 +41,8 @@ static int gui_fullscreen; @@ -41,6 +41,8 @@ static int gui_fullscreen;
41 static int gui_key_modifier_pressed; 41 static int gui_key_modifier_pressed;
42 static int gui_keysym; 42 static int gui_keysym;
43 static int gui_fullscreen_initial_grab; 43 static int gui_fullscreen_initial_grab;
  44 +static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
  45 +static uint8_t modifiers_state[256];
44 46
45 static void sdl_update(DisplayState *ds, int x, int y, int w, int h) 47 static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
46 { 48 {
@@ -275,10 +277,22 @@ static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) @@ -275,10 +277,22 @@ static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
275 277
276 #endif 278 #endif
277 279
  280 +static void reset_keys(void)
  281 +{
  282 + int i;
  283 + for(i = 0; i < 256; i++) {
  284 + if (modifiers_state[i]) {
  285 + if (i & 0x80)
  286 + kbd_put_keycode(0xe0);
  287 + kbd_put_keycode(i | 0x80);
  288 + modifiers_state[i] = 0;
  289 + }
  290 + }
  291 +}
  292 +
278 static void sdl_process_key(SDL_KeyboardEvent *ev) 293 static void sdl_process_key(SDL_KeyboardEvent *ev)
279 { 294 {
280 - int keycode, v, i;  
281 - static uint8_t modifiers_state[256]; 295 + int keycode, v;
282 296
283 if (ev->keysym.sym == SDLK_PAUSE) { 297 if (ev->keysym.sym == SDLK_PAUSE) {
284 /* specific case */ 298 /* specific case */
@@ -297,13 +311,7 @@ static void sdl_process_key(SDL_KeyboardEvent *ev) @@ -297,13 +311,7 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
297 switch(keycode) { 311 switch(keycode) {
298 case 0x00: 312 case 0x00:
299 /* sent when leaving window: reset the modifiers state */ 313 /* sent when leaving window: reset the modifiers state */
300 - for(i = 0; i < 256; i++) {  
301 - if (modifiers_state[i]) {  
302 - if (i & 0x80)  
303 - kbd_put_keycode(0xe0);  
304 - kbd_put_keycode(i | 0x80);  
305 - }  
306 - } 314 + reset_keys();
307 return; 315 return;
308 case 0x2a: /* Left Shift */ 316 case 0x2a: /* Left Shift */
309 case 0x36: /* Right Shift */ 317 case 0x36: /* Right Shift */
@@ -341,7 +349,7 @@ static void sdl_update_caption(void) @@ -341,7 +349,7 @@ static void sdl_update_caption(void)
341 strcat(buf, " [Stopped]"); 349 strcat(buf, " [Stopped]");
342 } 350 }
343 if (gui_grab) { 351 if (gui_grab) {
344 - strcat(buf, " - Press Ctrl-Shift to exit grab"); 352 + strcat(buf, " - Press Ctrl-Alt to exit grab");
345 } 353 }
346 SDL_WM_SetCaption(buf, "QEMU"); 354 SDL_WM_SetCaption(buf, "QEMU");
347 } 355 }
@@ -422,17 +430,19 @@ static void sdl_refresh(DisplayState *ds) @@ -422,17 +430,19 @@ static void sdl_refresh(DisplayState *ds)
422 case SDL_KEYDOWN: 430 case SDL_KEYDOWN:
423 case SDL_KEYUP: 431 case SDL_KEYUP:
424 if (ev->type == SDL_KEYDOWN) { 432 if (ev->type == SDL_KEYDOWN) {
425 - mod_state = (SDL_GetModState() & (KMOD_LSHIFT | KMOD_LCTRL)) ==  
426 - (KMOD_LSHIFT | KMOD_LCTRL); 433 + mod_state = (SDL_GetModState() & gui_grab_code) ==
  434 + gui_grab_code;
427 gui_key_modifier_pressed = mod_state; 435 gui_key_modifier_pressed = mod_state;
428 if (gui_key_modifier_pressed) { 436 if (gui_key_modifier_pressed) {
429 - switch(ev->key.keysym.sym) {  
430 - case SDLK_f: 437 + int keycode;
  438 + keycode = sdl_keyevent_to_keycode(&ev->key);
  439 + switch(keycode) {
  440 + case 0x21: /* 'f' key on US keyboard */
431 toggle_full_screen(ds); 441 toggle_full_screen(ds);
432 gui_keysym = 1; 442 gui_keysym = 1;
433 break; 443 break;
434 - case SDLK_F1 ... SDLK_F12:  
435 - console_select(ev->key.keysym.sym - SDLK_F1); 444 + case 0x02 ... 0x0a: /* '1' to '9' keys */
  445 + console_select(keycode - 0x02);
436 if (is_active_console(vga_console)) { 446 if (is_active_console(vga_console)) {
437 /* tell the vga console to redisplay itself */ 447 /* tell the vga console to redisplay itself */
438 vga_invalidate_display(); 448 vga_invalidate_display();
@@ -446,8 +456,7 @@ static void sdl_refresh(DisplayState *ds) @@ -446,8 +456,7 @@ static void sdl_refresh(DisplayState *ds)
446 default: 456 default:
447 break; 457 break;
448 } 458 }
449 - }  
450 - if (!is_active_console(vga_console)) { 459 + } else if (!is_active_console(vga_console)) {
451 int keysym; 460 int keysym;
452 keysym = 0; 461 keysym = 0;
453 if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) { 462 if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
@@ -483,15 +492,18 @@ static void sdl_refresh(DisplayState *ds) @@ -483,15 +492,18 @@ static void sdl_refresh(DisplayState *ds)
483 } 492 }
484 } 493 }
485 } else if (ev->type == SDL_KEYUP) { 494 } else if (ev->type == SDL_KEYUP) {
486 - mod_state = (SDL_GetModState() & (KMOD_LSHIFT | KMOD_LCTRL)); 495 + mod_state = (SDL_GetModState() & gui_grab_code);
487 if (!mod_state) { 496 if (!mod_state) {
488 if (gui_key_modifier_pressed) { 497 if (gui_key_modifier_pressed) {
489 if (gui_keysym == 0) { 498 if (gui_keysym == 0) {
490 - /* exit/enter grab if pressing Ctrl-Shift */ 499 + /* exit/enter grab if pressing Ctrl-Alt */
491 if (!gui_grab) 500 if (!gui_grab)
492 sdl_grab_start(); 501 sdl_grab_start();
493 else 502 else
494 sdl_grab_end(); 503 sdl_grab_end();
  504 + /* SDL does not send back all the
  505 + modifiers key, so we must correct it */
  506 + reset_keys();
495 break; 507 break;
496 } 508 }
497 gui_key_modifier_pressed = 0; 509 gui_key_modifier_pressed = 0;