Skip to content

Commit

Permalink
Reapply DOSBox-X specific patches to SDL2 library
Browse files Browse the repository at this point in the history
  • Loading branch information
maron2000 committed Jul 1, 2024
1 parent b1de9c5 commit fcf88b8
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 39 deletions.
22 changes: 8 additions & 14 deletions vs/sdl2/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1620,22 +1620,16 @@ CheckNoErrorDeprecatedDeclarationsWerror()
dnl See if GCC's -Wdeclaration-after-statement is supported.
dnl This lets us catch things that would fail on a C89 compiler when using
dnl a modern GCC.
dnl EDIT 2023/04/01 DOSBox-X: We don't care about ancient compilers. A compiler
dnl that old doesn't support C++ and even if it did, it wouldn't be new enough
dnl for this code base. We have to disable this because this is preventing
dnl DOSBox-X from compiling with the latest XCode on ARM-based Macbooks because
dnl the *.m files have variable declarations after statements. At no point is
dnl this code going to compile itself like it's 1993. Come on guys. --J.C.
CheckDeclarationAfterStatement()
{
AC_MSG_CHECKING(for GCC -Wdeclaration-after-statement option)
have_gcc_declaration_after_statement=no

save_CFLAGS="$CFLAGS"
CFLAGS="$save_CFLAGS -Wdeclaration-after-statement -Werror=declaration-after-statement"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
int x = 0;
]],[])], [have_gcc_declaration_after_statement=yes],[])
AC_MSG_RESULT($have_gcc_declaration_after_statement)
CFLAGS="$save_CFLAGS"

if test x$have_gcc_declaration_after_statement = xyes; then
EXTRA_CFLAGS="$EXTRA_CFLAGS -Wdeclaration-after-statement -Werror=declaration-after-statement"
fi
dnl We don't care about C89 compilers.
true
}

dnl See if GCC's -Wall is supported.
Expand Down
4 changes: 4 additions & 0 deletions vs/sdl2/include/SDL_config_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ typedef unsigned int uintptr_t;
#define SDL_VIDEO_RENDER_D3D12 1
#endif

#if defined(__WIN32__) && (defined(__arm__) || defined(__arm64__) || defined(_M_ARM) || defined(_M_ARM64))
#define NO_OPENGL /* Don't enable for DOSBox-X on Windows ARM */
#else
/* Enable OpenGL support */
#ifndef SDL_VIDEO_OPENGL
#define SDL_VIDEO_OPENGL 1
Expand All @@ -318,6 +321,7 @@ typedef unsigned int uintptr_t;
#ifndef SDL_VIDEO_OPENGL_EGL
#define SDL_VIDEO_OPENGL_EGL 1
#endif
#endif

/* Enable Vulkan support */
#define SDL_VIDEO_VULKAN 1
Expand Down
1 change: 1 addition & 0 deletions vs/sdl2/include/SDL_keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ extern DECLSPEC const char *SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
* \sa SDL_GetScancodeName
*/
extern DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *name);
extern DECLSPEC SDL_bool SDLCALL SDL_IM_Composition(int more); // Added for DOSBox-X

/**
* Get a human-readable name for a key.
Expand Down
10 changes: 8 additions & 2 deletions vs/sdl2/include/SDL_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
#define main SDL_main
#endif

#ifdef __cplusplus
#define SDL_MAIN_NOEXCEPT noexcept(false) // Added for DOSBox-X
#else
#define SDL_MAIN_NOEXCEPT // Added for DOSBox-X
#endif

#include "begin_code.h"
#ifdef __cplusplus
extern "C" {
Expand All @@ -152,8 +158,8 @@ extern "C" {
* The prototype for the application's main() function
*/
typedef int (*SDL_main_func)(int argc, char *argv[]);
extern SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]);

//extern SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]);
extern SDLMAIN_DECLSPEC int SDL_main(int argc, char* argv[]) SDL_MAIN_NOEXCEPT; // Changed for DOSBox-X

