Commit de2200d36d70acf874dd806e6bee8a2793e7edc6

Authored by bellard
1 parent 710c15a2

fixed window switch - fixed caps lock and num lock - simplified keycodes (initia…

…l idea by Mark Jonckheere)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@886 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 69 additions and 27 deletions
... ... @@ -63,25 +63,24 @@ static void sdl_resize(DisplayState *ds, int w, int h)
63 63 ds->depth = screen->format->BitsPerPixel;
64 64 }
65 65  
66   -static const uint32_t x_keycode_to_pc_keycode[61] = {
67   - 0x47e0, /* 97 Home */
68   - 0x48e0, /* 98 Up */
69   - 0x49e0, /* 99 PgUp */
70   - 0x4be0, /* 100 Left */
  66 +static const uint8_t x_keycode_to_pc_keycode[61] = {
  67 + 0xc7, /* 97 Home */
  68 + 0xc8, /* 98 Up */
  69 + 0xc9, /* 99 PgUp */
  70 + 0xcb, /* 100 Left */
71 71 0x4c, /* 101 KP-5 */
72   - 0x4de0, /* 102 Right */
73   - 0x4fe0, /* 103 End */
74   - 0x50e0, /* 104 Down */
75   - 0x51e0, /* 105 PgDn */
76   - 0x52e0, /* 106 Ins */
77   - 0x53e0, /* 107 Del */
78   - 0x1ce0, /* 108 Enter */
79   - 0x1de0, /* 109 Ctrl-R */
80   - 0x451de1, /* 110 Pause */
81   - 0x37e0, /* 111 Print */
82   - 0x35e0, /* 112 Divide */
83   - 0x38e0, /* 113 Alt-R */
84   - 0x46e0, /* 114 Break */
  72 + 0xcd, /* 102 Right */
  73 + 0xcf, /* 103 End */
  74 + 0xd0, /* 104 Down */
  75 + 0xd1, /* 105 PgDn */
  76 + 0xd2, /* 106 Ins */
  77 + 0xd3, /* 107 Del */
  78 + 0x9c, /* 108 Enter */
  79 + 0x9d, /* 109 Ctrl-R */
  80 + 0xb7, /* 111 Print */
  81 + 0xb5, /* 112 Divide */
  82 + 0xb8, /* 113 Alt-R */
  83 + 0xc6, /* 114 Break */
85 84 0x0, /* 115 */
86 85 0x0, /* 116 */
87 86 0x0, /* 117 */
... ... @@ -129,11 +128,25 @@ static const uint32_t x_keycode_to_pc_keycode[61] = {
129 128  
130 129 static void sdl_process_key(SDL_KeyboardEvent *ev)
131 130 {
132   - int keycode, v;
133   -
  131 + int keycode, v, i;
  132 + static uint8_t modifiers_state[256];
  133 +
  134 + if (ev->keysym.sym == SDLK_PAUSE) {
  135 + /* specific case */
  136 + v = 0;
  137 + if (ev->type == SDL_KEYUP)
  138 + v |= 0x80;
  139 + kbd_put_keycode(0xe1);
  140 + kbd_put_keycode(0x1d | v);
  141 + kbd_put_keycode(0x45 | v);
  142 + return;
  143 + }
  144 +
134 145 /* XXX: not portable, but avoids complicated mappings */
135 146 keycode = ev->keysym.scancode;
136 147  
  148 + /* XXX: windows version may not work: 0xe0/0xe1 should be trapped
  149 + ? */
137 150 #ifndef _WIN32
138 151 if (keycode < 9) {
139 152 keycode = 0;
... ... @@ -146,15 +159,44 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
146 159 keycode = 0;
147 160 }
148 161 #endif
149   -
150   - /* now send the key code */
151   - while (keycode != 0) {
152   - v = keycode & 0xff;
  162 +
  163 + switch(keycode) {
  164 + case 0x00:
  165 + /* sent when leaving window: reset the modifiers state */
  166 + for(i = 0; i < 256; i++) {
  167 + if (modifiers_state[i]) {
  168 + if (i & 0x80)
  169 + kbd_put_keycode(0xe0);
  170 + kbd_put_keycode(i | 0x80);
  171 + }
  172 + }
  173 + return;
  174 + case 0x2a: /* Left Shift */
  175 + case 0x36: /* Right Shift */
  176 + case 0x1d: /* Left CTRL */
  177 + case 0x9d: /* Right CTRL */
  178 + case 0x38: /* Left ALT */
  179 + case 0xb8: /* Right ALT */
153 180 if (ev->type == SDL_KEYUP)
154   - v |= 0x80;
155   - kbd_put_keycode(v);
156   - keycode >>= 8;
  181 + modifiers_state[keycode] = 0;
  182 + else
  183 + modifiers_state[keycode] = 1;
  184 + break;
  185 + case 0x45: /* num lock */
  186 + case 0x3a: /* caps lock */
  187 + /* SDL does not send the key up event, so we generate it */
  188 + kbd_put_keycode(keycode);
  189 + kbd_put_keycode(keycode | 0x80);
  190 + return;
157 191 }
  192 +
  193 + /* now send the key code */
  194 + if (keycode & 0x80)
  195 + kbd_put_keycode(0xe0);
  196 + if (ev->type == SDL_KEYUP)
  197 + kbd_put_keycode(keycode | 0x80);
  198 + else
  199 + kbd_put_keycode(keycode & 0x7f);
158 200 }
159 201  
160 202 static void sdl_update_caption(void)
... ...