From a96a9e9868e96d9ee9bc17668a19e099692ed8ec Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 22 Sep 2017 15:40:59 -0300 Subject: [PATCH] Add --disable-wintab CLI option This can be used to avoid loading wintab32.dll which sometimes locks Aseprite loading. --- src/app/app.cpp | 5 +++++ src/app/cli/app_options.cpp | 10 ++++++++++ src/app/cli/app_options.h | 6 ++++++ src/she/common/system.h | 18 ++++++++++++++++++ src/she/system.h | 6 ++++++ src/she/win/window.cpp | 21 +++++++++++++-------- src/she/win/window.h | 3 +++ 7 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index 435d1571c..fed693c62 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -146,6 +146,11 @@ App::App() void App::initialize(const AppOptions& options) { +#ifdef _WIN32 + if (options.disableWintab()) + she::instance()->useWintabAPI(false); +#endif + m_isGui = options.startUI() && !options.previewCLI(); m_isShell = options.startShell(); m_coreModules = new CoreModules; diff --git a/src/app/cli/app_options.cpp b/src/app/cli/app_options.cpp index 153c6f017..be31aa993 100644 --- a/src/app/cli/app_options.cpp +++ b/src/app/cli/app_options.cpp @@ -70,6 +70,9 @@ AppOptions::AppOptions(int argc, const char* argv[]) , m_oneFrame(m_po.add("oneframe").description("Load just the first frame")) , m_verbose(m_po.add("verbose").mnemonic('v').description("Explain what is being done")) , m_debug(m_po.add("debug").description("Extreme verbose mode and\ncopy log to desktop")) +#ifdef _WIN32 + , m_disableWintab(m_po.add("disable-wintab").description("Don't load wintab32.dll library")) +#endif , m_help(m_po.add("help").mnemonic('?').description("Display this help and exits")) , m_version(m_po.add("version").description("Output version information and exit")) { @@ -109,4 +112,11 @@ bool AppOptions::hasExporterParams() const m_po.enabled(m_sheet); } +#ifdef _WIN32 +bool AppOptions::disableWintab() const +{ + return m_po.enabled(m_disableWintab); +} +#endif + } diff --git a/src/app/cli/app_options.h b/src/app/cli/app_options.h index 6bf3ecadf..e926e4394 100644 --- a/src/app/cli/app_options.h +++ b/src/app/cli/app_options.h @@ -84,6 +84,9 @@ public: const Option& oneFrame() const { return m_oneFrame; } bool hasExporterParams() const; +#ifdef _WIN32 + bool disableWintab() const; +#endif private: std::string m_exeName; @@ -140,6 +143,9 @@ private: Option& m_verbose; Option& m_debug; +#ifdef _WIN32 + Option& m_disableWintab; +#endif Option& m_help; Option& m_version; diff --git a/src/she/common/system.h b/src/she/common/system.h index 7c2cfa282..952a93c06 100644 --- a/src/she/common/system.h +++ b/src/she/common/system.h @@ -37,6 +37,9 @@ public: CommonSystem() : m_nativeDialogs(nullptr) , m_menus(nullptr) { +#ifdef _WIN32 + m_useWintabAPI = true; +#endif } ~CommonSystem() { @@ -48,6 +51,18 @@ public: delete this; } + void useWintabAPI(bool state) override { +#ifdef _WIN32 + m_useWintabAPI = state; +#endif + } + +#ifdef _WIN32 + bool useWintabAPI() const { + return m_useWintabAPI; + } +#endif + Logger* logger() override { #ifdef __APPLE__ return getOsxLogger(); @@ -114,6 +129,9 @@ public: } private: +#ifdef _WIN32 + bool m_useWintabAPI; +#endif NativeDialogs* m_nativeDialogs; Menus* m_menus; base::UniquePtr m_ft; diff --git a/src/she/system.h b/src/she/system.h index eb7d908b6..ee88b0959 100644 --- a/src/she/system.h +++ b/src/she/system.h @@ -37,6 +37,12 @@ namespace she { virtual void activateApp() = 0; virtual void finishLaunching() = 0; virtual Capabilities capabilities() const = 0; + + // Disables loading wintab32.dll (sometimes a program can be + // locked when we load the wintab32.dll, so we need a way to + // opt-out loading this library.) + virtual void useWintabAPI(bool enable) = 0; + virtual Logger* logger() = 0; virtual Menus* menus() = 0; virtual NativeDialogs* nativeDialogs() = 0; diff --git a/src/she/win/window.cpp b/src/she/win/window.cpp index a7a1eab17..489bb111d 100644 --- a/src/she/win/window.cpp +++ b/src/she/win/window.cpp @@ -372,10 +372,10 @@ LRESULT WinWindow::wndProc(UINT msg, WPARAM wparam, LPARAM lparam) case WM_CREATE: LOG("WIN: Creating window %p\n", m_hwnd); - // Attach Wacom context - m_hpenctx = - static_cast(she::instance()) - ->penApi().open(m_hwnd); + if (system()->useWintabAPI()) { + // Attach Wacom context + m_hpenctx = system()->penApi().open(m_hwnd); + } break; case WM_DESTROY: @@ -383,8 +383,7 @@ LRESULT WinWindow::wndProc(UINT msg, WPARAM wparam, LPARAM lparam) m_hwnd, m_hpenctx); if (m_hpenctx) { - static_cast(she::instance()) - ->penApi().close(m_hpenctx); + system()->penApi().close(m_hpenctx); m_hpenctx = nullptr; } break; @@ -781,7 +780,7 @@ LRESULT WinWindow::wndProc(UINT msg, WPARAM wparam, LPARAM lparam) } case WT_CSRCHANGE: { // From Wintab 1.1 - auto& api = static_cast(she::instance())->penApi(); + auto& api = system()->penApi(); UINT serial = wparam; HCTX ctx = (HCTX)lparam; PACKET packet; @@ -810,7 +809,7 @@ LRESULT WinWindow::wndProc(UINT msg, WPARAM wparam, LPARAM lparam) } case WT_PACKET: { - auto& api = static_cast(she::instance())->penApi(); + auto& api = system()->penApi(); UINT serial = wparam; HCTX ctx = (HCTX)lparam; PACKET packet; @@ -938,4 +937,10 @@ LRESULT CALLBACK WinWindow::staticWndProc(HWND hwnd, UINT msg, WPARAM wparam, LP } } +// static +WindowSystem* WinWindow::system() +{ + return static_cast(she::instance()); +} + } // namespace she diff --git a/src/she/win/window.h b/src/she/win/window.h index 0d8cc8756..8a2aabee3 100644 --- a/src/she/win/window.h +++ b/src/she/win/window.h @@ -19,6 +19,7 @@ namespace she { class Event; class Surface; + class WindowSystem; class WinWindow { public: @@ -62,6 +63,8 @@ namespace she { static HWND createHwnd(WinWindow* self, int width, int height); static LRESULT CALLBACK staticWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); + static WindowSystem* system(); + mutable HWND m_hwnd; HCURSOR m_hcursor; gfx::Size m_clientSize;