2022-03-17 15:53:45 +01:00
|
|
|
#include "InputManager.hpp"
|
|
|
|
#include "../Compositor.hpp"
|
|
|
|
|
|
|
|
void CInputManager::onMouseMoved(wlr_event_pointer_motion* e) {
|
|
|
|
// TODO: sensitivity
|
|
|
|
|
2022-03-19 20:30:21 +01:00
|
|
|
float sensitivity = g_pConfigManager->getFloat("general:sensitivity");
|
2022-03-17 15:53:45 +01:00
|
|
|
|
2022-03-19 20:30:21 +01:00
|
|
|
wlr_cursor_move(g_pCompositor->m_sWLRCursor, e->device, e->delta_x * sensitivity, e->delta_y * sensitivity);
|
2022-03-18 20:42:49 +01:00
|
|
|
|
2022-03-18 23:52:36 +01:00
|
|
|
mouseMoveUnified(e->time_msec);
|
2022-03-18 20:42:49 +01:00
|
|
|
// todo: pointer
|
2022-03-17 16:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::onMouseWarp(wlr_event_pointer_motion_absolute* e) {
|
|
|
|
wlr_cursor_warp_absolute(g_pCompositor->m_sWLRCursor, e->device, e->x, e->y);
|
2022-03-18 20:42:49 +01:00
|
|
|
|
2022-03-18 23:52:36 +01:00
|
|
|
mouseMoveUnified(e->time_msec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::mouseMoveUnified(uint32_t time) {
|
|
|
|
|
2022-03-20 14:36:55 +01:00
|
|
|
wlr_surface* foundSurface = nullptr;
|
|
|
|
Vector2D mouseCoords = getMouseCoordsInternal();
|
|
|
|
const auto PMONITOR = g_pCompositor->getMonitorFromCursor();
|
|
|
|
Vector2D surfacePos;
|
|
|
|
|
2022-03-21 19:18:33 +01:00
|
|
|
// first, we check if the workspace doesnt have a fullscreen window
|
|
|
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
|
|
|
|
if (PWORKSPACE->hasFullscreenWindow) {
|
|
|
|
const auto PFULLSCREENWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->ID);
|
|
|
|
|
|
|
|
// should never ever happen but who knows
|
|
|
|
if (PFULLSCREENWINDOW) {
|
|
|
|
foundSurface = g_pXWaylandManager->getWindowSurface(PFULLSCREENWINDOW);
|
|
|
|
if (foundSurface)
|
|
|
|
surfacePos = PFULLSCREENWINDOW->m_vRealPosition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// then surfaces on top
|
|
|
|
if (!foundSurface)
|
|
|
|
foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &surfacePos);
|
|
|
|
|
2022-03-20 14:36:55 +01:00
|
|
|
if (!foundSurface)
|
2022-03-21 19:18:33 +01:00
|
|
|
foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfacePos);
|
2022-03-20 14:36:55 +01:00
|
|
|
|
|
|
|
// then windows
|
|
|
|
if (!foundSurface && g_pCompositor->vectorToWindowIdeal(mouseCoords)) {
|
|
|
|
foundSurface = g_pXWaylandManager->getWindowSurface(g_pCompositor->windowFromCursor());
|
|
|
|
if (foundSurface)
|
|
|
|
surfacePos = g_pCompositor->windowFromCursor()->m_vRealPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
// then surfaces below
|
|
|
|
if (!foundSurface)
|
|
|
|
foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM], &surfacePos);
|
|
|
|
|
|
|
|
if (!foundSurface)
|
|
|
|
foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], &surfacePos);
|
|
|
|
|
2022-03-18 23:52:36 +01:00
|
|
|
|
2022-03-20 14:36:55 +01:00
|
|
|
if (!foundSurface) {
|
2022-03-18 23:52:36 +01:00
|
|
|
wlr_xcursor_manager_set_cursor_image(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", g_pCompositor->m_sWLRCursor);
|
|
|
|
|
|
|
|
wlr_seat_pointer_clear_focus(g_pCompositor->m_sWLRSeat);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (time)
|
2022-03-18 20:42:49 +01:00
|
|
|
wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sWLRSeat);
|
2022-03-18 23:52:36 +01:00
|
|
|
|
2022-03-20 14:36:55 +01:00
|
|
|
g_pCompositor->focusSurface(foundSurface);
|
2022-03-18 23:52:36 +01:00
|
|
|
|
2022-03-20 14:36:55 +01:00
|
|
|
Vector2D surfaceLocal = Vector2D(g_pCompositor->m_sWLRCursor->x, g_pCompositor->m_sWLRCursor->y) - surfacePos;
|
2022-03-18 23:52:36 +01:00
|
|
|
|
2022-03-20 14:36:55 +01:00
|
|
|
wlr_seat_pointer_notify_enter(g_pCompositor->m_sWLRSeat, foundSurface, surfaceLocal.x, surfaceLocal.y);
|
2022-03-18 23:52:36 +01:00
|
|
|
wlr_seat_pointer_notify_motion(g_pCompositor->m_sWLRSeat, time, surfaceLocal.x, surfaceLocal.y);
|
2022-03-19 20:30:21 +01:00
|
|
|
|
|
|
|
g_pCompositor->m_pLastMonitor = g_pCompositor->getMonitorFromCursor();
|
2022-03-20 11:14:24 +01:00
|
|
|
g_pLayoutManager->getCurrentLayout()->onMouseMove(getMouseCoordsInternal());
|
2022-03-18 20:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::onMouseButton(wlr_event_pointer_button* e) {
|
|
|
|
wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sWLRSeat);
|
|
|
|
|
2022-03-20 18:23:16 +01:00
|
|
|
const auto PKEYBOARD = wlr_seat_get_keyboard(g_pCompositor->m_sWLRSeat);
|
|
|
|
|
2022-03-18 20:42:49 +01:00
|
|
|
switch (e->state) {
|
|
|
|
case WLR_BUTTON_PRESSED:
|
2022-03-20 18:23:39 +01:00
|
|
|
if ((e->button == BTN_LEFT || e->button == BTN_RIGHT) && wlr_keyboard_get_modifiers(PKEYBOARD) == (uint32_t)g_pConfigManager->getInt("general:main_mod_internal")) {
|
2022-03-20 11:14:24 +01:00
|
|
|
currentlyDraggedWindow = g_pCompositor->windowFloatingFromCursor();
|
|
|
|
dragButton = e->button;
|
|
|
|
|
|
|
|
g_pLayoutManager->getCurrentLayout()->onBeginDragWindow();
|
2022-03-21 19:18:33 +01:00
|
|
|
|
|
|
|
return;
|
2022-03-20 11:14:24 +01:00
|
|
|
}
|
2022-03-18 20:42:49 +01:00
|
|
|
break;
|
|
|
|
case WLR_BUTTON_RELEASED:
|
2022-03-20 11:14:24 +01:00
|
|
|
currentlyDraggedWindow = nullptr;
|
|
|
|
dragButton = -1;
|
2022-03-18 20:42:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// notify app if we didnt handle it
|
|
|
|
wlr_seat_pointer_notify_button(g_pCompositor->m_sWLRSeat, e->time_msec, e->button, e->state);
|
2022-03-17 16:56:33 +01:00
|
|
|
}
|
|
|
|
|
2022-03-17 19:03:15 +01:00
|
|
|
Vector2D CInputManager::getMouseCoordsInternal() {
|
2022-03-19 20:30:21 +01:00
|
|
|
return Vector2D(g_pCompositor->m_sWLRCursor->x, g_pCompositor->m_sWLRCursor->y);
|
2022-03-17 20:55:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::newKeyboard(wlr_input_device* keyboard) {
|
2022-03-18 23:25:26 +01:00
|
|
|
m_lKeyboards.push_back(SKeyboard());
|
2022-03-17 20:55:04 +01:00
|
|
|
|
2022-03-18 23:25:26 +01:00
|
|
|
const auto PNEWKEYBOARD = &m_lKeyboards.back();
|
2022-03-17 20:55:04 +01:00
|
|
|
|
|
|
|
PNEWKEYBOARD->keyboard = keyboard;
|
|
|
|
|
|
|
|
xkb_rule_names rules;
|
|
|
|
|
|
|
|
const auto CONTEXT = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
|
|
|
const auto KEYMAP = xkb_keymap_new_from_names(CONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
|
|
|
|
|
|
|
wlr_keyboard_set_keymap(keyboard->keyboard, KEYMAP);
|
|
|
|
xkb_keymap_unref(KEYMAP);
|
|
|
|
xkb_context_unref(CONTEXT);
|
|
|
|
wlr_keyboard_set_repeat_info(keyboard->keyboard, 25, 600);
|
|
|
|
|
|
|
|
wl_signal_add(&keyboard->keyboard->events.modifiers, &PNEWKEYBOARD->listen_keyboardMod);
|
|
|
|
wl_signal_add(&keyboard->keyboard->events.key, &PNEWKEYBOARD->listen_keyboardKey);
|
|
|
|
wl_signal_add(&keyboard->events.destroy, &PNEWKEYBOARD->listen_keyboardDestroy);
|
|
|
|
|
|
|
|
wlr_seat_set_keyboard(g_pCompositor->m_sWLRSeat, keyboard);
|
2022-03-19 11:27:19 +01:00
|
|
|
|
|
|
|
Debug::log(LOG, "New keyboard created, pointers Hypr: %x and WLR: %x", PNEWKEYBOARD, keyboard);
|
2022-03-17 20:55:04 +01:00
|
|
|
}
|
|
|
|
|
2022-03-18 22:53:27 +01:00
|
|
|
void CInputManager::newMouse(wlr_input_device* mouse) {
|
|
|
|
if (wlr_input_device_is_libinput(mouse)) {
|
|
|
|
const auto LIBINPUTDEV = (libinput_device*)wlr_libinput_get_device_handle(mouse);
|
|
|
|
|
|
|
|
if (libinput_device_config_tap_get_finger_count(LIBINPUTDEV)) // this is for tapping (like on a laptop)
|
|
|
|
libinput_device_config_tap_set_enabled(LIBINPUTDEV, LIBINPUT_CONFIG_TAP_ENABLED);
|
|
|
|
|
|
|
|
if (libinput_device_config_scroll_has_natural_scroll(LIBINPUTDEV))
|
|
|
|
libinput_device_config_scroll_set_natural_scroll_enabled(LIBINPUTDEV, 0 /* Natural */);
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, mouse);
|
2022-03-19 11:27:19 +01:00
|
|
|
|
|
|
|
Debug::log(LOG, "New mouse created, pointer WLR: %x", mouse);
|
2022-03-18 22:53:27 +01:00
|
|
|
}
|
|
|
|
|
2022-03-18 23:25:26 +01:00
|
|
|
void CInputManager::destroyKeyboard(SKeyboard* pKeyboard) {
|
|
|
|
wl_list_remove(&pKeyboard->listen_keyboardMod.link);
|
|
|
|
wl_list_remove(&pKeyboard->listen_keyboardKey.link);
|
|
|
|
wl_list_remove(&pKeyboard->listen_keyboardDestroy.link);
|
|
|
|
|
|
|
|
m_lKeyboards.remove(*pKeyboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CInputManager::destroyMouse(wlr_input_device* mouse) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2022-03-18 23:06:45 +01:00
|
|
|
void CInputManager::onKeyboardKey(wlr_event_keyboard_key* e, SKeyboard* pKeyboard) {
|
|
|
|
const auto KEYCODE = e->keycode + 8; // Because to xkbcommon it's +8 from libinput
|
2022-03-17 20:55:04 +01:00
|
|
|
|
2022-03-18 23:06:45 +01:00
|
|
|
const xkb_keysym_t* keysyms;
|
|
|
|
int syms = xkb_state_key_get_syms(pKeyboard->keyboard->keyboard->xkb_state, KEYCODE, &keysyms);
|
|
|
|
|
|
|
|
const auto MODS = wlr_keyboard_get_modifiers(pKeyboard->keyboard->keyboard);
|
|
|
|
|
|
|
|
wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sWLRSeat);
|
2022-03-17 20:55:04 +01:00
|
|
|
|
2022-03-19 22:03:40 +01:00
|
|
|
bool found = false;
|
2022-03-18 23:06:45 +01:00
|
|
|
if (e->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
2022-03-19 17:48:18 +01:00
|
|
|
for (int i = 0; i < syms; ++i)
|
2022-03-19 22:03:40 +01:00
|
|
|
found = g_pKeybindManager->handleKeybinds(MODS, keysyms[i]) || found;
|
2022-03-19 11:27:19 +01:00
|
|
|
} else if (e->state == WL_KEYBOARD_KEY_STATE_RELEASED) {
|
2022-03-19 17:48:18 +01:00
|
|
|
// hee hee
|
2022-03-18 23:06:45 +01:00
|
|
|
}
|
|
|
|
|
2022-03-19 22:03:40 +01:00
|
|
|
if (!found) {
|
|
|
|
wlr_seat_set_keyboard(g_pCompositor->m_sWLRSeat, pKeyboard->keyboard);
|
|
|
|
wlr_seat_keyboard_notify_key(g_pCompositor->m_sWLRSeat, e->time_msec, e->keycode, e->state);
|
|
|
|
}
|
2022-03-18 23:06:45 +01:00
|
|
|
}
|
2022-03-17 20:55:04 +01:00
|
|
|
|
2022-03-18 23:06:45 +01:00
|
|
|
void CInputManager::onKeyboardMod(void* data, SKeyboard* pKeyboard) {
|
|
|
|
wlr_seat_set_keyboard(g_pCompositor->m_sWLRSeat, pKeyboard->keyboard);
|
|
|
|
wlr_seat_keyboard_notify_modifiers(g_pCompositor->m_sWLRSeat, &pKeyboard->keyboard->keyboard->modifiers);
|
2022-03-17 19:03:15 +01:00
|
|
|
}
|