Skip to content

Commit

Permalink
Remove System::tabletAPI() function
Browse files Browse the repository at this point in the history
We can just use System::tabletOptions().api.
  • Loading branch information
dacap committed Jun 18, 2024
1 parent ff41af6 commit b5e0ac9
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
1 change: 0 additions & 1 deletion os/common/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion os/none/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 0 additions & 3 deletions os/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions os/tablet_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ 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;

// 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
Expand Down
1 change: 0 additions & 1 deletion os/win/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 16 additions & 11 deletions os/win/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 &&
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -2146,16 +2144,15 @@ 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");
}
else {
queueEvent(ev);
m_lastWintabEvent.setType(Event::None);

sys->_setInternalMousePosition(ev);
system()->_setInternalMousePosition(ev);
}
}

Expand Down Expand Up @@ -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()
{
Expand Down
3 changes: 3 additions & 0 deletions os/win/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -111,6 +112,8 @@ namespace os {
return true;
}

TabletAPI tabletAPI() const;

virtual void onResize(const gfx::Size& sz) { }
virtual void onStartResizing() { }
virtual void onEndResizing() { }
Expand Down

0 comments on commit b5e0ac9

Please sign in to comment.