src/events/SDL_keyboard.c
changeset 3685 64ce267332c6
parent 3502 98a819296cdc
child 3697 f7b03b6838cb
equal deleted inserted replaced
3684:cc564f08884f 3685:64ce267332c6
   644 {
   644 {
   645     SDL_scancode_names[scancode] = name;
   645     SDL_scancode_names[scancode] = name;
   646 }
   646 }
   647 
   647 
   648 void
   648 void
   649 SDL_SetKeyboardFocus(int index, SDL_WindowID windowID)
   649 SDL_SetKeyboardFocus(int index, SDL_Window * window)
   650 {
   650 {
   651     SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   651     SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   652     int i;
   652     int i;
   653     SDL_bool focus;
   653     SDL_bool focus;
   654 
   654 
   655     if (!keyboard) {
   655     if (!keyboard) {
   656         return;
   656         return;
   657     }
   657     }
   658 
   658 
   659     /* See if the current window has lost focus */
   659     /* See if the current window has lost focus */
   660     if (keyboard->focus && keyboard->focus != windowID) {
   660     if (keyboard->focus && keyboard->focus != window) {
   661         focus = SDL_FALSE;
   661         focus = SDL_FALSE;
   662         for (i = 0; i < SDL_num_keyboards; ++i) {
   662         for (i = 0; i < SDL_num_keyboards; ++i) {
   663             if (i != index) {
   663             if (i != index) {
   664                 SDL_Keyboard *check = SDL_GetKeyboard(i);
   664                 SDL_Keyboard *check = SDL_GetKeyboard(i);
   665                 if (check && check->focus == keyboard->focus) {
   665                 if (check && check->focus == keyboard->focus) {
   672             SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_LOST,
   672             SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_LOST,
   673                                 0, 0);
   673                                 0, 0);
   674         }
   674         }
   675     }
   675     }
   676 
   676 
   677     keyboard->focus = windowID;
   677     keyboard->focus = window;
   678 
   678 
   679     if (keyboard->focus) {
   679     if (keyboard->focus) {
   680         SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED,
   680         SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED,
   681                             0, 0);
   681                             0, 0);
   682     }
   682     }
   807         event.key.state = state;
   807         event.key.state = state;
   808         event.key.keysym.scancode = scancode;
   808         event.key.keysym.scancode = scancode;
   809         event.key.keysym.sym = keyboard->keymap[scancode];
   809         event.key.keysym.sym = keyboard->keymap[scancode];
   810         event.key.keysym.mod = modstate;
   810         event.key.keysym.mod = modstate;
   811         event.key.keysym.unicode = 0;
   811         event.key.keysym.unicode = 0;
   812         event.key.windowID = keyboard->focus;
   812         event.key.windowID = keyboard->focus->id;
   813         posted = (SDL_PushEvent(&event) > 0);
   813         posted = (SDL_PushEvent(&event) > 0);
   814     }
   814     }
   815     return (posted);
   815     return (posted);
   816 }
   816 }
   817 
   817 
   830     if (SDL_ProcessEvents[SDL_TEXTINPUT] == SDL_ENABLE) {
   830     if (SDL_ProcessEvents[SDL_TEXTINPUT] == SDL_ENABLE) {
   831         SDL_Event event;
   831         SDL_Event event;
   832         event.text.type = SDL_TEXTINPUT;
   832         event.text.type = SDL_TEXTINPUT;
   833         event.text.which = (Uint8) index;
   833         event.text.which = (Uint8) index;
   834         SDL_strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
   834         SDL_strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
   835         event.text.windowID = keyboard->focus;
   835         event.text.windowID = keyboard->focus->id;
   836         posted = (SDL_PushEvent(&event) > 0);
   836         posted = (SDL_PushEvent(&event) > 0);
   837     }
   837     }
   838     return (posted);
   838     return (posted);
   839 }
   839 }
   840 
   840