1
1

Compare commits

...

1 Commits

Author SHA1 Message Date
98f3090952 Add debugging info for Wintab. 2021-06-22 17:47:22 -07:00
5 changed files with 226 additions and 0 deletions

View File

@@ -52,6 +52,13 @@
# define GHOST_PRINTF(x, ...)
#endif // WITH_GHOST_DEBUG
#include <stdio.h> //for printf()
#define WINTAB_PRINTF(x, ...) \
{ \
printf(x, __VA_ARGS__); \
} \
(void)0
#ifdef WITH_ASSERT_ABORT
# include <stdio.h> //for fprintf()
# include <stdlib.h> //for abort()

View File

@@ -876,6 +876,13 @@ GHOST_EventButton *GHOST_SystemWin32::processButtonEvent(GHOST_TEventType type,
int msgPosY = GET_Y_LPARAM(msgPos);
system->pushEvent(new GHOST_EventCursor(
::GetMessageTime(), GHOST_kEventCursorMove, window, msgPosX, msgPosY, td));
if (type == GHOST_kEventButtonDown) {
WINTAB_PRINTF("%p OS button down\n", window->getHWND());
}
else if (type == GHOST_kEventButtonUp) {
WINTAB_PRINTF("%p OS button up\n", window->getHWND());
}
}
window->updateMouseCapture(type == GHOST_kEventButtonDown ? MousePressed : MouseReleased);
@@ -918,6 +925,8 @@ void GHOST_SystemWin32::processWintabEvent(GHOST_WindowWin32 *window)
break;
}
case GHOST_kEventButtonDown: {
WINTAB_PRINTF("%p wintab button down", window->getHWND());
UINT message;
switch (info.button) {
case GHOST_kButtonMaskLeft:
@@ -945,6 +954,11 @@ void GHOST_SystemWin32::processWintabEvent(GHOST_WindowWin32 *window)
if (!useWintabPos) {
continue;
}
else {
WINTAB_PRINTF(" ... but associated to system button mismatched position\n");
}
WINTAB_PRINTF(" ... associated to system button\n");
/* Steal the Win32 event which was previously peeked. */
PeekMessage(&msg, window->getHWND(), message, message, PM_REMOVE | PM_NOYIELD);
@@ -962,9 +976,14 @@ void GHOST_SystemWin32::processWintabEvent(GHOST_WindowWin32 *window)
mouseMoveHandled = true;
break;
}
else {
WINTAB_PRINTF(" ... but no system button\n");
}
}
case GHOST_kEventButtonUp: {
WINTAB_PRINTF("%p wintab button up", window->getHWND());
if (!useWintabPos) {
WINTAB_PRINTF(" ... but Wintab position isn't trusted\n");
continue;
}
@@ -990,10 +1009,14 @@ void GHOST_SystemWin32::processWintabEvent(GHOST_WindowWin32 *window)
if (PeekMessage(&msg, window->getHWND(), message, message, PM_REMOVE | PM_NOYIELD) &&
msg.message != WM_QUIT) {
WINTAB_PRINTF(" ... associated to system button\n");
window->updateMouseCapture(MouseReleased);
system->pushEvent(
new GHOST_EventButton(info.time, info.type, window, info.button, info.tabletData));
}
else {
WINTAB_PRINTF(" ... but no system button\n");
}
break;
}
default:
@@ -1584,6 +1607,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
// Wintab events, processed
////////////////////////////////////////////////////////////////////////
case WT_CSRCHANGE: {
WINTAB_PRINTF("%p WT_CSRCHANGE\n", window->getHWND());
GHOST_Wintab *wt = window->getWintab();
if (wt) {
wt->updateCursorInfo();
@@ -1592,6 +1616,12 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
break;
}
case WT_PROXIMITY: {
WINTAB_PRINTF(
"%p WT_PROXIMITY loword (!0 enter 0 leave context): %d, hiword (!0 enter !0 leave "
"hardware): %d\n",
window->getHWND(),
LOWORD(lParam),
HIWORD(lParam));
GHOST_Wintab *wt = window->getWintab();
if (wt) {
bool inRange = LOWORD(lParam);
@@ -1607,6 +1637,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
break;
}
case WT_INFOCHANGE: {
WINTAB_PRINTF("%p WT_INFOCHANGE\n", window->getHWND());
GHOST_Wintab *wt = window->getWintab();
if (wt) {
wt->processInfoChange(lParam);
@@ -1623,6 +1654,31 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
eventHandled = true;
break;
////////////////////////////////////////////////////////////////////////
// Wintab events, debug
////////////////////////////////////////////////////////////////////////
case WT_CTXOPEN:
WINTAB_PRINTF("%p WT_CTXOPEN\n", window->getHWND());
break;
case WT_CTXCLOSE:
WINTAB_PRINTF("%p WT_CTXCLOSE\n", window->getHWND());
break;
case WT_CTXUPDATE:
WINTAB_PRINTF("%p WT_CTXUPDATE\n", window->getHWND());
break;
case WT_CTXOVERLAP:
switch (lParam) {
case CXS_DISABLED:
WINTAB_PRINTF("%p WT_CTXOVERLAP CXS_DISABLED\n", window->getHWND());
break;
case CXS_OBSCURED:
WINTAB_PRINTF("%p WT_CTXOVERLAP CXS_OBSCURED\n", window->getHWND());
break;
case CXS_ONTOP:
WINTAB_PRINTF("%p WT_CTXOVERLAP CXS_ONTOP\n", window->getHWND());
break;
}
break;
////////////////////////////////////////////////////////////////////////
// Pointer events, processed
////////////////////////////////////////////////////////////////////////
case WM_POINTERUPDATE:
@@ -1683,6 +1739,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
break;
case WM_MOUSEMOVE:
if (!window->m_mousePresent) {
WINTAB_PRINTF("%p mouse enter\n", window->getHWND());
TRACKMOUSEEVENT tme = {sizeof(tme)};
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwnd;
@@ -1731,6 +1788,7 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
}
break;
case WM_MOUSELEAVE: {
WINTAB_PRINTF("%p mouse leave\n", window->getHWND());
window->m_mousePresent = false;
if (window->getTabletData().Active == GHOST_kTabletModeNone) {
processCursorEvent(window);

View File

@@ -938,6 +938,7 @@ GHOST_Wintab *GHOST_WindowWin32::getWintab() const
void GHOST_WindowWin32::loadWintab(bool enable)
{
if (!m_wintab) {
WINTAB_PRINTF("Loading Wintab for window %p\n", m_hWnd);
if (m_wintab = GHOST_Wintab::loadWintab(m_hWnd)) {
if (enable) {
m_wintab->enable();
@@ -960,6 +961,7 @@ void GHOST_WindowWin32::loadWintab(bool enable)
void GHOST_WindowWin32::closeWintab()
{
WINTAB_PRINTF("Closing Wintab for window %p\n", m_hWnd);
delete m_wintab;
m_wintab = NULL;
}

View File

@@ -21,6 +21,7 @@
#define _USE_MATH_DEFINES
#include "GHOST_Wintab.h"
#include "GHOST_Debug.h"
GHOST_Wintab *GHOST_Wintab::loadWintab(HWND hwnd)
{
@@ -130,6 +131,11 @@ GHOST_Wintab *GHOST_Wintab::loadWintab(HWND hwnd)
}
}
int sanityQueueSize = queueSizeGet(hctx.get());
WINTAB_PRINTF("initializeWintab queueSize: %d, queueSizeGet: %d\n", queueSize, sanityQueueSize);
WINTAB_PRINTF("Loaded Wintab context %p\n", hctx.get());
return new GHOST_Wintab(hwnd,
std::move(handle),
info,
@@ -200,6 +206,51 @@ GHOST_Wintab::GHOST_Wintab(HWND hwnd,
{
m_fpInfo(WTI_INTERFACE, IFC_NDEVICES, &m_numDevices);
updateCursorInfo();
/* Debug info. */
WINTAB_PRINTF("initializeWintab numDevices: %d\n", m_numDevices);
UINT maxcontexts, opencontexts;
m_fpInfo(WTI_INTERFACE, IFC_NCONTEXTS, &maxcontexts);
m_fpInfo(WTI_STATUS, STA_CONTEXTS, &opencontexts);
WINTAB_PRINTF("%u max contexts, %u open contexts\n", maxcontexts, opencontexts);
/* Print button maps. */
BYTE logicalButtons[32] = {0};
BYTE systemButtons[32] = {0};
for (int i = 0; i < 3; i++) {
WINTAB_PRINTF("initializeWintab cursor %d buttons\n", i);
UINT lbut = m_fpInfo(WTI_CURSORS + i, CSR_BUTTONMAP, &logicalButtons);
if (lbut) {
WINTAB_PRINTF("%d", logicalButtons[0]);
for (int j = 1; j < lbut; j++) {
WINTAB_PRINTF(", %d", logicalButtons[j]);
}
WINTAB_PRINTF("\n");
}
else {
WINTAB_PRINTF("logical button error\n");
}
UINT sbut = m_fpInfo(WTI_CURSORS + i, CSR_SYSBTNMAP, &systemButtons);
if (sbut) {
WINTAB_PRINTF("%d", systemButtons[0]);
for (int j = 1; j < sbut; j++) {
WINTAB_PRINTF(", %d", systemButtons[j]);
}
WINTAB_PRINTF("\n");
}
else {
WINTAB_PRINTF("system button error\n");
}
}
printContextInfo();
}
GHOST_Wintab::~GHOST_Wintab()
{
WINTAB_PRINTF("Closing Wintab context %p\n", m_context.get());
}
void GHOST_Wintab::enable()
@@ -265,6 +316,7 @@ void GHOST_Wintab::updateCursorInfo()
BOOL pressureSupport = m_fpInfo(WTI_DEVICES, DVC_NPRESSURE, &Pressure);
m_maxPressure = pressureSupport ? Pressure.axMax : 0;
WINTAB_PRINTF("cursorInfo maxPressure: %d\n", m_maxPressure);
BOOL tiltSupport = m_fpInfo(WTI_DEVICES, DVC_ORIENTATION, &Orientation);
/* Check if tablet supports azimuth [0] and altitude [1], encoded in axResolution. */
@@ -275,12 +327,14 @@ void GHOST_Wintab::updateCursorInfo()
else {
m_maxAzimuth = m_maxAltitude = 0;
}
WINTAB_PRINTF("cursorInfo maxAzimuth: %d, maxAltitude: %d\n", m_maxAzimuth, m_maxAltitude);
}
void GHOST_Wintab::processInfoChange(LPARAM lParam)
{
/* Update number of connected Wintab digitizers. */
if (LOWORD(lParam) == WTI_INTERFACE && HIWORD(lParam) == IFC_NDEVICES) {
WINTAB_PRINTF("%p processWintabInfoChangeEvent numDevices: %d\n", m_numDevices);
m_fpInfo(WTI_INTERFACE, IFC_NDEVICES, &m_numDevices);
}
}
@@ -489,3 +543,104 @@ bool GHOST_Wintab::testCoordinates(int sysX, int sysY, int wtX, int wtY)
return false;
}
}
void GHOST_Wintab::printContextInfo()
{
LOGCONTEXT debuglc;
m_fpInfo(WTI_DEFSYSCTX, 0, &debuglc);
/* Print system context. */
WINTAB_PRINTF("lcOutOrgX: %d, lcOutOrgY: %d, lcOutExtX: %d, lcOutExtY: %d\n",
debuglc.lcOutOrgX,
debuglc.lcOutOrgY,
debuglc.lcOutExtX,
debuglc.lcOutExtY);
WINTAB_PRINTF("lcInOrgX: %d, lcInOrgY: %d, lcInExtX: %d, lcInExtY: %d\n",
debuglc.lcInOrgX,
debuglc.lcInOrgY,
debuglc.lcInExtX,
debuglc.lcInExtY);
WINTAB_PRINTF("lcSysOrgX: %d, lcSysOrgY: %d, lcSysExtX: %d, lcSysExtY: %d\n",
debuglc.lcSysOrgX,
debuglc.lcSysOrgY,
debuglc.lcSysExtX,
debuglc.lcSysExtY);
WINTAB_PRINTF("left: %d, top: %d, width: %d, height: %d\n",
::GetSystemMetrics(SM_XVIRTUALSCREEN),
::GetSystemMetrics(SM_YVIRTUALSCREEN),
::GetSystemMetrics(SM_CXVIRTUALSCREEN),
::GetSystemMetrics(SM_CYVIRTUALSCREEN));
/* Print system context, manually populated. */
m_fpInfo(WTI_DEFSYSCTX, CTX_OUTORGX, &debuglc.lcOutOrgX);
m_fpInfo(WTI_DEFSYSCTX, CTX_OUTORGY, &debuglc.lcOutOrgY);
m_fpInfo(WTI_DEFSYSCTX, CTX_OUTEXTX, &debuglc.lcOutExtX);
m_fpInfo(WTI_DEFSYSCTX, CTX_OUTEXTY, &debuglc.lcOutExtY);
m_fpInfo(WTI_DEFSYSCTX, CTX_SYSORGX, &debuglc.lcSysOrgX);
m_fpInfo(WTI_DEFSYSCTX, CTX_SYSORGY, &debuglc.lcSysOrgY);
m_fpInfo(WTI_DEFSYSCTX, CTX_SYSEXTX, &debuglc.lcSysExtX);
m_fpInfo(WTI_DEFSYSCTX, CTX_SYSEXTY, &debuglc.lcSysExtY);
WINTAB_PRINTF("index def lcOutOrgX: %d, lcOutOrgY: %d, lcOutExtX: %d, lcOutExtY: %d\n",
debuglc.lcOutOrgX,
debuglc.lcOutOrgY,
debuglc.lcOutExtX,
debuglc.lcOutExtY);
WINTAB_PRINTF("index def lcSysOrgX: %d, lcSysOrgY: %d, lcSysExtX: %d, lcSysExtY: %d\n",
debuglc.lcSysOrgX,
debuglc.lcSysOrgY,
debuglc.lcSysExtX,
debuglc.lcSysExtY);
for (unsigned int i = 0; i < m_numDevices; i++) {
/* Print individual device system context. */
m_fpInfo(WTI_DSCTXS + i, 0, &debuglc);
WINTAB_PRINTF("dev %d lcOutOrgX: %d, lcOutOrgY: %d, lcOutExtX: %d, lcOutExtY: %d\n",
i,
debuglc.lcOutOrgX,
debuglc.lcOutOrgY,
debuglc.lcOutExtX,
debuglc.lcOutExtY);
WINTAB_PRINTF("dev %d lcSysOrgX: %d, lcSysOrgY: %d, lcSysExtX: %d, lcSysExtY: %d\n",
i,
debuglc.lcSysOrgX,
debuglc.lcSysOrgY,
debuglc.lcSysExtX,
debuglc.lcSysExtY);
/* Print individual device system context, manually populated. */
m_fpInfo(WTI_DSCTXS + i, CTX_OUTORGX, &debuglc.lcOutOrgX);
m_fpInfo(WTI_DSCTXS + i, CTX_OUTORGY, &debuglc.lcOutOrgY);
m_fpInfo(WTI_DSCTXS + i, CTX_OUTEXTX, &debuglc.lcOutExtX);
m_fpInfo(WTI_DSCTXS + i, CTX_OUTEXTY, &debuglc.lcOutExtY);
m_fpInfo(WTI_DSCTXS + i, CTX_SYSORGX, &debuglc.lcSysOrgX);
m_fpInfo(WTI_DSCTXS + i, CTX_SYSORGY, &debuglc.lcSysOrgY);
m_fpInfo(WTI_DSCTXS + i, CTX_SYSEXTX, &debuglc.lcSysExtX);
m_fpInfo(WTI_DSCTXS + i, CTX_SYSEXTY, &debuglc.lcSysExtY);
WINTAB_PRINTF("index def dev %d lcOutOrgX: %d, lcOutOrgY: %d, lcOutExtX: %d, lcOutExtY: %d\n",
i,
debuglc.lcOutOrgX,
debuglc.lcOutOrgY,
debuglc.lcOutExtX,
debuglc.lcOutExtY);
WINTAB_PRINTF("index def dev %d lcSysOrgX: %d, lcSysOrgY: %d, lcSysExtX: %d, lcSysExtY: %d\n",
i,
debuglc.lcSysOrgX,
debuglc.lcSysOrgY,
debuglc.lcSysExtX,
debuglc.lcSysExtY);
/* Print device axis. */
AXIS axis_x, axis_y;
m_fpInfo(WTI_DEVICES + i, DVC_X, &axis_x);
m_fpInfo(WTI_DEVICES + i, DVC_Y, &axis_y);
WINTAB_PRINTF("dev %d axis_x org: %d, axis_y org: %d axis_x ext: %d, axis_y ext: %d\n",
i,
axis_x.axMin,
axis_y.axMin,
axis_x.axMax - axis_x.axMin + 1,
axis_y.axMax - axis_y.axMin + 1);
/* Other stuff while we have a logcontext. */
WINTAB_PRINTF("sysmode %d\n", debuglc.lcSysMode);
}
}

View File

@@ -159,6 +159,8 @@ class GHOST_Wintab {
*/
GHOST_TabletData getLastTabletData();
~GHOST_Wintab();
private:
/** Wintab DLL handle. */
unique_hmodule m_handle;
@@ -247,4 +249,6 @@ class GHOST_Wintab {
* \param system: System coordinates.
*/
static void extractCoordinates(LOGCONTEXT &lc, Coord &tablet, Coord &system);
void printContextInfo();
};