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
This commit is contained in:
bellard 2004-10-03 14:33:54 +00:00
parent f98593103b
commit 32ff25bf68

52
sdl.c
View file

@ -41,6 +41,8 @@ static int gui_fullscreen;
static int gui_key_modifier_pressed; static int gui_key_modifier_pressed;
static int gui_keysym; static int gui_keysym;
static int gui_fullscreen_initial_grab; static int gui_fullscreen_initial_grab;
static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
static uint8_t modifiers_state[256];
static void sdl_update(DisplayState *ds, int x, int y, int w, int h) static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
{ {
@ -275,10 +277,22 @@ static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
#endif #endif
static void reset_keys(void)
{
int i;
for(i = 0; i < 256; i++) {
if (modifiers_state[i]) {
if (i & 0x80)
kbd_put_keycode(0xe0);
kbd_put_keycode(i | 0x80);
modifiers_state[i] = 0;
}
}
}
static void sdl_process_key(SDL_KeyboardEvent *ev) static void sdl_process_key(SDL_KeyboardEvent *ev)
{ {
int keycode, v, i; int keycode, v;
static uint8_t modifiers_state[256];
if (ev->keysym.sym == SDLK_PAUSE) { if (ev->keysym.sym == SDLK_PAUSE) {
/* specific case */ /* specific case */
@ -297,13 +311,7 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
switch(keycode) { switch(keycode) {
case 0x00: case 0x00:
/* sent when leaving window: reset the modifiers state */ /* sent when leaving window: reset the modifiers state */
for(i = 0; i < 256; i++) { reset_keys();
if (modifiers_state[i]) {
if (i & 0x80)
kbd_put_keycode(0xe0);
kbd_put_keycode(i | 0x80);
}
}
return; return;
case 0x2a: /* Left Shift */ case 0x2a: /* Left Shift */
case 0x36: /* Right Shift */ case 0x36: /* Right Shift */
@ -341,7 +349,7 @@ static void sdl_update_caption(void)
strcat(buf, " [Stopped]"); strcat(buf, " [Stopped]");
} }
if (gui_grab) { if (gui_grab) {
strcat(buf, " - Press Ctrl-Shift to exit grab"); strcat(buf, " - Press Ctrl-Alt to exit grab");
} }
SDL_WM_SetCaption(buf, "QEMU"); SDL_WM_SetCaption(buf, "QEMU");
} }
@ -422,17 +430,19 @@ static void sdl_refresh(DisplayState *ds)
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_KEYUP: case SDL_KEYUP:
if (ev->type == SDL_KEYDOWN) { if (ev->type == SDL_KEYDOWN) {
mod_state = (SDL_GetModState() & (KMOD_LSHIFT | KMOD_LCTRL)) == mod_state = (SDL_GetModState() & gui_grab_code) ==
(KMOD_LSHIFT | KMOD_LCTRL); gui_grab_code;
gui_key_modifier_pressed = mod_state; gui_key_modifier_pressed = mod_state;
if (gui_key_modifier_pressed) { if (gui_key_modifier_pressed) {
switch(ev->key.keysym.sym) { int keycode;
case SDLK_f: keycode = sdl_keyevent_to_keycode(&ev->key);
switch(keycode) {
case 0x21: /* 'f' key on US keyboard */
toggle_full_screen(ds); toggle_full_screen(ds);
gui_keysym = 1; gui_keysym = 1;
break; break;
case SDLK_F1 ... SDLK_F12: case 0x02 ... 0x0a: /* '1' to '9' keys */
console_select(ev->key.keysym.sym - SDLK_F1); console_select(keycode - 0x02);
if (is_active_console(vga_console)) { if (is_active_console(vga_console)) {
/* tell the vga console to redisplay itself */ /* tell the vga console to redisplay itself */
vga_invalidate_display(); vga_invalidate_display();
@ -446,8 +456,7 @@ static void sdl_refresh(DisplayState *ds)
default: default:
break; break;
} }
} } else if (!is_active_console(vga_console)) {
if (!is_active_console(vga_console)) {
int keysym; int keysym;
keysym = 0; keysym = 0;
if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) { if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
@ -483,15 +492,18 @@ static void sdl_refresh(DisplayState *ds)
} }
} }
} else if (ev->type == SDL_KEYUP) { } else if (ev->type == SDL_KEYUP) {
mod_state = (SDL_GetModState() & (KMOD_LSHIFT | KMOD_LCTRL)); mod_state = (SDL_GetModState() & gui_grab_code);
if (!mod_state) { if (!mod_state) {
if (gui_key_modifier_pressed) { if (gui_key_modifier_pressed) {
if (gui_keysym == 0) { if (gui_keysym == 0) {
/* exit/enter grab if pressing Ctrl-Shift */ /* exit/enter grab if pressing Ctrl-Alt */
if (!gui_grab) if (!gui_grab)
sdl_grab_start(); sdl_grab_start();
else else
sdl_grab_end(); sdl_grab_end();
/* SDL does not send back all the
modifiers key, so we must correct it */
reset_keys();
break; break;
} }
gui_key_modifier_pressed = 0; gui_key_modifier_pressed = 0;