mirror of
				https://github.com/encounter/SDL.git
				synced 2025-10-25 19:20:25 +00:00 
			
		
		
		
	Added KMOD_SCROLL to track the scroll lock state
Fixes https://github.com/libsdl-org/SDL/issues/4566
This commit is contained in:
		
							parent
							
								
									609cea1eb8
								
							
						
					
					
						commit
						cb1e20b058
					
				| @ -338,7 +338,7 @@ typedef enum | |||||||
|     KMOD_NUM = 0x1000, |     KMOD_NUM = 0x1000, | ||||||
|     KMOD_CAPS = 0x2000, |     KMOD_CAPS = 0x2000, | ||||||
|     KMOD_MODE = 0x4000, |     KMOD_MODE = 0x4000, | ||||||
|     KMOD_RESERVED = 0x8000, |     KMOD_SCROLL = 0x8000, | ||||||
| 
 | 
 | ||||||
|     KMOD_CTRL = KMOD_LCTRL | KMOD_RCTRL, |     KMOD_CTRL = KMOD_LCTRL | KMOD_RCTRL, | ||||||
|     KMOD_SHIFT = KMOD_LSHIFT | KMOD_RSHIFT, |     KMOD_SHIFT = KMOD_LSHIFT | KMOD_RSHIFT, | ||||||
|  | |||||||
| @ -767,6 +767,9 @@ SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode) | |||||||
|         case SDLK_CAPSLOCK: |         case SDLK_CAPSLOCK: | ||||||
|             keyboard->modstate ^= KMOD_CAPS; |             keyboard->modstate ^= KMOD_CAPS; | ||||||
|             break; |             break; | ||||||
|  |         case SDLK_SCROLLLOCK: | ||||||
|  |             keyboard->modstate ^= KMOD_SCROLL; | ||||||
|  |             break; | ||||||
|         default: |         default: | ||||||
|             keyboard->modstate |= modifier; |             keyboard->modstate |= modifier; | ||||||
|             break; |             break; | ||||||
|  | |||||||
| @ -627,6 +627,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |||||||
| 
 | 
 | ||||||
|                 SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0); |                 SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0); | ||||||
|                 SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0); |                 SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0); | ||||||
|  |                 SDL_ToggleModState(KMOD_SCROLL, (GetKeyState(VK_SCROLL) & 0x0001) != 0); | ||||||
|             } else { |             } else { | ||||||
|                 RECT rect; |                 RECT rect; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -106,6 +106,7 @@ WIN_InitKeyboard(_THIS) | |||||||
|     /* Are system caps/num/scroll lock active? Set our state to match. */ |     /* Are system caps/num/scroll lock active? Set our state to match. */ | ||||||
|     SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0); |     SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0); | ||||||
|     SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0); |     SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0); | ||||||
|  |     SDL_ToggleModState(KMOD_SCROLL, (GetKeyState(VK_SCROLL) & 0x0001) != 0); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void | void | ||||||
|  | |||||||
| @ -353,6 +353,32 @@ X11_GetNumLockModifierMask(_THIS) | |||||||
|     return num_mask; |     return num_mask; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static unsigned | ||||||
|  | X11_GetScrollLockModifierMask(_THIS) | ||||||
|  | { | ||||||
|  |     SDL_VideoData *viddata = (SDL_VideoData *) _this->driverdata; | ||||||
|  |     Display *display = viddata->display; | ||||||
|  |     unsigned num_mask = 0; | ||||||
|  |     int i, j; | ||||||
|  |     XModifierKeymap *xmods; | ||||||
|  |     unsigned n; | ||||||
|  | 
 | ||||||
|  |     xmods = X11_XGetModifierMapping(display); | ||||||
|  |     n = xmods->max_keypermod; | ||||||
|  |     for(i = 3; i < 8; i++) { | ||||||
|  |         for(j = 0; j < n; j++) { | ||||||
|  |             KeyCode kc = xmods->modifiermap[i * n + j]; | ||||||
|  |             if (viddata->key_layout[kc] == SDL_SCANCODE_SCROLLLOCK) { | ||||||
|  |                 num_mask = 1 << i; | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     X11_XFreeModifiermap(xmods); | ||||||
|  | 
 | ||||||
|  |     return num_mask; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static void | static void | ||||||
| X11_ReconcileKeyboardState(_THIS) | X11_ReconcileKeyboardState(_THIS) | ||||||
| { | { | ||||||
| @ -371,6 +397,7 @@ X11_ReconcileKeyboardState(_THIS) | |||||||
|     if (X11_XQueryPointer(display, DefaultRootWindow(display), &junk_window, &junk_window, &x, &y, &x, &y, &mask)) { |     if (X11_XQueryPointer(display, DefaultRootWindow(display), &junk_window, &junk_window, &x, &y, &x, &y, &mask)) { | ||||||
|         SDL_ToggleModState(KMOD_CAPS, (mask & LockMask) != 0); |         SDL_ToggleModState(KMOD_CAPS, (mask & LockMask) != 0); | ||||||
|         SDL_ToggleModState(KMOD_NUM, (mask & X11_GetNumLockModifierMask(_this)) != 0); |         SDL_ToggleModState(KMOD_NUM, (mask & X11_GetNumLockModifierMask(_this)) != 0); | ||||||
|  |         SDL_ToggleModState(KMOD_SCROLL, (mask & X11_GetScrollLockModifierMask(_this)) != 0); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     keyboardState = SDL_GetKeyboardState(0); |     keyboardState = SDL_GetKeyboardState(0); | ||||||
|  | |||||||
| @ -86,6 +86,8 @@ print_modifiers(char **text, size_t *maxlen) | |||||||
|         print_string(text, maxlen, " CAPS"); |         print_string(text, maxlen, " CAPS"); | ||||||
|     if (mod & KMOD_MODE) |     if (mod & KMOD_MODE) | ||||||
|         print_string(text, maxlen, " MODE"); |         print_string(text, maxlen, " MODE"); | ||||||
|  |     if (mod & KMOD_SCROLL) | ||||||
|  |         print_string(text, maxlen, " SCROLL"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void | static void | ||||||
|  | |||||||
| @ -86,6 +86,8 @@ print_modifiers(char **text, size_t *maxlen) | |||||||
|         print_string(text, maxlen, " CAPS"); |         print_string(text, maxlen, " CAPS"); | ||||||
|     if (mod & KMOD_MODE) |     if (mod & KMOD_MODE) | ||||||
|         print_string(text, maxlen, " MODE"); |         print_string(text, maxlen, " MODE"); | ||||||
|  |     if (mod & KMOD_SCROLL) | ||||||
|  |         print_string(text, maxlen, " SCROLL"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void | static void | ||||||
|  | |||||||
| @ -305,7 +305,7 @@ keyboard_getSetModState(void *arg) | |||||||
|     KMOD_NUM | |     KMOD_NUM | | ||||||
|     KMOD_CAPS | |     KMOD_CAPS | | ||||||
|     KMOD_MODE | |     KMOD_MODE | | ||||||
|     KMOD_RESERVED; |     KMOD_SCROLL; | ||||||
| 
 | 
 | ||||||
|    /* Get state, cache for later reset */ |    /* Get state, cache for later reset */ | ||||||
|    result = SDL_GetModState(); |    result = SDL_GetModState(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user