diff --git a/libs/wacom/WinTab/Utils.cpp b/libs/wacom/WinTab/Utils.cpp index 17f3e3a..ed15601 100644 --- a/libs/wacom/WinTab/Utils.cpp +++ b/libs/wacom/WinTab/Utils.cpp @@ -61,7 +61,9 @@ BOOL LoadWintab( void ) { // ghWintab = LoadLibraryA( "C:\\dev\\mainline\\Wacom\\Win\\Win32\\Debug\\Wacom_Tablet.dll" ); // ghWintab = LoadLibraryA( "C:\\dev\\mainline\\Wacom\\Win\\Win32\\Debug\\Wintab32.dll" ); - ghWintab = LoadLibraryA( "Wintab32.dll" ); + LOG("calling LoadLibrary"); + ghWintab = LoadLibrary(L"Wintab32.dll"); + LOG("LoadLibrary called"); if ( !ghWintab ) { @@ -71,6 +73,8 @@ BOOL LoadWintab( void ) return FALSE; } + LOG("WinTab found"); + // Explicitly find the exported Wintab functions in which we are interested. // We are using the ASCII, not unicode versions (where applicable). GETPROCADDRESS( WTOPENA, WTOpenA ); diff --git a/src/log.cpp b/src/log.cpp index 9bd472b..d6fc094 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -115,7 +115,7 @@ void LogRemote::log(const wchar_t* format, ...) mbstate_t st = {}; std::string converted; - converted.reserve(string_to_convert.size()); + converted.resize(string_to_convert.size()); const wchar_t * wptr = string_to_convert.c_str(); std::wcsrtombs((char*)converted.data(), &wptr, converted.capacity(), &st); diff --git a/src/main.cpp b/src/main.cpp index 40b3b17..14ac206 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,7 @@ int gl_count = 0; std::deque> tasklist; std::mutex task_mutex; float timer_stylus = 0; +bool sandboxed = false; //Returns the last Win32 error, in string format. Returns an empty string if there is no error. std::string GetLastErrorAsString() @@ -184,14 +185,38 @@ int read_WMI_info() auto log_field = [](const wchar_t* section, IWbemClassObject* clsObj, const wchar_t* field) { VARIANT vRet; + CIMTYPE pType; VariantInit(&vRet); - if (SUCCEEDED(clsObj->Get(field, 0, &vRet, NULL, NULL)) && vRet.vt == VT_BSTR) + if (SUCCEEDED(clsObj->Get(field, 0, &vRet, &pType, NULL))) { - LOGW(L"%s %s: %s", section, field, vRet.bstrVal); + if (pType == CIM_STRING && pType != CIM_EMPTY && pType != CIM_ILLEGAL) + { + LOGW(L"%s %s: %s", section, field, vRet.bstrVal); + } + else if (pType == CIM_UINT32 && pType != CIM_EMPTY && pType != CIM_ILLEGAL) + { + LOGW(L"%s %s: %d", section, field, vRet.uintVal); + } + VariantClear(&vRet); } }; + auto get_int = [](IWbemClassObject* clsObj, const wchar_t* field) { + VARIANT vRet; + CIMTYPE pType; + VariantInit(&vRet); + int ret = 0; + if (SUCCEEDED(clsObj->Get(field, 0, &vRet, &pType, NULL))) + { + if (pType == CIM_UINT32 && pType != CIM_EMPTY && pType != CIM_ILLEGAL) + ret = vRet.uintVal; + VariantClear(&vRet); + } + return ret; + }; + + // GET DEVICE INFO { IEnumWbemClassObject* pEnumerator = NULL; @@ -249,7 +274,69 @@ int read_WMI_info() pEnumerator->Release(); } + pService->Release(); + pService = NULL; + if (FAILED(hRes = pLocator->ConnectServer(L"root\\Microsoft\\Windows\\DeviceGuard", NULL, NULL, NULL, WBEM_FLAG_CONNECT_USE_MAX_WAIT, NULL, NULL, &pService))) + { + pLocator->Release(); + LOG("Unable to connect to \"DeviceGuard\": %x", hRes); + return 1; + } + + // GET DEVICE GUARD + { + IEnumWbemClassObject* pEnumerator = NULL; + if (FAILED(hRes = pService->ExecQuery(L"WQL", L"SELECT * FROM Win32_DeviceGuard", WBEM_FLAG_FORWARD_ONLY, NULL, &pEnumerator))) + { + pLocator->Release(); + pService->Release(); + LOG("Unable to retrive desktop monitors: %x", hRes); + return 1; + } + + IWbemClassObject* clsObj = NULL; + int numElems; + while ((hRes = pEnumerator->Next(WBEM_INFINITE, 1, &clsObj, (ULONG*)&numElems)) != WBEM_S_FALSE) + { + if (FAILED(hRes)) + break; + + if (get_int(clsObj, L"CodeIntegrityPolicyEnforcementStatus") > 0) + { + LOG("SANDBOX DETECTED"); + sandboxed = true; + } + + SAFEARRAY *psaNames = NULL; + if (SUCCEEDED(clsObj->GetNames(0, WBEM_FLAG_ALWAYS | WBEM_FLAG_NONSYSTEM_ONLY, 0, &psaNames))) + { + // Get the number of properties. + long lLower, lUpper; + BSTR PropName = NULL; + SafeArrayGetLBound(psaNames, 1, &lLower); + SafeArrayGetUBound(psaNames, 1, &lUpper); + + for (long i = lLower; i <= lUpper; i++) + { + // Get this property. + SafeArrayGetElement(psaNames, &i, &PropName); + + LOGW(L"Prop: %s", PropName); + log_field(L"DeviceGuard", clsObj, PropName); + + SysFreeString(PropName); + } + + SafeArrayDestroy(psaNames); + } + + clsObj->Release(); + } + pEnumerator->Release(); + } + + pLocator->Release(); CoUninitialize(); @@ -365,10 +452,16 @@ int main(int argc, char** argv) RegisterClass(&wc); + auto monitor = MonitorFromWindow(0, MONITOR_DEFAULTTOPRIMARY); + auto x = unsigned{}; + auto y = unsigned{}; + GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y); + App::I.zoom = (float)x / 96.f; + AdjustWindowRect(&clientRect, WS_OVERLAPPEDWINDOW, false); - hWnd = CreateWindow(wc.lpszClassName, L"PanoPainter", WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, clientRect.right - clientRect.left, - clientRect.bottom - clientRect.top, 0, 0, hInst, 0); + hWnd = CreateWindow(wc.lpszClassName, L"PanoPainter", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, + (float)(clientRect.right - clientRect.left) * App::I.zoom, + (float)(clientRect.bottom - clientRect.top) * App::I.zoom, 0, 0, hInst, 0); // Setup GL Rendering Context pfd.nSize = sizeof(pfd); @@ -427,9 +520,9 @@ int main(int argc, char** argv) wglDeleteContext(hRC); DestroyWindow(hWnd); - hWnd = CreateWindow(wc.lpszClassName, window_title, WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, clientRect.right - clientRect.left, - clientRect.bottom - clientRect.top, 0, 0, hInst, 0); + hWnd = CreateWindow(wc.lpszClassName, window_title, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, + (float)(clientRect.right - clientRect.left) * App::I.zoom, + (float)(clientRect.bottom - clientRect.top) * App::I.zoom, 0, 0, hInst, 0); hDC = GetDC(hWnd); wglChoosePixelFormatARB(hDC, pixel_attribs, nullptr, 1, &pxfmt, &numFormat); @@ -462,35 +555,38 @@ int main(int argc, char** argv) LOG("RegisterTouchWindow error: %s", GetLastErrorAsString().c_str()); } - auto monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); - auto x = unsigned{}; - auto y = unsigned{}; - GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &x, &y); - App::I.zoom = (float)x / 96.f; - + LOG("init app"); App::I.init(); + LOG("show main window"); ShowWindow(hWnd, SW_NORMAL); - WacomTablet::I.init(hWnd); +// if (!sandboxed) +// { +// LOG("init WinTab"); +// WacomTablet::I.init(hWnd); +// } +// else +// { +// LOG("SKIP init WinTab"); +// } + + LOG("change icon"); SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON1))); + LOG("set redraw interval"); SetTimer(hWnd, 1, 500, [](HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { App::I.redraw = true; }); - SetWindowPos(hWnd, NULL, 0, 0, - (float)(clientRect.right - clientRect.left) * App::I.zoom, - (float)(clientRect.bottom - clientRect.top) * App::I.zoom, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER); - bool running = true; std::mutex render_mutex; std::condition_variable render_cv; std::thread renderer([&] { BT_SetTerminate(); + LOG("start render thread"); const float target_fps = 10; const float target_tick_rate = 60; unsigned long t0 = GetTickCount(); @@ -552,6 +648,8 @@ int main(int argc, char** argv) { WacomTablet::I.m_stylus = false; WacomTablet::I.m_eraser = false; + WacomTablet::I.m_ink = false; + WacomTablet::I.m_ink_pen = false; App::I.redraw = true; } if (App::I.redraw) @@ -575,6 +673,7 @@ int main(int argc, char** argv) }); MSG msg; + LOG("start main loop"); while (running) { // If there any message in the queue process it @@ -701,9 +800,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { std::lock_guard lock(task_mutex); tasklist.emplace_back([lp, extra, p = WacomTablet::I.get_pressure()]{ - auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; - if ((extra & 0xFFFFFF00) == 0xFF515700) - pointer_source = kEventSource::Touch; + kEventSource pointer_source; + if (WacomTablet::I.m_ink) + { + pointer_source = WacomTablet::I.m_ink_pen? kEventSource::Stylus : kEventSource::Touch; + } + else + { + pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; + if ((extra & 0xFFFFFF00) == 0xFF515700) + pointer_source = kEventSource::Touch; + } App::I.mouse_move((float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), p, pointer_source, WacomTablet::I.m_eraser); }); } @@ -713,9 +820,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) std::lock_guard lock(task_mutex); tasklist.emplace_back([lp, extra, hWnd, p = WacomTablet::I.get_pressure()]{ SetCapture(hWnd); - auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; - if ((extra & 0xFFFFFF00) == 0xFF515700) - pointer_source = kEventSource::Touch; + kEventSource pointer_source; + if (WacomTablet::I.m_ink) + { + pointer_source = WacomTablet::I.m_ink_pen ? kEventSource::Stylus : kEventSource::Touch; + } + else + { + pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; + if ((extra & 0xFFFFFF00) == 0xFF515700) + pointer_source = kEventSource::Touch; + } App::I.mouse_down(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), p, pointer_source, WacomTablet::I.m_eraser); }); } @@ -726,9 +841,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) tasklist.emplace_back([lp, extra]{ WacomTablet::I.reset_pressure(); ReleaseCapture(); - auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; - if ((extra & 0xFFFFFF00) == 0xFF515700) - pointer_source = kEventSource::Touch; + kEventSource pointer_source; + if (WacomTablet::I.m_ink) + { + pointer_source = WacomTablet::I.m_ink_pen ? kEventSource::Stylus : kEventSource::Touch; + } + else + { + pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; + if ((extra & 0xFFFFFF00) == 0xFF515700) + pointer_source = kEventSource::Touch; + } App::I.mouse_up(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), pointer_source, WacomTablet::I.m_eraser); }); } @@ -738,9 +861,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) std::lock_guard lock(task_mutex); tasklist.emplace_back([lp, extra, hWnd]{ SetCapture(hWnd); - auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; - if ((extra & 0xFFFFFF00) == 0xFF515700) - pointer_source = kEventSource::Touch; + kEventSource pointer_source; + if (WacomTablet::I.m_ink) + { + pointer_source = WacomTablet::I.m_ink_pen ? kEventSource::Stylus : kEventSource::Touch; + } + else + { + pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; + if ((extra & 0xFFFFFF00) == 0xFF515700) + pointer_source = kEventSource::Touch; + } App::I.mouse_down(1, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), 1.f, pointer_source, 0); }); } @@ -750,9 +881,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) std::lock_guard lock(task_mutex); tasklist.emplace_back([lp, extra]{ ReleaseCapture(); - auto pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; - if ((extra & 0xFFFFFF00) == 0xFF515700) - pointer_source = kEventSource::Touch; + kEventSource pointer_source; + if (WacomTablet::I.m_ink) + { + pointer_source = WacomTablet::I.m_ink_pen ? kEventSource::Stylus : kEventSource::Touch; + } + else + { + pointer_source = WacomTablet::I.m_stylus ? kEventSource::Stylus : kEventSource::Mouse; + if ((extra & 0xFFFFFF00) == 0xFF515700) + pointer_source = kEventSource::Touch; + } App::I.mouse_up(1, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp), pointer_source, 0); }); } @@ -808,6 +947,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) // success, process touchInfo // mark as handled to skip call to DefWindowProc //fHandled = TRUE; + WacomTablet::I.m_ink = true; + WacomTablet::I.m_ink_pen = false; + WacomTablet::I.m_pen_pres = 1; } break; case PT_PEN: @@ -822,6 +964,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) // mark as handled to skip call to DefWindowProc //fHandled = TRUE; //penInfo.pressure + WacomTablet::I.m_ink = true; + WacomTablet::I.m_ink_pen = true; + WacomTablet::I.m_pen_pres = (float)penInfo.pressure / 1024.f; } break; default: diff --git a/src/wacom.cpp b/src/wacom.cpp index 02c187d..d45d966 100644 --- a/src/wacom.cpp +++ b/src/wacom.cpp @@ -126,6 +126,7 @@ bool WacomTablet::init(HWND hWnd) if (ret != sizeof(LOGCONTEXTA)) return false; #endif // _DEBUG + LOG("TabletInit"); g_hCtx = TabletInit(hWnd); if (!g_hCtx) { @@ -166,6 +167,9 @@ void WacomTablet::handle_message(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lPar static POINT ptOld, ptNew; static UINT prsOld, prsNew; + if (!gpWTPacket) + return; + if (gpWTPacket((HCTX)lParam, (UINT)wParam, &pkt)) { if (HIWORD(pkt.pkButtons) == TBN_DOWN) diff --git a/src/wacom.h b/src/wacom.h index d085a39..f53240d 100644 --- a/src/wacom.h +++ b/src/wacom.h @@ -20,6 +20,8 @@ public: bool m_mouse_down = false; bool m_stylus = false; bool m_eraser = false; + bool m_ink = false; + bool m_ink_pen = false; HCTX TabletInit(HWND hWnd);