internal: Formatter rework (#3186)

This commit is contained in:
Vaxry 2023-09-06 12:51:36 +02:00 committed by GitHub
parent c3a83daa1e
commit 61a71c65ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 671 additions and 655 deletions

View file

@ -41,8 +41,8 @@ void CAnimatedVariable::create(ANIMATEDVARTYPE type, std::any val, SAnimationPro
default: ASSERT(false); break;
}
} catch (std::exception& e) {
Debug::log(ERR, "CAnimatedVariable create error: %s", e.what());
RASSERT(false, "CAnimatedVariable create error: %s", e.what());
Debug::log(ERR, "CAnimatedVariable create error: {}", e.what());
RASSERT(false, "CAnimatedVariable create error: {}", e.what());
}
}

View file

@ -18,7 +18,7 @@ void CBezierCurve::setup(std::vector<Vector2D>* pVec) {
m_dPoints.emplace_back(Vector2D(1, 1));
RASSERT(m_dPoints.size() == 4, "CBezierCurve only supports cubic beziers! (points num: %i)", m_dPoints.size());
RASSERT(m_dPoints.size() == 4, "CBezierCurve only supports cubic beziers! (points num: {})", m_dPoints.size());
// bake BAKEDPOINTS points for faster lookups
// T -> X ( / BAKEDPOINTS )
@ -34,8 +34,8 @@ void CBezierCurve::setup(std::vector<Vector2D>* pVec) {
getYForPoint(i);
const auto ELAPSEDCALCAVG = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - BEGINCALC).count() / 1000.f / 10.f;
Debug::log(LOG, "Created a bezier curve, baked %i points, mem usage: %.2fkB, time to bake: %.2fµs. Estimated average calc time: %.2fµs.", BAKEDPOINTS, POINTSSIZE, ELAPSEDUS,
ELAPSEDCALCAVG);
Debug::log(LOG, "Created a bezier curve, baked {} points, mem usage: {:.2f}kB, time to bake: {:.2f}µs. Estimated average calc time: {:.2f}µs.", BAKEDPOINTS, POINTSSIZE,
ELAPSEDUS, ELAPSEDCALCAVG);
}
float CBezierCurve::getYForT(float t) {

View file

@ -151,27 +151,13 @@ void addWLSignal(wl_signal* pSignal, wl_listener* pListener, void* pOwner, const
wl_signal_add(pSignal, pListener);
Debug::log(LOG, "Registered signal for owner %lx: %lx -> %lx (owner: %s)", pOwner, pSignal, pListener, ownerString.c_str());
Debug::log(LOG, "Registered signal for owner {:x}: {:x} -> {:x} (owner: {})", (uintptr_t)pOwner, (uintptr_t)pSignal, (uintptr_t)pListener, ownerString);
}
void handleNoop(struct wl_listener* listener, void* data) {
// Do nothing
}
std::string getFormat(const char* fmt, ...) {
char* outputStr = nullptr;
va_list args;
va_start(args, fmt);
vasprintf(&outputStr, fmt, args);
va_end(args);
std::string output = std::string(outputStr);
free(outputStr);
return output;
}
std::string escapeJSONStrings(const std::string& str) {
std::ostringstream oss;
for (auto& c : str) {
@ -224,7 +210,7 @@ float getPlusMinusKeywordResult(std::string source, float relative) {
try {
return relative + stof(source);
} catch (...) {
Debug::log(ERR, "Invalid arg \"%s\" in getPlusMinusKeywordResult!", source.c_str());
Debug::log(ERR, "Invalid arg \"{}\" in getPlusMinusKeywordResult!", source.c_str());
return INT_MAX;
}
}
@ -539,10 +525,10 @@ void logSystemInfo() {
uname(&unameInfo);
Debug::log(LOG, "System name: %s", unameInfo.sysname);
Debug::log(LOG, "Node name: %s", unameInfo.nodename);
Debug::log(LOG, "Release: %s", unameInfo.release);
Debug::log(LOG, "Version: %s", unameInfo.version);
Debug::log(LOG, "System name: {}", unameInfo.sysname);
Debug::log(LOG, "Node name: {}", unameInfo.nodename);
Debug::log(LOG, "Release: {}", unameInfo.release);
Debug::log(LOG, "Version: {}", unameInfo.version);
Debug::log(NONE, "\n");
@ -551,7 +537,7 @@ void logSystemInfo() {
#else
const std::string GPUINFO = execAndGet("lspci -vnn | grep VGA");
#endif
Debug::log(LOG, "GPU information:\n%s\n", GPUINFO.c_str());
Debug::log(LOG, "GPU information:\n{}\n", GPUINFO.c_str());
if (GPUINFO.contains("NVIDIA")) {
Debug::log(WARN, "Warning: you're using an NVIDIA GPU. Make sure you follow the instructions on the wiki if anything is amiss.\n");
@ -560,7 +546,7 @@ void logSystemInfo() {
// log etc
Debug::log(LOG, "os-release:");
Debug::log(NONE, "%s", execAndGet("cat /etc/os-release").c_str());
Debug::log(NONE, "{}", execAndGet("cat /etc/os-release").c_str());
}
void matrixProjection(float mat[9], int w, int h, wl_output_transform tr) {
@ -646,7 +632,7 @@ int64_t configStringToInt(const std::string& VALUE) {
const auto VALUEWITHOUTFUNC = VALUE.substr(5, VALUE.length() - 6);
if (removeBeginEndSpacesTabs(VALUEWITHOUTFUNC).length() != 8) {
Debug::log(WARN, "invalid length %i for rgba", VALUEWITHOUTFUNC.length());
Debug::log(WARN, "invalid length {} for rgba", VALUEWITHOUTFUNC.length());
throw std::invalid_argument("rgba() expects length of 8 characters (4 bytes)");
}
@ -658,7 +644,7 @@ int64_t configStringToInt(const std::string& VALUE) {
const auto VALUEWITHOUTFUNC = VALUE.substr(4, VALUE.length() - 5);
if (removeBeginEndSpacesTabs(VALUEWITHOUTFUNC).length() != 6) {
Debug::log(WARN, "invalid length %i for rgb", VALUEWITHOUTFUNC.length());
Debug::log(WARN, "invalid length {} for rgb", VALUEWITHOUTFUNC.length());
throw std::invalid_argument("rgb() expects length of 6 characters (3 bytes)");
}
@ -716,6 +702,10 @@ std::vector<SCallstackFrameInfo> getBacktrace() {
}
void throwError(const std::string& err) {
Debug::log(CRIT, "Critical error thrown: %s", err.c_str());
Debug::log(CRIT, "Critical error thrown: {}", err.c_str());
throw std::runtime_error(err);
}
std::string sendToLog(uint8_t level, const std::string& s) {
Debug::log((LogLevel)level, s);
}

View file

@ -5,6 +5,7 @@
#include <wlr/util/box.h>
#include "Vector2D.hpp"
#include <vector>
#include <format>
struct SCallstackFrameInfo {
void* adr = nullptr;
@ -13,7 +14,6 @@ struct SCallstackFrameInfo {
std::string absolutePath(const std::string&, const std::string&);
void addWLSignal(wl_signal*, wl_listener*, void* pOwner, const std::string& ownerString);
std::string getFormat(const char* fmt, ...); // Basically Debug::log to a string
std::string escapeJSONStrings(const std::string& str);
void scaleBox(wlr_box*, float);
std::string removeBeginEndSpacesTabs(std::string);
@ -30,4 +30,28 @@ void matrixProjection(float mat[9], int w, int h, wl
double normalizeAngleRad(double ang);
std::string replaceInString(std::string subject, const std::string& search, const std::string& replace);
std::vector<SCallstackFrameInfo> getBacktrace();
void throwError(const std::string& err);
void throwError(const std::string& err);
// why, C++.
std::string sendToLog(uint8_t, const std::string&);
template <typename... Args>
std::string getFormat(const std::string& fmt, Args&&... args) {
std::string fmtdMsg;
try {
fmtdMsg += std::vformat(fmt, std::make_format_args(args...));
} catch (std::exception& e) {
std::string exceptionMsg = e.what();
sendToLog(2, std::format("caught exception in getFormat: {}", exceptionMsg));
const auto CALLSTACK = getBacktrace();
sendToLog(0, "stacktrace:");
for (size_t i = 0; i < CALLSTACK.size(); ++i) {
sendToLog(1, std::format("\t #{} | {}", i, CALLSTACK[i].desc));
}
}
return fmtdMsg;
}

View file

@ -79,12 +79,12 @@ void CMonitor::onConnect(bool noRule) {
if (PREFSTATE)
wlr_output_set_mode(output, PREFSTATE);
else
Debug::log(WARN, "No mode found for disabled output %s", output->name);
Debug::log(WARN, "No mode found for disabled output {}", output->name);
wlr_output_enable(output, 0);
if (!wlr_output_commit(output))
Debug::log(ERR, "Couldn't commit disabled state on output %s", output->name);
Debug::log(ERR, "Couldn't commit disabled state on output {}", output->name);
Events::listener_change(nullptr, nullptr);
@ -136,8 +136,8 @@ void CMonitor::onConnect(bool noRule) {
wlr_xcursor_manager_load(g_pCompositor->m_sWLRXCursorMgr, scale);
Debug::log(LOG, "Added new monitor with name %s at %i,%i with size %ix%i, pointer %lx", output->name, (int)vecPosition.x, (int)vecPosition.y, (int)vecPixelSize.x,
(int)vecPixelSize.y, output);
Debug::log(LOG, "Added new monitor with name {} at {},{} with size {}x{}, pointer {:x}", output->name, (int)vecPosition.x, (int)vecPosition.y, (int)vecPixelSize.x,
(int)vecPixelSize.y, (uintptr_t)output);
setupDefaultWS(monitorRule);
@ -197,7 +197,7 @@ void CMonitor::onDisconnect() {
if (!m_bEnabled || g_pCompositor->m_bIsShuttingDown)
return;
Debug::log(LOG, "onDisconnect called for %s", output->name);
Debug::log(LOG, "onDisconnect called for {}", output->name);
// Cleanup everything. Move windows back, snap cursor, shit.
CMonitor* BACKUPMON = nullptr;
@ -239,7 +239,7 @@ void CMonitor::onDisconnect() {
m_aLayerSurfaceLayers[i].clear();
}
Debug::log(LOG, "Removed monitor %s!", szName.c_str());
Debug::log(LOG, "Removed monitor {}!", szName.c_str());
g_pEventManager->postEvent(SHyprIPCEvent{"monitorremoved", szName});
EMIT_HOOK_EVENT("monitorRemoved", this);
@ -356,12 +356,12 @@ void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) {
WORKSPACEID = g_pCompositor->m_vWorkspaces.size() + 1;
newDefaultWorkspaceName = std::to_string(WORKSPACEID);
Debug::log(LOG, "Invalid workspace= directive name in monitor parsing, workspace name \"%s\" is invalid.", g_pConfigManager->getDefaultWorkspaceFor(szName).c_str());
Debug::log(LOG, "Invalid workspace= directive name in monitor parsing, workspace name \"{}\" is invalid.", g_pConfigManager->getDefaultWorkspaceFor(szName).c_str());
}
auto PNEWWORKSPACE = g_pCompositor->getWorkspaceByID(WORKSPACEID);
Debug::log(LOG, "New monitor: WORKSPACEID %d, exists: %d", WORKSPACEID, (int)(PNEWWORKSPACE != nullptr));
Debug::log(LOG, "New monitor: WORKSPACEID {}, exists: {}", WORKSPACEID, (int)(PNEWWORKSPACE != nullptr));
if (PNEWWORKSPACE) {
// workspace exists, move it to the newly connected monitor
@ -500,7 +500,7 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal) {
if (pWorkspace->m_bIsSpecialWorkspace) {
if (specialWorkspaceID != pWorkspace->m_iID) {
Debug::log(LOG, "changeworkspace on special, togglespecialworkspace to id %i", pWorkspace->m_iID);
Debug::log(LOG, "changeworkspace on special, togglespecialworkspace to id {}", pWorkspace->m_iID);
g_pKeybindManager->m_mDispatchers["togglespecialworkspace"](pWorkspace->m_szName == "special" ? "" : pWorkspace->m_szName);
}
return;

View file

@ -55,7 +55,7 @@ SSurfaceTreeNode* createSubsurfaceNode(SSurfaceTreeNode* pParent, SSubsurface* p
PNODE->pParent = pParent;
PNODE->pSubsurface = pSubsurface;
Debug::log(LOG, "Creating a subsurface Node! (pWindow: %lx)", pWindow);
Debug::log(LOG, "Creating a subsurface Node! (pWindow: {:x})", (uintptr_t)pWindow);
return PNODE;
}
@ -63,7 +63,7 @@ SSurfaceTreeNode* createSubsurfaceNode(SSurfaceTreeNode* pParent, SSubsurface* p
SSurfaceTreeNode* SubsurfaceTree::createTreeRoot(wlr_surface* pSurface, applyGlobalOffsetFn fn, void* data, CWindow* pWindow) {
const auto PNODE = createTree(pSurface, pWindow);
Debug::log(LOG, "Creating a surfaceTree Root! (pWindow: %lx)", pWindow);
Debug::log(LOG, "Creating a surfaceTree Root! (pWindow: {:x})", (uintptr_t)pWindow);
PNODE->offsetfn = fn;
PNODE->globalOffsetData = data;
@ -83,7 +83,7 @@ void SubsurfaceTree::destroySurfaceTree(SSurfaceTreeNode* pNode) {
}
if (!exists) {
Debug::log(ERR, "Tried to remove a SurfaceTreeNode that doesn't exist?? (Node %lx)", pNode);
Debug::log(ERR, "Tried to remove a SurfaceTreeNode that doesn't exist?? (Node {:x})", (uintptr_t)pNode);
return;
}
@ -145,7 +145,7 @@ void Events::listener_newSubsurfaceNode(void* owner, void* data) {
const auto PNEWSUBSURFACE = &pNode->childSubsurfaces.emplace_back();
Debug::log(LOG, "Added a new subsurface %lx", PSUBSURFACE);
Debug::log(LOG, "Added a new subsurface {:x}", (uintptr_t)PSUBSURFACE);
PNEWSUBSURFACE->pSubsurface = PSUBSURFACE;
PNEWSUBSURFACE->pParent = pNode;
@ -174,7 +174,7 @@ void Events::listener_mapSubsurface(void* owner, void* data) {
if (subsurface->pChild)
return;
Debug::log(LOG, "Subsurface %lx mapped", subsurface->pSubsurface);
Debug::log(LOG, "Subsurface {:x} mapped", (uintptr_t)subsurface->pSubsurface);
subsurface->pChild = createSubsurfaceNode(subsurface->pParent, subsurface, subsurface->pSubsurface->surface, subsurface->pWindowOwner);
}
@ -182,7 +182,7 @@ void Events::listener_mapSubsurface(void* owner, void* data) {
void Events::listener_unmapSubsurface(void* owner, void* data) {
SSubsurface* subsurface = (SSubsurface*)owner;
Debug::log(LOG, "Subsurface %lx unmapped", subsurface);
Debug::log(LOG, "Subsurface {:x} unmapped", (uintptr_t)subsurface);
if (subsurface->pSubsurface->surface == g_pCompositor->m_pLastFocus)
g_pInputManager->releaseAllMouseButtons();
@ -221,7 +221,7 @@ void Events::listener_commitSubsurface(void* owner, void* data) {
if (!g_pHyprRenderer->shouldRenderWindow(pNode->pWindowOwner)) {
static auto* const PLOGDAMAGE = &g_pConfigManager->getConfigValuePtr("debug:log_damage")->intValue;
if (*PLOGDAMAGE)
Debug::log(LOG, "Refusing to commit damage from %lx because it's invisible.", pNode->pWindowOwner);
Debug::log(LOG, "Refusing to commit damage from {:x} because it's invisible.", (uintptr_t)pNode->pWindowOwner);
return;
}
@ -254,7 +254,7 @@ void Events::listener_destroySubsurface(void* owner, void* data) {
SubsurfaceTree::destroySurfaceTree(subsurface->pChild);
}
Debug::log(LOG, "Subsurface %lx destroyed", subsurface);
Debug::log(LOG, "Subsurface {:x} destroyed", (uintptr_t)subsurface);
subsurface->hyprListener_destroy.removeCallback();
subsurface->hyprListener_map.removeCallback();
@ -266,7 +266,7 @@ void Events::listener_destroySubsurface(void* owner, void* data) {
void Events::listener_destroySubsurfaceNode(void* owner, void* data) {
SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner;
Debug::log(LOG, "Subsurface Node %lx destroyed", pNode);
Debug::log(LOG, "Subsurface Node {:x} destroyed", (uintptr_t)pNode);
for (auto& c : pNode->childSubsurfaces)
destroySubsurface(&c);

View file

@ -25,7 +25,7 @@ CHyprWLListener::~CHyprWLListener() {
void CHyprWLListener::removeCallback() {
if (isConnected()) {
Debug::log(LOG, "Callback %lx -> %lx, %s removed.", &m_pCallback, &m_pOwner, m_szAuthor.c_str());
Debug::log(LOG, "Callback {:x} -> {:x}, {} removed.", (uintptr_t)&m_pCallback, (uintptr_t)&m_pOwner, m_szAuthor.c_str());
wl_list_remove(&m_swWrapper.m_sListener.link);
wl_list_init(&m_swWrapper.m_sListener.link);
}

View file

@ -39,7 +39,7 @@ void CWLSurface::destroy() {
m_pWLRSurface = nullptr;
Debug::log(LOG, "CWLSurface %lx called destroy()", this);
Debug::log(LOG, "CWLSurface {:x} called destroy()", (uintptr_t)this);
}
void CWLSurface::init() {
@ -53,5 +53,5 @@ void CWLSurface::init() {
hyprListener_destroy.initCallback(
&m_pWLRSurface->events.destroy, [&](void* owner, void* data) { destroy(); }, this, "CWLSurface");
Debug::log(LOG, "CWLSurface %lx called init()", this);
Debug::log(LOG, "CWLSurface {:x} called init()", (uintptr_t)this);
}

View file

@ -31,7 +31,7 @@ CWorkspace::CWorkspace(int monitorID, std::string name, bool special) {
CWorkspace::~CWorkspace() {
m_vRenderOffset.unregister();
Debug::log(LOG, "Destroying workspace ID %d", m_iID);
Debug::log(LOG, "Destroying workspace ID {}", m_iID);
g_pEventManager->postEvent({"destroyworkspace", m_szName});
EMIT_HOOK_EVENT("destroyWorkspace", this);