From 0ea8bf17fa1df2b18d8d3a9fda56db472da94948 Mon Sep 17 00:00:00 2001 From: Peter Urbanec Date: Thu, 3 Mar 2011 19:26:33 +1100 Subject: [PATCH] wintab32: Better handling of XInput initialisation errors. --- dlls/winex11.drv/wintab.c | 16 ++++++++++------ dlls/wintab32/context.c | 31 +++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/dlls/winex11.drv/wintab.c b/dlls/winex11.drv/wintab.c index 7d7bfcc02cc..7a9e749b585 100644 --- a/dlls/winex11.drv/wintab.c +++ b/dlls/winex11.drv/wintab.c @@ -484,7 +484,7 @@ static void disable_system_cursors(void) /*********************************************************************** * X11DRV_LoadTabletInfo (X11DRV.@) */ -void CDECL X11DRV_LoadTabletInfo(HWND hwnddefault) +BOOL CDECL X11DRV_LoadTabletInfo(HWND hwnddefault) { const WCHAR SZ_CONTEXT_NAME[] = {'W','i','n','e',' ','T','a','b','l','e','t',' ','C','o','n','t','e','x','t',0}; const WCHAR SZ_DEVICE_NAME[] = {'W','i','n','e',' ','T','a','b','l','e','t',' ','D','e','v','i','c','e',0}; @@ -507,7 +507,7 @@ void CDECL X11DRV_LoadTabletInfo(HWND hwnddefault) if (!X11DRV_XInput_Init()) { ERR("Unable to initialize the XInput library.\n"); - return; + return FALSE; } hwndTabletDefault = hwnddefault; @@ -555,9 +555,9 @@ void CDECL X11DRV_LoadTabletInfo(HWND hwnddefault) devices = pXListInputDevices(data->display, &num_devices); if (!devices) { - WARN("XInput Extensions reported as not avalable\n"); + WARN("XInput Extensions reported as not available\n"); wine_tsx11_unlock(); - return; + return FALSE; } TRACE("XListInputDevices reports %d devices\n", num_devices); for (loop=0; loop < num_devices; loop++) @@ -778,6 +778,7 @@ void CDECL X11DRV_LoadTabletInfo(HWND hwnddefault) } wine_tsx11_unlock(); + return TRUE; } static int figure_deg(int x, int y) @@ -971,7 +972,7 @@ int CDECL X11DRV_AttachEventQueueToTablet(HWND hOwner) XEventClass event_list[7]; Window win = X11DRV_get_whole_window( hOwner ); - if (!win) return 0; + if (!win || !xinput_handle) return 0; TRACE("Creating context for window %p (%lx) %i cursors\n", hOwner, win, gNumCursors); @@ -1080,6 +1081,8 @@ UINT CDECL X11DRV_WTInfoW(UINT wCategory, UINT nIndex, LPVOID lpOutput) LPWTI_CURSORS_INFO tgtcursor; TRACE("(%u, %u, %p)\n", wCategory, nIndex, lpOutput); + if (!xinput_handle) return 0; + switch(wCategory) { case 0: @@ -1512,8 +1515,9 @@ int CDECL X11DRV_GetCurrentPacket(LPWTPACKET packet) /*********************************************************************** * LoadTabletInfo (X11DRV.@) */ -void CDECL X11DRV_LoadTabletInfo(HWND hwnddefault) +BOOL CDECL X11DRV_LoadTabletInfo(HWND hwnddefault) { + return FALSE; } /*********************************************************************** diff --git a/dlls/wintab32/context.c b/dlls/wintab32/context.c index 30f00216c81..c8940b38da6 100644 --- a/dlls/wintab32/context.c +++ b/dlls/wintab32/context.c @@ -42,7 +42,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(wintab32); * http://www.csl.sony.co.jp/projects/ar/restricted/wintabl.html */ -static BOOL gLoaded; static LPOPENCONTEXT gOpenContexts; static HCTX gTopContext = (HCTX)0xc00; @@ -151,12 +150,26 @@ static LPOPENCONTEXT TABLET_FindOpenContext(HCTX hCtx) return NULL; } -static void LoadTablet(void) +static inline BOOL LoadTablet(void) { - TRACE("Initializing the tablet to hwnd %p\n",hwndDefault); - gLoaded= TRUE; - if (pLoadTabletInfo) - pLoadTabletInfo(hwndDefault); + static enum {TI_START = 0, TI_OK, TI_FAIL} loaded = TI_START; + + if (loaded == TI_START) + { + TRACE("Initializing the tablet to hwnd %p\n",hwndDefault); + + if (pLoadTabletInfo && pLoadTabletInfo(hwndDefault)) + { + loaded = TI_OK; + } + else + { + loaded = TI_FAIL; + ERR("LoadTabletInfo(%p) failed\n", hwndDefault); + } + } + + return loaded == TI_OK; } int TABLET_PostTabletMessage(LPOPENCONTEXT newcontext, UINT msg, WPARAM wParam, @@ -366,9 +379,9 @@ static UINT WTInfoT(UINT wCategory, UINT nIndex, LPVOID lpOutput, BOOL bUnicode) { UINT result; + if (!LoadTablet()) return 0; + TRACE("(%d, %d, %p, %d)\n", wCategory, nIndex, lpOutput, bUnicode); - if (gLoaded == FALSE) - LoadTablet(); /* * Handle system extents here, as we can use user32.dll code to set them. @@ -450,6 +463,8 @@ HCTX WINAPI WTOpenW(HWND hWnd, LPLOGCONTEXTW lpLogCtx, BOOL fEnable) { LPOPENCONTEXT newcontext; + if (!LoadTablet()) return 0; + TRACE("hWnd=%p, lpLogCtx=%p, fEnable=%u\n", hWnd, lpLogCtx, fEnable); DUMPCONTEXT(*lpLogCtx);