refactor: Use new hyprutils casts (#11377)

This commit is contained in:
Kamikadze 2025-08-14 19:44:56 +05:00 committed by GitHub
parent aa6a78f0a4
commit beee22a95e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
116 changed files with 715 additions and 696 deletions

View file

@ -44,7 +44,7 @@ CAsyncDialogBox::CAsyncDialogBox(const std::string& title, const std::string& de
}
static int onFdWrite(int fd, uint32_t mask, void* data) {
auto box = (CAsyncDialogBox*)data;
auto box = sc<CAsyncDialogBox*>(data);
// lock the box to prevent a UAF
auto lock = box->lockSelf();
@ -68,7 +68,7 @@ void CAsyncDialogBox::onWrite(int fd, uint32_t mask) {
}
while ((ret = read(m_pipeReadFd.get(), buf.data(), 1023)) > 0) {
m_stdout += std::string_view{(char*)buf.data(), (size_t)ret};
m_stdout += std::string_view{(buf.data()), sc<size_t>(ret)};
}
// restore the flags (otherwise libwayland won't give us a hangup)

View file

@ -25,7 +25,7 @@ CHyprColor::CHyprColor(const Hyprgraphics::CColor& color, float a_) : a(a_) {
}
uint32_t CHyprColor::getAsHex() const {
return (uint32_t)(a * 255.f) * 0x1000000 + (uint32_t)(r * 255.f) * 0x10000 + (uint32_t)(g * 255.f) * 0x100 + (uint32_t)(b * 255.f) * 0x1;
return sc<uint32_t>(a * 255.f) * 0x1000000 + sc<uint32_t>(r * 255.f) * 0x10000 + sc<uint32_t>(g * 255.f) * 0x100 + sc<uint32_t>(b * 255.f) * 0x1;
}
Hyprgraphics::CColor::SSRGB CHyprColor::asRGB() const {

View file

@ -222,7 +222,7 @@ const SPixelFormat* NFormatUtils::getPixelFormatFromDRM(DRMFormat drm) {
const SPixelFormat* NFormatUtils::getPixelFormatFromGL(uint32_t glFormat, uint32_t glType, bool alpha) {
for (auto const& fmt : GLES3_FORMATS) {
if (fmt.glFormat == (int)glFormat && fmt.glType == (int)glType && fmt.withAlpha == alpha)
if (fmt.glFormat == sc<int>(glFormat) && fmt.glType == sc<int>(glType) && fmt.withAlpha == alpha)
return &fmt;
}

View file

@ -87,7 +87,7 @@ std::string escapeJSONStrings(const std::string& str) {
case '\t': oss << "\\t"; break;
default:
if ('\x00' <= c && c <= '\x1f') {
oss << "\\u" << std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(c);
oss << "\\u" << std::hex << std::setw(4) << std::setfill('0') << sc<int>(c);
} else {
oss << c;
}
@ -213,7 +213,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
if (!PLUSMINUSRESULT.has_value())
return {WORKSPACE_INVALID};
result.id = (int)PLUSMINUSRESULT.value();
result.id = sc<int>(PLUSMINUSRESULT.value());
WORKSPACEID remains = result.id;
@ -251,7 +251,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
remains -= 1;
// traverse valid workspaces until we reach the remains
if ((size_t)remains < namedWSes.size()) {
if (sc<size_t>(remains) < namedWSes.size()) {
result.id = namedWSes[remains];
} else {
remains -= namedWSes.size();
@ -272,7 +272,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
char walkDir = in[1];
// sanitize. 0 means invalid oob in -
predictedWSID = std::max(predictedWSID, static_cast<int64_t>(0));
predictedWSID = std::max(predictedWSID, sc<int64_t>(0));
// Count how many invalidWSes are in between (how bad the prediction was)
WORKSPACEID beginID = in[1] == '+' ? activeWSID + 1 : predictedWSID;
@ -295,7 +295,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
}
currentItem += remains;
currentItem = std::max(currentItem, static_cast<size_t>(0));
currentItem = std::max(currentItem, sc<size_t>(0));
if (currentItem >= namedWSes.size()) {
// At the seam between namedWSes and normal WSes. Behave like r+[diff] at imaginary ws 0
size_t diff = currentItem - (namedWSes.size() - 1);
@ -332,7 +332,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
// Need remainingWSes more
auto namedWSIdx = namedWSes.size() - remainingWSes;
// Sanitze
namedWSIdx = std::clamp(namedWSIdx, static_cast<size_t>(0), namedWSes.size() - static_cast<size_t>(1));
namedWSIdx = std::clamp(namedWSIdx, sc<size_t>(0), namedWSes.size() - sc<size_t>(1));
finalWSID = namedWSes[namedWSIdx];
} else {
// Couldn't find valid workspace in negative direction, search last first one back up positive direction
@ -376,10 +376,10 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
if (!PLUSMINUSRESULT.has_value())
return {WORKSPACE_INVALID};
result.id = (int)PLUSMINUSRESULT.value();
result.id = sc<int>(PLUSMINUSRESULT.value());
// result now has +/- what we should move on mon
int remains = (int)result.id;
int remains = sc<int>(result.id);
std::vector<WORKSPACEID> validWSes;
for (auto const& ws : g_pCompositor->getWorkspaces()) {
@ -400,7 +400,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
// clamp
if (currentItem < 0) {
currentItem = 0;
} else if (currentItem >= (ssize_t)validWSes.size()) {
} else if (currentItem >= sc<ssize_t>(validWSes.size())) {
currentItem = validWSes.size() - 1;
}
} else {
@ -409,7 +409,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
// get the current item
WORKSPACEID activeWSID = g_pCompositor->m_lastMonitor->m_activeWorkspace ? g_pCompositor->m_lastMonitor->m_activeWorkspace->m_id : 1;
for (ssize_t i = 0; i < (ssize_t)validWSes.size(); i++) {
for (ssize_t i = 0; i < sc<ssize_t>(validWSes.size()); i++) {
if (validWSes[i] == activeWSID) {
currentItem = i;
break;
@ -420,7 +420,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
currentItem += remains;
// sanitize
if (currentItem >= (ssize_t)validWSes.size()) {
if (currentItem >= sc<ssize_t>(validWSes.size())) {
currentItem = currentItem % validWSes.size();
} else if (currentItem < 0) {
currentItem = validWSes.size() + currentItem;
@ -436,7 +436,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
if (!PLUSMINUSRESULT.has_value())
return {WORKSPACE_INVALID};
result.id = std::max((int)PLUSMINUSRESULT.value(), 1);
result.id = std::max(sc<int>(PLUSMINUSRESULT.value()), 1);
} else {
Debug::log(ERR, "Relative workspace on no mon!");
return {WORKSPACE_INVALID};
@ -642,7 +642,7 @@ std::expected<int64_t, std::string> configStringToInt(const std::string& VALUE)
a = std::round(std::stof(trim(rolling.substr(0, rolling.find(',')))) * 255.f);
} catch (std::exception& e) { return std::unexpected("failed parsing " + VALUEWITHOUTFUNC); }
return a * (Hyprlang::INT)0x1000000 + *r * (Hyprlang::INT)0x10000 + *g * (Hyprlang::INT)0x100 + *b;
return a * sc<Hyprlang::INT>(0x1000000) + *r * sc<Hyprlang::INT>(0x10000) + *g * sc<Hyprlang::INT>(0x100) + *b;
} else if (VALUEWITHOUTFUNC.length() == 8) {
const auto RGBA = parseHex(VALUEWITHOUTFUNC);
@ -670,7 +670,7 @@ std::expected<int64_t, std::string> configStringToInt(const std::string& VALUE)
if (!r || !g || !b)
return std::unexpected("failed parsing " + VALUEWITHOUTFUNC);
return (Hyprlang::INT)0xFF000000 + *r * (Hyprlang::INT)0x10000 + *g * (Hyprlang::INT)0x100 + *b;
return sc<Hyprlang::INT>(0xFF000000) + *r * sc<Hyprlang::INT>(0x10000) + *g * sc<Hyprlang::INT>(0x100) + *b;
} else if (VALUEWITHOUTFUNC.length() == 6) {
auto r = parseHex(VALUEWITHOUTFUNC);
return r ? *r + 0xFF000000 : r;
@ -717,7 +717,7 @@ Vector2D configStringToVector2D(const std::string& VALUE) {
if (std::getline(iss, token))
throw std::invalid_argument("Invalid string format");
return Vector2D((double)x, (double)y);
return Vector2D(sc<double>(x), sc<double>(y));
}
double normalizeAngleRad(double ang) {
@ -910,7 +910,7 @@ std::expected<std::string, std::string> binaryNameForPid(pid_t pid) {
sysctl(mib, miblen, &exe, &sz, NULL, 0);
std::string path = exe;
#else
std::string path = std::format("/proc/{}/exe", (uint64_t)pid);
std::string path = std::format("/proc/{}/exe", sc<uint64_t>(pid));
#endif
std::error_code ec;

View file

@ -213,7 +213,7 @@ void CMonitor::onConnect(bool noRule) {
m_damage.setSize(m_transformedSize);
Debug::log(LOG, "Added new monitor with name {} at {:j0} with size {:j0}, pointer {:x}", m_output->name, m_position, m_pixelSize, (uintptr_t)m_output.get());
Debug::log(LOG, "Added new monitor with name {} at {:j0} with size {:j0}, pointer {:x}", m_output->name, m_position, m_pixelSize, rc<uintptr_t>(m_output.get()));
setupDefaultWS(monitorRule);
@ -577,7 +577,7 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {
addBest3Modes([](auto const& a, auto const& b) {
if (std::round(a->refreshRate) > std::round(b->refreshRate))
return true;
else if (DELTALESSTHAN((float)a->refreshRate, (float)b->refreshRate, 1.F) && a->pixelSize.x > b->pixelSize.x && a->pixelSize.y > b->pixelSize.y)
else if (DELTALESSTHAN(sc<float>(a->refreshRate), sc<float>(b->refreshRate), 1.F) && a->pixelSize.x > b->pixelSize.x && a->pixelSize.y > b->pixelSize.y)
return true;
return false;
});
@ -770,7 +770,7 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {
bool set10bit = false;
for (auto const& fmt : formats[(int)!RULE->enable10bit]) {
for (auto const& fmt : formats[sc<int>(!RULE->enable10bit)]) {
m_output->state->setFormat(fmt.second);
m_prevDrmFormat = m_drmFormat;
m_drmFormat = fmt.second;
@ -902,8 +902,8 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) {
// reload to fix mirrors
g_pConfigManager->m_wantsMonitorReload = true;
Debug::log(LOG, "Monitor {} data dump: res {:X}@{:.2f}Hz, scale {:.2f}, transform {}, pos {:X}, 10b {}", m_name, m_pixelSize, m_refreshRate, m_scale, (int)m_transform,
m_position, (int)m_enabled10bit);
Debug::log(LOG, "Monitor {} data dump: res {:X}@{:.2f}Hz, scale {:.2f}, transform {}, pos {:X}, 10b {}", m_name, m_pixelSize, m_refreshRate, m_scale, sc<int>(m_transform),
m_position, sc<int>(m_enabled10bit));
EMIT_HOOK_EVENT("monitorLayoutChanged", nullptr);
@ -1003,7 +1003,7 @@ void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) {
auto PNEWWORKSPACE = g_pCompositor->getWorkspaceByID(wsID);
Debug::log(LOG, "New monitor: WORKSPACEID {}, exists: {}", wsID, (int)(PNEWWORKSPACE != nullptr));
Debug::log(LOG, "New monitor: WORKSPACEID {}, exists: {}", wsID, sc<int>(PNEWWORKSPACE != nullptr));
if (PNEWWORKSPACE) {
// workspace exists, move it to the newly connected monitor
@ -1078,7 +1078,7 @@ void CMonitor::setMirror(const std::string& mirrorOf) {
setupDefaultWS(RULE);
applyMonitorRule((SMonitorRule*)&RULE, true); // will apply the offset and stuff
applyMonitorRule(const_cast<SMonitorRule*>(&RULE), true); // will apply the offset and stuff
} else {
PHLMONITOR BACKUPMON = nullptr;
for (auto const& m : g_pCompositor->m_monitors) {
@ -1469,7 +1469,8 @@ bool CMonitor::attemptDirectScanout() {
if (!params.success || !PSURFACE->m_current.texture->m_eglImage /* dmabuf */)
return false;
Debug::log(TRACE, "attemptDirectScanout: surface {:x} passed, will attempt, buffer {}", (uintptr_t)PSURFACE.get(), (uintptr_t)PSURFACE->m_current.buffer.m_buffer.get());
Debug::log(TRACE, "attemptDirectScanout: surface {:x} passed, will attempt, buffer {}", rc<uintptr_t>(PSURFACE.get()),
rc<uintptr_t>(PSURFACE->m_current.buffer.m_buffer.get()));
auto PBUFFER = PSURFACE->m_current.buffer.m_buffer;
@ -1532,7 +1533,7 @@ bool CMonitor::attemptDirectScanout() {
if (m_lastScanout.expired()) {
m_lastScanout = PCANDIDATE;
Debug::log(LOG, "Entered a direct scanout to {:x}: \"{}\"", (uintptr_t)PCANDIDATE.get(), PCANDIDATE->m_title);
Debug::log(LOG, "Entered a direct scanout to {:x}: \"{}\"", rc<uintptr_t>(PCANDIDATE.get()), PCANDIDATE->m_title);
}
m_scanoutNeedsCursorUpdate = false;

View file

@ -47,7 +47,7 @@ int NSystemd::sdNotify(int unsetEnvironment, const char* state) {
if (unixAddr.sun_path[0] == '@')
unixAddr.sun_path[0] = '\0';
if (connect(fd, (const sockaddr*)&unixAddr, sizeof(struct sockaddr_un)) < 0)
if (connect(fd, rc<const sockaddr*>(&unixAddr), sizeof(struct sockaddr_un)) < 0)
return -errno;
// arbitrary value which seems to be enough for s-d messages

View file

@ -1,4 +1,5 @@
#include "Math.hpp"
#include "../memory/Memory.hpp"
Hyprutils::Math::eTransform wlTransformToHyprutils(wl_output_transform t) {
switch (t) {
@ -17,7 +18,7 @@ Hyprutils::Math::eTransform wlTransformToHyprutils(wl_output_transform t) {
wl_output_transform invertTransform(wl_output_transform tr) {
if ((tr & WL_OUTPUT_TRANSFORM_90) && !(tr & WL_OUTPUT_TRANSFORM_FLIPPED))
tr = (wl_output_transform)(tr ^ (int)WL_OUTPUT_TRANSFORM_180);
tr = sc<wl_output_transform>(tr ^ sc<int>(WL_OUTPUT_TRANSFORM_180));
return tr;
}