summaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
authormemchr <118117622+memchr@users.noreply.github.com>2023-09-20 07:26:20 +0000
committerGitHub <noreply@github.com>2023-09-20 08:26:20 +0100
commit6594b50e57935dd66930ccd35dba7a1b4131399d (patch)
tree17d4fa7aabf0e447c7171346c5b851c999093149 /src/debug
parentd8d0cd75c2db16a14086e1d5119ed937a60c701e (diff)
logging/format: use std::format_string to catch formatting string errors at compile time (#3377)
* fix(log): use constexpr format string * deprecate getFormat
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/CrashReporter.cpp16
-rw-r--r--src/debug/HyprCtl.cpp141
-rw-r--r--src/debug/HyprDebugOverlay.cpp10
-rw-r--r--src/debug/Log.hpp25
4 files changed, 92 insertions, 100 deletions
diff --git a/src/debug/CrashReporter.cpp b/src/debug/CrashReporter.cpp
index 08699b38..ed4357d2 100644
--- a/src/debug/CrashReporter.cpp
+++ b/src/debug/CrashReporter.cpp
@@ -45,15 +45,15 @@ void CrashReporter::createAndSaveCrash(int sig) {
finalCrashReport += "--------------------------------------------\n Hyprland Crash Report\n--------------------------------------------\n";
finalCrashReport += getRandomMessage() + "\n\n";
- finalCrashReport += getFormat("Hyprland received signal {} ({})\n\n", sig, (const char*)strsignal(sig));
+ finalCrashReport += std::format("Hyprland received signal {} ({})\n\n", sig, (const char*)strsignal(sig));
- finalCrashReport += getFormat("Version: {}\nTag: {}\n\n", GIT_COMMIT_HASH, GIT_TAG);
+ finalCrashReport += std::format("Version: {}\nTag: {}\n\n", GIT_COMMIT_HASH, GIT_TAG);
if (g_pPluginSystem && !g_pPluginSystem->getAllPlugins().empty()) {
finalCrashReport += "Hyprland seems to be running with plugins. This crash might not be Hyprland's fault.\nPlugins:\n";
for (auto& p : g_pPluginSystem->getAllPlugins()) {
- finalCrashReport += getFormat("\t{} ({}) {}\n", p->name, p->author, p->version);
+ finalCrashReport += std::format("\t{} ({}) {}\n", p->name, p->author, p->version);
}
finalCrashReport += "\n\n";
@@ -65,7 +65,7 @@ void CrashReporter::createAndSaveCrash(int sig) {
uname(&unameInfo);
finalCrashReport +=
- getFormat("\tSystem name: {}\n\tNode name: {}\n\tRelease: {}\n\tVersion: {}\n\n", unameInfo.sysname, unameInfo.nodename, unameInfo.release, unameInfo.version);
+ std::format("\tSystem name: {}\n\tNode name: {}\n\tRelease: {}\n\tVersion: {}\n\n", unameInfo.sysname, unameInfo.nodename, unameInfo.release, unameInfo.version);
#if defined(__DragonFly__) || defined(__FreeBSD__)
const std::string GPUINFO = execAndGet("pciconf -lv | fgrep -A4 vga");
@@ -75,7 +75,7 @@ void CrashReporter::createAndSaveCrash(int sig) {
finalCrashReport += "GPU:\n\t" + GPUINFO;
- finalCrashReport += getFormat("\n\nos-release:\n\t{}\n\n\n", replaceInString(execAndGet("cat /etc/os-release"), "\n", "\n\t"));
+ finalCrashReport += std::format("\n\nos-release:\n\t{}\n\n\n", replaceInString(execAndGet("cat /etc/os-release"), "\n", "\n\t"));
finalCrashReport += "Backtrace:\n";
@@ -107,12 +107,12 @@ void CrashReporter::createAndSaveCrash(int sig) {
#endif
for (size_t i = 0; i < CALLSTACK.size(); ++i) {
- finalCrashReport += getFormat("\t#{} | {}\n", i, CALLSTACK[i].desc);
+ finalCrashReport += std::format("\t#{} | {}\n", i, CALLSTACK[i].desc);
#ifdef __clang__
- const auto CMD = getFormat("llvm-addr2line -e {} -f 0x{:x}", FPATH.c_str(), (uint64_t)CALLSTACK[i].adr);
+ const auto CMD = std::format("llvm-addr2line -e {} -f 0x{:x}", FPATH.c_str(), (uint64_t)CALLSTACK[i].adr);
#else
- const auto CMD = getFormat("addr2line -e {} -f 0x{:x}", FPATH.c_str(), (uint64_t)CALLSTACK[i].adr);
+ const auto CMD = std::format("addr2line -e {} -f 0x{:x}", FPATH.c_str(), (uint64_t)CALLSTACK[i].adr);
#endif
const auto ADDR2LINE = replaceInString(execAndGet(CMD.c_str()), "\n", "\n\t\t");
finalCrashReport += "\t\t" + ADDR2LINE.substr(0, ADDR2LINE.length() - 2);
diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp
index d4b36396..29d2b4d1 100644
--- a/src/debug/HyprCtl.cpp
+++ b/src/debug/HyprCtl.cpp
@@ -37,7 +37,7 @@ std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) {
if (!m->output)
continue;
- result += getFormat(
+ result += std::format(
R"#({{
"id": {},
"name": "{}",
@@ -82,16 +82,16 @@ std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) {
continue;
result +=
- getFormat("Monitor {} (ID {}):\n\t{}x{}@{:.5f} at {}x{}\n\tdescription: {}\n\tmake: {}\n\tmodel: {}\n\tserial: {}\n\tactive workspace: {} ({})\n\tspecial "
- "workspace: {} ({})\n\treserved: {} "
- "{} {} {}\n\tscale: {:.2f}\n\ttransform: "
- "{}\n\tfocused: {}\n\tdpmsStatus: {}\n\tvrr: {}\n\n",
- m->szName, m->ID, (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y,
- (m->output->description ? m->output->description : ""), (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""),
- (m->output->serial ? m->output->serial : ""), m->activeWorkspace, g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName, m->specialWorkspaceID,
- getWorkspaceNameFromSpecialID(m->specialWorkspaceID), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x,
- (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus,
- (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED));
+ std::format("Monitor {} (ID {}):\n\t{}x{}@{:.5f} at {}x{}\n\tdescription: {}\n\tmake: {}\n\tmodel: {}\n\tserial: {}\n\tactive workspace: {} ({})\n\tspecial "
+ "workspace: {} ({})\n\treserved: {} "
+ "{} {} {}\n\tscale: {:.2f}\n\ttransform: "
+ "{}\n\tfocused: {}\n\tdpmsStatus: {}\n\tvrr: {}\n\n",
+ m->szName, m->ID, (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y,
+ (m->output->description ? m->output->description : ""), (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""),
+ (m->output->serial ? m->output->serial : ""), m->activeWorkspace, g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName, m->specialWorkspaceID,
+ getWorkspaceNameFromSpecialID(m->specialWorkspaceID), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x,
+ (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus,
+ (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED));
}
}
@@ -112,7 +112,6 @@ static std::string getGroupedData(CWindow* w, HyprCtl::eHyprCtlOutputFormat form
} while (curr != w);
const auto comma = isJson ? ", " : ",";
- const auto fmt = isJson ? "\"0x{:x}\"" : "{:x}";
std::ostringstream result;
bool first = true;
@@ -121,8 +120,10 @@ static std::string getGroupedData(CWindow* w, HyprCtl::eHyprCtlOutputFormat form
first = false;
else
result << comma;
-
- result << getFormat(fmt, (uintptr_t)gw);
+ if (isJson)
+ result << std::format("\"0x{:x}\"", (uintptr_t)gw);
+ else
+ result << std::format("{:x}", (uintptr_t)gw);
}
return result.str();
@@ -130,7 +131,7 @@ static std::string getGroupedData(CWindow* w, HyprCtl::eHyprCtlOutputFormat form
static std::string getWindowData(CWindow* w, HyprCtl::eHyprCtlOutputFormat format) {
if (format == HyprCtl::FORMAT_JSON) {
- return getFormat(
+ return std::format(
R"#({{
"address": "0x{:x}",
"mapped": {},
@@ -167,7 +168,7 @@ static std::string getWindowData(CWindow* w, HyprCtl::eHyprCtlOutputFormat forma
(w->m_bIsFullscreen ? (g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? (int)g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_efFullscreenMode : 0) : 0),
w->m_bFakeFullscreenState ? "true" : "false", getGroupedData(w, format), (uintptr_t)w->m_pSwallowed);
} else {
- return getFormat(
+ return std::format(
"Window {:x} -> {}:\n\tmapped: {}\n\thidden: {}\n\tat: {},{}\n\tsize: {},{}\n\tworkspace: {} ({})\n\tfloating: {}\n\tmonitor: {}\n\tclass: {}\n\ttitle: "
"{}\n\tinitialClass: {}\n\tinitialTitle: {}\n\tpid: "
"{}\n\txwayland: {}\n\tpinned: "
@@ -177,8 +178,8 @@ static std::string getWindowData(CWindow* w, HyprCtl::eHyprCtlOutputFormat forma
(w->m_iWorkspaceID == -1 ? "" :
g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName :
std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID))),
- (int)w->m_bIsFloating, (int64_t)w->m_iMonitorID, g_pXWaylandManager->getAppIDClass(w), g_pXWaylandManager->getTitle(w), w->m_szInitialClass, w->m_szInitialTitle, w->getPID(),
- (int)w->m_bIsX11, (int)w->m_bPinned, (int)w->m_bIsFullscreen,
+ (int)w->m_bIsFloating, (int64_t)w->m_iMonitorID, g_pXWaylandManager->getAppIDClass(w), g_pXWaylandManager->getTitle(w), w->m_szInitialClass, w->m_szInitialTitle,
+ w->getPID(), (int)w->m_bIsX11, (int)w->m_bPinned, (int)w->m_bIsFullscreen,
(w->m_bIsFullscreen ? (g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_efFullscreenMode : 0) : 0),
(int)w->m_bFakeFullscreenState, getGroupedData(w, format), (uintptr_t)w->m_pSwallowed);
}
@@ -208,7 +209,7 @@ static std::string getWorkspaceData(CWorkspace* w, HyprCtl::eHyprCtlOutputFormat
const auto PLASTW = w->getLastFocusedWindow();
const auto PMONITOR = g_pCompositor->getMonitorFromID(w->m_iMonitorID);
if (format == HyprCtl::FORMAT_JSON) {
- return getFormat(R"#({{
+ return std::format(R"#({{
"id": {},
"name": "{}",
"monitor": "{}",
@@ -217,12 +218,12 @@ static std::string getWorkspaceData(CWorkspace* w, HyprCtl::eHyprCtlOutputFormat
"lastwindow": "0x{:x}",
"lastwindowtitle": "{}"
}})#",
- w->m_iID, escapeJSONStrings(w->m_szName), escapeJSONStrings(PMONITOR ? PMONITOR->szName : "?"), g_pCompositor->getWindowsOnWorkspace(w->m_iID),
- ((int)w->m_bHasFullscreenWindow == 1 ? "true" : "false"), (uintptr_t)PLASTW, PLASTW ? escapeJSONStrings(PLASTW->m_szTitle) : "");
+ w->m_iID, escapeJSONStrings(w->m_szName), escapeJSONStrings(PMONITOR ? PMONITOR->szName : "?"), g_pCompositor->getWindowsOnWorkspace(w->m_iID),
+ ((int)w->m_bHasFullscreenWindow == 1 ? "true" : "false"), (uintptr_t)PLASTW, PLASTW ? escapeJSONStrings(PLASTW->m_szTitle) : "");
} else {
- return getFormat("workspace ID {} ({}) on monitor {}:\n\twindows: {}\n\thasfullscreen: {}\n\tlastwindow: 0x{:x}\n\tlastwindowtitle: {}\n\n", w->m_iID, w->m_szName,
- PMONITOR ? PMONITOR->szName : "?", g_pCompositor->getWindowsOnWorkspace(w->m_iID), (int)w->m_bHasFullscreenWindow, (uintptr_t)PLASTW,
- PLASTW ? PLASTW->m_szTitle : "");
+ return std::format("workspace ID {} ({}) on monitor {}:\n\twindows: {}\n\thasfullscreen: {}\n\tlastwindow: 0x{:x}\n\tlastwindowtitle: {}\n\n", w->m_iID, w->m_szName,
+ PMONITOR ? PMONITOR->szName : "?", g_pCompositor->getWindowsOnWorkspace(w->m_iID), (int)w->m_bHasFullscreenWindow, (uintptr_t)PLASTW,
+ PLASTW ? PLASTW->m_szTitle : "");
}
}
@@ -274,7 +275,7 @@ std::string layersRequest(HyprCtl::eHyprCtlOutputFormat format) {
result += "{\n";
for (auto& mon : g_pCompositor->m_vMonitors) {
- result += getFormat(
+ result += std::format(
R"#("{}": {{
"levels": {{
)#",
@@ -282,13 +283,13 @@ std::string layersRequest(HyprCtl::eHyprCtlOutputFormat format) {
int layerLevel = 0;
for (auto& level : mon->m_aLayerSurfaceLayers) {
- result += getFormat(
+ result += std::format(
R"#(
"{}": [
)#",
layerLevel);
for (auto& layer : level) {
- result += getFormat(
+ result += std::format(
R"#( {{
"address": "0x{:x}",
"x": {},
@@ -321,15 +322,15 @@ std::string layersRequest(HyprCtl::eHyprCtlOutputFormat format) {
} else {
for (auto& mon : g_pCompositor->m_vMonitors) {
- result += getFormat("Monitor {}:\n", mon->szName);
+ result += std::format("Monitor {}:\n", mon->szName);
int layerLevel = 0;
static const std::array<std::string, 4> levelNames = {"background", "bottom", "top", "overlay"};
for (auto& level : mon->m_aLayerSurfaceLayers) {
- result += getFormat("\tLayer level {} ({}):\n", layerLevel, levelNames[layerLevel]);
+ result += std::format("\tLayer level {} ({}):\n", layerLevel, levelNames[layerLevel]);
for (auto& layer : level) {
- result += getFormat("\t\tLayer {:x}: xywh: {} {} {} {}, namespace: {}\n", (uintptr_t)layer.get(), layer->geometry.x, layer->geometry.y, layer->geometry.width,
- layer->geometry.height, layer->szNamespace);
+ result += std::format("\t\tLayer {:x}: xywh: {} {} {} {}, namespace: {}\n", (uintptr_t)layer.get(), layer->geometry.x, layer->geometry.y, layer->geometry.width,
+ layer->geometry.height, layer->szNamespace);
}
layerLevel++;
@@ -349,7 +350,7 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
result += "\"mice\": [\n";
for (auto& m : g_pInputManager->m_lMice) {
- result += getFormat(
+ result += std::format(
R"#( {{
"address": "0x{:x}",
"name": "{}",
@@ -365,7 +366,7 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
result += "\"keyboards\": [\n";
for (auto& k : g_pInputManager->m_lKeyboards) {
const auto KM = g_pInputManager->getActiveLayoutForKeyboard(&k);
- result += getFormat(
+ result += std::format(
R"#( {{
"address": "0x{:x}",
"name": "{}",
@@ -388,7 +389,7 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
result += "\"tablets\": [\n";
for (auto& d : g_pInputManager->m_lTabletPads) {
- result += getFormat(
+ result += std::format(
R"#( {{
"address": "0x{:x}",
"type": "tabletPad",
@@ -401,7 +402,7 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
}
for (auto& d : g_pInputManager->m_lTablets) {
- result += getFormat(
+ result += std::format(
R"#( {{
"address": "0x{:x}",
"name": "{}"
@@ -410,13 +411,13 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
}
for (auto& d : g_pInputManager->m_lTabletTools) {
- result += getFormat(
+ result += std::format(
R"#( {{
"address": "0x{:x}",
"type": "tabletTool",
"belongsTo": "0x{:x}"
}},)#",
- (uintptr_t)&d, d.wlrTabletTool ? d.wlrTabletTool->data : 0);
+ (uintptr_t)&d, d.wlrTabletTool ? (uintptr_t)d.wlrTabletTool->data : 0);
}
trimTrailingComma(result);
@@ -425,7 +426,7 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
result += "\"touch\": [\n";
for (auto& d : g_pInputManager->m_lTouchDevices) {
- result += getFormat(
+ result += std::format(
R"#( {{
"address": "0x{:x}",
"name": "{}"
@@ -439,7 +440,7 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
result += "\"switches\": [\n";
for (auto& d : g_pInputManager->m_lSwitches) {
- result += getFormat(
+ result += std::format(
R"#( {{
"address": "0x{:x}",
"name": "{}"
@@ -456,7 +457,7 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
result += "mice:\n";
for (auto& m : g_pInputManager->m_lMice) {
- result += getFormat(
+ result += std::format(
"\tMouse at {:x}:\n\t\t{}\n\t\t\tdefault speed: {:.5f}\n", (uintptr_t)&m, m.name,
(wlr_input_device_is_libinput(m.mouse) ? libinput_device_config_accel_get_default_speed((libinput_device*)wlr_libinput_get_device_handle(m.mouse)) : 0.f));
}
@@ -465,35 +466,35 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& k : g_pInputManager->m_lKeyboards) {
const auto KM = g_pInputManager->getActiveLayoutForKeyboard(&k);
- result +=
- getFormat("\tKeyboard at {:x}:\n\t\t{}\n\t\t\trules: r \"{}\", m \"{}\", l \"{}\", v \"{}\", o \"{}\"\n\t\t\tactive keymap: {}\n\t\t\tmain: {}\n", (uintptr_t)&k,
- k.name, k.currentRules.rules, k.currentRules.model, k.currentRules.layout, k.currentRules.variant, k.currentRules.options, KM, (k.active ? "yes" : "no"));
+ result += std::format("\tKeyboard at {:x}:\n\t\t{}\n\t\t\trules: r \"{}\", m \"{}\", l \"{}\", v \"{}\", o \"{}\"\n\t\t\tactive keymap: {}\n\t\t\tmain: {}\n",
+ (uintptr_t)&k, k.name, k.currentRules.rules, k.currentRules.model, k.currentRules.layout, k.currentRules.variant, k.currentRules.options, KM,
+ (k.active ? "yes" : "no"));
}
result += "\n\nTablets:\n";
for (auto& d : g_pInputManager->m_lTabletPads) {
- result += getFormat("\tTablet Pad at {:x} (belongs to {:x} -> {})\n", (uintptr_t)&d, (uintptr_t)d.pTabletParent, d.pTabletParent ? d.pTabletParent->name : "");
+ result += std::format("\tTablet Pad at {:x} (belongs to {:x} -> {})\n", (uintptr_t)&d, (uintptr_t)d.pTabletParent, d.pTabletParent ? d.pTabletParent->name : "");
}
for (auto& d : g_pInputManager->m_lTablets) {
- result += getFormat("\tTablet at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.name);
+ result += std::format("\tTablet at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.name);
}
for (auto& d : g_pInputManager->m_lTabletTools) {
- result += getFormat("\tTablet Tool at {:x} (belongs to {:x})\n", (uintptr_t)&d, d.wlrTabletTool ? d.wlrTabletTool->data : 0);
+ result += std::format("\tTablet Tool at {:x} (belongs to {:x})\n", (uintptr_t)&d, d.wlrTabletTool ? (uintptr_t)d.wlrTabletTool->data : 0);
}
result += "\n\nTouch:\n";
for (auto& d : g_pInputManager->m_lTouchDevices) {
- result += getFormat("\tTouch Device at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.name);
+ result += std::format("\tTouch Device at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.name);
}
result += "\n\nSwitches:\n";
for (auto& d : g_pInputManager->m_lSwitches) {
- result += getFormat("\tSwitch Device at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.pWlrDevice ? d.pWlrDevice->name : "");
+ result += std::format("\tSwitch Device at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.pWlrDevice ? d.pWlrDevice->name : "");
}
}
@@ -506,21 +507,21 @@ std::string animationsRequest(HyprCtl::eHyprCtlOutputFormat format) {
ret += "animations:\n";
for (auto& ac : g_pConfigManager->getAnimationConfig()) {
- ret += getFormat("\n\tname: {}\n\t\toverriden: {}\n\t\tbezier: {}\n\t\tenabled: {}\n\t\tspeed: {:.2f}\n\t\tstyle: {}\n", ac.first, (int)ac.second.overridden,
- ac.second.internalBezier, ac.second.internalEnabled, ac.second.internalSpeed, ac.second.internalStyle);
+ ret += std::format("\n\tname: {}\n\t\toverriden: {}\n\t\tbezier: {}\n\t\tenabled: {}\n\t\tspeed: {:.2f}\n\t\tstyle: {}\n", ac.first, (int)ac.second.overridden,
+ ac.second.internalBezier, ac.second.internalEnabled, ac.second.internalSpeed, ac.second.internalStyle);
}
ret += "beziers:\n";
for (auto& bz : g_pAnimationManager->getAllBeziers()) {
- ret += getFormat("\n\tname: {}\n", bz.first);
+ ret += std::format("\n\tname: {}\n", bz.first);
}
} else {
// json
ret += "[[";
for (auto& ac : g_pConfigManager->getAnimationConfig()) {
- ret += getFormat(R"#(
+ ret += std::format(R"#(
{{
"name": "{}",
"overridden": {},
@@ -529,8 +530,8 @@ std::string animationsRequest(HyprCtl::eHyprCtlOutputFormat format) {
"speed": {:.2f},
"style": "{}"
}},)#",
- ac.first, ac.second.overridden ? "true" : "false", ac.second.internalBezier, ac.second.internalEnabled ? "true" : "false", ac.second.internalSpeed,
- ac.second.internalStyle);
+ ac.first, ac.second.overridden ? "true" : "false", ac.second.internalBezier, ac.second.internalEnabled ? "true" : "false", ac.second.internalSpeed,
+ ac.second.internalStyle);
}
ret[ret.length() - 1] = ']';
@@ -538,11 +539,11 @@ std::string animationsRequest(HyprCtl::eHyprCtlOutputFormat format) {
ret += ",\n[";
for (auto& bz : g_pAnimationManager->getAllBeziers()) {
- ret += getFormat(R"#(
+ ret += std::format(R"#(
{{
"name": "{}"
}},)#",
- bz.first);
+ bz.first);
}
trimTrailingComma(ret);
@@ -558,16 +559,16 @@ std::string globalShortcutsRequest(HyprCtl::eHyprCtlOutputFormat format) {
const auto SHORTCUTS = g_pProtocolManager->m_pGlobalShortcutsProtocolManager->getAllShortcuts();
if (format == HyprCtl::eHyprCtlOutputFormat::FORMAT_NORMAL) {
for (auto& sh : SHORTCUTS)
- ret += getFormat("{}:{} -> {}\n", sh.appid, sh.id, sh.description);
+ ret += std::format("{}:{} -> {}\n", sh.appid, sh.id, sh.description);
} else {
ret += "[";
for (auto& sh : SHORTCUTS) {
- ret += getFormat(R"#(
+ ret += std::format(R"#(
{{
"name": "{}",
"description": "{}"
}},)#",
- escapeJSONStrings(sh.appid + ":" + sh.id), escapeJSONStrings(sh.description));
+ escapeJSONStrings(sh.appid + ":" + sh.id), escapeJSONStrings(sh.description));
}
trimTrailingComma(ret);
ret += "]\n";
@@ -592,14 +593,14 @@ std::string bindsRequest(HyprCtl::eHyprCtlOutputFormat format) {
if (kb.nonConsuming)
ret += "n";
- ret += getFormat("\n\tmodmask: {}\n\tsubmap: {}\n\tkey: {}\n\tkeycode: {}\n\tdispatcher: {}\n\targ: {}\n\n", kb.modmask, kb.submap, kb.key, kb.keycode, kb.handler,
- kb.arg);
+ ret += std::format("\n\tmodmask: {}\n\tsubmap: {}\n\tkey: {}\n\tkeycode: {}\n\tdispatcher: {}\n\targ: {}\n\n", kb.modmask, kb.submap, kb.key, kb.keycode, kb.handler,
+ kb.arg);
}
} else {
// json
ret += "[";
for (auto& kb : g_pKeybindManager->m_lKeybinds) {
- ret += getFormat(
+ ret += std::format(
R"#(
{{
"locked": {},
@@ -648,7 +649,7 @@ std::string versionRequest(HyprCtl::eHyprCtlOutputFormat format) {
return result;
} else {
- std::string result = getFormat(
+ std::string result = std::format(
R"#({{
"branch": "{}",
"commit": "{}",
@@ -779,15 +780,15 @@ std::string cursorPosRequest(HyprCtl::eHyprCtlOutputFormat format) {
const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal().floor();
if (format == HyprCtl::FORMAT_NORMAL) {
- return getFormat("{}, {}", (int)CURSORPOS.x, (int)CURSORPOS.y);
+ return std::format("{}, {}", (int)CURSORPOS.x, (int)CURSORPOS.y);
} else {
- return getFormat(R"#(
+ return std::format(R"#(
{{
"x": {},
"y": {}
}}
)#",
- (int)CURSORPOS.x, (int)CURSORPOS.y);
+ (int)CURSORPOS.x, (int)CURSORPOS.y);
}
return "error";
@@ -1039,10 +1040,10 @@ std::string dispatchGetOption(std::string request, HyprCtl::eHyprCtlOutputFormat
return "no such option";
if (format == HyprCtl::eHyprCtlOutputFormat::FORMAT_NORMAL)
- return getFormat("option {}\n\tint: {}\n\tfloat: {:.5f}\n\tstr: \"{}\"\n\tdata: {:x}\n\tset: {}", curitem, PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue,
- (uintptr_t)PCFGOPT->data.get(), PCFGOPT->set);
+ return std::format("option {}\n\tint: {}\n\tfloat: {:.5f}\n\tstr: \"{}\"\n\tdata: {:x}\n\tset: {}", curitem, PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue,
+ (uintptr_t)PCFGOPT->data.get(), PCFGOPT->set);
else {
- return getFormat(
+ return std::format(
R"#(
{{
"option": "{}",
@@ -1169,7 +1170,7 @@ std::string dispatchPlugin(std::string request) {
std::string list = "";
for (auto& p : PLUGINS) {
- list += getFormat("\nPlugin {} by {}:\n\tHandle: {:x}\n\tVersion: {}\n\tDescription: {}\n", p->name, p->author, (uintptr_t)p->m_pHandle, p->version, p->description);
+ list += std::format("\nPlugin {} by {}:\n\tHandle: {:x}\n\tVersion: {}\n\tDescription: {}\n", p->name, p->author, (uintptr_t)p->m_pHandle, p->version, p->description);
}
return list;
diff --git a/src/debug/HyprDebugOverlay.cpp b/src/debug/HyprDebugOverlay.cpp
index 4eb14cef..741f6e18 100644
--- a/src/debug/HyprDebugOverlay.cpp
+++ b/src/debug/HyprDebugOverlay.cpp
@@ -132,7 +132,7 @@ int CHyprMonitorDebugOverlay::draw(int offset) {
yOffset += 17;
cairo_move_to(g_pDebugOverlay->m_pCairo, 0, yOffset);
- text = getFormat("{} FPS", (int)FPS);
+ text = std::format("{} FPS", (int)FPS);
cairo_show_text(g_pDebugOverlay->m_pCairo, text.c_str());
cairo_text_extents(g_pDebugOverlay->m_pCairo, text.c_str(), &cairoExtents);
if (cairoExtents.width > maxX)
@@ -143,7 +143,7 @@ int CHyprMonitorDebugOverlay::draw(int offset) {
yOffset += 11;
cairo_move_to(g_pDebugOverlay->m_pCairo, 0, yOffset);
- text = getFormat("Avg Frametime: {:.2f}ms (var {:.2f}ms)", avgFrametime, varFrametime);
+ text = std::format("Avg Frametime: {:.2f}ms (var {:.2f}ms)", avgFrametime, varFrametime);
cairo_show_text(g_pDebugOverlay->m_pCairo, text.c_str());
cairo_text_extents(g_pDebugOverlay->m_pCairo, text.c_str(), &cairoExtents);
if (cairoExtents.width > maxX)
@@ -151,7 +151,7 @@ int CHyprMonitorDebugOverlay::draw(int offset) {
yOffset += 11;
cairo_move_to(g_pDebugOverlay->m_pCairo, 0, yOffset);
- text = getFormat("Avg Rendertime: {:.2f}ms (var {:.2f}ms)", avgRenderTime, varRenderTime);
+ text = std::format("Avg Rendertime: {:.2f}ms (var {:.2f}ms)", avgRenderTime, varRenderTime);
cairo_show_text(g_pDebugOverlay->m_pCairo, text.c_str());
cairo_text_extents(g_pDebugOverlay->m_pCairo, text.c_str(), &cairoExtents);
if (cairoExtents.width > maxX)
@@ -159,7 +159,7 @@ int CHyprMonitorDebugOverlay::draw(int offset) {
yOffset += 11;
cairo_move_to(g_pDebugOverlay->m_pCairo, 0, yOffset);
- text = getFormat("Avg Rendertime (No Overlay): {:.2f}ms (var {:.2f}ms)", avgRenderTimeNoOverlay, varRenderTimeNoOverlay);
+ text = std::format("Avg Rendertime (No Overlay): {:.2f}ms (var {:.2f}ms)", avgRenderTimeNoOverlay, varRenderTimeNoOverlay);
cairo_show_text(g_pDebugOverlay->m_pCairo, text.c_str());
cairo_text_extents(g_pDebugOverlay->m_pCairo, text.c_str(), &cairoExtents);
if (cairoExtents.width > maxX)
@@ -167,7 +167,7 @@ int CHyprMonitorDebugOverlay::draw(int offset) {
yOffset += 11;
cairo_move_to(g_pDebugOverlay->m_pCairo, 0, yOffset);
- text = getFormat("Avg Anim Tick: {:.2f}ms (var {:.2f}ms) ({:.2f} TPS)", avgAnimMgrTick, varAnimMgrTick, 1.0 / (avgAnimMgrTick / 1000.0));
+ text = std::format("Avg Anim Tick: {:.2f}ms (var {:.2f}ms) ({:.2f} TPS)", avgAnimMgrTick, varAnimMgrTick, 1.0 / (avgAnimMgrTick / 1000.0));
cairo_show_text(g_pDebugOverlay->m_pCairo, text.c_str());
cairo_text_extents(g_pDebugOverlay->m_pCairo, text.c_str(), &cairoExtents);
if (cairoExtents.width > maxX)
diff --git a/src/debug/Log.hpp b/src/debug/Log.hpp
index a65bccb1..125ed7f4 100644
--- a/src/debug/Log.hpp
+++ b/src/debug/Log.hpp
@@ -9,8 +9,7 @@
#define LOGMESSAGESIZE 1024
-enum LogLevel
-{
+enum LogLevel {
NONE = -1,
LOG = 0,
WARN,
@@ -29,7 +28,7 @@ namespace Debug {
void init(const std::string& IS);
template <typename... Args>
- void log(LogLevel level, const std::string& fmt, Args&&... args) {
+ void log(LogLevel level, std::format_string<Args...> fmt, Args&&... args) {
if (disableLogs && *disableLogs)
return;
@@ -63,20 +62,12 @@ namespace Debug {
#endif
}
- try {
- logMsg += std::vformat(fmt, std::make_format_args(args...));
- } catch (std::exception& e) {
- std::string exceptionMsg = e.what();
- Debug::log(ERR, "caught exception in Debug::log: {}", exceptionMsg);
-
- const auto CALLSTACK = getBacktrace();
-
- Debug::log(LOG, "stacktrace:");
-
- for (size_t i = 0; i < CALLSTACK.size(); ++i) {
- Debug::log(NONE, "\t #{} | {}", i, CALLSTACK[i].desc);
- }
- }
+ // no need for try {} catch {} because std::format_string<Args...> ensures that vformat never throw std::format_error
+ // because
+ // 1. any faulty format specifier that sucks will cause a compilation error.
+ // 2. and `std::bad_alloc` is catastrophic, (Almost any operation in stdlib could throw this.)
+ // 3. this is actually what std::format in stdlib does
+ logMsg += std::vformat(fmt.get(), std::make_format_args(args...));
ofs << logMsg << "\n";