Dynamically load wintab32.dll
authorSam Lantinga
Tue, 26 Aug 2008 06:03:48 +0000
changeset 2726f23ebf1ddac4
parent 2725 6ce6d56b63bf
child 2727 76c2fc9696ea
Dynamically load wintab32.dll
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32keyboard.c
src/video/win32/SDL_win32mouse.c
src/video/win32/SDL_win32video.c
src/video/win32/SDL_win32video.h
src/video/win32/SDL_win32window.c
src/video/win32/wactab/pktdef.h
src/video/win32/wactab/wintab.h
src/video/win32/wactab/wintabx.h
     1.1 --- a/src/video/win32/SDL_win32events.c	Tue Aug 26 05:57:41 2008 +0000
     1.2 +++ b/src/video/win32/SDL_win32events.c	Tue Aug 26 06:03:48 2008 +0000
     1.3 @@ -136,7 +136,9 @@
     1.4      case WT_PACKET:
     1.5          {
     1.6              /* if we receive such data we need to update the pressure */
     1.7 -            if (WTPacket((HCTX) lParam, wParam, &packet)) {
     1.8 +            SDL_VideoData *videodata = data->videodata;
     1.9 +            if (videodata->wintabDLL
    1.10 +                && videodata->WTPacket((HCTX) lParam, wParam, &packet)) {
    1.11                  SDL_ChangeEnd(tablet, (int) packet.pkCursor);
    1.12                  pressure = (int) packet.pkNormalPressure;
    1.13              }
     2.1 --- a/src/video/win32/SDL_win32keyboard.c	Tue Aug 26 05:57:41 2008 +0000
     2.2 +++ b/src/video/win32/SDL_win32keyboard.c	Tue Aug 26 06:03:48 2008 +0000
     2.3 @@ -55,7 +55,8 @@
     2.4      /* Make sure the alpha scancodes are correct.  T isn't usually remapped */
     2.5      if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) {
     2.6  #if 0
     2.7 -        printf("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
     2.8 +        printf
     2.9 +            ("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    2.10  #endif
    2.11          for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
    2.12              alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC);
    2.13 @@ -66,7 +67,8 @@
    2.14      }
    2.15      if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
    2.16  #if 0
    2.17 -        printf("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    2.18 +        printf
    2.19 +            ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
    2.20  #endif
    2.21          for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
    2.22              keypad_scancodes[i] =
     3.1 --- a/src/video/win32/SDL_win32mouse.c	Tue Aug 26 05:57:41 2008 +0000
     3.2 +++ b/src/video/win32/SDL_win32mouse.c	Tue Aug 26 06:03:48 2008 +0000
     3.3 @@ -154,7 +154,7 @@
     3.4          l = SDL_strlen(device_name);
     3.5  
     3.6          /* we're checking if the device isn't by any chance a tablet */
     3.7 -        if (tablet == -1) {
     3.8 +        if (data->wintabDLL && tablet == -1) {
     3.9              for (j = 0; j < l - 5; ++j) {
    3.10                  for (k = 0; k < 5; ++k) {
    3.11                      if (tab[k] !=
    3.12 @@ -173,8 +173,8 @@
    3.13          if (tablet == index) {
    3.14              AXIS pressure;
    3.15              int cursors;
    3.16 -            WTInfo(WTI_DEVICES, DVC_NPRESSURE, &pressure);
    3.17 -            WTInfo(WTI_DEVICES, DVC_NCSRTYPES, &cursors);
    3.18 +            data->WTInfo(WTI_DEVICES, DVC_NPRESSURE, &pressure);
    3.19 +            data->WTInfo(WTI_DEVICES, DVC_NCSRTYPES, &cursors);
    3.20              data->mouse =
    3.21                  SDL_AddMouse(&mouse, index, device_name, pressure.axMax,
    3.22                               pressure.axMin, cursors);
     4.1 --- a/src/video/win32/SDL_win32video.c	Tue Aug 26 05:57:41 2008 +0000
     4.2 +++ b/src/video/win32/SDL_win32video.c	Tue Aug 26 06:03:48 2008 +0000
     4.3 @@ -60,6 +60,9 @@
     4.4          FreeLibrary(data->d3dDLL);
     4.5      }
     4.6  #endif
     4.7 +    if (data->wintabDLL) {
     4.8 +        FreeLibrary(data->wintabDLL);
     4.9 +    }
    4.10      SDL_free(device->driverdata);
    4.11      SDL_free(device);
    4.12  }
    4.13 @@ -104,6 +107,32 @@
    4.14      }
    4.15  #endif /* SDL_VIDEO_RENDER_D3D */
    4.16  
    4.17 +    data->wintabDLL = LoadLibrary(TEXT("WINTAB32.DLL"));
    4.18 +    if (data->wintabDLL) {
    4.19 +#define PROCNAME(X) #X
    4.20 +        data->WTInfo =
    4.21 +            (UINT(*)(UINT, UINT, LPVOID)) GetProcAddress(data->wintabDLL,
    4.22 +                                                         PROCNAME(WTInfo));
    4.23 +        data->WTOpen =
    4.24 +            (HCTX(*)(HWND, LPLOGCONTEXT, BOOL)) GetProcAddress(data->
    4.25 +                                                               wintabDLL,
    4.26 +                                                               PROCNAME
    4.27 +                                                               (WTOpen));
    4.28 +        data->WTPacket =
    4.29 +            (int (*)(HCTX, UINT, LPVOID)) GetProcAddress(data->wintabDLL,
    4.30 +                                                         PROCNAME(WTPacket));
    4.31 +        data->WTClose =
    4.32 +            (BOOL(*)(HCTX)) GetProcAddress(data->wintabDLL,
    4.33 +                                           PROCNAME(WTClose));
    4.34 +#undef PROCNAME
    4.35 +
    4.36 +        if (!data->WTInfo || !data->WTOpen || !data->WTPacket
    4.37 +            || !data->WTClose) {
    4.38 +            FreeLibrary(data->wintabDLL);
    4.39 +            data->wintabDLL = NULL;
    4.40 +        }
    4.41 +    }
    4.42 +
    4.43      /* Set the function pointers */
    4.44      device->VideoInit = WIN_VideoInit;
    4.45      device->VideoQuit = WIN_VideoQuit;
     5.1 --- a/src/video/win32/SDL_win32video.h	Tue Aug 26 05:57:41 2008 +0000
     5.2 +++ b/src/video/win32/SDL_win32video.h	Tue Aug 26 06:03:48 2008 +0000
     5.3 @@ -66,6 +66,15 @@
     5.4      HANDLE d3dDLL;
     5.5      IDirect3D9 *d3d;
     5.6  #endif
     5.7 +/* *INDENT-OFF* */
     5.8 +    /* Function pointers for the Wacom API */
     5.9 +    HANDLE wintabDLL;
    5.10 +    UINT (*WTInfo) (UINT, UINT, LPVOID);
    5.11 +    HCTX (*WTOpen) (HWND, LPLOGCONTEXT, BOOL);
    5.12 +    int (*WTPacket) (HCTX, UINT, LPVOID);
    5.13 +    BOOL (*WTClose) (HCTX);
    5.14 +/* *INDENT-ON* */
    5.15 +
    5.16      int mouse;
    5.17      int keyboard;
    5.18      SDL_scancode *key_layout;
     6.1 --- a/src/video/win32/SDL_win32window.c	Tue Aug 26 05:57:41 2008 +0000
     6.2 +++ b/src/video/win32/SDL_win32window.c	Tue Aug 26 06:03:48 2008 +0000
     6.3 @@ -148,6 +148,7 @@
     6.4  int
     6.5  WIN_CreateWindow(_THIS, SDL_Window * window)
     6.6  {
     6.7 +    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
     6.8      RAWINPUTDEVICE Rid;
     6.9      AXIS TabX, TabY;
    6.10      LOGCONTEXT lc;
    6.11 @@ -205,15 +206,15 @@
    6.12      }
    6.13  
    6.14      /* we're configuring the tablet data. See Wintab reference for more info */
    6.15 -    if (WTInfo(WTI_DEFSYSCTX, 0, &lc) != 0) {
    6.16 +    if (videodata->wintabDLL && videodata->WTInfo(WTI_DEFSYSCTX, 0, &lc) != 0) {
    6.17          lc.lcPktData = PACKETDATA;
    6.18          lc.lcPktMode = PACKETMODE;
    6.19          lc.lcOptions |= CXO_MESSAGES;
    6.20          lc.lcOptions |= CXO_SYSTEM;
    6.21          lc.lcMoveMask = PACKETDATA;
    6.22          lc.lcBtnDnMask = lc.lcBtnUpMask = PACKETDATA;
    6.23 -        WTInfo(WTI_DEVICES, DVC_X, &TabX);
    6.24 -        WTInfo(WTI_DEVICES, DVC_Y, &TabY);
    6.25 +        videodata->WTInfo(WTI_DEVICES, DVC_X, &TabX);
    6.26 +        videodata->WTInfo(WTI_DEVICES, DVC_Y, &TabY);
    6.27          lc.lcInOrgX = 0;
    6.28          lc.lcInOrgY = 0;
    6.29          lc.lcInExtX = TabX.axMax;
    6.30 @@ -234,7 +235,7 @@
    6.31              }
    6.32              g_hCtx = tmp_hctx;
    6.33          }
    6.34 -        g_hCtx[window->id] = WTOpen(hwnd, &lc, TRUE);
    6.35 +        g_hCtx[window->id] = videodata->WTOpen(hwnd, &lc, TRUE);
    6.36      }
    6.37  
    6.38      /* we're telling the window, we want it to report raw input events from mice */
    6.39 @@ -438,6 +439,7 @@
    6.40  void
    6.41  WIN_DestroyWindow(_THIS, SDL_Window * window)
    6.42  {
    6.43 +    SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
    6.44      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    6.45  
    6.46      if (data) {
    6.47 @@ -448,7 +450,9 @@
    6.48  #endif
    6.49          ReleaseDC(data->hwnd, data->hdc);
    6.50          if (data->created) {
    6.51 -            WTClose(g_hCtx[window->id]);
    6.52 +            if (videodata->wintabDLL) {
    6.53 +                videodata->WTClose(g_hCtx[window->id]);
    6.54 +            }
    6.55              DestroyWindow(data->hwnd);
    6.56          }
    6.57          SDL_free(data);
     7.1 --- a/src/video/win32/wactab/pktdef.h	Tue Aug 26 05:57:41 2008 +0000
     7.2 +++ b/src/video/win32/wactab/pktdef.h	Tue Aug 26 06:03:48 2008 +0000
     7.3 @@ -1,3 +1,4 @@
     7.4 +/* *INDENT-OFF* */
     7.5  /* -------------------------------- pktdef.h -------------------------------- */
     7.6  /* Combined 16 & 32-bit version. */
     7.7  
     8.1 --- a/src/video/win32/wactab/wintab.h	Tue Aug 26 05:57:41 2008 +0000
     8.2 +++ b/src/video/win32/wactab/wintab.h	Tue Aug 26 06:03:48 2008 +0000
     8.3 @@ -1,3 +1,4 @@
     8.4 +/* *INDENT-OFF* */
     8.5  /* -------------------------------- wintab.h -------------------------------- */
     8.6  /* Combined 16 & 32-bit version. */
     8.7  
     9.1 --- a/src/video/win32/wactab/wintabx.h	Tue Aug 26 05:57:41 2008 +0000
     9.2 +++ b/src/video/win32/wactab/wintabx.h	Tue Aug 26 06:03:48 2008 +0000
     9.3 @@ -1,3 +1,4 @@
     9.4 +/* *INDENT-OFF* */
     9.5  /* ------------------------------- wintabx.h -------------------------------- */
     9.6  /* Combined 16 & 32-bit version. */
     9.7