/**
* Circumvent failure of SDL_Init() when not using SDL_main() as an entry
Expand Down
3 changes: 3 additions & 0 deletions vs/sdl2/include/SDL_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
extern "C" {
#endif

/* This is the DOSBox-X's modified SDL 2.x with IME support, not the general library */
#define SDL_DOSBOX_X_IME 1

/**
* Information about the version of SDL in use.
*
Expand Down
10 changes: 7 additions & 3 deletions vs/sdl2/src/joystick/windows/SDL_xinputjoystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,13 @@ static void UpdateXInputJoystickState(SDL_Joystick *joystick, XINPUT_STATE *pXIn

SDL_PrivateJoystickAxis(joystick, 0, pXInputState->Gamepad.sThumbLX);
SDL_PrivateJoystickAxis(joystick, 1, ~pXInputState->Gamepad.sThumbLY);
SDL_PrivateJoystickAxis(joystick, 2, ((int)pXInputState->Gamepad.bLeftTrigger * 257) - 32768);
SDL_PrivateJoystickAxis(joystick, 3, pXInputState->Gamepad.sThumbRX);
SDL_PrivateJoystickAxis(joystick, 4, ~pXInputState->Gamepad.sThumbRY);
//SDL_PrivateJoystickAxis(joystick, 2, ((int)pXInputState->Gamepad.bLeftTrigger * 257) - 32768);
//SDL_PrivateJoystickAxis(joystick, 3, pXInputState->Gamepad.sThumbRX);
//SDL_PrivateJoystickAxis(joystick, 4, ~pXInputState->Gamepad.sThumbRY);
// Fixes for DOSBox-X
SDL_PrivateJoystickAxis(joystick, 2, pXInputState->Gamepad.sThumbRX);
SDL_PrivateJoystickAxis(joystick, 3, ~pXInputState->Gamepad.sThumbRY);
SDL_PrivateJoystickAxis(joystick, 4, ((int)pXInputState->Gamepad.bLeftTrigger * 257) - 32768);
SDL_PrivateJoystickAxis(joystick, 5, ((int)pXInputState->Gamepad.bRightTrigger * 257) - 32768);

for (button = 0; button < (Uint8)SDL_arraysize(s_XInputButtons); ++button) {
Expand Down
72 changes: 70 additions & 2 deletions vs/sdl2/src/video/cocoa/SDL_cocoakeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,30 @@
/*#define DEBUG_IME NSLog */
#define DEBUG_IME(...)

#if 1 // inserted for DOSBox-X
@interface IMETextView : NSView
@property (nonatomic, copy) NSAttributedString *text;
@end

@implementation IMETextView
- (void)drawRect:(NSRect)dirtyRect
{
CGSize size;
[super drawRect:dirtyRect];
size = [_text size];
[[NSColor whiteColor] set];
NSRectFill(self.bounds);
[_text drawInRect:CGRectMake(0, 0, size.width, size.height)];
}
@end
#endif

@interface SDLTranslatorResponder : NSView <NSTextInputClient> {
NSString *_markedText;
NSRange _markedRange;
NSRange _selectedRange;
SDL_Rect _inputRect;
IMETextView *_markedLabel; // inserted for DOSBox-X
}
- (void)doCommandBySelector:(SEL)myselector;
- (void)setInputRect:(const SDL_Rect *)rect;
Expand Down Expand Up @@ -72,6 +91,8 @@ - (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
}

SDL_SendKeyboardText(str);
[_markedLabel setHidden:YES]; // inserted for DOSBox-X
_markedLabel.text = nil; // inserted for DOSBox-X
}

- (void)doCommandBySelector:(SEL)myselector
Expand All @@ -97,9 +118,21 @@ - (NSRange)selectedRange
return _selectedRange;
}

static SDL_bool ime_incompos = 0; // inserted for DOSBox-X
static long end_ticks = 0; // inserted for DOSBox-X

- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange
{
if ([aString isKindOfClass:[NSAttributedString class]]) {
#if 1 // inserted for DOSBox-X
CGSize size;
[aString addAttribute:NSFontAttributeName value:[NSFont systemFontOfSize:_inputRect.h] range:NSMakeRange(0, [aString length])];
_markedLabel.text = aString;
size = [aString size];
[_markedLabel setFrameSize:size];
[_markedLabel setHidden:NO];
[_markedLabel setNeedsDisplay:YES];
#endif
aString = [aString string];
}

Expand All @@ -124,11 +157,34 @@ - (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replaceme

- (void)unmarkText
{
_markedText = nil;

//[_markedText release]; // Maybe required for DOSBox-X
_markedText = nil;
[_markedLabel setHidden:YES]; // inserted for DOSBox-X
SDL_SendEditingText("", 0, 0);
}

#if 1 // inserted for DOSBox-X
#define IME_END_CR_WAIT 25
SDL_bool SDL_IM_Composition(int more) {
return ime_incompos||(end_ticks&&(TickCount()-end_ticks<IME_END_CR_WAIT*more)) ? SDL_TRUE : SDL_FALSE;
}

static int GetEnableIME()
{
TISInputSourceRef is = TISCopyCurrentKeyboardInputSource();
CFBooleanRef ret = (CFBooleanRef)TISGetInputSourceProperty(is, kTISPropertyInputSourceIsASCIICapable);
return CFBooleanGetValue(ret) ? 0 : 1;
}

- (void)keyboardInputSourceChanged:(NSNotification *)notification
{
if(!GetEnableIME()) {
[_markedLabel setHidden:YES];
[[NSTextInputContext currentInputContext] discardMarkedText];
}
}
#endif

- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
{
NSWindow *window = [self window];
Expand All @@ -145,6 +201,18 @@ - (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer
aRange.location, aRange.length, windowHeight,
NSStringFromRect(rect));

#if 1 // inserted for DOSBox-X
if(!_markedLabel) {
_markedLabel = [[IMETextView alloc] initWithFrame: NSMakeRect(0.0, 0.0, 0.0, 0.0)];
[[[self window] contentView] addSubview:_markedLabel];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardInputSourceChanged:)
name:NSTextInputContextKeyboardSelectionDidChangeNotification
object:nil];
}
[_markedLabel setFrameOrigin: NSMakePoint(_inputRect.x, windowHeight - _inputRect.y)];
#endif

rect = [window convertRectToScreen:rect];

return rect;
Expand Down
65 changes: 47 additions & 18 deletions vs/sdl2/src/video/windows/SDL_windowskeyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,27 @@
#include <oleauto.h>

#ifndef SDL_DISABLE_WINDOWS_IME
static Uint32 end_ticks = 0; // added for DOSBox-X
static SDL_bool ime_incompos; // added for DOSBox-X
static void IME_Init(SDL_VideoData *videodata, HWND hwnd);
static void IME_Enable(SDL_VideoData *videodata, HWND hwnd);
static void IME_Disable(SDL_VideoData *videodata, HWND hwnd);
static void IME_Quit(SDL_VideoData *videodata);
static SDL_bool IME_IsTextInputShown(SDL_VideoData *videodata);
#endif /* !SDL_DISABLE_WINDOWS_IME */

#if 1 // Added for DOSBox-X
SDL_bool SDL_IM_Composition(int more) {
(void)more;
#ifndef SDL_DISABLE_WINDOWS_IME
#define IME_END_CR_WAIT 50
return ime_incompos || end_ticks && (GetTickCount() - end_ticks < IME_END_CR_WAIT) ? SDL_TRUE : SDL_FALSE;
#else
return SDL_FALSE;
#endif
}
#endif

#ifndef MAPVK_VK_TO_VSC
#define MAPVK_VK_TO_VSC 0
#endif
Expand Down Expand Up @@ -249,27 +263,18 @@ void WIN_SetTextInputRect(_THIS, const SDL_Rect *rect)

himc = ImmGetContext(videodata->ime_hwnd_current);
if (himc) {
/* //reverted for DOSBox-X
COMPOSITIONFORM cof;
CANDIDATEFORM caf;

cof.dwStyle = CFS_RECT;
cof.ptCurrentPos.x = videodata->ime_rect.x;
cof.ptCurrentPos.y = videodata->ime_rect.y;
cof.rcArea.left = videodata->ime_rect.x;
cof.rcArea.right = (LONG)videodata->ime_rect.x + videodata->ime_rect.w;
cof.rcArea.top = videodata->ime_rect.y;
cof.rcArea.bottom = (LONG)videodata->ime_rect.y + videodata->ime_rect.h;
ImmSetCompositionWindow(himc, &cof);

caf.dwIndex = 0;
caf.dwStyle = CFS_EXCLUDE;
caf.ptCurrentPos.x = videodata->ime_rect.x;
caf.ptCurrentPos.y = videodata->ime_rect.y;
caf.rcArea.left = videodata->ime_rect.x;
caf.rcArea.right = (LONG)videodata->ime_rect.x + videodata->ime_rect.w;
caf.rcArea.top = videodata->ime_rect.y;
caf.rcArea.bottom = (LONG)videodata->ime_rect.y + videodata->ime_rect.h;
ImmSetCandidateWindow(himc, &caf);
*/
COMPOSITIONFORM cf;
cf.ptCurrentPos.x = videodata->ime_rect.x;
cf.ptCurrentPos.y = videodata->ime_rect.y;
cf.dwStyle = CFS_FORCE_POSITION;
ImmSetCompositionWindow(himc, &cf);

ImmReleaseContext(videodata->ime_hwnd_current, himc);
}
Expand Down Expand Up @@ -415,11 +420,14 @@ static void IME_Init(SDL_VideoData *videodata, HWND hwnd)
videodata->ime_available = SDL_TRUE;
IME_UpdateInputLocale(videodata);
IME_SetupAPI(videodata);
// Disabled because the candidate window will not be displayed. (for DOSBox-X)
/*
if (WIN_ShouldShowNativeUI()) {
videodata->ime_uiless = SDL_FALSE;
} else {
videodata->ime_uiless = UILess_SetupSinks(videodata);
}
*/
IME_UpdateInputLocale(videodata);
IME_Disable(videodata, hwnd);
}
Expand Down Expand Up @@ -1018,17 +1026,37 @@ SDL_bool IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, S
case WM_INPUTLANGCHANGE:
IME_InputLangChanged(videodata);
break;
#if 1 // added for DOSBox-X
case WM_IME_CHAR:
if(wParam == 0x20) {
// enable IME input space
PostMessage(hwnd, WM_KEYDOWN, 0x20, 0x390001);
}
else if(wParam == 0x3000) {
// input Zenkaku space
videodata->ime_composition[0] = 0x3000;
videodata->ime_composition[1] = 0;
IME_SendEditingEvent(videodata);
IME_SendInputEvent(videodata);
}
trap = SDL_TRUE;
break;
#endif
case WM_IME_SETCONTEXT:
// Disabled because the string being converted will not be displayed. (for DOSBox-X)
/*
if (videodata->ime_uiless) {
*lParam = 0;
}
break;
*/
case WM_IME_STARTCOMPOSITION:
videodata->ime_suppress_endcomposition_event = SDL_FALSE;
trap = SDL_TRUE;
ime_incompos = 1; /* added for DOSBox-X */
//trap = SDL_TRUE; /* disabled for DOSBox-X */
break;
case WM_IME_COMPOSITION:
trap = SDL_TRUE;
//trap = SDL_TRUE; /* disabled for DOSBox-X */
himc = ImmGetContext(hwnd);
if (*lParam & GCS_RESULTSTR) {
videodata->ime_suppress_endcomposition_event = SDL_TRUE;
Expand All @@ -1047,6 +1075,7 @@ SDL_bool IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, S
ImmReleaseContext(hwnd, himc);
break;
case WM_IME_ENDCOMPOSITION:
ime_incompos = 0; /* added for DOSBox-X */
videodata->ime_uicontext = 0;
videodata->ime_composition[0] = 0;
videodata->ime_readingstring[0] = 0;
Expand Down

0 comments on commit fcf88b8

Please sign in to comment.