2022-03-21 15:17:04 +01:00
|
|
|
#include "Events.hpp"
|
|
|
|
|
|
|
|
#include "../Compositor.hpp"
|
|
|
|
#include "../helpers/WLClasses.hpp"
|
2022-06-09 12:46:55 +02:00
|
|
|
#include "../managers/input/InputManager.hpp"
|
2022-03-21 15:17:04 +01:00
|
|
|
#include "../render/Renderer.hpp"
|
|
|
|
|
|
|
|
// ---------------------------------------------------- //
|
|
|
|
// _____ ________ _______ _____ ______ _____ //
|
|
|
|
// | __ \| ____\ \ / /_ _/ ____| ____|/ ____| //
|
|
|
|
// | | | | |__ \ \ / / | || | | |__ | (___ //
|
|
|
|
// | | | | __| \ \/ / | || | | __| \___ \ //
|
|
|
|
// | |__| | |____ \ / _| || |____| |____ ____) | //
|
|
|
|
// |_____/|______| \/ |_____\_____|______|_____/ //
|
|
|
|
// //
|
|
|
|
// ---------------------------------------------------- //
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_keyboardDestroy(void* owner, void* data) {
|
|
|
|
SKeyboard* PKEYBOARD = (SKeyboard*)owner;
|
|
|
|
g_pInputManager->destroyKeyboard(PKEYBOARD);
|
2022-03-21 15:17:04 +01:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
Debug::log(LOG, "Destroyed keyboard %x", PKEYBOARD);
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_keyboardKey(void* owner, void* data) {
|
|
|
|
SKeyboard* PKEYBOARD = (SKeyboard*)owner;
|
|
|
|
g_pInputManager->onKeyboardKey((wlr_keyboard_key_event*)data, PKEYBOARD);
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_keyboardMod(void* owner, void* data) {
|
|
|
|
SKeyboard* PKEYBOARD = (SKeyboard*)owner;
|
|
|
|
g_pInputManager->onKeyboardMod(data, PKEYBOARD);
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_mouseFrame(wl_listener* listener, void* data) {
|
|
|
|
wlr_seat_pointer_notify_frame(g_pCompositor->m_sSeat.seat);
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_mouseMove(wl_listener* listener, void* data) {
|
|
|
|
g_pInputManager->onMouseMoved((wlr_pointer_motion_event*)data);
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_mouseMoveAbsolute(wl_listener* listener, void* data) {
|
|
|
|
g_pInputManager->onMouseWarp((wlr_pointer_motion_absolute_event*)data);
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_mouseButton(wl_listener* listener, void* data) {
|
|
|
|
g_pInputManager->onMouseButton((wlr_pointer_button_event*)data);
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_mouseAxis(wl_listener* listener, void* data) {
|
2022-07-16 14:28:17 +02:00
|
|
|
g_pInputManager->onMouseWheel((wlr_pointer_axis_event*)data);
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_requestMouse(wl_listener* listener, void* data) {
|
|
|
|
const auto EVENT = (wlr_seat_pointer_request_set_cursor_event*)data;
|
2022-06-26 13:43:32 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
g_pInputManager->processMouseRequest(EVENT);
|
2022-03-21 15:17:04 +01:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_newInput(wl_listener* listener, void* data) {
|
|
|
|
const auto DEVICE = (wlr_input_device*)data;
|
2022-03-21 15:17:04 +01:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
switch (DEVICE->type) {
|
2022-07-16 11:44:12 +02:00
|
|
|
case WLR_INPUT_DEVICE_KEYBOARD:
|
|
|
|
Debug::log(LOG, "Attached a keyboard with name %s", DEVICE->name);
|
|
|
|
g_pInputManager->newKeyboard(DEVICE);
|
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_POINTER:
|
|
|
|
Debug::log(LOG, "Attached a mouse with name %s", DEVICE->name);
|
|
|
|
g_pInputManager->newMouse(DEVICE);
|
|
|
|
break;
|
|
|
|
case WLR_INPUT_DEVICE_TOUCH:
|
|
|
|
Debug::log(LOG, "Attached a touch device with name %s", DEVICE->name);
|
2022-09-21 15:39:25 +02:00
|
|
|
g_pInputManager->newTouchDevice(DEVICE);
|
2022-07-16 11:44:12 +02:00
|
|
|
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;
|
2022-10-04 21:07:21 +02:00
|
|
|
case WLR_INPUT_DEVICE_SWITCH:
|
|
|
|
Debug::log(LOG, "Attached a switch device with name %s", DEVICE->name);
|
|
|
|
g_pInputManager->newSwitch(DEVICE);
|
|
|
|
break;
|
2022-12-16 18:17:31 +01:00
|
|
|
default: Debug::log(WARN, "Unrecognized input device plugged in: %s", DEVICE->name); break;
|
2022-07-16 11:44:12 +02:00
|
|
|
}
|
2022-03-21 15:17:04 +01:00
|
|
|
|
2022-12-05 15:28:27 +01:00
|
|
|
g_pInputManager->updateCapabilities();
|
2022-04-17 21:40:04 +02:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_newConstraint(wl_listener* listener, void* data) {
|
|
|
|
const auto PCONSTRAINT = (wlr_pointer_constraint_v1*)data;
|
2022-04-17 21:40:04 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
Debug::log(LOG, "New mouse constraint at %x", PCONSTRAINT);
|
2022-04-17 21:40:04 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
g_pInputManager->m_lConstraints.emplace_back();
|
|
|
|
const auto CONSTRAINT = &g_pInputManager->m_lConstraints.back();
|
2022-04-17 21:40:04 +02:00
|
|
|
|
2022-12-16 18:17:31 +01:00
|
|
|
CONSTRAINT->pMouse = g_pCompositor->m_sSeat.mouse;
|
2022-07-16 11:44:12 +02:00
|
|
|
CONSTRAINT->constraint = PCONSTRAINT;
|
2022-04-17 21:40:04 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
CONSTRAINT->hyprListener_destroyConstraint.initCallback(&PCONSTRAINT->events.destroy, &Events::listener_destroyConstraint, CONSTRAINT, "Constraint");
|
|
|
|
CONSTRAINT->hyprListener_setConstraintRegion.initCallback(&PCONSTRAINT->events.set_region, &Events::listener_setConstraintRegion, CONSTRAINT, "Constraint");
|
2022-04-17 21:40:04 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
if (g_pCompositor->m_pLastFocus == PCONSTRAINT->surface) {
|
|
|
|
g_pInputManager->constrainMouse(CONSTRAINT->pMouse, PCONSTRAINT);
|
2022-12-10 15:43:46 +01:00
|
|
|
|
|
|
|
if (!CONSTRAINT->hintSet) {
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto PWINDOW = g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse);
|
2022-12-10 15:43:46 +01:00
|
|
|
CONSTRAINT->positionHint = g_pInputManager->getMouseCoordsInternal() - PWINDOW->m_vRealPosition.goalv();
|
|
|
|
}
|
2022-07-16 11:44:12 +02:00
|
|
|
}
|
2022-04-17 21:40:04 +02:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_destroyConstraint(void* owner, void* data) {
|
|
|
|
const auto PCONSTRAINT = (SConstraint*)owner;
|
2022-04-17 21:40:04 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
if (PCONSTRAINT->pMouse->currentConstraint == PCONSTRAINT->constraint) {
|
|
|
|
PCONSTRAINT->pMouse->hyprListener_commitConstraint.removeCallback();
|
2022-05-19 15:29:26 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
const auto PWINDOW = g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse);
|
2022-05-19 15:29:26 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
if (PWINDOW) {
|
|
|
|
if (PWINDOW->m_bIsX11) {
|
2022-12-16 18:17:31 +01:00
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, PCONSTRAINT->positionHint.x + PWINDOW->m_uSurface.xwayland->x,
|
|
|
|
PWINDOW->m_uSurface.xwayland->y + PCONSTRAINT->positionHint.y);
|
2022-05-19 15:29:26 +02:00
|
|
|
|
2022-12-10 15:43:46 +01:00
|
|
|
wlr_seat_pointer_warp(PCONSTRAINT->constraint->seat, PCONSTRAINT->positionHint.x, PCONSTRAINT->positionHint.y);
|
2022-07-16 11:44:12 +02:00
|
|
|
} else {
|
2022-12-16 18:17:31 +01:00
|
|
|
wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, PCONSTRAINT->positionHint.x + PWINDOW->m_vRealPosition.vec().x,
|
|
|
|
PCONSTRAINT->positionHint.y + PWINDOW->m_vRealPosition.vec().y);
|
2022-07-16 11:44:12 +02:00
|
|
|
|
2022-12-10 15:43:46 +01:00
|
|
|
wlr_seat_pointer_warp(PCONSTRAINT->constraint->seat, PCONSTRAINT->positionHint.x, PCONSTRAINT->positionHint.y);
|
2022-07-16 11:44:12 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-17 21:40:04 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
PCONSTRAINT->pMouse->currentConstraint = nullptr;
|
|
|
|
}
|
2022-05-19 15:29:26 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
Debug::log(LOG, "Unconstrained mouse from %x", PCONSTRAINT->constraint);
|
2022-05-19 15:29:26 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
g_pInputManager->m_lConstraints.remove(*PCONSTRAINT);
|
2022-04-17 21:40:04 +02:00
|
|
|
}
|
2022-05-19 15:29:26 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_setConstraintRegion(void* owner, void* data) {
|
|
|
|
// no
|
2022-05-12 12:13:02 +02:00
|
|
|
}
|
2022-05-19 15:29:26 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_newVirtPtr(wl_listener* listener, void* data) {
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto EV = (wlr_virtual_pointer_v1_new_pointer_event*)data;
|
2022-07-16 11:44:12 +02:00
|
|
|
const auto POINTER = EV->new_pointer;
|
2022-12-16 18:17:31 +01:00
|
|
|
const auto DEVICE = &POINTER->pointer.base;
|
2022-05-19 15:29:26 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
g_pInputManager->newMouse(DEVICE, true);
|
2022-05-12 12:13:02 +02:00
|
|
|
}
|
2022-04-17 21:40:04 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_destroyMouse(void* owner, void* data) {
|
|
|
|
const auto PMOUSE = (SMouse*)owner;
|
2022-04-17 21:40:04 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
g_pInputManager->destroyMouse(PMOUSE->mouse);
|
2022-04-17 21:40:04 +02:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_swipeBegin(wl_listener* listener, void* data) {
|
|
|
|
const auto EVENT = (wlr_pointer_swipe_begin_event*)data;
|
2022-07-07 11:52:12 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
g_pInputManager->onSwipeBegin(EVENT);
|
2022-05-12 12:13:02 +02:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_swipeUpdate(wl_listener* listener, void* data) {
|
|
|
|
const auto EVENT = (wlr_pointer_swipe_update_event*)data;
|
2022-05-12 12:13:02 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
g_pInputManager->onSwipeUpdate(EVENT);
|
2022-05-12 12:13:02 +02:00
|
|
|
}
|
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
void Events::listener_swipeEnd(wl_listener* listener, void* data) {
|
|
|
|
const auto EVENT = (wlr_pointer_swipe_end_event*)data;
|
2022-05-12 12:13:02 +02:00
|
|
|
|
2022-07-16 11:44:12 +02:00
|
|
|
g_pInputManager->onSwipeEnd(EVENT);
|
2022-06-26 18:28:30 +02:00
|
|
|
}
|
2022-07-16 16:12:31 +02:00
|
|
|
|
|
|
|
void Events::listener_pinchBegin(wl_listener* listener, void* data) {
|
|
|
|
const auto EV = (wlr_pointer_pinch_begin_event*)data;
|
|
|
|
wlr_pointer_gestures_v1_send_pinch_begin(g_pCompositor->m_sWLRPointerGestures, g_pCompositor->m_sSeat.seat, EV->time_msec, EV->fingers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_pinchUpdate(wl_listener* listener, void* data) {
|
|
|
|
const auto EV = (wlr_pointer_pinch_update_event*)data;
|
|
|
|
wlr_pointer_gestures_v1_send_pinch_update(g_pCompositor->m_sWLRPointerGestures, g_pCompositor->m_sSeat.seat, EV->time_msec, EV->dx, EV->dy, EV->scale, EV->rotation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_pinchEnd(wl_listener* listener, void* data) {
|
|
|
|
const auto EV = (wlr_pointer_pinch_end_event*)data;
|
|
|
|
wlr_pointer_gestures_v1_send_pinch_end(g_pCompositor->m_sWLRPointerGestures, g_pCompositor->m_sSeat.seat, EV->time_msec, EV->cancelled);
|
2022-08-05 16:21:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_newVirtualKeyboard(wl_listener* listener, void* data) {
|
|
|
|
const auto WLRKB = (wlr_virtual_keyboard_v1*)data;
|
|
|
|
|
|
|
|
g_pInputManager->newVirtualKeyboard(&WLRKB->keyboard.base);
|
2022-08-07 21:17:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_touchBegin(wl_listener* listener, void* data) {
|
|
|
|
g_pInputManager->onTouchDown((wlr_touch_down_event*)data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_touchEnd(wl_listener* listener, void* data) {
|
|
|
|
g_pInputManager->onTouchUp((wlr_touch_up_event*)data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_touchUpdate(wl_listener* listener, void* data) {
|
|
|
|
g_pInputManager->onTouchMove((wlr_touch_motion_event*)data);
|
2022-09-22 22:14:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_touchFrame(wl_listener* listener, void* data) {
|
|
|
|
wlr_seat_touch_notify_frame(g_pCompositor->m_sSeat.seat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_holdBegin(wl_listener* listener, void* data) {
|
|
|
|
g_pInputManager->onPointerHoldBegin((wlr_pointer_hold_begin_event*)data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Events::listener_holdEnd(wl_listener* listener, void* data) {
|
|
|
|
g_pInputManager->onPointerHoldEnd((wlr_pointer_hold_end_event*)data);
|
2022-07-16 16:12:31 +02:00
|
|
|
}
|