mirror of https://github.com/hyprwm/Hyprland
focus and move mouse to inputmanager
This commit is contained in:
parent
a1a8f3b6d5
commit
5811d968bf
|
@ -152,4 +152,45 @@ SMonitor* CCompositor::getMonitorFromCursor() {
|
||||||
|
|
||||||
void CCompositor::removeWindowFromVectorSafe(CWindow* pWindow) {
|
void CCompositor::removeWindowFromVectorSafe(CWindow* pWindow) {
|
||||||
m_lWindows.remove(*pWindow);
|
m_lWindows.remove(*pWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCompositor::windowExists(CWindow* pWindow) {
|
||||||
|
for (auto& w : m_lWindows) {
|
||||||
|
if (&w == pWindow)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CWindow* CCompositor::vectorToWindow(const Vector2D& pos) {
|
||||||
|
for (auto& w : m_lWindows) {
|
||||||
|
wlr_box box = {w.m_vPosition.x, w.m_vPosition.y, w.m_vSize.x, w.m_vSize.y};
|
||||||
|
if (wlr_box_contains_point(&box, pos.x, pos.y))
|
||||||
|
return &w;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCompositor::focusWindow(CWindow* pWindow) {
|
||||||
|
|
||||||
|
if (!pWindow) {
|
||||||
|
wlr_seat_keyboard_notify_clear_focus(m_sWLRSeat);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto PWINDOWSURFACE = g_pXWaylandManager->getWindowSurface(pWindow);
|
||||||
|
|
||||||
|
if (m_sWLRSeat->keyboard_state.focused_surface == PWINDOWSURFACE)
|
||||||
|
return; // Don't focus when already focused on this.
|
||||||
|
|
||||||
|
const auto KEYBOARD = wlr_seat_get_keyboard(m_sWLRSeat);
|
||||||
|
wlr_seat_keyboard_notify_enter(m_sWLRSeat, PWINDOWSURFACE, KEYBOARD->keycodes, KEYBOARD->num_keycodes, &KEYBOARD->modifiers);
|
||||||
|
|
||||||
|
g_pXWaylandManager->activateSurface(PWINDOWSURFACE, true);
|
||||||
|
if (m_pLastFocus && windowExists(m_pLastFocus))
|
||||||
|
g_pXWaylandManager->activateSurface(g_pXWaylandManager->getWindowSurface(m_pLastFocus), false);
|
||||||
|
|
||||||
|
m_pLastFocus = pWindow;
|
||||||
}
|
}
|
|
@ -50,12 +50,17 @@ public:
|
||||||
|
|
||||||
void startCompositor();
|
void startCompositor();
|
||||||
|
|
||||||
|
CWindow* m_pLastFocus = nullptr;
|
||||||
|
|
||||||
|
|
||||||
// ------------------------------------------------- //
|
// ------------------------------------------------- //
|
||||||
|
|
||||||
SMonitor* getMonitorFromID(const int&);
|
SMonitor* getMonitorFromID(const int&);
|
||||||
SMonitor* getMonitorFromCursor();
|
SMonitor* getMonitorFromCursor();
|
||||||
void removeWindowFromVectorSafe(CWindow*);
|
void removeWindowFromVectorSafe(CWindow*);
|
||||||
|
void focusWindow(CWindow*);
|
||||||
|
bool windowExists(CWindow*);
|
||||||
|
CWindow* vectorToWindow(const Vector2D&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -347,7 +347,7 @@ void Events::listener_newInput(wl_listener* listener, void* data) {
|
||||||
break;
|
break;
|
||||||
case WLR_INPUT_DEVICE_POINTER:
|
case WLR_INPUT_DEVICE_POINTER:
|
||||||
Debug::log(LOG, "Attached a mouse with name %s", DEVICE->name);
|
Debug::log(LOG, "Attached a mouse with name %s", DEVICE->name);
|
||||||
wlr_cursor_attach_input_device(g_pCompositor->m_sWLRCursor, DEVICE);
|
g_pInputManager->newMouse(DEVICE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -19,7 +19,8 @@ void CInputManager::onMouseMoved(wlr_event_pointer_motion* e) {
|
||||||
if (e->time_msec)
|
if (e->time_msec)
|
||||||
wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sWLRSeat);
|
wlr_idle_notify_activity(g_pCompositor->m_sWLRIdle, g_pCompositor->m_sWLRSeat);
|
||||||
|
|
||||||
// todo: focus
|
|
||||||
|
g_pCompositor->focusWindow(g_pCompositor->vectorToWindow(getMouseCoordsInternal()));
|
||||||
// todo: pointer
|
// todo: pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +75,20 @@ void CInputManager::newKeyboard(wlr_input_device* keyboard) {
|
||||||
wlr_seat_set_keyboard(g_pCompositor->m_sWLRSeat, keyboard);
|
wlr_seat_set_keyboard(g_pCompositor->m_sWLRSeat, keyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void CInputManager::onKeyboardKey(wlr_event_keyboard_key* event) {
|
void CInputManager::onKeyboardKey(wlr_event_keyboard_key* event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ public:
|
||||||
void onKeyboardMod(void*);
|
void onKeyboardMod(void*);
|
||||||
|
|
||||||
void newKeyboard(wlr_input_device*);
|
void newKeyboard(wlr_input_device*);
|
||||||
|
void newMouse(wlr_input_device*);
|
||||||
|
|
||||||
Vector2D getMouseCoordsInternal();
|
Vector2D getMouseCoordsInternal();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue