Mercurial > sdl-ios-xcode
annotate src/audio/SDL_audiodev.c @ 4384:6800e2560310 SDL-1.2
Fixed bugs #882 and 865, re-opening bug #634
Ronald Lamprecht to SDL
Hi,
Sam Lantinga wrote:
The problem with that fix is that it breaks IME events again. Maybe
we can handle keyboard events differently to prevent this issue?
Spending an hour reading MSDN, analysing SDL and another hour testing the reality on XP I am really wondering how patch r4990 could have ever worked in any situation. It's main effect is to break the unicode translation and causing spurious activation events!
Why does TranslateMessage(&msg) nothing useful? Simply because it does not affect "msg" at all! All keyboard events are dispatched without the slightest change (see MSDN). TranslateMessage() just appends additional WM_CHAR, WM_DEADCHAR, WM_SYSCHAR, WM_SYSDEADCHAR event messages to the queue. But I could not find any SDL event handling routine that catches these events and transforms them to proper SDL keyevents while eliminating the corresponding WM_KEYDOWN, etc. events. Thus any IME input like the '@' generated by "Alt + 6(Numpad) + 4(Numpad)" is simply lost.
But the situation is even worse! Up to r4990 the TranslateKey()/ToUnicode() calls did evaluate dead keys and did deliver proper key events for subsequent key strokes like '´' + 'e' resulting in 'é'. ToUnicode() needs proper key state informations to be able to handle these substitutions. But unfortunatly TranslateMessage() needs the same state information and eats it up while generating the WM_CHAR messages :-( Thus the current 1.2.14 breakes the partial IME support of previous releases, too.
The key state race condition between ToUnicode() and TranslateMessage() requires to avoid any ToUnicode() usage for receiving proper WM_CHAR, etc. messages generated by TranslateMessage(). (Yes - the '@' and 'é' appear as WM_CHAR messages when unicode is switched off).
The spurious SDL activation events are *not* caused by additional WM_ACTIVATE Windows messages! Besides DIB_HandleMessage() SDL_PrivateAppActive() is called by another source which I am not yet aware of - any hints?
Thus I do strongly recommend the deletion of the TranslateMessage(&msg) call as a quick fix.
A proper support of unicode and IME requires a clean SDL keyboard input concept first. Which SDL keyboards events should be transmitted to the app when the user presses '´' + 'e' ? Within the current unicode handling the first key stroke is hidden. Even though ToUnicode() delivers the proper key SDL does ignore it in TranslateKey(). Just the composed key event is transmitted to the app. That is what you expect for text input, but the app can no longer use keys like '^' as a key button because it will never receive a key event for it!
With a given concept it seems to be necessary to regenerate SDL key events out of the WM_CHAR, etc. events and to drop all related direct WM_KEYDOWN, etc. events while the remaining basic WM_KEYDOWN, etc. events would still have to result in SDL key events.
Anyway the source of the spurious WM_ACTIVATE should be located to avoid future trouble.
Greets,
Ronald
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 17 Nov 2009 04:59:13 +0000 |
parents | a1b03ba2fcd0 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
4159 | 3 Copyright (C) 1997-2009 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1138
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
94
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* Get the name of the audio device we use for output */ | |
25 | |
1567
12b6d331d82a
Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
26 #if SDL_AUDIO_DRIVER_BSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO |
0 | 27 |
28 #include <fcntl.h> | |
29 #include <sys/types.h> | |
30 #include <sys/stat.h> | |
31 | |
1358
c71e05b4dc2e
More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
32 #include "SDL_stdinc.h" |
0 | 33 #include "SDL_audiodev_c.h" |
34 | |
35 #ifndef _PATH_DEV_DSP | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
36 #if defined(__NETBSD__) || defined(__OPENBSD__) |
94
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
37 #define _PATH_DEV_DSP "/dev/audio" |
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
38 #else |
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
39 #define _PATH_DEV_DSP "/dev/dsp" |
ae6e6b73333f
Cleaned up the OpenBSD port, thanks to Peter Valchev
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
40 #endif |
0 | 41 #endif |
42 #ifndef _PATH_DEV_DSP24 | |
43 #define _PATH_DEV_DSP24 "/dev/sound/dsp" | |
44 #endif | |
45 #ifndef _PATH_DEV_AUDIO | |
46 #define _PATH_DEV_AUDIO "/dev/audio" | |
47 #endif | |
48 | |
49 | |
50 int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic) | |
51 { | |
52 const char *audiodev; | |
53 int audio_fd; | |
54 char audiopath[1024]; | |
55 | |
56 /* Figure out what our audio device is */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
57 if ( ((audiodev=SDL_getenv("SDL_PATH_DSP")) == NULL) && |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
58 ((audiodev=SDL_getenv("AUDIODEV")) == NULL) ) { |
0 | 59 if ( classic ) { |
60 audiodev = _PATH_DEV_AUDIO; | |
61 } else { | |
62 struct stat sb; | |
63 | |
64 /* Added support for /dev/sound/\* in Linux 2.4 */ | |
1138
fcfb783a3ca2
Commercial-OSS-on-Solaris patch...
Ryan C. Gordon <icculus@icculus.org>
parents:
1035
diff
changeset
|
65 if ( ((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode)) && |
fcfb783a3ca2
Commercial-OSS-on-Solaris patch...
Ryan C. Gordon <icculus@icculus.org>
parents:
1035
diff
changeset
|
66 ((stat(_PATH_DEV_DSP24, &sb) == 0) && S_ISCHR(sb.st_mode)) ) { |
0 | 67 audiodev = _PATH_DEV_DSP24; |
68 } else { | |
69 audiodev = _PATH_DEV_DSP; | |
70 } | |
71 } | |
72 } | |
73 audio_fd = open(audiodev, flags, 0); | |
74 | |
75 /* If the first open fails, look for other devices */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
76 if ( (audio_fd < 0) && (SDL_strlen(audiodev) < (sizeof(audiopath)-3)) ) { |
0 | 77 int exists, instance; |
78 struct stat sb; | |
79 | |
80 instance = 1; | |
81 do { /* Don't use errno ENOENT - it may not be thread-safe */ | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
82 SDL_snprintf(audiopath, SDL_arraysize(audiopath), |
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
83 "%s%d", audiodev, instance++); |
0 | 84 exists = 0; |
85 if ( stat(audiopath, &sb) == 0 ) { | |
86 exists = 1; | |
87 audio_fd = open(audiopath, flags, 0); | |
88 } | |
89 } while ( exists && (audio_fd < 0) ); | |
90 audiodev = audiopath; | |
91 } | |
92 if ( path != NULL ) { | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
93 SDL_strlcpy(path, audiodev, maxlen); |
0 | 94 path[maxlen-1] = '\0'; |
95 } | |
96 return(audio_fd); | |
97 } | |
98 | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
99 #elif SDL_AUDIO_DRIVER_PAUD |
0 | 100 |
101 /* Get the name of the audio device we use for output */ | |
102 | |
103 #include <sys/types.h> | |
104 #include <sys/stat.h> | |
105 | |
1358
c71e05b4dc2e
More header massaging... works great on Windows. ;-)
Sam Lantinga <slouken@libsdl.org>
parents:
1338
diff
changeset
|
106 #include "SDL_stdinc.h" |
0 | 107 #include "SDL_audiodev_c.h" |
108 | |
109 #ifndef _PATH_DEV_DSP | |
110 #define _PATH_DEV_DSP "/dev/%caud%c/%c" | |
111 #endif | |
112 | |
113 char devsettings[][3] = | |
114 { | |
115 { 'p', '0', '1' }, { 'p', '0', '2' }, { 'p', '0', '3' }, { 'p', '0', '4' }, | |
116 { 'p', '1', '1' }, { 'p', '1', '2' }, { 'p', '1', '3' }, { 'p', '1', '4' }, | |
117 { 'p', '2', '1' }, { 'p', '2', '2' }, { 'p', '2', '3' }, { 'p', '2', '4' }, | |
118 { 'p', '3', '1' }, { 'p', '3', '2' }, { 'p', '3', '3' }, { 'p', '3', '4' }, | |
119 { 'b', '0', '1' }, { 'b', '0', '2' }, { 'b', '0', '3' }, { 'b', '0', '4' }, | |
120 { 'b', '1', '1' }, { 'b', '1', '2' }, { 'b', '1', '3' }, { 'b', '1', '4' }, | |
121 { 'b', '2', '1' }, { 'b', '2', '2' }, { 'b', '2', '3' }, { 'b', '2', '4' }, | |
122 { 'b', '3', '1' }, { 'b', '3', '2' }, { 'b', '3', '3' }, { 'b', '3', '4' }, | |
123 { '\0', '\0', '\0' } | |
124 }; | |
125 | |
126 static int OpenUserDefinedDevice(char *path, int maxlen, int flags) | |
127 { | |
128 const char *audiodev; | |
129 int audio_fd; | |
130 | |
131 /* Figure out what our audio device is */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
132 if ((audiodev=SDL_getenv("SDL_PATH_DSP")) == NULL) { |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
133 audiodev=SDL_getenv("AUDIODEV"); |
0 | 134 } |
135 if ( audiodev == NULL ) { | |
136 return -1; | |
137 } | |
138 audio_fd = open(audiodev, flags, 0); | |
139 if ( path != NULL ) { | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
140 SDL_strlcpy(path, audiodev, maxlen); |
0 | 141 path[maxlen-1] = '\0'; |
142 } | |
143 return audio_fd; | |
144 } | |
145 | |
146 int SDL_OpenAudioPath(char *path, int maxlen, int flags, int classic) | |
147 { | |
148 struct stat sb; | |
149 int audio_fd; | |
150 char audiopath[1024]; | |
151 int cycle; | |
152 | |
153 audio_fd = OpenUserDefinedDevice(path,maxlen,flags); | |
154 if ( audio_fd != -1 ) { | |
155 return audio_fd; | |
156 } | |
157 | |
158 cycle = 0; | |
159 while( devsettings[cycle][0] != '\0' ) { | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
160 SDL_snprintf( audiopath, SDL_arraysize(audiopath), |
0 | 161 _PATH_DEV_DSP, |
162 devsettings[cycle][0], | |
163 devsettings[cycle][1], | |
164 devsettings[cycle][2]); | |
165 | |
166 if ( stat(audiopath, &sb) == 0 ) { | |
167 audio_fd = open(audiopath, flags, 0); | |
168 if ( audio_fd > 0 ) { | |
169 if ( path != NULL ) { | |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
170 SDL_strlcpy( path, audiopath, maxlen ); |
0 | 171 } |
172 return audio_fd; | |
173 } | |
174 } | |
175 } | |
176 return -1; | |
177 } | |
178 | |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
179 #endif /* Audio driver selection */ |