set proximity in tablets

This commit is contained in:
vaxerski 2022-06-09 18:09:09 +02:00
parent 824d8b954d
commit 6317f64ba0
3 changed files with 27 additions and 21 deletions

View file

@ -48,6 +48,7 @@ public:
void newTabletTool(wlr_input_device*); void newTabletTool(wlr_input_device*);
void newTabletPad(wlr_input_device*); void newTabletPad(wlr_input_device*);
void focusTablet(STablet*, wlr_tablet_tool*, bool motion = false);
SKeyboard* m_pActiveKeyboard = nullptr; SKeyboard* m_pActiveKeyboard = nullptr;

View file

@ -47,15 +47,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) {
if (PTOOL->active) { if (PTOOL->active) {
g_pInputManager->refocus(); g_pInputManager->refocus();
if (const auto PWINDOW = g_pCompositor->m_pLastWindow; g_pCompositor->windowValidMapped(PWINDOW)) { g_pInputManager->focusTablet(PTAB, EVENT->tool, true);
const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal();
const auto LOCAL = CURSORPOS - PWINDOW->m_vRealPosition.goalv();
Debug::log(LOG, "Tablet Tool focus to %s", PWINDOW->m_szTitle.c_str());
wlr_tablet_v2_tablet_tool_notify_motion(PTOOL->wlrTabletToolV2, LOCAL.x, LOCAL.y);
}
} }
if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) { if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) {
@ -107,6 +99,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) {
if (EVENT->state == WLR_TABLET_TOOL_TIP_DOWN) { if (EVENT->state == WLR_TABLET_TOOL_TIP_DOWN) {
Debug::log(LOG, "Tip down"); Debug::log(LOG, "Tip down");
g_pInputManager->refocus(); g_pInputManager->refocus();
g_pInputManager->focusTablet(PTAB, EVENT->tool);
wlr_send_tablet_v2_tablet_tool_down(PTOOL->wlrTabletToolV2); wlr_send_tablet_v2_tablet_tool_down(PTOOL->wlrTabletToolV2);
} }
else { else {
@ -143,16 +136,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) {
PTOOL->active = true; PTOOL->active = true;
Debug::log(LOG, "Tool active -> true"); Debug::log(LOG, "Tool active -> true");
g_pInputManager->refocus(); g_pInputManager->refocus();
g_pInputManager->focusTablet(PTAB, EVENT->tool);
if (const auto PWINDOW = g_pCompositor->m_pLastWindow; g_pCompositor->windowValidMapped(PWINDOW)) {
const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal();
const auto LOCAL = CURSORPOS - PWINDOW->m_vRealPosition.goalv();
Debug::log(LOG, "Tablet Tool focus to %s", PWINDOW->m_szTitle.c_str());
wlr_tablet_v2_tablet_tool_notify_motion(PTOOL->wlrTabletToolV2, LOCAL.x, LOCAL.y);
}
} }
}, PNEWTABLET, "Tablet"); }, PNEWTABLET, "Tablet");
@ -247,3 +231,24 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) {
}, PNEWPAD, "Tablet Pad"); }, PNEWPAD, "Tablet Pad");
} }
void CInputManager::focusTablet(STablet* pTab, wlr_tablet_tool* pTool, bool motion) {
const auto PTOOL = g_pInputManager->ensureTabletToolPresent(pTab, pTool);
if (const auto PWINDOW = g_pCompositor->m_pLastWindow; g_pCompositor->windowValidMapped(PWINDOW)) {
const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal();
const auto LOCAL = CURSORPOS - PWINDOW->m_vRealPosition.goalv();
Debug::log(LOG, "Tablet Tool focus to %s", PWINDOW->m_szTitle.c_str());
if (PTOOL->wlrTabletToolV2->focused_surface != g_pCompositor->m_pLastFocus)
wlr_tablet_v2_tablet_tool_notify_proximity_out(PTOOL->wlrTabletToolV2);
if (g_pCompositor->m_pLastFocus)
wlr_tablet_v2_tablet_tool_notify_proximity_in(PTOOL->wlrTabletToolV2, pTab->wlrTabletV2, g_pCompositor->m_pLastFocus);
if (motion)
wlr_tablet_v2_tablet_tool_notify_motion(PTOOL->wlrTabletToolV2, LOCAL.x, LOCAL.y);
}
}