Angband.oook.cz
Angband.oook.cz
AboutDownloadVariantsLadderForumCompetitionSpoilersComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old January 10, 2012, 21:09   #1
Tobias
Adept
 
Tobias's Avatar
 
Join Date: Dec 2009
Posts: 172
Tobias is on a distinguished road
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
Tobias is offline   Reply With Quote
Old January 12, 2012, 12:48   #2
Magnate
Angband Devteam member
 
Join Date: May 2007
Location: London, UK
Posts: 4,992
Magnate is on a distinguished road
Send a message via MSN to Magnate Send a message via Yahoo to Magnate Send a message via Skype™ to Magnate
Brilliant - thank you. That's so straightforward that even I could commit it. I've updated the ticket.
__________________
"3.4 is much better than 3.1, 3.2 or 3.3. It still is easier than 3.0.9, but it is more convenient to play without being ridiculously easy, so it is my new favorite of the versions." - Timo Pietila
Magnate is offline   Reply With Quote
Old January 12, 2012, 13:30   #3
Tobias
Adept
 
Tobias's Avatar
 
Join Date: Dec 2009
Posts: 172
Tobias is on a distinguished road
Quote:
Originally Posted by Magnate View Post
Brilliant - thank you. That's so straightforward that even I could commit it. I've updated the ticket.
It IS possible that it will need some more lines of skips. I only tested this for german keyboard layout.
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
Tobias is offline   Reply With Quote
Old January 12, 2012, 14:07   #4
Magnate
Angband Devteam member
 
Join Date: May 2007
Location: London, UK
Posts: 4,992
Magnate is on a distinguished road
Send a message via MSN to Magnate Send a message via Yahoo to Magnate Send a message via Skype™ to Magnate
Quote:
Originally Posted by Tobias View Post
It IS possible that it will need some more lines of skips. I only tested this for german keyboard layout.
If the bug also hits some non-number keys on other keyboards it might have to be expanded.
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.
__________________
"3.4 is much better than 3.1, 3.2 or 3.3. It still is easier than 3.0.9, but it is more convenient to play without being ridiculously easy, so it is my new favorite of the versions." - Timo Pietila
Magnate is offline   Reply With Quote
Old May 11, 2012, 15:11   #5
PowerWyrm
Knight
 
PowerWyrm's Avatar
 
Join Date: Apr 2008
Posts: 729
PowerWyrm is on a distinguished road
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 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.
PowerWyrm is offline   Reply With Quote
Old May 31, 2012, 09:27   #6
PowerWyrm
Knight
 
PowerWyrm's Avatar
 
Join Date: Apr 2008
Posts: 729
PowerWyrm is on a distinguished road
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 http://www.mangband.org/forum/viewforum.php?f=9 to learn more about this new variant!
PowerWyrm is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
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 02:06
[All] Keyboard interface and keymaps Remuz Vanilla 12 April 17, 2008 23:24


All times are GMT +1. The time now is 15:24.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.