From 47404534d0cf94b969daee5e0e4dc20c65c35fb2 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Jun 2022 12:46:55 +0200 Subject: added tablet v2 support (alpha alpha) --- src/managers/input/Tablets.cpp | 188 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 src/managers/input/Tablets.cpp (limited to 'src/managers/input/Tablets.cpp') diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp new file mode 100644 index 00000000..df0a7171 --- /dev/null +++ b/src/managers/input/Tablets.cpp @@ -0,0 +1,188 @@ +#include "InputManager.hpp" +#include "../../Compositor.hpp" + +void CInputManager::newTabletTool(wlr_input_device* pDevice) { + const auto PNEWTABLET = &m_lTablets.emplace_back(); + + PNEWTABLET->wlrTablet = pDevice->tablet; + PNEWTABLET->wlrDevice = pDevice; + PNEWTABLET->wlrTabletV2 = wlr_tablet_create(g_pCompositor->m_sWLRTabletManager, g_pCompositor->m_sSeat.seat, pDevice); + PNEWTABLET->wlrTablet->data = PNEWTABLET; + + wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, pDevice); + + PNEWTABLET->hyprListener_Destroy.initCallback(&pDevice->events.destroy, [](void* owner, void* data) { + const auto PTAB = (STablet*)owner; + + g_pInputManager->m_lTablets.remove(*PTAB); + + Debug::log(LOG, "Removed a tablet"); + }, PNEWTABLET, "Tablet"); + + PNEWTABLET->hyprListener_Axis.initCallback(&pDevice->tablet->events.axis, [](void* owner, void* data) { + + const auto EVENT = (wlr_tablet_tool_axis_event*)data; + const auto PTAB = (STablet*)owner; + + switch (EVENT->tool->type) { + case WLR_TABLET_TOOL_TYPE_MOUSE: + wlr_cursor_move(g_pCompositor->m_sWLRCursor, PTAB->wlrDevice, EVENT->dx, EVENT->dy); + g_pInputManager->refocus(); + break; + default: + double x = (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_X) ? EVENT->x : NAN; + double y = (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_Y) ? EVENT->y : NAN; + wlr_cursor_warp_absolute(g_pCompositor->m_sWLRCursor, PTAB->wlrDevice, x, y); + g_pInputManager->refocus(); + break; + } + + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); + + // TODO: this might be wrong + if (PTOOL->active) + g_pInputManager->refocus(); + + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) + wlr_tablet_v2_tablet_tool_notify_pressure(PTOOL->wlrTabletToolV2, EVENT->pressure); + + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) + wlr_tablet_v2_tablet_tool_notify_distance(PTOOL->wlrTabletToolV2, EVENT->distance); + + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_ROTATION) + wlr_tablet_v2_tablet_tool_notify_rotation(PTOOL->wlrTabletToolV2, EVENT->rotation); + + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_SLIDER) + wlr_tablet_v2_tablet_tool_notify_slider(PTOOL->wlrTabletToolV2, EVENT->slider); + + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) + wlr_tablet_v2_tablet_tool_notify_wheel(PTOOL->wlrTabletToolV2, EVENT->wheel_delta, 0); + + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_X) + PTOOL->tiltX = EVENT->tilt_x; + + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_Y) + PTOOL->tiltY = EVENT->tilt_y; + + if (EVENT->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y)) + wlr_tablet_v2_tablet_tool_notify_tilt(PTOOL->wlrTabletToolV2, PTOOL->tiltX, PTOOL->tiltY); + + }, PNEWTABLET, "Tablet"); + + PNEWTABLET->hyprListener_Tip.initCallback(&pDevice->tablet->events.tip, [](void* owner, void* data) { + const auto EVENT = (wlr_tablet_tool_tip_event*)data; + const auto PTAB = (STablet*)owner; + + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); + + // TODO: this might be wrong + if (EVENT->state == WLR_TABLET_TOOL_TIP_DOWN) + wlr_send_tablet_v2_tablet_tool_down(PTOOL->wlrTabletToolV2); + else + wlr_send_tablet_v2_tablet_tool_up(PTOOL->wlrTabletToolV2); + + }, PNEWTABLET, "Tablet"); + + PNEWTABLET->hyprListener_Button.initCallback(&pDevice->tablet->events.button, [](void* owner, void* data) { + const auto EVENT = (wlr_tablet_tool_button_event*)data; + const auto PTAB = (STablet*)owner; + + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); + + wlr_tablet_v2_tablet_tool_notify_button(PTOOL->wlrTabletToolV2, (zwp_tablet_pad_v2_button_state)EVENT->button, (zwp_tablet_pad_v2_button_state)EVENT->state); + + }, PNEWTABLET, "Tablet"); + + PNEWTABLET->hyprListener_Proximity.initCallback(&pDevice->tablet->events.proximity, [](void* owner, void* data) { + const auto EVENT = (wlr_tablet_tool_proximity_event*)data; + const auto PTAB = (STablet*)owner; + + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); + + if (EVENT->state == WLR_TABLET_TOOL_PROXIMITY_OUT) { + PTOOL->active = false; + } else { + PTOOL->active = true; + g_pInputManager->refocus(); + } + + }, PNEWTABLET, "Tablet"); +} + +STabletTool* CInputManager::ensureTabletToolPresent(STablet* pTablet, wlr_tablet_tool* pTool) { + if (pTool->data == nullptr) { + const auto PTOOL = &m_lTabletTools.emplace_back(); + + PTOOL->wlrTabletTool = pTool; + pTool->data = PTOOL; + + PTOOL->wlrTabletToolV2 = wlr_tablet_tool_create(g_pCompositor->m_sWLRTabletManager, g_pCompositor->m_sSeat.seat, pTool); + + PTOOL->hyprListener_TabletToolDestroy.initCallback(&pTool->events.destroy, [](void* owner, void* data) { + const auto PTOOL = (STabletTool*)owner; + + PTOOL->wlrTabletTool->data = nullptr; + g_pInputManager->m_lTabletTools.remove(*PTOOL); + }, PTOOL, "Tablet Tool V1"); + + //TODO: set cursor request + } + + return (STabletTool*)pTool->data; +} + +void CInputManager::newTabletPad(wlr_input_device* pDevice) { + const auto PNEWPAD = &m_lTabletPads.emplace_back(); + + PNEWPAD->wlrTabletPadV2 = wlr_tablet_pad_create(g_pCompositor->m_sWLRTabletManager, g_pCompositor->m_sSeat.seat, pDevice); + + PNEWPAD->hyprListener_Button.initCallback(&pDevice->tablet_pad->events.button, [](void* owner, void* data) { + + const auto EVENT = (wlr_tablet_pad_button_event*)data; + const auto PPAD = (STabletPad*)owner; + + wlr_tablet_v2_tablet_pad_notify_mode(PPAD->wlrTabletPadV2, EVENT->group, EVENT->mode, EVENT->time_msec); + wlr_tablet_v2_tablet_pad_notify_button(PPAD->wlrTabletPadV2, EVENT->button, EVENT->time_msec, (zwp_tablet_pad_v2_button_state)EVENT->state); + + }, PNEWPAD, "Tablet Pad"); + + PNEWPAD->hyprListener_Strip.initCallback(&pDevice->tablet_pad->events.strip, [](void* owner, void* data) { + + const auto EVENT = (wlr_tablet_pad_strip_event*)data; + const auto PPAD = (STabletPad*)owner; + + wlr_tablet_v2_tablet_pad_notify_strip(PPAD->wlrTabletPadV2, EVENT->strip, EVENT->position, EVENT->source == WLR_TABLET_PAD_STRIP_SOURCE_FINGER, EVENT->time_msec); + + }, PNEWPAD, "Tablet Pad"); + + PNEWPAD->hyprListener_Ring.initCallback(&pDevice->tablet_pad->events.strip, [](void* owner, void* data) { + + const auto EVENT = (wlr_tablet_pad_ring_event*)data; + const auto PPAD = (STabletPad*)owner; + + wlr_tablet_v2_tablet_pad_notify_ring(PPAD->wlrTabletPadV2, EVENT->ring, EVENT->position, EVENT->source == WLR_TABLET_PAD_RING_SOURCE_FINGER, EVENT->time_msec); + + }, PNEWPAD, "Tablet Pad"); + + PNEWPAD->hyprListener_Attach.initCallback(&pDevice->tablet_pad->events.strip, [](void* owner, void* data) { + + const auto TABLET = (wlr_tablet_tool*)data; + const auto PPAD = (STabletPad*)owner; + + PPAD->pTabletParent = (STablet*)TABLET->data; + + if (!PPAD->pTabletParent) + Debug::log(ERR, "tabletpad got attached to a nullptr tablet!! this might be bad."); + + }, PNEWPAD, "Tablet Pad"); + + PNEWPAD->hyprListener_Destroy.initCallback(&pDevice->events.destroy, [](void* owner, void* data) { + + const auto PPAD = (STabletPad*)owner; + + g_pInputManager->m_lTabletPads.remove(*PPAD); + + Debug::log(LOG, "Removed a tablet pad"); + + }, PNEWPAD, "Tablet Pad"); +} \ No newline at end of file -- cgit v1.2.3 From 1841d244f03793acc260ddadd34d64095e08dfa2 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Jun 2022 14:40:56 +0200 Subject: log shit in tablets --- src/managers/input/Tablets.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/managers/input/Tablets.cpp') diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index df0a7171..b6a3c7d7 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -9,6 +9,8 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { PNEWTABLET->wlrTabletV2 = wlr_tablet_create(g_pCompositor->m_sWLRTabletManager, g_pCompositor->m_sSeat.seat, pDevice); PNEWTABLET->wlrTablet->data = PNEWTABLET; + Debug::log(LOG, "Attaching tablet to cursor!"); + wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, pDevice); PNEWTABLET->hyprListener_Destroy.initCallback(&pDevice->events.destroy, [](void* owner, void* data) { @@ -21,6 +23,8 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { PNEWTABLET->hyprListener_Axis.initCallback(&pDevice->tablet->events.axis, [](void* owner, void* data) { + Debug::log(LOG, "Tablet axis"); + const auto EVENT = (wlr_tablet_tool_axis_event*)data; const auto PTAB = (STablet*)owner; @@ -73,6 +77,8 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_tool_tip_event*)data; const auto PTAB = (STablet*)owner; + Debug::log(LOG, "Tablet tip"); + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); // TODO: this might be wrong @@ -87,6 +93,8 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_tool_button_event*)data; const auto PTAB = (STablet*)owner; + Debug::log(LOG, "Tablet button"); + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); wlr_tablet_v2_tablet_tool_notify_button(PTOOL->wlrTabletToolV2, (zwp_tablet_pad_v2_button_state)EVENT->button, (zwp_tablet_pad_v2_button_state)EVENT->state); @@ -97,12 +105,16 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_tool_proximity_event*)data; const auto PTAB = (STablet*)owner; + Debug::log(LOG, "Tablet proxim"); + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); if (EVENT->state == WLR_TABLET_TOOL_PROXIMITY_OUT) { PTOOL->active = false; + Debug::log(LOG, "Tool active -> false"); } else { PTOOL->active = true; + Debug::log(LOG, "Tool active -> true"); g_pInputManager->refocus(); } @@ -113,6 +125,8 @@ STabletTool* CInputManager::ensureTabletToolPresent(STablet* pTablet, wlr_tablet if (pTool->data == nullptr) { const auto PTOOL = &m_lTabletTools.emplace_back(); + Debug::log(LOG, "Creating tablet tool v2 for %x", pTool); + PTOOL->wlrTabletTool = pTool; pTool->data = PTOOL; @@ -138,6 +152,8 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { PNEWPAD->hyprListener_Button.initCallback(&pDevice->tablet_pad->events.button, [](void* owner, void* data) { + Debug::log(LOG, "TabletPad button"); + const auto EVENT = (wlr_tablet_pad_button_event*)data; const auto PPAD = (STabletPad*)owner; @@ -151,6 +167,8 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_pad_strip_event*)data; const auto PPAD = (STabletPad*)owner; + Debug::log(LOG, "TabletPad strip"); + wlr_tablet_v2_tablet_pad_notify_strip(PPAD->wlrTabletPadV2, EVENT->strip, EVENT->position, EVENT->source == WLR_TABLET_PAD_STRIP_SOURCE_FINGER, EVENT->time_msec); }, PNEWPAD, "Tablet Pad"); @@ -160,6 +178,8 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_pad_ring_event*)data; const auto PPAD = (STabletPad*)owner; + Debug::log(LOG, "TabletPad ring"); + wlr_tablet_v2_tablet_pad_notify_ring(PPAD->wlrTabletPadV2, EVENT->ring, EVENT->position, EVENT->source == WLR_TABLET_PAD_RING_SOURCE_FINGER, EVENT->time_msec); }, PNEWPAD, "Tablet Pad"); @@ -169,6 +189,8 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { const auto TABLET = (wlr_tablet_tool*)data; const auto PPAD = (STabletPad*)owner; + Debug::log(LOG, "TabletPad attach"); + PPAD->pTabletParent = (STablet*)TABLET->data; if (!PPAD->pTabletParent) @@ -180,6 +202,8 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { const auto PPAD = (STabletPad*)owner; + Debug::log(LOG, "TabletPad destroy"); + g_pInputManager->m_lTabletPads.remove(*PPAD); Debug::log(LOG, "Removed a tablet pad"); -- cgit v1.2.3 From c218ed443243017ca32a8b2dde4180f520c25c00 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Jun 2022 17:16:01 +0200 Subject: notify tablet motion --- src/managers/input/Tablets.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/managers/input/Tablets.cpp') diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index b6a3c7d7..f46ad775 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -44,9 +44,18 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); // TODO: this might be wrong - if (PTOOL->active) + if (PTOOL->active) { g_pInputManager->refocus(); + 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(); + + wlr_tablet_v2_tablet_tool_notify_motion(PTOOL->wlrTabletToolV2, LOCAL.x, LOCAL.y); + } + } + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) wlr_tablet_v2_tablet_tool_notify_pressure(PTOOL->wlrTabletToolV2, EVENT->pressure); @@ -116,6 +125,14 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { PTOOL->active = true; Debug::log(LOG, "Tool active -> true"); g_pInputManager->refocus(); + + 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(); + + wlr_tablet_v2_tablet_tool_notify_motion(PTOOL->wlrTabletToolV2, LOCAL.x, LOCAL.y); + } } }, PNEWTABLET, "Tablet"); -- cgit v1.2.3 From 824d8b954dd012a6a60c20ced71fdbb00ca3b35c Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Jun 2022 17:40:05 +0200 Subject: logify even more --- src/managers/input/Tablets.cpp | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'src/managers/input/Tablets.cpp') diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index f46ad775..bb139000 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -52,24 +52,36 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { 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) { + Debug::log(LOG, "Updated pressure to %f", EVENT->pressure); wlr_tablet_v2_tablet_tool_notify_pressure(PTOOL->wlrTabletToolV2, EVENT->pressure); + } - if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) { + Debug::log(LOG, "Updated distance to %f", EVENT->distance); wlr_tablet_v2_tablet_tool_notify_distance(PTOOL->wlrTabletToolV2, EVENT->distance); + } - if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_ROTATION) + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_ROTATION) { + Debug::log(LOG, "Updated rotation to %f", EVENT->rotation); wlr_tablet_v2_tablet_tool_notify_rotation(PTOOL->wlrTabletToolV2, EVENT->rotation); + } - if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_SLIDER) + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_SLIDER) { + Debug::log(LOG, "Updated slider to %f", EVENT->slider); wlr_tablet_v2_tablet_tool_notify_slider(PTOOL->wlrTabletToolV2, EVENT->slider); + } - if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) { + Debug::log(LOG, "Updated wheel delta to %f", EVENT->wheel_delta); wlr_tablet_v2_tablet_tool_notify_wheel(PTOOL->wlrTabletToolV2, EVENT->wheel_delta, 0); + } if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_X) PTOOL->tiltX = EVENT->tilt_x; @@ -77,9 +89,10 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_Y) PTOOL->tiltY = EVENT->tilt_y; - if (EVENT->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y)) + if (EVENT->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y)){ + Debug::log(LOG, "Updated tilt to %f, %f", EVENT->tilt_x, EVENT->tilt_y); wlr_tablet_v2_tablet_tool_notify_tilt(PTOOL->wlrTabletToolV2, PTOOL->tiltX, PTOOL->tiltY); - + } }, PNEWTABLET, "Tablet"); PNEWTABLET->hyprListener_Tip.initCallback(&pDevice->tablet->events.tip, [](void* owner, void* data) { @@ -91,10 +104,15 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); // TODO: this might be wrong - if (EVENT->state == WLR_TABLET_TOOL_TIP_DOWN) + if (EVENT->state == WLR_TABLET_TOOL_TIP_DOWN) { + Debug::log(LOG, "Tip down"); + g_pInputManager->refocus(); wlr_send_tablet_v2_tablet_tool_down(PTOOL->wlrTabletToolV2); - else + } + else { + Debug::log(LOG, "Tip up"); wlr_send_tablet_v2_tablet_tool_up(PTOOL->wlrTabletToolV2); + } }, PNEWTABLET, "Tablet"); @@ -125,12 +143,14 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { PTOOL->active = true; Debug::log(LOG, "Tool active -> true"); g_pInputManager->refocus(); - + 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); } } -- cgit v1.2.3 From 6317f64ba0eb304de47bf3f5aa490d76ea0c4384 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Jun 2022 18:09:09 +0200 Subject: set proximity in tablets --- src/managers/input/Tablets.cpp | 45 +++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'src/managers/input/Tablets.cpp') diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index bb139000..75ee0316 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -47,15 +47,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { if (PTOOL->active) { g_pInputManager->refocus(); - 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); - } + g_pInputManager->focusTablet(PTAB, EVENT->tool, true); } 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) { Debug::log(LOG, "Tip down"); g_pInputManager->refocus(); + g_pInputManager->focusTablet(PTAB, EVENT->tool); wlr_send_tablet_v2_tablet_tool_down(PTOOL->wlrTabletToolV2); } else { @@ -143,16 +136,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { PTOOL->active = true; Debug::log(LOG, "Tool active -> true"); g_pInputManager->refocus(); - - 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); - } + g_pInputManager->focusTablet(PTAB, EVENT->tool); } }, PNEWTABLET, "Tablet"); @@ -246,4 +230,25 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { Debug::log(LOG, "Removed a tablet pad"); }, PNEWPAD, "Tablet Pad"); -} \ No newline at end of file +} + +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); + } +} -- cgit v1.2.3 From 8929172bc2cbd9e0c931065091d45f2012466d33 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Jun 2022 19:19:42 +0200 Subject: remove redundant logs --- src/managers/input/Tablets.cpp | 49 ++++++------------------------------------ 1 file changed, 7 insertions(+), 42 deletions(-) (limited to 'src/managers/input/Tablets.cpp') diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index 75ee0316..32eef28d 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -23,8 +23,6 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { PNEWTABLET->hyprListener_Axis.initCallback(&pDevice->tablet->events.axis, [](void* owner, void* data) { - Debug::log(LOG, "Tablet axis"); - const auto EVENT = (wlr_tablet_tool_axis_event*)data; const auto PTAB = (STablet*)owner; @@ -50,30 +48,20 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { g_pInputManager->focusTablet(PTAB, EVENT->tool, true); } - if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) { - Debug::log(LOG, "Updated pressure to %f", EVENT->pressure); + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_PRESSURE) wlr_tablet_v2_tablet_tool_notify_pressure(PTOOL->wlrTabletToolV2, EVENT->pressure); - } - if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) { - Debug::log(LOG, "Updated distance to %f", EVENT->distance); + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_DISTANCE) wlr_tablet_v2_tablet_tool_notify_distance(PTOOL->wlrTabletToolV2, EVENT->distance); - } - if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_ROTATION) { - Debug::log(LOG, "Updated rotation to %f", EVENT->rotation); + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_ROTATION) wlr_tablet_v2_tablet_tool_notify_rotation(PTOOL->wlrTabletToolV2, EVENT->rotation); - } - if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_SLIDER) { - Debug::log(LOG, "Updated slider to %f", EVENT->slider); + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_SLIDER) wlr_tablet_v2_tablet_tool_notify_slider(PTOOL->wlrTabletToolV2, EVENT->slider); - } - if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) { - Debug::log(LOG, "Updated wheel delta to %f", EVENT->wheel_delta); + if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_WHEEL) wlr_tablet_v2_tablet_tool_notify_wheel(PTOOL->wlrTabletToolV2, EVENT->wheel_delta, 0); - } if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_X) PTOOL->tiltX = EVENT->tilt_x; @@ -81,29 +69,24 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { if (EVENT->updated_axes & WLR_TABLET_TOOL_AXIS_TILT_Y) PTOOL->tiltY = EVENT->tilt_y; - if (EVENT->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y)){ - Debug::log(LOG, "Updated tilt to %f, %f", EVENT->tilt_x, EVENT->tilt_y); + if (EVENT->updated_axes & (WLR_TABLET_TOOL_AXIS_TILT_X | WLR_TABLET_TOOL_AXIS_TILT_Y)) wlr_tablet_v2_tablet_tool_notify_tilt(PTOOL->wlrTabletToolV2, PTOOL->tiltX, PTOOL->tiltY); - } + }, PNEWTABLET, "Tablet"); PNEWTABLET->hyprListener_Tip.initCallback(&pDevice->tablet->events.tip, [](void* owner, void* data) { const auto EVENT = (wlr_tablet_tool_tip_event*)data; const auto PTAB = (STablet*)owner; - Debug::log(LOG, "Tablet tip"); - const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); // TODO: this might be wrong if (EVENT->state == WLR_TABLET_TOOL_TIP_DOWN) { - Debug::log(LOG, "Tip down"); g_pInputManager->refocus(); g_pInputManager->focusTablet(PTAB, EVENT->tool); wlr_send_tablet_v2_tablet_tool_down(PTOOL->wlrTabletToolV2); } else { - Debug::log(LOG, "Tip up"); wlr_send_tablet_v2_tablet_tool_up(PTOOL->wlrTabletToolV2); } @@ -113,8 +96,6 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_tool_button_event*)data; const auto PTAB = (STablet*)owner; - Debug::log(LOG, "Tablet button"); - const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); wlr_tablet_v2_tablet_tool_notify_button(PTOOL->wlrTabletToolV2, (zwp_tablet_pad_v2_button_state)EVENT->button, (zwp_tablet_pad_v2_button_state)EVENT->state); @@ -125,16 +106,12 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_tool_proximity_event*)data; const auto PTAB = (STablet*)owner; - Debug::log(LOG, "Tablet proxim"); - const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); if (EVENT->state == WLR_TABLET_TOOL_PROXIMITY_OUT) { PTOOL->active = false; - Debug::log(LOG, "Tool active -> false"); } else { PTOOL->active = true; - Debug::log(LOG, "Tool active -> true"); g_pInputManager->refocus(); g_pInputManager->focusTablet(PTAB, EVENT->tool); } @@ -173,8 +150,6 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { PNEWPAD->hyprListener_Button.initCallback(&pDevice->tablet_pad->events.button, [](void* owner, void* data) { - Debug::log(LOG, "TabletPad button"); - const auto EVENT = (wlr_tablet_pad_button_event*)data; const auto PPAD = (STabletPad*)owner; @@ -188,8 +163,6 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_pad_strip_event*)data; const auto PPAD = (STabletPad*)owner; - Debug::log(LOG, "TabletPad strip"); - wlr_tablet_v2_tablet_pad_notify_strip(PPAD->wlrTabletPadV2, EVENT->strip, EVENT->position, EVENT->source == WLR_TABLET_PAD_STRIP_SOURCE_FINGER, EVENT->time_msec); }, PNEWPAD, "Tablet Pad"); @@ -199,8 +172,6 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_pad_ring_event*)data; const auto PPAD = (STabletPad*)owner; - Debug::log(LOG, "TabletPad ring"); - wlr_tablet_v2_tablet_pad_notify_ring(PPAD->wlrTabletPadV2, EVENT->ring, EVENT->position, EVENT->source == WLR_TABLET_PAD_RING_SOURCE_FINGER, EVENT->time_msec); }, PNEWPAD, "Tablet Pad"); @@ -210,8 +181,6 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { const auto TABLET = (wlr_tablet_tool*)data; const auto PPAD = (STabletPad*)owner; - Debug::log(LOG, "TabletPad attach"); - PPAD->pTabletParent = (STablet*)TABLET->data; if (!PPAD->pTabletParent) @@ -223,8 +192,6 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { const auto PPAD = (STabletPad*)owner; - Debug::log(LOG, "TabletPad destroy"); - g_pInputManager->m_lTabletPads.remove(*PPAD); Debug::log(LOG, "Removed a tablet pad"); @@ -240,8 +207,6 @@ void CInputManager::focusTablet(STablet* pTab, wlr_tablet_tool* pTool, bool moti 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); -- cgit v1.2.3 From 09b130374df035188b34a36e55d6fdda935c7df8 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Jun 2022 19:38:39 +0200 Subject: unfocus tablets --- src/managers/input/Tablets.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/managers/input/Tablets.cpp') diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index 32eef28d..5029ac45 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -39,7 +39,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { break; } - const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(EVENT->tool); // TODO: this might be wrong if (PTOOL->active) { @@ -78,7 +78,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_tool_tip_event*)data; const auto PTAB = (STablet*)owner; - const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(EVENT->tool); // TODO: this might be wrong if (EVENT->state == WLR_TABLET_TOOL_TIP_DOWN) { @@ -96,7 +96,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_tool_button_event*)data; const auto PTAB = (STablet*)owner; - const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(EVENT->tool); wlr_tablet_v2_tablet_tool_notify_button(PTOOL->wlrTabletToolV2, (zwp_tablet_pad_v2_button_state)EVENT->button, (zwp_tablet_pad_v2_button_state)EVENT->state); @@ -106,7 +106,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { const auto EVENT = (wlr_tablet_tool_proximity_event*)data; const auto PTAB = (STablet*)owner; - const auto PTOOL = g_pInputManager->ensureTabletToolPresent(PTAB, EVENT->tool); + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(EVENT->tool); if (EVENT->state == WLR_TABLET_TOOL_PROXIMITY_OUT) { PTOOL->active = false; @@ -119,7 +119,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { }, PNEWTABLET, "Tablet"); } -STabletTool* CInputManager::ensureTabletToolPresent(STablet* pTablet, wlr_tablet_tool* pTool) { +STabletTool* CInputManager::ensureTabletToolPresent(wlr_tablet_tool* pTool) { if (pTool->data == nullptr) { const auto PTOOL = &m_lTabletTools.emplace_back(); @@ -200,7 +200,7 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { } void CInputManager::focusTablet(STablet* pTab, wlr_tablet_tool* pTool, bool motion) { - const auto PTOOL = g_pInputManager->ensureTabletToolPresent(pTab, pTool); + const auto PTOOL = g_pInputManager->ensureTabletToolPresent(pTool); if (const auto PWINDOW = g_pCompositor->m_pLastWindow; g_pCompositor->windowValidMapped(PWINDOW)) { const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal(); @@ -215,5 +215,16 @@ void CInputManager::focusTablet(STablet* pTab, wlr_tablet_tool* pTool, bool moti if (motion) wlr_tablet_v2_tablet_tool_notify_motion(PTOOL->wlrTabletToolV2, LOCAL.x, LOCAL.y); + } else { + wlr_tablet_v2_tablet_tool_notify_proximity_out(PTOOL->wlrTabletToolV2); } } + +void CInputManager::unfocusAllTablets() { + for (auto& tt : m_lTabletTools) { + if (!tt.wlrTabletTool->data) + continue; + + wlr_tablet_v2_tablet_tool_notify_proximity_out(((STabletTool*)tt.wlrTabletTool->data)->wlrTabletToolV2); + } +} \ No newline at end of file -- cgit v1.2.3 From 506977c13d118feedffb7b7fc10d5b16e5400f78 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Jun 2022 19:40:16 +0200 Subject: unfocus on destroy --- src/managers/input/Tablets.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/managers/input/Tablets.cpp') diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index 5029ac45..bb2c5c6d 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -16,6 +16,8 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { PNEWTABLET->hyprListener_Destroy.initCallback(&pDevice->events.destroy, [](void* owner, void* data) { const auto PTAB = (STablet*)owner; + g_pInputManager->unfocusAllTablets(); + g_pInputManager->m_lTablets.remove(*PTAB); Debug::log(LOG, "Removed a tablet"); @@ -133,6 +135,8 @@ STabletTool* CInputManager::ensureTabletToolPresent(wlr_tablet_tool* pTool) { PTOOL->hyprListener_TabletToolDestroy.initCallback(&pTool->events.destroy, [](void* owner, void* data) { const auto PTOOL = (STabletTool*)owner; + g_pInputManager->unfocusAllTablets(); + PTOOL->wlrTabletTool->data = nullptr; g_pInputManager->m_lTabletTools.remove(*PTOOL); }, PTOOL, "Tablet Tool V1"); @@ -192,6 +196,8 @@ void CInputManager::newTabletPad(wlr_input_device* pDevice) { const auto PPAD = (STabletPad*)owner; + g_pInputManager->unfocusAllTablets(); + g_pInputManager->m_lTabletPads.remove(*PPAD); Debug::log(LOG, "Removed a tablet pad"); -- cgit v1.2.3 From 53146ccf69a53850f8ad2af85f0ccf6e1143b878 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Jun 2022 19:47:05 +0200 Subject: oopsie --- src/managers/input/Tablets.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/managers/input/Tablets.cpp') diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index bb2c5c6d..d21ef518 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -213,24 +213,27 @@ void CInputManager::focusTablet(STablet* pTab, wlr_tablet_tool* pTool, bool moti const auto LOCAL = CURSORPOS - PWINDOW->m_vRealPosition.goalv(); - if (PTOOL->wlrTabletToolV2->focused_surface != g_pCompositor->m_pLastFocus) + if (PTOOL->pSurface != g_pCompositor->m_pLastFocus) wlr_tablet_v2_tablet_tool_notify_proximity_out(PTOOL->wlrTabletToolV2); - if (g_pCompositor->m_pLastFocus) + if (g_pCompositor->m_pLastFocus) { + PTOOL->pSurface = 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); } else { - wlr_tablet_v2_tablet_tool_notify_proximity_out(PTOOL->wlrTabletToolV2); + if (PTOOL->pSurface) + wlr_tablet_v2_tablet_tool_notify_proximity_out(PTOOL->wlrTabletToolV2); } } void CInputManager::unfocusAllTablets() { for (auto& tt : m_lTabletTools) { - if (!tt.wlrTabletTool->data) + if (!tt.wlrTabletToolV2 || !tt.pSurface || !tt.active) continue; - wlr_tablet_v2_tablet_tool_notify_proximity_out(((STabletTool*)tt.wlrTabletTool->data)->wlrTabletToolV2); + wlr_tablet_v2_tablet_tool_notify_proximity_out(tt.wlrTabletToolV2); } } \ No newline at end of file -- cgit v1.2.3 From fbc78534599f3129b11899795ba3d099eae4c5fd Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 9 Jun 2022 21:19:31 +0200 Subject: de-focusify on lost proximity --- src/managers/input/Tablets.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/managers/input/Tablets.cpp') diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index d21ef518..3977fc94 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -112,6 +112,12 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { if (EVENT->state == WLR_TABLET_TOOL_PROXIMITY_OUT) { PTOOL->active = false; + + if (PTOOL->pSurface) { + wlr_tablet_v2_tablet_tool_notify_proximity_out(PTOOL->wlrTabletToolV2); + PTOOL->pSurface = nullptr; + } + } else { PTOOL->active = true; g_pInputManager->refocus(); -- cgit v1.2.3