mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 01:05:59 +01:00
commit
b5a446ddfd
13 changed files with 382 additions and 16 deletions
|
@ -10,7 +10,7 @@
|
||||||
#include "config/ConfigManager.hpp"
|
#include "config/ConfigManager.hpp"
|
||||||
#include "managers/ThreadManager.hpp"
|
#include "managers/ThreadManager.hpp"
|
||||||
#include "managers/XWaylandManager.hpp"
|
#include "managers/XWaylandManager.hpp"
|
||||||
#include "managers/InputManager.hpp"
|
#include "managers/input/InputManager.hpp"
|
||||||
#include "managers/LayoutManager.hpp"
|
#include "managers/LayoutManager.hpp"
|
||||||
#include "managers/KeybindManager.hpp"
|
#include "managers/KeybindManager.hpp"
|
||||||
#include "managers/AnimationManager.hpp"
|
#include "managers/AnimationManager.hpp"
|
||||||
|
|
|
@ -156,8 +156,18 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
|
||||||
|
|
||||||
void CConfigManager::handleRawExec(const std::string& command, const std::string& args) {
|
void CConfigManager::handleRawExec(const std::string& command, const std::string& args) {
|
||||||
// Exec in the background dont wait for it.
|
// Exec in the background dont wait for it.
|
||||||
|
|
||||||
|
std::string toExec = args;
|
||||||
|
|
||||||
|
if (g_pXWaylandManager->m_sWLRXWayland)
|
||||||
|
toExec = std::string("WAYLAND_DISPLAY=") + std::string(g_pCompositor->m_szWLDisplaySocket) + " DISPLAY=" + std::string(g_pXWaylandManager->m_sWLRXWayland->display_name) + " " + toExec;
|
||||||
|
else
|
||||||
|
toExec = std::string("WAYLAND_DISPLAY=") + std::string(g_pCompositor->m_szWLDisplaySocket) + " " + toExec;
|
||||||
|
|
||||||
|
Debug::log(LOG, "Config executing %s", toExec.c_str());
|
||||||
|
|
||||||
if (fork() == 0) {
|
if (fork() == 0) {
|
||||||
execl("/bin/sh", "/bin/sh", "-c", args.c_str(), nullptr);
|
execl("/bin/sh", "/bin/sh", "-c", toExec.c_str(), nullptr);
|
||||||
|
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,20 @@ std::string devicesRequest() {
|
||||||
result += getFormat("\tKeyboard at %x:\n\t\t%s\n", &k, k.keyboard->name);
|
result += getFormat("\tKeyboard at %x:\n\t\t%s\n", &k, k.keyboard->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result += "\n\nTablets:\n";
|
||||||
|
|
||||||
|
for (auto& d : g_pInputManager->m_lTabletPads) {
|
||||||
|
result += getFormat("\tTablet Pad at %x (belongs to %x -> %s)\n", &d, d.pTabletParent, d.pTabletParent ? d.pTabletParent->wlrDevice ? d.pTabletParent->wlrDevice->name : "" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& d : g_pInputManager->m_lTablets) {
|
||||||
|
result += getFormat("\tTablet at %x:\n\t\t%s\n", &d, d.wlrDevice ? d.wlrDevice->name : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& d : g_pInputManager->m_lTabletTools) {
|
||||||
|
result += getFormat("\tTablet Tool at %x (belongs to %x)\n", &d, d.wlrTabletTool ? d.wlrTabletTool->data : 0);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "../Compositor.hpp"
|
#include "../Compositor.hpp"
|
||||||
#include "../helpers/WLClasses.hpp"
|
#include "../helpers/WLClasses.hpp"
|
||||||
#include "../managers/InputManager.hpp"
|
#include "../managers/input/InputManager.hpp"
|
||||||
#include "../render/Renderer.hpp"
|
#include "../render/Renderer.hpp"
|
||||||
|
|
||||||
// ---------------------------------------------------- //
|
// ---------------------------------------------------- //
|
||||||
|
@ -78,14 +78,20 @@ void Events::listener_newInput(wl_listener* listener, void* data) {
|
||||||
Debug::log(WARN, "!!!! Hyprland does not directly support touchscreens, bugs may occur !!!!");
|
Debug::log(WARN, "!!!! Hyprland does not directly support touchscreens, bugs may occur !!!!");
|
||||||
wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, DEVICE);
|
wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, DEVICE);
|
||||||
break;
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_TABLET_TOOL:
|
||||||
|
Debug::log(LOG, "Attached a tablet tool with name %s", DEVICE->name);
|
||||||
|
g_pInputManager->newTabletTool(DEVICE);
|
||||||
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_TABLET_PAD:
|
||||||
|
Debug::log(LOG, "Attached a tablet pad with name %s", DEVICE->name);
|
||||||
|
g_pInputManager->newTabletPad(DEVICE);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Debug::log(WARN, "Unrecognized input device plugged in: %s", DEVICE->name);
|
Debug::log(WARN, "Unrecognized input device plugged in: %s", DEVICE->name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t capabilities = WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_KEYBOARD;
|
g_pInputManager->updateCapabilities(DEVICE);
|
||||||
|
|
||||||
wlr_seat_set_capabilities(g_pCompositor->m_sSeat.seat, capabilities);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::listener_newConstraint(wl_listener* listener, void* data) {
|
void Events::listener_newConstraint(wl_listener* listener, void* data) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../Compositor.hpp"
|
#include "../Compositor.hpp"
|
||||||
#include "../helpers/WLClasses.hpp"
|
#include "../helpers/WLClasses.hpp"
|
||||||
#include "../managers/InputManager.hpp"
|
#include "../managers/input/InputManager.hpp"
|
||||||
#include "../render/Renderer.hpp"
|
#include "../render/Renderer.hpp"
|
||||||
#include "Events.hpp"
|
#include "Events.hpp"
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug::log(LOG, "New LayerSurface has no preferred monitor. Assigning Monitor %s", PMONITOR->szName);
|
Debug::log(LOG, "New LayerSurface has no preferred monitor. Assigning Monitor %s", PMONITOR->szName.c_str());
|
||||||
|
|
||||||
WLRLAYERSURFACE->output = PMONITOR->output;
|
WLRLAYERSURFACE->output = PMONITOR->output;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "../Compositor.hpp"
|
#include "../Compositor.hpp"
|
||||||
#include "../helpers/WLClasses.hpp"
|
#include "../helpers/WLClasses.hpp"
|
||||||
#include "../managers/InputManager.hpp"
|
#include "../managers/input/InputManager.hpp"
|
||||||
#include "../render/Renderer.hpp"
|
#include "../render/Renderer.hpp"
|
||||||
|
|
||||||
// ------------------------------ //
|
// ------------------------------ //
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../Compositor.hpp"
|
#include "../Compositor.hpp"
|
||||||
#include "../helpers/WLClasses.hpp"
|
#include "../helpers/WLClasses.hpp"
|
||||||
#include "../managers/InputManager.hpp"
|
#include "../managers/input/InputManager.hpp"
|
||||||
#include "../render/Renderer.hpp"
|
#include "../render/Renderer.hpp"
|
||||||
#include "Events.hpp"
|
#include "Events.hpp"
|
||||||
#include "../debug/HyprCtl.hpp"
|
#include "../debug/HyprCtl.hpp"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "../Compositor.hpp"
|
#include "../Compositor.hpp"
|
||||||
#include "../helpers/WLClasses.hpp"
|
#include "../helpers/WLClasses.hpp"
|
||||||
#include "../managers/InputManager.hpp"
|
#include "../managers/input/InputManager.hpp"
|
||||||
#include "../render/Renderer.hpp"
|
#include "../render/Renderer.hpp"
|
||||||
|
|
||||||
// --------------------------------------------- //
|
// --------------------------------------------- //
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "../Compositor.hpp"
|
#include "../Compositor.hpp"
|
||||||
#include "../helpers/WLClasses.hpp"
|
#include "../helpers/WLClasses.hpp"
|
||||||
#include "../managers/InputManager.hpp"
|
#include "../managers/input/InputManager.hpp"
|
||||||
#include "../render/Renderer.hpp"
|
#include "../render/Renderer.hpp"
|
||||||
|
|
||||||
// ------------------------------------------------------------ //
|
// ------------------------------------------------------------ //
|
||||||
|
|
|
@ -154,3 +154,55 @@ struct SDrag {
|
||||||
DYNLISTENER(unmapIcon);
|
DYNLISTENER(unmapIcon);
|
||||||
DYNLISTENER(commitIcon);
|
DYNLISTENER(commitIcon);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct STablet {
|
||||||
|
DYNLISTENER(Tip);
|
||||||
|
DYNLISTENER(Axis);
|
||||||
|
DYNLISTENER(Button);
|
||||||
|
DYNLISTENER(Proximity);
|
||||||
|
DYNLISTENER(Destroy);
|
||||||
|
|
||||||
|
wlr_tablet* wlrTablet = nullptr;
|
||||||
|
wlr_tablet_v2_tablet* wlrTabletV2 = nullptr;
|
||||||
|
wlr_input_device* wlrDevice = nullptr;
|
||||||
|
|
||||||
|
bool operator==(const STablet& b) {
|
||||||
|
return wlrDevice == b.wlrDevice;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct STabletTool {
|
||||||
|
wlr_tablet_tool* wlrTabletTool = nullptr;
|
||||||
|
wlr_tablet_v2_tablet_tool* wlrTabletToolV2 = nullptr;
|
||||||
|
|
||||||
|
wlr_tablet_v2_tablet* wlrTabletOwnerV2 = nullptr;
|
||||||
|
|
||||||
|
wlr_surface* pSurface = nullptr;
|
||||||
|
|
||||||
|
double tiltX = 0;
|
||||||
|
double tiltY = 0;
|
||||||
|
|
||||||
|
bool active = true;
|
||||||
|
|
||||||
|
DYNLISTENER(TabletToolDestroy);
|
||||||
|
DYNLISTENER(TabletToolSetCursor);
|
||||||
|
|
||||||
|
bool operator==(const STabletTool& b) {
|
||||||
|
return wlrTabletTool == b.wlrTabletTool;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct STabletPad {
|
||||||
|
wlr_tablet_v2_tablet_pad* wlrTabletPadV2 = nullptr;
|
||||||
|
STablet* pTabletParent = nullptr;
|
||||||
|
|
||||||
|
DYNLISTENER(Attach);
|
||||||
|
DYNLISTENER(Button);
|
||||||
|
DYNLISTENER(Strip);
|
||||||
|
DYNLISTENER(Ring);
|
||||||
|
DYNLISTENER(Destroy);
|
||||||
|
|
||||||
|
bool operator==(const STabletPad& b) {
|
||||||
|
return wlrTabletPadV2 == b.wlrTabletPadV2;
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,7 +1,8 @@
|
||||||
#include "InputManager.hpp"
|
#include "InputManager.hpp"
|
||||||
#include "../Compositor.hpp"
|
#include "../../Compositor.hpp"
|
||||||
|
|
||||||
void CInputManager::onMouseMoved(wlr_pointer_motion_event* e) {
|
void CInputManager::onMouseMoved(wlr_pointer_motion_event* e) {
|
||||||
|
unfocusAllTablets();
|
||||||
|
|
||||||
float sensitivity = g_pConfigManager->getFloat("general:sensitivity");
|
float sensitivity = g_pConfigManager->getFloat("general:sensitivity");
|
||||||
|
|
||||||
|
@ -18,6 +19,8 @@ void CInputManager::onMouseMoved(wlr_pointer_motion_event* e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInputManager::onMouseWarp(wlr_pointer_motion_absolute_event* e) {
|
void CInputManager::onMouseWarp(wlr_pointer_motion_absolute_event* e) {
|
||||||
|
unfocusAllTablets();
|
||||||
|
|
||||||
wlr_cursor_warp_absolute(g_pCompositor->m_sWLRCursor, &e->pointer->base, e->x, e->y);
|
wlr_cursor_warp_absolute(g_pCompositor->m_sWLRCursor, &e->pointer->base, e->x, e->y);
|
||||||
|
|
||||||
mouseMoveUnified(e->time_msec);
|
mouseMoveUnified(e->time_msec);
|
||||||
|
@ -500,3 +503,23 @@ void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* co
|
||||||
void Events::listener_commitConstraint(void* owner, void* data) {
|
void Events::listener_commitConstraint(void* owner, void* data) {
|
||||||
//g_pInputManager->recheckConstraint((SMouse*)owner);
|
//g_pInputManager->recheckConstraint((SMouse*)owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CInputManager::updateCapabilities(wlr_input_device* pDev) {
|
||||||
|
// TODO: this is dumb
|
||||||
|
|
||||||
|
switch (pDev->type) {
|
||||||
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
||||||
|
m_uiCapabilities |= WL_SEAT_CAPABILITY_KEYBOARD;
|
||||||
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_POINTER:
|
||||||
|
m_uiCapabilities |= WL_SEAT_CAPABILITY_POINTER;
|
||||||
|
break;
|
||||||
|
case WLR_INPUT_DEVICE_TOUCH:
|
||||||
|
m_uiCapabilities |= WL_SEAT_CAPABILITY_TOUCH;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
wlr_seat_set_capabilities(g_pCompositor->m_sSeat.seat, m_uiCapabilities);
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../defines.hpp"
|
#include "../../defines.hpp"
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "../helpers/WLClasses.hpp"
|
#include "../../helpers/WLClasses.hpp"
|
||||||
#include "../Window.hpp"
|
#include "../../Window.hpp"
|
||||||
|
|
||||||
class CInputManager {
|
class CInputManager {
|
||||||
public:
|
public:
|
||||||
|
@ -28,6 +28,7 @@ public:
|
||||||
void setKeyboardLayout();
|
void setKeyboardLayout();
|
||||||
|
|
||||||
void updateDragIcon();
|
void updateDragIcon();
|
||||||
|
void updateCapabilities(wlr_input_device*);
|
||||||
|
|
||||||
|
|
||||||
// for dragging floating windows
|
// for dragging floating windows
|
||||||
|
@ -40,11 +41,26 @@ public:
|
||||||
std::list<SKeyboard> m_lKeyboards;
|
std::list<SKeyboard> m_lKeyboards;
|
||||||
std::list<SMouse> m_lMice;
|
std::list<SMouse> m_lMice;
|
||||||
|
|
||||||
|
// tablets
|
||||||
|
std::list<STablet> m_lTablets;
|
||||||
|
std::list<STabletTool> m_lTabletTools;
|
||||||
|
std::list<STabletPad> m_lTabletPads;
|
||||||
|
|
||||||
|
void newTabletTool(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;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
uint32_t m_uiCapabilities = 0;
|
||||||
|
|
||||||
void mouseMoveUnified(uint32_t, bool refocus = false);
|
void mouseMoveUnified(uint32_t, bool refocus = false);
|
||||||
|
|
||||||
|
STabletTool* ensureTabletToolPresent(wlr_tablet_tool*);
|
||||||
|
|
||||||
|
void unfocusAllTablets();
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::unique_ptr<CInputManager> g_pInputManager;
|
inline std::unique_ptr<CInputManager> g_pInputManager;
|
245
src/managers/input/Tablets.cpp
Normal file
245
src/managers/input/Tablets.cpp
Normal file
|
@ -0,0 +1,245 @@
|
||||||
|
#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;
|
||||||
|
|
||||||
|
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) {
|
||||||
|
const auto PTAB = (STablet*)owner;
|
||||||
|
|
||||||
|
g_pInputManager->unfocusAllTablets();
|
||||||
|
|
||||||
|
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(EVENT->tool);
|
||||||
|
|
||||||
|
// TODO: this might be wrong
|
||||||
|
if (PTOOL->active) {
|
||||||
|
g_pInputManager->refocus();
|
||||||
|
|
||||||
|
g_pInputManager->focusTablet(PTAB, EVENT->tool, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
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(EVENT->tool);
|
||||||
|
|
||||||
|
// TODO: this might be wrong
|
||||||
|
if (EVENT->state == WLR_TABLET_TOOL_TIP_DOWN) {
|
||||||
|
g_pInputManager->refocus();
|
||||||
|
g_pInputManager->focusTablet(PTAB, EVENT->tool);
|
||||||
|
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(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(EVENT->tool);
|
||||||
|
|
||||||
|
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();
|
||||||
|
g_pInputManager->focusTablet(PTAB, EVENT->tool);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, PNEWTABLET, "Tablet");
|
||||||
|
}
|
||||||
|
|
||||||
|
STabletTool* CInputManager::ensureTabletToolPresent(wlr_tablet_tool* pTool) {
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
g_pInputManager->unfocusAllTablets();
|
||||||
|
|
||||||
|
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->unfocusAllTablets();
|
||||||
|
|
||||||
|
g_pInputManager->m_lTabletPads.remove(*PPAD);
|
||||||
|
|
||||||
|
Debug::log(LOG, "Removed a tablet pad");
|
||||||
|
|
||||||
|
}, PNEWPAD, "Tablet Pad");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInputManager::focusTablet(STablet* pTab, wlr_tablet_tool* pTool, bool motion) {
|
||||||
|
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();
|
||||||
|
|
||||||
|
const auto LOCAL = CURSORPOS - PWINDOW->m_vRealPosition.goalv();
|
||||||
|
|
||||||
|
if (PTOOL->pSurface != g_pCompositor->m_pLastFocus)
|
||||||
|
wlr_tablet_v2_tablet_tool_notify_proximity_out(PTOOL->wlrTabletToolV2);
|
||||||
|
|
||||||
|
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 {
|
||||||
|
if (PTOOL->pSurface)
|
||||||
|
wlr_tablet_v2_tablet_tool_notify_proximity_out(PTOOL->wlrTabletToolV2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInputManager::unfocusAllTablets() {
|
||||||
|
for (auto& tt : m_lTabletTools) {
|
||||||
|
if (!tt.wlrTabletToolV2 || !tt.pSurface || !tt.active)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
wlr_tablet_v2_tablet_tool_notify_proximity_out(tt.wlrTabletToolV2);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue