From 93c32a5170ac0312fa164d3091f8a41235dbc3aa Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 26 Aug 2008 06:03:48 +0000 Subject: [PATCH] Dynamically load wintab32.dll --- src/video/win32/SDL_win32events.c | 4 +++- src/video/win32/SDL_win32keyboard.c | 6 ++++-- src/video/win32/SDL_win32mouse.c | 6 +++--- src/video/win32/SDL_win32video.c | 29 +++++++++++++++++++++++++++++ src/video/win32/SDL_win32video.h | 9 +++++++++ src/video/win32/SDL_win32window.c | 14 +++++++++----- src/video/win32/wactab/pktdef.h | 1 + src/video/win32/wactab/wintab.h | 1 + src/video/win32/wactab/wintabx.h | 1 + 9 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/video/win32/SDL_win32events.c b/src/video/win32/SDL_win32events.c index 90a3e18b4..a84b0c25a 100644 --- a/src/video/win32/SDL_win32events.c +++ b/src/video/win32/SDL_win32events.c @@ -136,7 +136,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WT_PACKET: { /* if we receive such data we need to update the pressure */ - if (WTPacket((HCTX) lParam, wParam, &packet)) { + SDL_VideoData *videodata = data->videodata; + if (videodata->wintabDLL + && videodata->WTPacket((HCTX) lParam, wParam, &packet)) { SDL_ChangeEnd(tablet, (int) packet.pkCursor); pressure = (int) packet.pkNormalPressure; } diff --git a/src/video/win32/SDL_win32keyboard.c b/src/video/win32/SDL_win32keyboard.c index 2b06e45b5..7cba3bb95 100644 --- a/src/video/win32/SDL_win32keyboard.c +++ b/src/video/win32/SDL_win32keyboard.c @@ -55,7 +55,8 @@ WIN_InitKeyboard(_THIS) /* Make sure the alpha scancodes are correct. T isn't usually remapped */ if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) { #if 0 - printf("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list , including a description of your keyboard hardware.\n"); + printf + ("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list , including a description of your keyboard hardware.\n"); #endif for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) { alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC); @@ -66,7 +67,8 @@ WIN_InitKeyboard(_THIS) } if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) { #if 0 - printf("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list , including a description of your keyboard hardware.\n"); + printf + ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list , including a description of your keyboard hardware.\n"); #endif for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) { keypad_scancodes[i] = diff --git a/src/video/win32/SDL_win32mouse.c b/src/video/win32/SDL_win32mouse.c index b43fedb77..9b9aacf66 100644 --- a/src/video/win32/SDL_win32mouse.c +++ b/src/video/win32/SDL_win32mouse.c @@ -154,7 +154,7 @@ WIN_InitMouse(_THIS) l = SDL_strlen(device_name); /* we're checking if the device isn't by any chance a tablet */ - if (tablet == -1) { + if (data->wintabDLL && tablet == -1) { for (j = 0; j < l - 5; ++j) { for (k = 0; k < 5; ++k) { if (tab[k] != @@ -173,8 +173,8 @@ WIN_InitMouse(_THIS) if (tablet == index) { AXIS pressure; int cursors; - WTInfo(WTI_DEVICES, DVC_NPRESSURE, &pressure); - WTInfo(WTI_DEVICES, DVC_NCSRTYPES, &cursors); + data->WTInfo(WTI_DEVICES, DVC_NPRESSURE, &pressure); + data->WTInfo(WTI_DEVICES, DVC_NCSRTYPES, &cursors); data->mouse = SDL_AddMouse(&mouse, index, device_name, pressure.axMax, pressure.axMin, cursors); diff --git a/src/video/win32/SDL_win32video.c b/src/video/win32/SDL_win32video.c index 215093473..29cdfe76a 100644 --- a/src/video/win32/SDL_win32video.c +++ b/src/video/win32/SDL_win32video.c @@ -60,6 +60,9 @@ WIN_DeleteDevice(SDL_VideoDevice * device) FreeLibrary(data->d3dDLL); } #endif + if (data->wintabDLL) { + FreeLibrary(data->wintabDLL); + } SDL_free(device->driverdata); SDL_free(device); } @@ -104,6 +107,32 @@ WIN_CreateDevice(int devindex) } #endif /* SDL_VIDEO_RENDER_D3D */ + data->wintabDLL = LoadLibrary(TEXT("WINTAB32.DLL")); + if (data->wintabDLL) { +#define PROCNAME(X) #X + data->WTInfo = + (UINT(*)(UINT, UINT, LPVOID)) GetProcAddress(data->wintabDLL, + PROCNAME(WTInfo)); + data->WTOpen = + (HCTX(*)(HWND, LPLOGCONTEXT, BOOL)) GetProcAddress(data-> + wintabDLL, + PROCNAME + (WTOpen)); + data->WTPacket = + (int (*)(HCTX, UINT, LPVOID)) GetProcAddress(data->wintabDLL, + PROCNAME(WTPacket)); + data->WTClose = + (BOOL(*)(HCTX)) GetProcAddress(data->wintabDLL, + PROCNAME(WTClose)); +#undef PROCNAME + + if (!data->WTInfo || !data->WTOpen || !data->WTPacket + || !data->WTClose) { + FreeLibrary(data->wintabDLL); + data->wintabDLL = NULL; + } + } + /* Set the function pointers */ device->VideoInit = WIN_VideoInit; device->VideoQuit = WIN_VideoQuit; diff --git a/src/video/win32/SDL_win32video.h b/src/video/win32/SDL_win32video.h index ff449fdf6..095d7a562 100644 --- a/src/video/win32/SDL_win32video.h +++ b/src/video/win32/SDL_win32video.h @@ -66,6 +66,15 @@ typedef struct SDL_VideoData HANDLE d3dDLL; IDirect3D9 *d3d; #endif +/* *INDENT-OFF* */ + /* Function pointers for the Wacom API */ + HANDLE wintabDLL; + UINT (*WTInfo) (UINT, UINT, LPVOID); + HCTX (*WTOpen) (HWND, LPLOGCONTEXT, BOOL); + int (*WTPacket) (HCTX, UINT, LPVOID); + BOOL (*WTClose) (HCTX); +/* *INDENT-ON* */ + int mouse; int keyboard; SDL_scancode *key_layout; diff --git a/src/video/win32/SDL_win32window.c b/src/video/win32/SDL_win32window.c index c1683803a..f4122cc1a 100644 --- a/src/video/win32/SDL_win32window.c +++ b/src/video/win32/SDL_win32window.c @@ -148,6 +148,7 @@ SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) int WIN_CreateWindow(_THIS, SDL_Window * window) { + SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; RAWINPUTDEVICE Rid; AXIS TabX, TabY; LOGCONTEXT lc; @@ -205,15 +206,15 @@ WIN_CreateWindow(_THIS, SDL_Window * window) } /* we're configuring the tablet data. See Wintab reference for more info */ - if (WTInfo(WTI_DEFSYSCTX, 0, &lc) != 0) { + if (videodata->wintabDLL && videodata->WTInfo(WTI_DEFSYSCTX, 0, &lc) != 0) { lc.lcPktData = PACKETDATA; lc.lcPktMode = PACKETMODE; lc.lcOptions |= CXO_MESSAGES; lc.lcOptions |= CXO_SYSTEM; lc.lcMoveMask = PACKETDATA; lc.lcBtnDnMask = lc.lcBtnUpMask = PACKETDATA; - WTInfo(WTI_DEVICES, DVC_X, &TabX); - WTInfo(WTI_DEVICES, DVC_Y, &TabY); + videodata->WTInfo(WTI_DEVICES, DVC_X, &TabX); + videodata->WTInfo(WTI_DEVICES, DVC_Y, &TabY); lc.lcInOrgX = 0; lc.lcInOrgY = 0; lc.lcInExtX = TabX.axMax; @@ -234,7 +235,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window) } g_hCtx = tmp_hctx; } - g_hCtx[window->id] = WTOpen(hwnd, &lc, TRUE); + g_hCtx[window->id] = videodata->WTOpen(hwnd, &lc, TRUE); } /* we're telling the window, we want it to report raw input events from mice */ @@ -438,6 +439,7 @@ WIN_SetWindowGrab(_THIS, SDL_Window * window) void WIN_DestroyWindow(_THIS, SDL_Window * window) { + SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; SDL_WindowData *data = (SDL_WindowData *) window->driverdata; if (data) { @@ -448,7 +450,9 @@ WIN_DestroyWindow(_THIS, SDL_Window * window) #endif ReleaseDC(data->hwnd, data->hdc); if (data->created) { - WTClose(g_hCtx[window->id]); + if (videodata->wintabDLL) { + videodata->WTClose(g_hCtx[window->id]); + } DestroyWindow(data->hwnd); } SDL_free(data); diff --git a/src/video/win32/wactab/pktdef.h b/src/video/win32/wactab/pktdef.h index 2c352b1e2..4c8f573d8 100644 --- a/src/video/win32/wactab/pktdef.h +++ b/src/video/win32/wactab/pktdef.h @@ -1,3 +1,4 @@ +/* *INDENT-OFF* */ /* -------------------------------- pktdef.h -------------------------------- */ /* Combined 16 & 32-bit version. */ diff --git a/src/video/win32/wactab/wintab.h b/src/video/win32/wactab/wintab.h index e94e50d4b..d1f495e8e 100644 --- a/src/video/win32/wactab/wintab.h +++ b/src/video/win32/wactab/wintab.h @@ -1,3 +1,4 @@ +/* *INDENT-OFF* */ /* -------------------------------- wintab.h -------------------------------- */ /* Combined 16 & 32-bit version. */ diff --git a/src/video/win32/wactab/wintabx.h b/src/video/win32/wactab/wintabx.h index b913ba670..7bd4ef18e 100644 --- a/src/video/win32/wactab/wintabx.h +++ b/src/video/win32/wactab/wintabx.h @@ -1,3 +1,4 @@ +/* *INDENT-OFF* */ /* ------------------------------- wintabx.h -------------------------------- */ /* Combined 16 & 32-bit version. */