summaryrefslogtreecommitdiff
path: root/src/managers/input
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2024-06-08 10:07:59 +0200
committerGitHub <noreply@github.com>2024-06-08 10:07:59 +0200
commit6967a31450441fc5605c05db6f65505dace4b263 (patch)
tree255a3cff7f3e2eb8a50c952eab9b270a7937561d /src/managers/input
parentc31d9ef4172452f6f219f91d9b87a24d91f0cf3a (diff)
wayland/core: move to new impl (#6268)
* wayland/core/dmabuf: move to new impl it's the final countdown
Diffstat (limited to 'src/managers/input')
-rw-r--r--src/managers/input/IdleInhibitor.cpp4
-rw-r--r--src/managers/input/InputManager.cpp60
-rw-r--r--src/managers/input/InputManager.hpp24
-rw-r--r--src/managers/input/InputMethodPopup.cpp22
-rw-r--r--src/managers/input/InputMethodPopup.hpp16
-rw-r--r--src/managers/input/InputMethodRelay.cpp20
-rw-r--r--src/managers/input/InputMethodRelay.hpp10
-rw-r--r--src/managers/input/Tablets.cpp6
-rw-r--r--src/managers/input/TextInput.cpp71
-rw-r--r--src/managers/input/TextInput.hpp44
-rw-r--r--src/managers/input/Touch.cpp2
11 files changed, 140 insertions, 139 deletions
diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp
index a71059e4..a38acdbf 100644
--- a/src/managers/input/IdleInhibitor.cpp
+++ b/src/managers/input/IdleInhibitor.cpp
@@ -14,7 +14,7 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) {
recheckIdleInhibitorStatus();
});
- auto WLSurface = CWLSurface::surfaceFromWlr(PINHIBIT->inhibitor->surface);
+ auto WLSurface = CWLSurface::fromResource(PINHIBIT->inhibitor->surface.lock());
if (!WLSurface) {
Debug::log(LOG, "Inhibitor has no HL Surface attached to it, likely meaning it's a non-desktop element. Assuming it's visible.");
@@ -37,7 +37,7 @@ void CInputManager::recheckIdleInhibitorStatus() {
return;
}
- auto WLSurface = CWLSurface::surfaceFromWlr(ii->inhibitor->surface);
+ auto WLSurface = CWLSurface::fromResource(ii->inhibitor->surface.lock());
if (!WLSurface)
continue;
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index 27d04699..c12ac389 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -43,7 +43,7 @@ CInputManager::CInputManager() {
Debug::log(LOG, "cursorImage request: shape {} -> {}", (uint32_t)event.shape, event.shapeName);
- m_sCursorSurfaceInfo.wlSurface.unassign();
+ m_sCursorSurfaceInfo.wlSurface->unassign();
m_sCursorSurfaceInfo.vHotspot = {};
m_sCursorSurfaceInfo.name = event.shapeName;
m_sCursorSurfaceInfo.hidden = false;
@@ -58,6 +58,8 @@ CInputManager::CInputManager() {
m_sListeners.newVirtualMouse =
PROTO::virtualPointer->events.newPointer.registerListener([this](std::any data) { this->newVirtualMouse(std::any_cast<SP<CVirtualPointerV1Resource>>(data)); });
m_sListeners.setCursor = g_pSeatManager->events.setCursor.registerListener([this](std::any d) { this->processMouseRequest(d); });
+
+ m_sCursorSurfaceInfo.wlSurface = CWLSurface::create();
}
CInputManager::~CInputManager() {
@@ -115,8 +117,8 @@ void CInputManager::sendMotionEventsToFocused() {
return;
// todo: this sucks ass
- const auto PWINDOW = g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus);
- const auto PLS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_pLastFocus);
+ const auto PWINDOW = g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus.lock());
+ const auto PLS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_pLastFocus.lock());
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
@@ -125,7 +127,7 @@ void CInputManager::sendMotionEventsToFocused() {
m_bEmptyFocusCursorSet = false;
- g_pSeatManager->setPointerFocus(g_pCompositor->m_pLastFocus, LOCAL);
+ g_pSeatManager->setPointerFocus(g_pCompositor->m_pLastFocus.lock(), LOCAL);
}
void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
@@ -141,14 +143,14 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
const auto FOLLOWMOUSE = *PFOLLOWONDND && PROTO::data->dndActive() ? 1 : *PFOLLOWMOUSE;
- m_pFoundSurfaceToFocus = nullptr;
+ m_pFoundSurfaceToFocus.reset();
m_pFoundLSToFocus.reset();
m_pFoundWindowToFocus.reset();
- wlr_surface* foundSurface = nullptr;
- Vector2D surfaceCoords;
- Vector2D surfacePos = Vector2D(-1337, -1337);
- PHLWINDOW pFoundWindow;
- PHLLS pFoundLayerSurface;
+ SP<CWLSurfaceResource> foundSurface;
+ Vector2D surfaceCoords;
+ Vector2D surfacePos = Vector2D(-1337, -1337);
+ PHLWINDOW pFoundWindow;
+ PHLLS pFoundLayerSurface;
if (!g_pCompositor->m_bReadyToProcess || g_pCompositor->m_bIsShuttingDown || g_pCompositor->m_bUnsafeState)
return;
@@ -191,12 +193,12 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
if (forcedFocus) {
pFoundWindow = forcedFocus;
surfacePos = pFoundWindow->m_vRealPosition.value();
- foundSurface = pFoundWindow->m_pWLSurface.wlr();
+ foundSurface = pFoundWindow->m_pWLSurface->resource();
}
// constraints
if (!g_pSeatManager->mouse.expired() && isConstrained()) {
- const auto SURF = CWLSurface::surfaceFromWlr(g_pCompositor->m_pLastFocus);
+ const auto SURF = CWLSurface::fromResource(g_pCompositor->m_pLastFocus.lock());
const auto CONSTRAINT = SURF->constraint();
if (SURF && CONSTRAINT) {
@@ -223,7 +225,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
// if we are holding a pointer button,
// and we're not dnd-ing, don't refocus. Keep focus on last surface.
if (!PROTO::data->dndActive() && !m_lCurrentlyHeldButtons.empty() && g_pCompositor->m_pLastFocus && g_pSeatManager->state.pointerFocus && !m_bHardInput) {
- foundSurface = g_pSeatManager->state.pointerFocus;
+ foundSurface = g_pSeatManager->state.pointerFocus.lock();
// IME popups aren't desktop-like elements
// TODO: make them.
@@ -233,7 +235,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
m_bFocusHeldByButtons = true;
m_bRefocusHeldByButtons = refocus;
} else {
- auto HLSurface = CWLSurface::surfaceFromWlr(foundSurface);
+ auto HLSurface = CWLSurface::fromResource(foundSurface);
if (HLSurface) {
const auto BOX = HLSurface->getSurfaceBoxGlobal();
@@ -275,7 +277,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
if (!foundSurface) {
auto popup = g_pInputManager->m_sIMERelay.popupFromCoords(mouseCoords);
if (popup) {
- foundSurface = popup->getWlrSurface();
+ foundSurface = popup->getSurface();
surfacePos = popup->globalBox().pos();
}
}
@@ -306,7 +308,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords);
surfacePos = Vector2D(-1337, -1337);
} else {
- foundSurface = pFoundWindow->m_pWLSurface.wlr();
+ foundSurface = pFoundWindow->m_pWLSurface->resource();
surfacePos = pFoundWindow->m_vRealPosition.value();
}
}
@@ -345,7 +347,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
if (!pFoundWindow->m_bIsX11) {
foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords);
} else {
- foundSurface = pFoundWindow->m_pWLSurface.wlr();
+ foundSurface = pFoundWindow->m_pWLSurface->resource();
surfacePos = pFoundWindow->m_vRealPosition.value();
}
}
@@ -369,9 +371,9 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
return; // setGrab will refocus
} else {
// we need to grab the last surface.
- foundSurface = g_pSeatManager->state.pointerFocus;
+ foundSurface = g_pSeatManager->state.pointerFocus.lock();
- auto HLSurface = CWLSurface::surfaceFromWlr(foundSurface);
+ auto HLSurface = CWLSurface::fromResource(foundSurface);
if (HLSurface) {
const auto BOX = HLSurface->getSurfaceBoxGlobal();
@@ -423,7 +425,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
bool allowKeyboardRefocus = true;
if (!refocus && g_pCompositor->m_pLastFocus) {
- const auto PLS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_pLastFocus);
+ const auto PLS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_pLastFocus.lock());
if (PLS && PLS->layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE)
allowKeyboardRefocus = false;
@@ -441,7 +443,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
return;
}
- if (pFoundWindow && foundSurface == pFoundWindow->m_pWLSurface.wlr() && !m_bCursorImageOverridden) {
+ if (pFoundWindow && foundSurface == pFoundWindow->m_pWLSurface->resource() && !m_bCursorImageOverridden) {
const auto BOX = pFoundWindow->getWindowMainSurfaceBox();
if (!VECINRECT(mouseCoords, BOX.x, BOX.y, BOX.x + BOX.width, BOX.y + BOX.height))
setCursorImageOverride("left_ptr");
@@ -555,11 +557,11 @@ void CInputManager::processMouseRequest(std::any E) {
Debug::log(LOG, "cursorImage request: surface {:x}", (uintptr_t)e.surf);
- if (e.surf != m_sCursorSurfaceInfo.wlSurface.wlr()) {
- m_sCursorSurfaceInfo.wlSurface.unassign();
+ if (e.surf != m_sCursorSurfaceInfo.wlSurface->resource()) {
+ m_sCursorSurfaceInfo.wlSurface->unassign();
if (e.surf)
- m_sCursorSurfaceInfo.wlSurface.assign(e.surf);
+ m_sCursorSurfaceInfo.wlSurface->assign(e.surf);
}
if (e.surf) {
@@ -573,7 +575,7 @@ void CInputManager::processMouseRequest(std::any E) {
m_sCursorSurfaceInfo.name = "";
m_sCursorSurfaceInfo.inUse = true;
- g_pHyprRenderer->setCursorSurface(&m_sCursorSurfaceInfo.wlSurface, e.hotspot.x, e.hotspot.y);
+ g_pHyprRenderer->setCursorSurface(m_sCursorSurfaceInfo.wlSurface, e.hotspot.x, e.hotspot.y);
}
void CInputManager::restoreCursorIconToApp() {
@@ -586,8 +588,8 @@ void CInputManager::restoreCursorIconToApp() {
}
if (m_sCursorSurfaceInfo.name.empty()) {
- if (m_sCursorSurfaceInfo.wlSurface.exists())
- g_pHyprRenderer->setCursorSurface(&m_sCursorSurfaceInfo.wlSurface, m_sCursorSurfaceInfo.vHotspot.x, m_sCursorSurfaceInfo.vHotspot.y);
+ if (m_sCursorSurfaceInfo.wlSurface->exists())
+ g_pHyprRenderer->setCursorSurface(m_sCursorSurfaceInfo.wlSurface, m_sCursorSurfaceInfo.vHotspot.x, m_sCursorSurfaceInfo.vHotspot.y);
} else {
g_pHyprRenderer->setCursorFromName(m_sCursorSurfaceInfo.name);
}
@@ -696,7 +698,7 @@ void CInputManager::processMouseDownNormal(const IPointer::SButtonEvent& e) {
if (!g_pSeatManager->state.pointerFocus)
break;
- auto HLSurf = CWLSurface::surfaceFromWlr(g_pSeatManager->state.pointerFocus);
+ auto HLSurf = CWLSurface::fromResource(g_pSeatManager->state.pointerFocus.lock());
if (HLSurf && HLSurf->getWindow())
g_pCompositor->changeWindowZOrder(HLSurf->getWindow(), true);
@@ -1399,7 +1401,7 @@ bool CInputManager::isConstrained() {
if (!C)
continue;
- if (!C->isActive() || C->owner()->wlr() != g_pCompositor->m_pLastFocus)
+ if (!C->isActive() || C->owner()->resource() != g_pCompositor->m_pLastFocus)
continue;
return true;
diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp
index f7d9ae57..9fdf061c 100644
--- a/src/managers/input/InputManager.hpp
+++ b/src/managers/input/InputManager.hpp
@@ -44,10 +44,10 @@ enum eBorderIconDirection {
};
struct STouchData {
- PHLWINDOWREF touchFocusWindow;
- PHLLSREF touchFocusLS;
- wlr_surface* touchFocusSurface = nullptr;
- Vector2D touchSurfaceOrigin;
+ PHLWINDOWREF touchFocusWindow;
+ PHLLSREF touchFocusLS;
+ WP<CWLSurfaceResource> touchFocusSurface;
+ Vector2D touchSurfaceOrigin;
};
// The third row is always 0 0 1 and is not expected by `libinput_device_config_calibration_set_matrix`
@@ -236,9 +236,9 @@ class CInputManager {
void applyConfigToKeyboard(SP<IKeyboard>);
// this will be set after a refocus()
- wlr_surface* m_pFoundSurfaceToFocus = nullptr;
- PHLLSREF m_pFoundLSToFocus;
- PHLWINDOWREF m_pFoundWindowToFocus;
+ WP<CWLSurfaceResource> m_pFoundSurfaceToFocus;
+ PHLLSREF m_pFoundLSToFocus;
+ PHLWINDOWREF m_pFoundWindowToFocus;
// for holding focus on buttons held
bool m_bFocusHeldByButtons = false;
@@ -268,11 +268,11 @@ class CInputManager {
// cursor surface
struct cursorSI {
- bool hidden = false; // null surface = hidden
- CWLSurface wlSurface;
- Vector2D vHotspot;
- std::string name; // if not empty, means set by name.
- bool inUse = false;
+ bool hidden = false; // null surface = hidden
+ SP<CWLSurface> wlSurface;
+ Vector2D vHotspot;
+ std::string name; // if not empty, means set by name.
+ bool inUse = false;
} m_sCursorSurfaceInfo;
void restoreCursorIconToApp(); // no-op if restored
diff --git a/src/managers/input/InputMethodPopup.cpp b/src/managers/input/InputMethodPopup.cpp
index 9ff584e6..a8757030 100644
--- a/src/managers/input/InputMethodPopup.cpp
+++ b/src/managers/input/InputMethodPopup.cpp
@@ -3,22 +3,24 @@
#include "../../Compositor.hpp"
#include "../../protocols/FractionalScale.hpp"
#include "../../protocols/InputMethodV2.hpp"
+#include "../../protocols/core/Compositor.hpp"
CInputPopup::CInputPopup(SP<CInputMethodPopupV2> popup_) : popup(popup_) {
listeners.commit = popup_->events.commit.registerListener([this](std::any d) { onCommit(); });
listeners.map = popup_->events.map.registerListener([this](std::any d) { onMap(); });
listeners.unmap = popup_->events.unmap.registerListener([this](std::any d) { onUnmap(); });
listeners.destroy = popup_->events.destroy.registerListener([this](std::any d) { onDestroy(); });
- surface.assign(popup_->surface());
+ surface = CWLSurface::create();
+ surface->assign(popup_->surface());
}
-CWLSurface* CInputPopup::queryOwner() {
+SP<CWLSurface> CInputPopup::queryOwner() {
const auto FOCUSED = g_pInputManager->m_sIMERelay.getFocusedTextInput();
if (!FOCUSED)
return nullptr;
- return CWLSurface::surfaceFromWlr(FOCUSED->focusedSurface());
+ return CWLSurface::fromResource(FOCUSED->focusedSurface());
}
void CInputPopup::onDestroy() {
@@ -36,7 +38,7 @@ void CInputPopup::onMap() {
if (!PMONITOR)
return;
- PROTO::fractional->sendScale(surface.wlr(), PMONITOR->scale);
+ PROTO::fractional->sendScale(surface->resource(), PMONITOR->scale);
}
void CInputPopup::onUnmap() {
@@ -69,7 +71,7 @@ void CInputPopup::damageSurface() {
}
Vector2D pos = globalBox().pos();
- g_pHyprRenderer->damageSurface(surface.wlr(), pos.x, pos.y);
+ g_pHyprRenderer->damageSurface(surface->resource(), pos.x, pos.y);
}
void CInputPopup::updateBox() {
@@ -98,7 +100,7 @@ void CInputPopup::updateBox() {
cursorBoxParent = {0, 0, (int)parentBox.w, (int)parentBox.h};
}
- Vector2D currentPopupSize = surface.getViewporterCorrectedSize();
+ Vector2D currentPopupSize = surface->getViewporterCorrectedSize();
CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle());
@@ -127,9 +129,9 @@ void CInputPopup::updateBox() {
const auto PML = g_pCompositor->getMonitorFromID(lastMonitor);
if (PML)
- wlr_surface_send_leave(surface.wlr(), PML->output);
+ surface->resource()->leave(PML->self.lock());
- wlr_surface_send_enter(surface.wlr(), PM->output);
+ surface->resource()->enter(PM->self.lock());
lastMonitor = PM->ID;
}
@@ -151,6 +153,6 @@ bool CInputPopup::isVecInPopup(const Vector2D& point) {
return globalBox().containsPoint(point);
}
-wlr_surface* CInputPopup::getWlrSurface() {
- return surface.wlr();
+SP<CWLSurfaceResource> CInputPopup::getSurface() {
+ return surface->resource();
}
diff --git a/src/managers/input/InputMethodPopup.hpp b/src/managers/input/InputMethodPopup.hpp
index 61b45d74..9c5491bf 100644
--- a/src/managers/input/InputMethodPopup.hpp
+++ b/src/managers/input/InputMethodPopup.hpp
@@ -12,18 +12,18 @@ class CInputPopup {
public:
CInputPopup(SP<CInputMethodPopupV2> popup);
- void damageEntire();
- void damageSurface();
+ void damageEntire();
+ void damageSurface();
- bool isVecInPopup(const Vector2D& point);
+ bool isVecInPopup(const Vector2D& point);
- CBox globalBox();
- wlr_surface* getWlrSurface();
+ CBox globalBox();
+ SP<CWLSurfaceResource> getSurface();
- void onCommit();
+ void onCommit();
private:
- CWLSurface* queryOwner();
+ SP<CWLSurface> queryOwner();
void updateBox();
void onDestroy();
@@ -31,7 +31,7 @@ class CInputPopup {
void onUnmap();
WP<CInputMethodPopupV2> popup;
- CWLSurface surface;
+ SP<CWLSurface> surface;
CBox lastBoxLocal;
uint64_t lastMonitor = -1;
diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp
index abf18fba..92ab14d8 100644
--- a/src/managers/input/InputMethodRelay.cpp
+++ b/src/managers/input/InputMethodRelay.cpp
@@ -3,9 +3,11 @@
#include "../../Compositor.hpp"
#include "../../protocols/TextInputV3.hpp"
#include "../../protocols/InputMethodV2.hpp"
+#include "../../protocols/core/Compositor.hpp"
CInputMethodRelay::CInputMethodRelay() {
- static auto P = g_pHookSystem->hookDynamic("keyboardFocus", [&](void* self, SCallbackInfo& info, std::any param) { onKeyboardFocus(std::any_cast<wlr_surface*>(param)); });
+ static auto P =
+ g_pHookSystem->hookDynamic("keyboardFocus", [&](void* self, SCallbackInfo& info, std::any param) { onKeyboardFocus(std::any_cast<SP<CWLSurfaceResource>>(param)); });
listeners.newTIV3 = PROTO::textInputV3->events.newTextInput.registerListener([this](std::any ti) { onNewTextInput(ti); });
listeners.newIME = PROTO::ime->events.newIME.registerListener([this](std::any ime) { onNewIME(std::any_cast<SP<CInputMethodV2>>(ime)); });
@@ -54,17 +56,17 @@ void CInputMethodRelay::onNewIME(SP<CInputMethodV2> pIME) {
return;
for (auto& ti : m_vTextInputs) {
- if (ti->client() != wl_resource_get_client(g_pCompositor->m_pLastFocus->resource))
+ if (ti->client() != g_pCompositor->m_pLastFocus->client())
continue;
if (ti->isV3())
- ti->enter(g_pCompositor->m_pLastFocus);
+ ti->enter(g_pCompositor->m_pLastFocus.lock());
else
- ti->onEnabled(g_pCompositor->m_pLastFocus);
+ ti->onEnabled(g_pCompositor->m_pLastFocus.lock());
}
}
-void CInputMethodRelay::setIMEPopupFocus(CInputPopup* pPopup, wlr_surface* pSurface) {
+void CInputMethodRelay::setIMEPopupFocus(CInputPopup* pPopup, SP<CWLSurfaceResource> pSurface) {
pPopup->onCommit();
}
@@ -125,7 +127,7 @@ void CInputMethodRelay::commitIMEState(CTextInput* pInput) {
pInput->commitStateToIME(m_pIME.lock());
}
-void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) {
+void CInputMethodRelay::onKeyboardFocus(SP<CWLSurfaceResource> pSurface) {
if (m_pIME.expired())
return;
@@ -145,7 +147,7 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) {
if (!ti->isV3())
continue;
- if (ti->client() != wl_resource_get_client(pSurface->resource))
+ if (ti->client() != pSurface->client())
continue;
ti->enter(pSurface);
@@ -161,9 +163,9 @@ CInputPopup* CInputMethodRelay::popupFromCoords(const Vector2D& point) {
return nullptr;
}
-CInputPopup* CInputMethodRelay::popupFromSurface(const wlr_surface* surface) {
+CInputPopup* CInputMethodRelay::popupFromSurface(const SP<CWLSurfaceResource> surface) {
for (auto& p : m_vIMEPopups) {
- if (p->getWlrSurface() == surface)
+ if (p->getSurface() == surface)
return p.get();
}
diff --git a/src/managers/input/InputMethodRelay.hpp b/src/managers/input/InputMethodRelay.hpp
index 2896e8e8..e942add8 100644
--- a/src/managers/input/InputMethodRelay.hpp
+++ b/src/managers/input/InputMethodRelay.hpp
@@ -26,15 +26,15 @@ class CInputMethodRelay {
void commitIMEState(CTextInput* pInput);
void removeTextInput(CTextInput* pInput);
- void onKeyboardFocus(wlr_surface*);
+ void onKeyboardFocus(SP<CWLSurfaceResource>);
CTextInput* getFocusedTextInput();
- void setIMEPopupFocus(CInputPopup*, wlr_surface*);
+ void setIMEPopupFocus(CInputPopup*, SP<CWLSurfaceResource>);
void removePopup(CInputPopup*);
CInputPopup* popupFromCoords(const Vector2D& point);
- CInputPopup* popupFromSurface(const wlr_surface* surface);
+ CInputPopup* popupFromSurface(const SP<CWLSurfaceResource> surface);
void updateAllPopups();
@@ -44,7 +44,7 @@ class CInputMethodRelay {
std::vector<std::unique_ptr<CTextInput>> m_vTextInputs;
std::vector<std::unique_ptr<CInputPopup>> m_vIMEPopups;
- wlr_surface* m_pLastKbFocus = nullptr;
+ WP<CWLSurfaceResource> m_pLastKbFocus;
struct {
CHyprSignalListener newTIV3;
@@ -57,6 +57,6 @@ class CInputMethodRelay {
friend class CHyprRenderer;
friend class CInputManager;
friend class CTextInputV1ProtocolManager;
- friend struct CTextInput;
+ friend class CTextInput;
friend class CHyprRenderer;
};
diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp
index 56e817ec..f1157e4b 100644
--- a/src/managers/input/Tablets.cpp
+++ b/src/managers/input/Tablets.cpp
@@ -20,7 +20,7 @@ static void unfocusTool(SP<CTabletTool> tool) {
PROTO::tablet->proximityOut(tool);
}
-static void focusTool(SP<CTabletTool> tool, SP<CTablet> tablet, wlr_surface* surf) {
+static void focusTool(SP<CTabletTool> tool, SP<CTablet> tablet, SP<CWLSurfaceResource> surf) {
if (tool->getSurface() == surf || !surf)
return;
@@ -37,7 +37,7 @@ static void focusTool(SP<CTabletTool> tool, SP<CTablet> tablet, wlr_surface* sur
}
static void refocusTablet(SP<CTablet> tab, SP<CTabletTool> tool, bool motion = false) {
- const auto LASTHLSURFACE = CWLSurface::surfaceFromWlr(g_pSeatManager->state.pointerFocus);
+ const auto LASTHLSURFACE = CWLSurface::fromResource(g_pSeatManager->state.pointerFocus.lock());
if (!LASTHLSURFACE || !tool->active) {
if (tool->getSurface())
@@ -57,7 +57,7 @@ static void refocusTablet(SP<CTablet> tab, SP<CTabletTool> tool, bool motion = f
const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal();
- focusTool(tool, tab, g_pSeatManager->state.pointerFocus);
+ focusTool(tool, tab, g_pSeatManager->state.pointerFocus.lock());
if (!motion)
return;
diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp
index b3f0b0cb..4c7ffe6e 100644
--- a/src/managers/input/TextInput.cpp
+++ b/src/managers/input/TextInput.cpp
@@ -5,6 +5,7 @@
#include "../../Compositor.hpp"
#include "../../protocols/TextInputV3.hpp"
#include "../../protocols/InputMethodV2.hpp"
+#include "../../protocols/core/Compositor.hpp"
CTextInput::CTextInput(STextInputV1* ti) : pV1Input(ti) {
ti->pTextInput = this;
@@ -56,8 +57,8 @@ void CTextInput::initCallbacks() {
hyprListener_textInputDestroy.removeCallback();
hyprListener_textInputDisable.removeCallback();
hyprListener_textInputEnable.removeCallback();
- hyprListener_surfaceDestroyed.removeCallback();
- hyprListener_surfaceUnmapped.removeCallback();
+ listeners.surfaceUnmap.reset();
+ listeners.surfaceDestroy.reset();
g_pInputManager->m_sIMERelay.removeTextInput(this);
},
@@ -65,7 +66,7 @@ void CTextInput::initCallbacks() {
}
}
-void CTextInput::onEnabled(wlr_surface* surfV1) {
+void CTextInput::onEnabled(SP<CWLSurfaceResource> surfV1) {
Debug::log(LOG, "TI ENABLE");
if (g_pInputManager->m_sIMERelay.m_pIME.expired()) {
@@ -75,7 +76,7 @@ void CTextInput::onEnabled(wlr_surface* surfV1) {
// v1 only, map surface to PTI
if (!isV3()) {
- wlr_surface* pSurface = surfV1;
+ SP<CWLSurfaceResource> pSurface = surfV1;
if (g_pCompositor->m_pLastFocus != pSurface || !pV1Input->active)
return;
@@ -97,8 +98,8 @@ void CTextInput::onDisabled() {
if (!isV3())
leave();
- hyprListener_surfaceDestroyed.removeCallback();
- hyprListener_surfaceUnmapped.removeCallback();
+ listeners.surfaceUnmap.reset();
+ listeners.surfaceDestroy.reset();
g_pInputManager->m_sIMERelay.deactivateIME(this);
}
@@ -117,50 +118,44 @@ void CTextInput::onCommit() {
g_pInputManager->m_sIMERelay.commitIMEState(this);
}
-void CTextInput::setFocusedSurface(wlr_surface* pSurface) {
+void CTextInput::setFocusedSurface(SP<CWLSurfaceResource> pSurface) {
if (pSurface == pFocusedSurface)
return;
pFocusedSurface = pSurface;
- hyprListener_surfaceUnmapped.removeCallback();
- hyprListener_surfaceDestroyed.removeCallback();
+ listeners.surfaceUnmap.reset();
+ listeners.surfaceDestroy.reset();
if (!pSurface)
return;
- hyprListener_surfaceUnmapped.initCallback(
- &pSurface->events.unmap,
- [this](void* owner, void* data) {
- Debug::log(LOG, "Unmap TI owner1");
-
- if (enterLocks)
- enterLocks--;
- pFocusedSurface = nullptr;
- hyprListener_surfaceUnmapped.removeCallback();
- hyprListener_surfaceDestroyed.removeCallback();
- },
- this, "CTextInput");
-
- hyprListener_surfaceDestroyed.initCallback(
- &pSurface->events.destroy,
- [this](void* owner, void* data) {
- Debug::log(LOG, "destroy TI owner1");
-
- if (enterLocks)
- enterLocks--;
- pFocusedSurface = nullptr;
- hyprListener_surfaceUnmapped.removeCallback();
- hyprListener_surfaceDestroyed.removeCallback();
- },
- this, "CTextInput");
+ listeners.surfaceUnmap = pSurface->events.unmap.registerListener([this](std::any d) {
+ Debug::log(LOG, "Unmap TI owner1");
+
+ if (enterLocks)
+ enterLocks--;
+ pFocusedSurface.reset();
+ listeners.surfaceUnmap.reset();
+ listeners.surfaceDestroy.reset();
+ });
+
+ listeners.surfaceDestroy = pSurface->events.destroy.registerListener([this](std::any d) {
+ Debug::log(LOG, "Destroy TI owner1");
+
+ if (enterLocks)
+ enterLocks--;
+ pFocusedSurface.reset();
+ listeners.surfaceUnmap.reset();
+ listeners.surfaceDestroy.reset();
+ });
}
bool CTextInput::isV3() {
return !pV1Input;
}
-void CTextInput::enter(wlr_surface* pSurface) {
+void CTextInput::enter(SP<CWLSurfaceResource> pSurface) {
if (!pSurface || !pSurface->mapped)
return;
@@ -182,7 +177,7 @@ void CTextInput::enter(wlr_surface* pSurface) {
if (isV3())
pV3Input->enter(pSurface);
else {
- zwp_text_input_v1_send_enter(pV1Input->resourceImpl, pSurface->resource);
+ zwp_text_input_v1_send_enter(pV1Input->resourceImpl, pSurface->getResource()->resource());
pV1Input->active = true;
}
@@ -211,8 +206,8 @@ void CTextInput::leave() {
g_pInputManager->m_sIMERelay.deactivateIME(this);
}
-wlr_surface* CTextInput::focusedSurface() {
- return pFocusedSurface;
+SP<CWLSurfaceResource> CTextInput::focusedSurface() {
+ return pFocusedSurface.lock();
}
wl_client* CTextInput::client() {
diff --git a/src/managers/input/TextInput.hpp b/src/managers/input/TextInput.hpp
index ff21da95..30fbb4cc 100644
--- a/src/managers/input/TextInput.hpp
+++ b/src/managers/input/TextInput.hpp
@@ -6,12 +6,12 @@
#include "../../helpers/signal/Listener.hpp"
#include <memory>
-struct wlr_surface;
struct wl_client;
struct STextInputV1;
class CTextInputV3;
class CInputMethodV2;
+class CWLSurfaceResource;
class CTextInput {
public:
@@ -19,43 +19,43 @@ class CTextInput {
CTextInput(STextInputV1* ti);
~CTextInput();
- bool isV3();
- void enter(wlr_surface* pSurface);
- void leave();
- void tiV1Destroyed();
- wl_client* client();
- void commitStateToIME(SP<CInputMethodV2> ime);
- void updateIMEState(SP<CInputMethodV2> ime);
+ bool isV3();
+ void enter(SP<CWLSurfaceResource> pSurface);
+ void leave();
+ void tiV1Destroyed();
+ wl_client* client();
+ void commitStateToIME(SP<CInputMethodV2> ime);
+ void updateIMEState(SP<CInputMethodV2> ime);
- void onEnabled(wlr_surface* surfV1 = nullptr);
- void onDisabled();
- void onCommit();
+ void onEnabled(SP<CWLSurfaceResource> surfV1 = nullptr);
+ void onDisabled();
+ void onCommit();
- bool hasCursorRectangle();
- CBox cursorBox();
+ bool hasCursorRectangle();
+ CBox cursorBox();
- wlr_surface* focusedSurface();
+ SP<CWLSurfaceResource> focusedSurface();
private:
- void setFocusedSurface(wlr_surface* pSurface);
- void initCallbacks();
+ void setFocusedSurface(SP<CWLSurfaceResource> pSurface);
+ void initCallbacks();
- wlr_surface* pFocusedSurface = nullptr;
- int enterLocks = 0;
- WP<CTextInputV3> pV3Input;
- STextInputV1* pV1Input = nullptr;
+ WP<CWLSurfaceResource> pFocusedSurface;
+ int enterLocks = 0;
+ WP<CTextInputV3> pV3Input;
+ STextInputV1* pV1Input = nullptr;
DYNLISTENER(textInputEnable);
DYNLISTENER(textInputDisable);
DYNLISTENER(textInputCommit);
DYNLISTENER(textInputDestroy);
- DYNLISTENER(surfaceUnmapped);
- DYNLISTENER(surfaceDestroyed);
struct {
CHyprSignalListener enable;
CHyprSignalListener disable;
CHyprSignalListener commit;
CHyprSignalListener destroy;
+ CHyprSignalListener surfaceUnmap;
+ CHyprSignalListener surfaceDestroy;
} listeners;
}; \ No newline at end of file
diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp
index 7748813b..a1f949c2 100644
--- a/src/managers/input/Touch.cpp
+++ b/src/managers/input/Touch.cpp
@@ -77,7 +77,7 @@ void CInputManager::onTouchDown(ITouch::SDownEvent e) {
} else
return; // oops, nothing found.
- g_pSeatManager->sendTouchDown(m_sTouchData.touchFocusSurface, e.timeMs, e.touchID, local);
+ g_pSeatManager->sendTouchDown(m_sTouchData.touchFocusSurface.lock(), e.timeMs, e.touchID, local);
PROTO::idle->onActivity();
}