From beee22a95ed9044950e5486f22edd813e00ffa2c Mon Sep 17 00:00:00 2001 From: Kamikadze <40305144+Kam1k4dze@users.noreply.github.com> Date: Thu, 14 Aug 2025 19:44:56 +0500 Subject: refactor: Use new hyprutils casts (#11377) --- src/managers/input/IdleInhibitor.cpp | 4 +-- src/managers/input/InputManager.cpp | 51 ++++++++++++++++----------------- src/managers/input/InputMethodPopup.cpp | 2 +- src/managers/input/Swipe.cpp | 6 ++-- src/managers/input/TextInput.cpp | 2 +- src/managers/input/Touch.cpp | 4 +-- 6 files changed, 34 insertions(+), 35 deletions(-) (limited to 'src/managers/input') diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp index 8c33956b..82f43f47 100644 --- a/src/managers/input/IdleInhibitor.cpp +++ b/src/managers/input/IdleInhibitor.cpp @@ -8,7 +8,7 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) { const auto PINHIBIT = m_idleInhibitors.emplace_back(makeUnique()).get(); PINHIBIT->inhibitor = std::any_cast>(inhibitor); - Debug::log(LOG, "New idle inhibitor registered for surface {:x}", (uintptr_t)PINHIBIT->inhibitor->m_surface.get()); + Debug::log(LOG, "New idle inhibitor registered for surface {:x}", rc(PINHIBIT->inhibitor->m_surface.get())); PINHIBIT->inhibitor->m_listeners.destroy = PINHIBIT->inhibitor->m_resource->m_events.destroy.listen([this, PINHIBIT] { std::erase_if(m_idleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; }); @@ -89,7 +89,7 @@ bool CInputManager::isWindowInhibiting(const PHLWINDOW& w, bool onlyHl) { return; if (WLSurface->visible()) - *(bool*)data = true; + *sc(data) = true; }, &isInhibiting); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index cbb4c3cc..f8d2a160 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -54,7 +54,7 @@ CInputManager::CInputManager() { if (wl_resource_get_client(event.pMgr->resource()) != g_pSeatManager->m_state.pointerFocusResource->client()) return; - Debug::log(LOG, "cursorImage request: shape {} -> {}", (uint32_t)event.shape, event.shapeName); + Debug::log(LOG, "cursorImage request: shape {} -> {}", sc(event.shape), event.shapeName); m_cursorSurfaceInfo.wlSurface->unassign(); m_cursorSurfaceInfo.vHotspot = {}; @@ -113,11 +113,11 @@ void CInputManager::onMouseMoved(IPointer::SMotionEvent e) { const auto DELTA = *PNOACCEL == 1 ? unaccel : delta; if (g_pSeatManager->m_isPointerFrameSkipped) - g_pPointerManager->storeMovement((uint64_t)e.timeMs, DELTA, unaccel); + g_pPointerManager->storeMovement(e.timeMs, DELTA, unaccel); else - g_pPointerManager->setStoredMovement((uint64_t)e.timeMs, DELTA, unaccel); + g_pPointerManager->setStoredMovement(e.timeMs, DELTA, unaccel); - PROTO::relativePointer->sendRelativeMotion((uint64_t)e.timeMs * 1000, DELTA, unaccel); + PROTO::relativePointer->sendRelativeMotion(sc(e.timeMs) * 1000, DELTA, unaccel); if (e.mouse) recheckMouseWarpOnMouseInput(); @@ -236,13 +236,13 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse) { g_pCompositor->warpCursorTo(CLOSEST, true); g_pSeatManager->sendPointerMotion(time, CLOSESTLOCAL); - PROTO::relativePointer->sendRelativeMotion((uint64_t)time * 1000, {}, {}); + PROTO::relativePointer->sendRelativeMotion(sc(time) * 1000, {}, {}); } return; } else - Debug::log(ERR, "BUG THIS: Null SURF/CONSTRAINT in mouse refocus. Ignoring constraints. {:x} {:x}", (uintptr_t)SURF.get(), (uintptr_t)CONSTRAINT.get()); + Debug::log(ERR, "BUG THIS: Null SURF/CONSTRAINT in mouse refocus. Ignoring constraints. {:x} {:x}", rc(SURF.get()), rc(CONSTRAINT.get())); } if (PMONITOR != g_pCompositor->m_lastMonitor && (*PMOUSEFOCUSMON || refocus) && m_forcedFocus.expired()) @@ -644,7 +644,7 @@ void CInputManager::processMouseRequest(const CSeatManager::SSetCursorEvent& eve if (!cursorImageUnlocked()) return; - Debug::log(LOG, "cursorImage request: surface {:x}", (uintptr_t)event.surf.get()); + Debug::log(LOG, "cursorImage request: surface {:x}", rc(event.surf.get())); if (event.surf != m_cursorSurfaceInfo.wlSurface->resource()) { m_cursorSurfaceInfo.wlSurface->unassign(); @@ -937,7 +937,7 @@ void CInputManager::newKeyboard(SP keeb) { setupKeyboard(PNEWKEYBOARD); - Debug::log(LOG, "New keyboard created, pointers Hypr: {:x}", (uintptr_t)PNEWKEYBOARD.get()); + Debug::log(LOG, "New keyboard created, pointers Hypr: {:x}", rc(PNEWKEYBOARD.get())); } void CInputManager::newKeyboard(SP keyboard) { @@ -945,7 +945,7 @@ void CInputManager::newKeyboard(SP keyboard) { setupKeyboard(PNEWKEYBOARD); - Debug::log(LOG, "New keyboard created, pointers Hypr: {:x} and AQ: {:x}", (uintptr_t)PNEWKEYBOARD.get(), (uintptr_t)keyboard.get()); + Debug::log(LOG, "New keyboard created, pointers Hypr: {:x} and AQ: {:x}", rc(PNEWKEYBOARD.get()), rc(keyboard.get())); } void CInputManager::newVirtualKeyboard(SP keyboard) { @@ -953,7 +953,7 @@ void CInputManager::newVirtualKeyboard(SP keyboard) setupKeyboard(PNEWKEYBOARD); - Debug::log(LOG, "New virtual keyboard created at {:x}", (uintptr_t)PNEWKEYBOARD.get()); + Debug::log(LOG, "New virtual keyboard created at {:x}", rc(PNEWKEYBOARD.get())); } void CInputManager::setupKeyboard(SP keeb) { @@ -974,7 +974,7 @@ void CInputManager::setupKeyboard(SP keeb) { return; destroyKeyboard(PKEEB); - Debug::log(LOG, "Destroyed keyboard {:x}", (uintptr_t)keeb); + Debug::log(LOG, "Destroyed keyboard {:x}", rc(keeb)); }); keeb->m_keyboardEvents.key.listenStatic([this, keeb = keeb.get()](const IKeyboard::SKeyEvent& event) { @@ -1035,7 +1035,7 @@ void CInputManager::applyConfigToKeyboard(SP pKeyboard) { const auto HASCONFIG = g_pConfigManager->deviceConfigExists(devname); - Debug::log(LOG, "ApplyConfigToKeyboard for \"{}\", hasconfig: {}", devname, (int)HASCONFIG); + Debug::log(LOG, "ApplyConfigToKeyboard for \"{}\", hasconfig: {}", devname, sc(HASCONFIG)); const auto REPEATRATE = g_pConfigManager->getDeviceInt(devname, "repeat_rate", "input:repeat_rate"); const auto REPEATDELAY = g_pConfigManager->getDeviceInt(devname, "repeat_delay", "input:repeat_delay"); @@ -1119,7 +1119,7 @@ void CInputManager::newMouse(SP mouse) { setupMouse(PMOUSE); - Debug::log(LOG, "New mouse created, pointer AQ: {:x}", (uintptr_t)mouse.get()); + Debug::log(LOG, "New mouse created, pointer AQ: {:x}", rc(mouse.get())); } void CInputManager::setupMouse(SP mauz) { @@ -1135,8 +1135,8 @@ void CInputManager::setupMouse(SP mauz) { const auto LIBINPUTDEV = mauz->aq()->getLibinputHandle(); Debug::log(LOG, "New mouse has libinput sens {:.2f} ({:.2f}) with accel profile {} ({})", libinput_device_config_accel_get_speed(LIBINPUTDEV), - libinput_device_config_accel_get_default_speed(LIBINPUTDEV), (int)libinput_device_config_accel_get_profile(LIBINPUTDEV), - (int)libinput_device_config_accel_get_default_profile(LIBINPUTDEV)); + libinput_device_config_accel_get_default_speed(LIBINPUTDEV), sc(libinput_device_config_accel_get_profile(LIBINPUTDEV)), + sc(libinput_device_config_accel_get_default_profile(LIBINPUTDEV))); } g_pPointerManager->attachPointer(mauz); @@ -1223,7 +1223,7 @@ void CInputManager::setPointerConfigs() { const auto TAP_DRAG_LOCK = g_pConfigManager->getDeviceInt(devname, "drag_lock", "input:touchpad:drag_lock"); if (TAP_DRAG_LOCK >= 0 && TAP_DRAG_LOCK <= 2) { - libinput_device_config_tap_set_drag_lock_enabled(LIBINPUTDEV, static_cast(TAP_DRAG_LOCK)); + libinput_device_config_tap_set_drag_lock_enabled(LIBINPUTDEV, sc(TAP_DRAG_LOCK)); } if (libinput_device_config_tap_get_finger_count(LIBINPUTDEV)) // this is for tapping (like on a laptop) @@ -1241,13 +1241,12 @@ void CInputManager::setPointerConfigs() { } if (libinput_device_config_3fg_drag_get_finger_count(LIBINPUTDEV) >= 3) { - const auto DRAG_3FG_STATE = static_cast(g_pConfigManager->getDeviceInt(devname, "drag_3fg", "input:touchpad:drag_3fg")); + const auto DRAG_3FG_STATE = sc(g_pConfigManager->getDeviceInt(devname, "drag_3fg", "input:touchpad:drag_3fg")); libinput_device_config_3fg_drag_set_enabled(LIBINPUTDEV, DRAG_3FG_STATE); } if (libinput_device_config_dwt_is_available(LIBINPUTDEV)) { - const auto DWT = - static_cast(g_pConfigManager->getDeviceInt(devname, "disable_while_typing", "input:touchpad:disable_while_typing") != 0); + const auto DWT = sc(g_pConfigManager->getDeviceInt(devname, "disable_while_typing", "input:touchpad:disable_while_typing") != 0); libinput_device_config_dwt_set_enabled(LIBINPUTDEV, DWT); } @@ -1319,7 +1318,7 @@ static void removeFromHIDs(WP hid) { } void CInputManager::destroyKeyboard(SP pKeyboard) { - Debug::log(LOG, "Keyboard at {:x} removed", (uintptr_t)pKeyboard.get()); + Debug::log(LOG, "Keyboard at {:x} removed", rc(pKeyboard.get())); std::erase_if(m_keyboards, [pKeyboard](const auto& other) { return other == pKeyboard; }); @@ -1343,7 +1342,7 @@ void CInputManager::destroyKeyboard(SP pKeyboard) { } void CInputManager::destroyPointer(SP mouse) { - Debug::log(LOG, "Pointer at {:x} removed", (uintptr_t)mouse.get()); + Debug::log(LOG, "Pointer at {:x} removed", rc(mouse.get())); std::erase_if(m_pointers, [mouse](const auto& other) { return other == mouse; }); @@ -1356,7 +1355,7 @@ void CInputManager::destroyPointer(SP mouse) { } void CInputManager::destroyTouchDevice(SP touch) { - Debug::log(LOG, "Touch device at {:x} removed", (uintptr_t)touch.get()); + Debug::log(LOG, "Touch device at {:x} removed", rc(touch.get())); std::erase_if(m_touches, [touch](const auto& other) { return other == touch; }); @@ -1364,7 +1363,7 @@ void CInputManager::destroyTouchDevice(SP touch) { } void CInputManager::destroyTablet(SP tablet) { - Debug::log(LOG, "Tablet device at {:x} removed", (uintptr_t)tablet.get()); + Debug::log(LOG, "Tablet device at {:x} removed", rc(tablet.get())); std::erase_if(m_tablets, [tablet](const auto& other) { return other == tablet; }); @@ -1372,7 +1371,7 @@ void CInputManager::destroyTablet(SP tablet) { } void CInputManager::destroyTabletTool(SP tool) { - Debug::log(LOG, "Tablet tool at {:x} removed", (uintptr_t)tool.get()); + Debug::log(LOG, "Tablet tool at {:x} removed", rc(tool.get())); std::erase_if(m_tabletTools, [tool](const auto& other) { return other == tool; }); @@ -1380,7 +1379,7 @@ void CInputManager::destroyTabletTool(SP tool) { } void CInputManager::destroyTabletPad(SP pad) { - Debug::log(LOG, "Tablet pad at {:x} removed", (uintptr_t)pad.get()); + Debug::log(LOG, "Tablet pad at {:x} removed", rc(pad.get())); std::erase_if(m_tabletPads, [pad](const auto& other) { return other == pad; }); @@ -1674,7 +1673,7 @@ void CInputManager::newTouchDevice(SP pDevice) { destroyTouchDevice(PDEV); }); - Debug::log(LOG, "New touch device added at {:x}", (uintptr_t)PNEWDEV.get()); + Debug::log(LOG, "New touch device added at {:x}", rc(PNEWDEV.get())); } void CInputManager::setTouchDeviceConfigs(SP dev) { diff --git a/src/managers/input/InputMethodPopup.cpp b/src/managers/input/InputMethodPopup.cpp index 71fdd5a4..27acd08c 100644 --- a/src/managers/input/InputMethodPopup.cpp +++ b/src/managers/input/InputMethodPopup.cpp @@ -99,7 +99,7 @@ void CInputPopup::updateBox() { if (!cursorRect) { Vector2D coords = OWNER ? OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 500, 500}).pos() : Vector2D{0, 0}; parentBox = {coords, {500, 500}}; - cursorBoxParent = {0, 0, (int)parentBox.w, (int)parentBox.h}; + cursorBoxParent = {0, 0, sc(parentBox.w), sc(parentBox.h)}; } Vector2D currentPopupSize = m_surface->getViewporterCorrectedSize() / m_surface->resource()->m_current.scale; diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index 355ffee3..1d9b80e2 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -67,7 +67,7 @@ void CInputManager::endWorkspaceSwipe() { // commit auto workspaceIDLeft = getWorkspaceIDNameFromString((*PSWIPEUSER ? "r-1" : "m-1")).id; auto workspaceIDRight = getWorkspaceIDNameFromString((*PSWIPEUSER ? "r+1" : "m+1")).id; - const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, (int64_t)1LL, (int64_t)UINT32_MAX); + const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, sc(1LL), sc(UINT32_MAX)); // If we've been swiping off the right end with PSWIPENEW enabled, there is // no workspace there yet, and we need to choose an ID for a new one now. @@ -213,7 +213,7 @@ void CInputManager::updateWorkspaceSwipe(double delta) { static auto PSWIPEUSER = CConfigValue("gestures:workspace_swipe_use_r"); static auto PWORKSPACEGAP = CConfigValue("general:gaps_workspaces"); - const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, (int64_t)1LL, (int64_t)UINT32_MAX); + const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, sc(1LL), sc(UINT32_MAX)); const auto XDISTANCE = m_activeSwipe.pMonitor->m_size.x + *PWORKSPACEGAP; const auto YDISTANCE = m_activeSwipe.pMonitor->m_size.y + *PWORKSPACEGAP; const auto ANIMSTYLE = m_activeSwipe.pWorkspaceBegin->m_renderOffset->getStyle(); @@ -234,7 +234,7 @@ void CInputManager::updateWorkspaceSwipe(double delta) { m_activeSwipe.pWorkspaceBegin->m_forceRendering = true; - m_activeSwipe.delta = std::clamp(m_activeSwipe.delta, (double)-SWIPEDISTANCE, (double)SWIPEDISTANCE); + m_activeSwipe.delta = std::clamp(m_activeSwipe.delta, sc(-SWIPEDISTANCE), sc(SWIPEDISTANCE)); if ((m_activeSwipe.pWorkspaceBegin->m_id == workspaceIDLeft && *PSWIPENEW && (m_activeSwipe.delta < 0)) || (m_activeSwipe.delta > 0 && m_activeSwipe.pWorkspaceBegin->getWindows() == 0 && workspaceIDRight <= m_activeSwipe.pWorkspaceBegin->m_id) || diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index c1ce2062..5da5e47a 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -251,7 +251,7 @@ void CTextInput::commitStateToIME(SP ime) { ime->textChangeCause(ZWP_TEXT_INPUT_V3_CHANGE_CAUSE_INPUT_METHOD); if (m_v1Input->m_pendingContentType.isPending) - ime->textContentType((zwpTextInputV3ContentHint)INPUT->m_pendingContentType.hint, (zwpTextInputV3ContentPurpose)INPUT->m_pendingContentType.purpose); + ime->textContentType(sc(INPUT->m_pendingContentType.hint), sc(INPUT->m_pendingContentType.purpose)); } g_pInputManager->m_relay.updateAllPopups(); diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp index 4a67d2f2..9e19c4e8 100644 --- a/src/managers/input/Touch.cpp +++ b/src/managers/input/Touch.cpp @@ -16,7 +16,7 @@ void CInputManager::onTouchDown(ITouch::SDownEvent e) { static auto PSWIPETOUCH = CConfigValue("gestures:workspace_swipe_touch"); static auto PGAPSOUTDATA = CConfigValue("general:gaps_out"); - auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); + auto* const PGAPSOUT = sc((PGAPSOUTDATA.ptr())->getData()); // TODO: WORKSPACERULE.gapsOut.value_or() auto gapsOut = *PGAPSOUT; static auto PBORDERSIZE = CConfigValue("general:border_size"); @@ -126,7 +126,7 @@ void CInputManager::onTouchMove(ITouch::SMotionEvent e) { const bool VERTANIMS = ANIMSTYLE == "slidevert" || ANIMSTYLE.starts_with("slidefadevert"); static auto PSWIPEINVR = CConfigValue("gestures:workspace_swipe_touch_invert"); static auto PSWIPEDIST = CConfigValue("gestures:workspace_swipe_distance"); - const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, (int64_t)1LL, (int64_t)UINT32_MAX); + const auto SWIPEDISTANCE = std::clamp(*PSWIPEDIST, sc(1LL), sc(UINT32_MAX)); // Handle the workspace swipe if there is one if (m_activeSwipe.initialDirection == -1) { if (*PSWIPEINVR) -- cgit v1.2.3