From b5e0ac9598f3ed75d0ef6857ac28b9f0d2b475a6 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 18 Jun 2024 14:01:49 -0300 Subject: [PATCH] Remove System::tabletAPI() function We can just use System::tabletOptions().api. --- os/common/system.h | 1 - os/none/os.cpp | 1 - os/system.h | 3 --- os/tablet_options.h | 2 ++ os/win/system.h | 1 - os/win/window.cpp | 27 ++++++++++++++++----------- os/win/window.h | 3 +++ 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/os/common/system.h b/os/common/system.h index d5c4f451c..88e792695 100644 --- a/os/common/system.h +++ b/os/common/system.h @@ -40,7 +40,6 @@ class CommonSystem : public System { // moment) void setTabletOptions(const TabletOptions&) override { } TabletOptions tabletOptions() const override { return TabletOptions(); } - TabletAPI tabletAPI() const override { return TabletAPI::Default; } Logger* logger() override { return nullptr; diff --git a/os/none/os.cpp b/os/none/os.cpp index 620357fee..ee3b5aa47 100644 --- a/os/none/os.cpp +++ b/os/none/os.cpp @@ -30,7 +30,6 @@ class NoneSystem : public System { Capabilities capabilities() const override { return (Capabilities)0; } void setTabletOptions(const TabletOptions&) override { } TabletOptions tabletOptions() const override { return TabletOptions(); } - TabletAPI tabletAPI() const override { return TabletAPI::Default; } Logger* logger() override { return nullptr; } Menus* menus() override { return nullptr; } NativeDialogs* nativeDialogs() override { return nullptr; } diff --git a/os/system.h b/os/system.h index 2deaf0b2f..d520db490 100644 --- a/os/system.h +++ b/os/system.h @@ -120,9 +120,6 @@ namespace os { virtual void setTabletOptions(const TabletOptions& opts) = 0; virtual TabletOptions tabletOptions() const = 0; - // Shortcut alternative (could be faster?) for tabletOptions().api - virtual TabletAPI tabletAPI() const = 0; - // Sub-interfaces virtual Logger* logger() = 0; virtual Menus* menus() = 0; diff --git a/os/tablet_options.h b/os/tablet_options.h index a4da1f943..b86b2ecba 100644 --- a/os/tablet_options.h +++ b/os/tablet_options.h @@ -33,6 +33,7 @@ namespace os { }; struct TabletOptions { +#if LAF_WINDOWS // Windows API to get stylus/digital tablet position of the pen // (Windows Pointer API, legacy Wintab, etc.). TabletAPI api = TabletAPI::Default; @@ -40,6 +41,7 @@ namespace os { // Use a fix for live streaming software like OBS to set the // cursor position each time we receive a pointer event like bool setCursorFix = false; +#endif }; } // namespace os diff --git a/os/win/system.h b/os/win/system.h index 5a07cc12a..089c78207 100644 --- a/os/win/system.h +++ b/os/win/system.h @@ -30,7 +30,6 @@ class SystemWin : public CommonSystem { void setTabletOptions(const TabletOptions& options) override; TabletOptions tabletOptions() const override { return m_tabletOptions; } - TabletAPI tabletAPI() const override { return m_tabletOptions.api; } bool isKeyPressed(KeyScancode scancode) override; int getUnicodeFromScancode(KeyScancode scancode) override; diff --git a/os/win/window.cpp b/os/win/window.cpp index 84cf071ab..6e941f60e 100644 --- a/os/win/window.cpp +++ b/os/win/window.cpp @@ -861,7 +861,7 @@ void WindowWin::setInterpretOneFingerGestureAsMouseMovement(bool state) void WindowWin::onTabletOptionsChange() { LOG("WIN: On window %p tablet options change tablet API=%d\n", - m_hwnd, int(system()->tabletAPI())); + m_hwnd, int(tabletAPI())); closeWintabCtx(); openWintabCtx(); @@ -882,7 +882,7 @@ LRESULT WindowWin::wndProc(UINT msg, WPARAM wparam, LPARAM lparam) case WM_CREATE: { LOG("WIN: Creating window %p (tablet API %d)\n", - m_hwnd, int(system()->tabletAPI())); + m_hwnd, int(tabletAPI())); openWintabCtx(); if (m_borderless && @@ -1294,7 +1294,7 @@ LRESULT WindowWin::wndProc(UINT msg, WPARAM wparam, LPARAM lparam) ev.position().x, ev.position().y, ev.button(), (int)m_pointerType); - if (system()->tabletAPI() == TabletAPI::WintabPackets && + if (tabletAPI() == TabletAPI::WintabPackets && same_mouse_event(ev, m_lastWintabEvent)) { MOUSE_TRACE(" - IGNORED (WinTab)\n"); } @@ -1329,7 +1329,7 @@ LRESULT WindowWin::wndProc(UINT msg, WPARAM wparam, LPARAM lparam) ev.position().x, ev.position().y, ev.button()); - if (system()->tabletAPI() == TabletAPI::WintabPackets && + if (tabletAPI() == TabletAPI::WintabPackets && same_mouse_event(ev, m_lastWintabEvent)) { MOUSE_TRACE(" - IGNORED (WinTab)\n"); } @@ -1940,7 +1940,6 @@ LRESULT WindowWin::wndProc(UINT msg, WPARAM wparam, LPARAM lparam) } case WT_PACKET: { - const TabletAPI tabletAPI = system()->tabletAPI(); auto& api = system()->wintabApi(); HCTX ctx = (HCTX)lparam; if (m_packets.size() < api.packetQueueSize()) @@ -1973,7 +1972,7 @@ LRESULT WindowWin::wndProc(UINT msg, WPARAM wparam, LPARAM lparam) } m_pointerType = wt_packet_pkcursor_to_pointer_type(packet.pkCursor); - if (tabletAPI == TabletAPI::WintabPackets) { + if (tabletAPI() == TabletAPI::WintabPackets) { POINT pos = { packet.pkX, // Wintab API uses lower-left corner as the origin (api.outBounds().h-1) - packet.pkY }; @@ -2019,8 +2018,7 @@ LRESULT WindowWin::wndProc(UINT msg, WPARAM wparam, LPARAM lparam) } case WT_INFOCHANGE: { - const TabletAPI tabletAPI = system()->tabletAPI(); - MOUSE_TRACE("WT_INFOCHANGE tablet API %d\n", int(tabletAPI)); + MOUSE_TRACE("WT_INFOCHANGE tablet API %d\n", int(tabletAPI())); if (m_hpenctx) { closeWintabCtx(); @@ -2146,8 +2144,7 @@ void WindowWin::handleMouseMove(Event& ev) ev.setType(Event::MouseMove); - auto sys = system(); - if (sys->tabletAPI() == TabletAPI::WintabPackets && + if (tabletAPI() == TabletAPI::WintabPackets && same_mouse_event(ev, m_lastWintabEvent)) { MOUSE_TRACE(" - IGNORED (WinTab)\n"); } @@ -2155,7 +2152,7 @@ void WindowWin::handleMouseMove(Event& ev) queueEvent(ev); m_lastWintabEvent.setType(Event::None); - sys->_setInternalMousePosition(ev); + system()->_setInternalMousePosition(ev); } } @@ -2492,6 +2489,14 @@ void WindowWin::notifyFullScreenStateToShell() taskbar->MarkFullscreenWindow(m_hwnd, m_fullscreen ? TRUE: FALSE); } +TabletAPI WindowWin::tabletAPI() const +{ + if (auto sys = system()) + return sys->tabletOptions().api; + else + return TabletAPI::Default; +} + //static void WindowWin::registerClass() { diff --git a/os/win/window.h b/os/win/window.h index 352fdb093..2cc6b54b9 100644 --- a/os/win/window.h +++ b/os/win/window.h @@ -16,6 +16,7 @@ #include "os/native_cursor.h" #include "os/pointer_type.h" #include "os/screen.h" +#include "os/tablet_options.h" #include "os/win/dnd.h" #include "os/win/wintab.h" @@ -111,6 +112,8 @@ namespace os { return true; } + TabletAPI tabletAPI() const; + virtual void onResize(const gfx::Size& sz) { } virtual void onStartResizing() { } virtual void onEndResizing() { }