![]() |
#1 |
Adept
Join Date: Dec 2009
Posts: 172
![]() |
Fix for the Non-English keyboard layouts bug
Bug http://trac.rephial.org/ticket/1460 has been getting on my nerves again. I think I found the problem.
The problem is that SDL seems to use the Keycode of the pressed key instead of the modified key, when the modifier is Alt-Gr (SDL calls it Mode). So here key_code still contains the correct symbol (which is why it sometimes works). key_sym does contain the wrong key. Angband uses key_sym instead of key_code for some keys (no idea why). I added a conditional to skip use of key_sym for the number keys if Alt-Gr is pressed. It might be better to skip the whole case-block if Alt-Gr is pressed. But I have no idea if this might break something else. The diff is vs. V4 from last week btw. Code:
diff --git a/src/main-sdl.c b/src/main-sdl.c index 74ddc9e..c9b9378 100644 --- a/src/main-sdl.c +++ b/src/main-sdl.c @@ -2386,6 +2386,7 @@ static void sdl_keypress(SDL_keysym keysym) bool ms = (keysym.mod & KMOD_SHIFT) > 0; bool ma = (keysym.mod & KMOD_ALT) > 0; bool mm = (keysym.mod & KMOD_META) > 0; + bool mg = (keysym.mod & KMOD_MODE) > 0; bool kp = FALSE; byte mods = (ma ? KC_MOD_ALT : 0) | (mm ? KC_MOD_META : 0); @@ -2415,16 +2416,16 @@ static void sdl_keypress(SDL_keysym keysym) case SDLK_KP_EQUALS: ch = '='; kp = TRUE; break; /* have have these to get consistent ctrl-shift behaviour */ - case SDLK_0: if (!ms || mc || ma) ch = '0'; break; - case SDLK_1: if (!ms || mc || ma) ch = '1'; break; - case SDLK_2: if (!ms || mc || ma) ch = '2'; break; - case SDLK_3: if (!ms || mc || ma) ch = '3'; break; - case SDLK_4: if (!ms || mc || ma) ch = '4'; break; - case SDLK_5: if (!ms || mc || ma) ch = '5'; break; - case SDLK_6: if (!ms || mc || ma) ch = '6'; break; - case SDLK_7: if (!ms || mc || ma) ch = '7'; break; - case SDLK_8: if (!ms || mc || ma) ch = '8'; break; - case SDLK_9: if (!ms || mc || ma) ch = '9'; break; + case SDLK_0: if ((!ms || mc || ma) && !mg) ch = '0'; break; + case SDLK_1: if ((!ms || mc || ma) && !mg) ch = '1'; break; + case SDLK_2: if ((!ms || mc || ma) && !mg) ch = '2'; break; + case SDLK_3: if ((!ms || mc || ma) && !mg) ch = '3'; break; + case SDLK_4: if ((!ms || mc || ma) && !mg) ch = '4'; break; + case SDLK_5: if ((!ms || mc || ma) && !mg) ch = '5'; break; + case SDLK_6: if ((!ms || mc || ma) && !mg) ch = '6'; break; + case SDLK_7: if ((!ms || mc || ma) && !mg) ch = '7'; break; + case SDLK_8: if ((!ms || mc || ma) && !mg) ch = '8'; break; + case SDLK_9: if ((!ms || mc || ma) && !mg) ch = '9'; break; case SDLK_UP: ch = ARROW_UP; break; case SDLK_DOWN: ch = ARROW_DOWN; break;
__________________
My Angband videos : http://www.youtube.com/view_play_lis...385E85F31166B2 |
![]() |
![]() |
![]() |
#2 |
Angband Devteam member
|
Brilliant - thank you. That's so straightforward that even I could commit it. I've updated the ticket.
__________________
"Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles |
![]() |
![]() |
![]() |
#3 | |
Adept
Join Date: Dec 2009
Posts: 172
![]() |
Quote:
If the bug also hits some non-number keys on other keyboards it might have to be expanded.
__________________
My Angband videos : http://www.youtube.com/view_play_lis...385E85F31166B2 |
|
![]() |
![]() |
![]() |
#4 |
Angband Devteam member
|
Sure, but the important thing is that you've added the mg bool to test for the ALT_MODE. This is the key thing that was missing.
__________________
"Been away so long I hardly knew the place, gee it's good to be back home" - The Beatles |
![]() |
![]() |
![]() |
#5 |
Prophet
Join Date: Apr 2008
Posts: 2,972
![]() |
Doesn't work for me
![]() I'm using a french keyboard and pressing Alt-Gr + "0" to get "@" is interpreted by SDL as SDLK_0 with mods = KMOD_NUM | KMOD_RALT | KMOD_LCTRL. Moreover, when I change KMOD_MODE to KMOD_RALT | KMOD_LCTRL in the proposed fix, it works for keys like "~", "[" or "@" as intended, but now the keys mapped to SDLK_0-9 with only mods = KMOD_NUM don't work anymore: "&" acts like "1", "(" like "5"... The only way I found to remove the bug completely is to remove the case SDLK_ lines like it was done in main-win.
__________________
PWMAngband variant maintainer - check https://github.com/draconisPW/PWMAngband (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant! Last edited by PowerWyrm; May 11, 2012 at 15:39. |
![]() |
![]() |
![]() |
#6 |
Prophet
Join Date: Apr 2008
Posts: 2,972
![]() |
Another related problem on SDL: with an AZERTY keyboard, keys '0' (0x30) to '9' (0x39) are accessed using SHIFT + key; with the current code, these keys are not processed because MODS_INCLUDE_SHIFT() in ui-event.h reports them as requiring SHIFT. To fix that, MODS_INCLUDE_SHIFT() should include range 0x30 to 0x39:
Code:
#define MODS_INCLUDE_SHIFT(v) \ (((((v) >= 0x21) && ((v) <= 0x60)) || \ (((v) >= 0x7B) && ((v) <= 0x7E)))? FALSE: TRUE)
__________________
PWMAngband variant maintainer - check https://github.com/draconisPW/PWMAngband (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant! |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Favorite Angbanding keyboard? | Max Stats | Idle chatter | 23 | August 6, 2013 05:33 |
Oangband bug fix | bron | Variants | 5 | July 19, 2011 10:19 |
QUERTZ keyboard bug | Antoine | Development | 7 | May 25, 2011 17:38 |
Scandinavian Keyboard Layouts | chris | Development | 3 | November 12, 2010 03:06 |
[All] Keyboard interface and keymaps | Remuz | Vanilla | 12 | April 17, 2008 23:24 |