Skip to content

Commit 8919da3

Browse files
authored
Display IME candidate list and composition text correctly on Windows (CleverRaven#63672)
* Use SDL hint to display IME UI on Windows * Fix long IME composition text being cut off * Update MXE version, UI documentation, comments, and fix android soft keyboard in string editor window * Use SDL 2.26.2 in MinGW builds
1 parent e63b066 commit 8919da3

6 files changed

+76
-12
lines changed

.github/workflows/matrix.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ jobs:
169169
sound: 1
170170
localize: 1
171171
libbacktrace: 1
172-
title: GCC 11, Ubuntu cross-compile to MinGW-Win64, Tiles, Sound
172+
title: GCC 12, Ubuntu cross-compile to MinGW-Win64, Tiles, Sound
173173
ldflags: -static-libgcc -static-libstdc++
174-
mxe_target: x86_64-w64-mingw32.static.gcc11
174+
mxe_target: x86_64-w64-mingw32.static.gcc12
175175
wine: wine
176176
# ~285MB in a clean build
177177
# ~36MB compressed

.github/workflows/release.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,16 @@ jobs:
246246
- name: Install MXE
247247
if: matrix.mxe != 'none'
248248
run: |
249-
curl -L -o mxe-${{ matrix.mxe }}.tar.xz https://github.com/BrettDong/MXE-GCC/releases/download/mxe-gcc-11.2/mxe-${{ matrix.mxe }}.tar.xz
250-
curl -L -o mxe-${{ matrix.mxe }}.tar.xz.sha256 https://github.com/BrettDong/MXE-GCC/releases/download/mxe-gcc-11.2/mxe-${{ matrix.mxe }}.tar.xz.sha256
249+
curl -L -o mxe-${{ matrix.mxe }}.tar.xz https://github.com/BrettDong/MXE-GCC/releases/download/mxe-sdl-2-0-20/mxe-${{ matrix.mxe }}.tar.xz
250+
curl -L -o mxe-${{ matrix.mxe }}.tar.xz.sha256 https://github.com/BrettDong/MXE-GCC/releases/download/mxe-sdl-2-0-20/mxe-${{ matrix.mxe }}.tar.xz.sha256
251251
shasum -a 256 -c ./mxe-${{ matrix.mxe }}.tar.xz.sha256
252252
sudo tar xJf mxe-${{ matrix.mxe }}.tar.xz -C /opt
253+
curl -L -o SDL2-devel-2.26.2-mingw.tar.gz https://github.com/libsdl-org/SDL/releases/download/release-2.26.2/SDL2-devel-2.26.2-mingw.tar.gz
254+
shasum -a 256 -c ./build-scripts/SDL2-devel-2.26.2-mingw.tar.gz.sha256
255+
sudo tar -xzf SDL2-devel-2.26.2-mingw.tar.gz -C /opt/mxe/usr/${{ matrix.mxe }}-w64-mingw32.static.gcc12 --strip-components=2 SDL2-2.26.2/${{ matrix.mxe }}-w64-mingw32
253256
curl -L -o libbacktrace-${{ matrix.mxe }}-w64-mingw32.tar.gz https://github.com/Qrox/libbacktrace/releases/download/2020-01-03/libbacktrace-${{ matrix.mxe }}-w64-mingw32.tar.gz
254257
shasum -a 256 -c ./build-scripts/libbacktrace-${{ matrix.mxe }}-w64-mingw32-sha256
255-
sudo tar -xzf libbacktrace-${{ matrix.mxe }}-w64-mingw32.tar.gz --exclude=LICENSE -C /opt/mxe/usr/${{ matrix.mxe }}-w64-mingw32.static.gcc11
258+
sudo tar -xzf libbacktrace-${{ matrix.mxe }}-w64-mingw32.tar.gz --exclude=LICENSE -C /opt/mxe/usr/${{ matrix.mxe }}-w64-mingw32.static.gcc12
256259
- name: Install dependencies (Linux)
257260
if: runner.os == 'Linux' && matrix.mxe == 'none' && matrix.android == 'none'
258261
run: |
@@ -286,7 +289,7 @@ jobs:
286289
- name: Build CDDA (windows mxe)
287290
if: matrix.mxe != 'none'
288291
env:
289-
PLATFORM: /opt/mxe/usr/bin/${{ matrix.mxe }}-w64-mingw32.static.gcc11-
292+
PLATFORM: /opt/mxe/usr/bin/${{ matrix.mxe }}-w64-mingw32.static.gcc12-
290293
run: |
291294
make -j$((`nproc`+0)) CROSS="${PLATFORM}" TILES=1 SOUND=1 RELEASE=1 LOCALIZE=1 LANGUAGES=all BACKTRACE=1 PCH=0 bindist
292295
mv cataclysmdda-0.F.zip cdda-${{ matrix.artifact }}-${{ needs.release.outputs.timestamp }}.zip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fd2b7ac21d1c487b87fd6c0a9fc87cfb6936c528c3ec197f6127bf925eb38356 *SDL2-devel-2.26.2-mingw.tar.gz

build-scripts/requirements.sh

+16-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ if [ -n "${MXE_TARGET}" ]; then
6767
set +e
6868
retry=0
6969
until [[ "$retry" -ge 5 ]]; do
70-
curl -L -o mxe-x86_64.tar.xz https://github.com/BrettDong/MXE-GCC/releases/download/mxe-gcc-11.2/mxe-x86_64.tar.xz && curl -L -o mxe-x86_64.tar.xz.sha256 https://github.com/BrettDong/MXE-GCC/releases/download/mxe-gcc-11.2/mxe-x86_64.tar.xz.sha256 && shasum -a 256 -c ./mxe-x86_64.tar.xz.sha256 && break
70+
curl -L -o mxe-x86_64.tar.xz https://github.com/BrettDong/MXE-GCC/releases/download/mxe-sdl-2-0-20/mxe-x86_64.tar.xz && curl -L -o mxe-x86_64.tar.xz.sha256 https://github.com/BrettDong/MXE-GCC/releases/download/mxe-sdl-2-0-20/mxe-x86_64.tar.xz.sha256 && shasum -a 256 -c ./mxe-x86_64.tar.xz.sha256 && break
7171
retry=$((retry+1))
7272
rm -f mxe-x86_64.tar.xz mxe-x86_64.tar.xz.sha256
7373
sleep 10
@@ -85,6 +85,21 @@ if [ -n "${MXE_TARGET}" ]; then
8585
export CXX="$COMPILER"
8686
export CCACHE=1
8787

88+
set +e
89+
retry=0
90+
until [[ "$retry" -ge 5 ]]; do
91+
curl -L -o SDL2-devel-2.26.2-mingw.tar.gz https://github.com/libsdl-org/SDL/releases/download/release-2.26.2/SDL2-devel-2.26.2-mingw.tar.gz && shasum -a 256 -c ./build-scripts/SDL2-devel-2.26.2-mingw.tar.gz.sha256 && break
92+
retry=$((retry+1))
93+
rm -f SDL2-devel-2.26.2-mingw.tar.gz
94+
sleep 10
95+
done
96+
if [[ "$retry" -ge 5 ]]; then
97+
echo "Error downloading or checksum failed for SDL2-devel-2.26.2-mingw.tar.gz"
98+
exit 1
99+
fi
100+
set -e
101+
sudo tar -xzf SDL2-devel-2.26.2-mingw.tar.gz -C ${MXE_DIR}/usr/${MXE_TARGET} --strip-components=2 SDL2-2.26.2/x86_64-w64-mingw32
102+
88103
set +e
89104
retry=0
90105
until [[ "$retry" -ge 5 ]]; do

doc/USER_INTERFACE_AND_ACCESSIBILITY.md

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ files:
1212

1313
Details on how to use `ui_adaptor` can be found within `ui_manager.h`.
1414

15+
## SDL version requirement of the tiles build
16+
17+
In theory, any version of SDL2 is supported. However, newer versions of SDL adds
18+
several hints that are used to fix some incorrect behaviors of older SDL versions.
19+
These hints and the minimum SDL version requirements can be found within `InitSDL`
20+
in `sdltiles.cpp`. For example, SDL 2.0.20 is required for IME candidate list
21+
to show correctly on Windows, and SDL 2.0.22 is required for long IME composition
22+
text to show correctly.
23+
1524
## Compatibility with screen readers
1625

1726
There are people who use screen readers to play Cataclysm DDA. In order for screen

src/sdltiles.cpp

+41-5
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,22 @@ static void InitSDL()
174174
int ret;
175175

176176
#if defined(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING)
177+
// Requires SDL 2.0.5. Disables thread naming so that gdb works correctly
178+
// with the game.
177179
SDL_SetHint( SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1" );
178180
#endif
179181

182+
#if defined(_WIN32) && defined(SDL_HINT_IME_SHOW_UI)
183+
// Requires SDL 2.0.20. Shows the native IME UI instead of using SDL's
184+
// broken implementation on Windows which does not show.
185+
SDL_SetHint( SDL_HINT_IME_SHOW_UI, "1" );
186+
#endif
187+
188+
#if defined(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT)
189+
// Requires SDL 2.0.22. Support long IME composition text.
190+
SDL_SetHint( SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, "1" );
191+
#endif
192+
180193
#if defined(__linux__)
181194
// https://bugzilla.libsdl.org/show_bug.cgi?id=3472#c5
182195
if( SDL_COMPILEDVERSION == SDL_VERSIONNUM( 2, 0, 5 ) ) {
@@ -2519,9 +2532,8 @@ bool is_string_input( input_context &ctx )
25192532
{
25202533
std::string &category = ctx.get_category();
25212534
return category == "STRING_INPUT"
2522-
|| category == "HELP_KEYBINDINGS"
2523-
|| category == "NEW_CHAR_DESCRIPTION"
2524-
|| category == "WORLDGEN_CONFIRM_DIALOG";
2535+
|| category == "STRING_EDITOR"
2536+
|| category == "HELP_KEYBINDINGS";
25252537
}
25262538

25272539
int get_key_event_from_string( const std::string &str )
@@ -3204,11 +3216,35 @@ static void CheckMessages()
32043216
last_input = input_event();
32053217
last_input.type = input_event_t::keyboard_char;
32063218
}
3207-
last_input.edit = ev.edit.text;
3219+
// Convert to string explicitly to avoid accidentally using
3220+
// the array out of scope.
3221+
last_input.edit = std::string( ev.edit.text );
32083222
last_input.edit_refresh = true;
32093223
text_refresh = true;
3224+
break;
32103225
}
3211-
break;
3226+
#if defined(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT)
3227+
case SDL_TEXTEDITING_EXT: {
3228+
if( !ev.editExt.text ) {
3229+
break;
3230+
}
3231+
if( strlen( ev.editExt.text ) > 0 ) {
3232+
const unsigned lc = UTF8_getch( ev.editExt.text );
3233+
last_input = input_event( lc, input_event_t::keyboard_char );
3234+
} else {
3235+
// no key pressed in this event
3236+
last_input = input_event();
3237+
last_input.type = input_event_t::keyboard_char;
3238+
}
3239+
// Convert to string explicitly to avoid accidentally using
3240+
// a pointer that will be freed
3241+
last_input.edit = std::string( ev.editExt.text );
3242+
last_input.edit_refresh = true;
3243+
text_refresh = true;
3244+
SDL_free( ev.editExt.text );
3245+
break;
3246+
}
3247+
#endif
32123248
case SDL_CONTROLLERBUTTONDOWN:
32133249
case SDL_CONTROLLERBUTTONUP:
32143250
gamepad::handle_button_event( ev );

0 commit comments

Comments
 (0)