Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all .c_str() calls when using std::vformat #3198

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CCompositor::CCompositor() {

Debug::init(m_szInstanceSignature);

Debug::log(LOG, "Instance Signature: {}", m_szInstanceSignature.c_str());
Debug::log(LOG, "Instance Signature: {}", m_szInstanceSignature);

Debug::log(LOG, "Hyprland PID: {}", m_iHyprlandPID);

Expand All @@ -69,7 +69,7 @@ CCompositor::CCompositor() {

setRandomSplash();

Debug::log(LOG, "\nCurrent splash: {}\n\n", m_szCurrentSplash.c_str());
Debug::log(LOG, "\nCurrent splash: {}\n\n", m_szCurrentSplash);
}

CCompositor::~CCompositor() {
Expand Down Expand Up @@ -441,10 +441,10 @@ void CCompositor::startCompositor() {
const auto RETVAL = wl_display_add_socket(m_sWLDisplay, CANDIDATESTR.c_str());
if (RETVAL >= 0) {
m_szWLDisplaySocket = CANDIDATESTR;
Debug::log(LOG, "wl_display_add_socket for {} succeeded with {}", CANDIDATESTR.c_str(), RETVAL);
Debug::log(LOG, "wl_display_add_socket for {} succeeded with {}", CANDIDATESTR, RETVAL);
break;
} else {
Debug::log(WARN, "wl_display_add_socket for {} returned {}: skipping candidate {}", CANDIDATESTR.c_str(), RETVAL, candidate);
Debug::log(WARN, "wl_display_add_socket for {} returned {}: skipping candidate {}", CANDIDATESTR, RETVAL, candidate);
}
}

Expand Down Expand Up @@ -474,7 +474,7 @@ void CCompositor::startCompositor() {
"dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP HYPRLAND_INSTANCE_SIGNATURE",
nullptr);

Debug::log(LOG, "Running on WAYLAND_DISPLAY: {}", m_szWLDisplaySocket.c_str());
Debug::log(LOG, "Running on WAYLAND_DISPLAY: {}", m_szWLDisplaySocket);

if (!wlr_backend_start(m_sWLRBackend)) {
Debug::log(CRIT, "Backend did not start!");
Expand Down Expand Up @@ -988,7 +988,7 @@ void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) {
wl_signal_emit_mutable(&m_sSeat.seat->keyboard_state.events.focus_change, &event);

if (pWindowOwner)
Debug::log(LOG, "Set keyboard focus to surface {:x}, with window name: {}", (uintptr_t)pSurface, pWindowOwner->m_szTitle.c_str());
Debug::log(LOG, "Set keyboard focus to surface {:x}, with window name: {}", (uintptr_t)pSurface, pWindowOwner->m_szTitle);
else
Debug::log(LOG, "Set keyboard focus to surface {:x}", (uintptr_t)pSurface);

Expand Down Expand Up @@ -2357,7 +2357,7 @@ void CCompositor::renameWorkspace(const int& id, const std::string& name) {
if (isWorkspaceSpecial(id))
return;

Debug::log(LOG, "renameWorkspace: Renaming workspace {} to '{}'", id, name.c_str());
Debug::log(LOG, "renameWorkspace: Renaming workspace {} to '{}'", id, name);
PWORKSPACE->m_szName = name;

g_pEventManager->postEvent({"renameworkspace", std::to_string(PWORKSPACE->m_iID) + "," + PWORKSPACE->m_szName});
Expand Down Expand Up @@ -2485,7 +2485,7 @@ void CCompositor::arrangeMonitors() {

if (m->activeMonitorRule.offset != Vector2D{-INT32_MAX, -INT32_MAX}) {
// explicit.
Debug::log(LOG, "arrangeMonitors: {} explicit [{:.2f}, {:.2f}]", m->szName.c_str(), m->activeMonitorRule.offset.x, m->activeMonitorRule.offset.y);
Debug::log(LOG, "arrangeMonitors: {} explicit [{:.2f}, {:.2f}]", m->szName, m->activeMonitorRule.offset.x, m->activeMonitorRule.offset.y);

m->moveTo(m->activeMonitorRule.offset);
arranged.push_back(m);
Expand All @@ -2508,7 +2508,7 @@ void CCompositor::arrangeMonitors() {
}

for (auto& m : toArrange) {
Debug::log(LOG, "arrangeMonitors: {} auto [{}, {:.2f}]", m->szName.c_str(), maxOffset, 0.f);
Debug::log(LOG, "arrangeMonitors: {} auto [{}, {:.2f}]", m->szName, maxOffset, 0.f);
m->moveTo({maxOffset, 0});
maxOffset += m->vecSize.x;
}
Expand All @@ -2517,7 +2517,7 @@ void CCompositor::arrangeMonitors() {
// and set xwayland positions aka auto for all
maxOffset = 0;
for (auto& m : m_vMonitors) {
Debug::log(LOG, "arrangeMonitors: {} xwayland [{}, {:.2f}]", m->szName.c_str(), maxOffset, 0.f);
Debug::log(LOG, "arrangeMonitors: {} xwayland [{}, {:.2f}]", m->szName, maxOffset, 0.f);
m->vecXWaylandPosition = {maxOffset, 0};
maxOffset += (*PXWLFORCESCALEZERO ? m->vecTransformedSize.x : m->vecSize.x);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,11 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
} else if (r.szRule.find("rounding") == 0) {
try {
m_sAdditionalConfigData.rounding = std::stoi(r.szRule.substr(r.szRule.find_first_of(' ') + 1));
} catch (std::exception& e) { Debug::log(ERR, "Rounding rule \"{}\" failed with: {}", r.szRule.c_str(), e.what()); }
} catch (std::exception& e) { Debug::log(ERR, "Rounding rule \"{}\" failed with: {}", r.szRule, e.what()); }
} else if (r.szRule.find("bordersize") == 0) {
try {
m_sAdditionalConfigData.borderSize = std::stoi(r.szRule.substr(r.szRule.find_first_of(' ') + 1));
} catch (std::exception& e) { Debug::log(ERR, "Bordersize rule \"{}\" failed with: {}", r.szRule.c_str(), e.what()); }
} catch (std::exception& e) { Debug::log(ERR, "Bordersize rule \"{}\" failed with: {}", r.szRule, e.what()); }
} else if (r.szRule.find("opacity") == 0) {
try {
CVarList vars(r.szRule, 0, ' ');
Expand Down Expand Up @@ -529,7 +529,7 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
opacityIDX++;
}
}
} catch (std::exception& e) { Debug::log(ERR, "Opacity rule \"{}\" failed with: {}", r.szRule.c_str(), e.what()); }
} catch (std::exception& e) { Debug::log(ERR, "Opacity rule \"{}\" failed with: {}", r.szRule, e.what()); }
} else if (r.szRule == "noanim") {
m_sAdditionalConfigData.forceNoAnims = true;
} else if (r.szRule.find("animation") == 0) {
Expand All @@ -546,7 +546,7 @@ void CWindow::applyDynamicRule(const SWindowRule& r) {
} else {
m_sSpecialRenderData.activeBorderColor = configStringToInt(colorPart);
}
} catch (std::exception& e) { Debug::log(ERR, "BorderColor rule \"{}\" failed with: {}", r.szRule.c_str(), e.what()); }
} catch (std::exception& e) { Debug::log(ERR, "BorderColor rule \"{}\" failed with: {}", r.szRule, e.what()); }
} else if (r.szRule == "dimaround") {
m_sAdditionalConfigData.dimAround = true;
} else if (r.szRule == "keepaspectratio") {
Expand Down
56 changes: 28 additions & 28 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
if (COMMAND.find("device:") != 0 /* devices parsed later */ && COMMAND.find("plugin:") != 0 /* plugins parsed later */) {
if (COMMAND[0] == '$') {
// register a dynamic var
Debug::log(LOG, "Registered dynamic var \"{}\" -> {}", COMMAND.c_str(), VALUE.c_str());
Debug::log(LOG, "Registered dynamic var \"{}\" -> {}", COMMAND, VALUE);
configDynamicVars.emplace_back(std::make_pair<>(COMMAND.substr(1), VALUE));

std::sort(configDynamicVars.begin(), configDynamicVars.end(), [&](const auto& a, const auto& b) { return a.first.length() > b.first.length(); });
Expand Down Expand Up @@ -401,21 +401,21 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
try {
CONFIGENTRY->intValue = configStringToInt(VALUE);
} catch (std::exception& e) {
Debug::log(WARN, "Error reading value of {}", COMMAND.c_str());
Debug::log(WARN, "Error reading value of {}", COMMAND);
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">. " + e.what();
}
} else if (CONFIGENTRY->floatValue != -__FLT_MAX__) {
try {
CONFIGENTRY->floatValue = stof(VALUE);
} catch (...) {
Debug::log(WARN, "Error reading value of {}", COMMAND.c_str());
Debug::log(WARN, "Error reading value of {}", COMMAND);
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
}
} else if (CONFIGENTRY->strValue != "") {
try {
CONFIGENTRY->strValue = VALUE;
} catch (...) {
Debug::log(WARN, "Error reading value of {}", COMMAND.c_str());
Debug::log(WARN, "Error reading value of {}", COMMAND);
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
}
} else if (CONFIGENTRY->vecValue != Vector2D(-__FLT_MAX__, -__FLT_MAX__)) {
Expand All @@ -428,11 +428,11 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
CONFIGENTRY->vecValue = Vector2D(std::stof(X), std::stof(Y));
}
} else {
Debug::log(WARN, "Error reading value of {}", COMMAND.c_str());
Debug::log(WARN, "Error reading value of {}", COMMAND);
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
}
} catch (...) {
Debug::log(WARN, "Error reading value of {}", COMMAND.c_str());
Debug::log(WARN, "Error reading value of {}", COMMAND);
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
}
} else if (CONFIGENTRY->data.get() != nullptr) {
Expand All @@ -451,29 +451,29 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
try {
data->m_fAngle = std::stoi(var.substr(0, var.find("deg"))) * (PI / 180.0); // radians
} catch (...) {
Debug::log(WARN, "Error reading value of {}", COMMAND.c_str());
Debug::log(WARN, "Error reading value of {}", COMMAND);
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">.";
}

break;
}

if (data->m_vColors.size() >= 10) {
Debug::log(WARN, "Error reading value of {}", COMMAND.c_str());
Debug::log(WARN, "Error reading value of {}", COMMAND);
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">. Max colors in a gradient is 10.";
break;
}

try {
data->m_vColors.push_back(CColor(configStringToInt(var)));
} catch (std::exception& e) {
Debug::log(WARN, "Error reading value of {}", COMMAND.c_str());
Debug::log(WARN, "Error reading value of {}", COMMAND);
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">. " + e.what();
}
}

if (data->m_vColors.size() == 0) {
Debug::log(WARN, "Error reading value of {}", COMMAND.c_str());
Debug::log(WARN, "Error reading value of {}", COMMAND);
parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">. No colors provided.";

data->m_vColors.push_back(0); // transparent
Expand All @@ -495,7 +495,7 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
struct stat fileStat;
int err = stat(PATH.c_str(), &fileStat);
if (err != 0) {
Debug::log(WARN, "Error at ticking config at {}, error {}: {}", PATH.c_str(), err, strerror(err));
Debug::log(WARN, "Error at ticking config at {}, error {}: {}", PATH, err, strerror(err));
return;
}

Expand Down Expand Up @@ -552,7 +552,7 @@ static bool parseModeLine(const std::string& modeline, drmModeModeInfo& mode) {
if (it != flagsmap.end())
mode.flags |= it->second;
else
Debug::log(ERR, "invalid flag {} in modeline", it->first.c_str());
Debug::log(ERR, "invalid flag {} in modeline", it->first);
}

snprintf(mode.name, sizeof(mode.name), "%dx%d@%d", mode.hdisplay, mode.vdisplay, mode.vrefresh / 1000);
Expand Down Expand Up @@ -923,7 +923,7 @@ void CConfigManager::handleWindowRule(const std::string& command, const std::str

// verify we support a rule
if (!windowRuleValid(RULE)) {
Debug::log(ERR, "Invalid rule found: {}", RULE.c_str());
Debug::log(ERR, "Invalid rule found: {}", RULE);
parseError = "Invalid rule found: " + RULE;
return;
}
Expand All @@ -948,7 +948,7 @@ void CConfigManager::handleLayerRule(const std::string& command, const std::stri
}

if (!layerRuleValid(RULE)) {
Debug::log(ERR, "Invalid rule found: {}", RULE.c_str());
Debug::log(ERR, "Invalid rule found: {}", RULE);
parseError = "Invalid rule found: " + RULE;
return;
}
Expand All @@ -966,7 +966,7 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s
const auto VALUE = value.substr(value.find_first_of(',') + 1);

if (!windowRuleValid(RULE) && RULE != "unset") {
Debug::log(ERR, "Invalid rulev2 found: {}", RULE.c_str());
Debug::log(ERR, "Invalid rulev2 found: {}", RULE);
parseError = "Invalid rulev2 found: " + RULE;
return;
}
Expand All @@ -987,7 +987,7 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s

if (TITLEPOS == std::string::npos && CLASSPOS == std::string::npos && X11POS == std::string::npos && FLOATPOS == std::string::npos && FULLSCREENPOS == std::string::npos &&
PINNEDPOS == std::string::npos && WORKSPACEPOS == std::string::npos) {
Debug::log(ERR, "Invalid rulev2 syntax: {}", VALUE.c_str());
Debug::log(ERR, "Invalid rulev2 syntax: {}", VALUE);
parseError = "Invalid rulev2 syntax: " + VALUE;
return;
}
Expand Down Expand Up @@ -1132,7 +1132,7 @@ void CConfigManager::handleWorkspaceRules(const std::string& command, const std:
auto wsIdent = removeBeginEndSpacesTabs(value.substr(FIRST_DELIM + 1, (WORKSPACE_DELIM - FIRST_DELIM - 1)));
id = getWorkspaceIDFromString(wsIdent, name);
if (id == INT_MAX) {
Debug::log(ERR, "Invalid workspace identifier found: {}", wsIdent.c_str());
Debug::log(ERR, "Invalid workspace identifier found: {}", wsIdent);
parseError = "Invalid workspace identifier found: " + wsIdent;
return;
}
Expand Down Expand Up @@ -1211,7 +1211,7 @@ void CConfigManager::handleSource(const std::string& command, const std::string&
struct stat fileStat;
int err = stat(value.c_str(), &fileStat);
if (err != 0) {
Debug::log(WARN, "Error at ticking config at {}, error {}: {}", value.c_str(), err, strerror(err));
Debug::log(WARN, "Error at ticking config at {}, error {}: {}", value, err, strerror(err));
return;
}

Expand Down Expand Up @@ -1271,7 +1271,7 @@ void CConfigManager::handleEnv(const std::string& command, const std::string& va
#endif
"dbus-update-activation-environment --systemd " +
ARGS[0];
handleRawExec("", CMD.c_str());
handleRawExec("", CMD);
}
}

Expand Down Expand Up @@ -1491,7 +1491,7 @@ void CConfigManager::loadConfigLoadVars() {
// paths
configPaths.clear();
std::string mainConfigPath = getMainConfigPath();
Debug::log(LOG, "Using config: {}", mainConfigPath.c_str());
Debug::log(LOG, "Using config: {}", mainConfigPath);
configPaths.push_back(mainConfigPath);
std::string configPath = mainConfigPath.substr(0, mainConfigPath.find_last_of('/'));
// find_last_of never returns npos since main_config at least has /hypr/
Expand Down Expand Up @@ -1549,7 +1549,7 @@ void CConfigManager::loadConfigLoadVars() {
parseLine(line);
} catch (...) {
Debug::log(ERR, "Error reading line from config. Line:");
Debug::log(NONE, "{}", line.c_str());
Debug::log(NONE, "{}", line);

parseError += "Config error at line " + std::to_string(linenum) + " (" + mainConfigPath + "): Line parsing error.";
}
Expand Down Expand Up @@ -1658,7 +1658,7 @@ void CConfigManager::tick() {
struct stat fileStat;
int err = stat(cf.c_str(), &fileStat);
if (err != 0) {
Debug::log(WARN, "Error at ticking config at {}, error {}: {}", cf.c_str(), err, strerror(err));
Debug::log(WARN, "Error at ticking config at {}, error {}: {}", cf, err, strerror(err));
continue;
}

Expand Down Expand Up @@ -1692,7 +1692,7 @@ SConfigValue CConfigManager::getConfigValueSafeDevice(const std::string& dev, co

if (it == deviceConfigs.end()) {
if (fallback.empty()) {
Debug::log(ERR, "getConfigValueSafeDevice: No device config for {} found???", dev.c_str());
Debug::log(ERR, "getConfigValueSafeDevice: No device config for {} found???", dev);
return SConfigValue();
}
return configValues[fallback];
Expand Down Expand Up @@ -1768,7 +1768,7 @@ SMonitorRule CConfigManager::getMonitorRuleFor(const std::string& name, const st
if (found)
return *found;

Debug::log(WARN, "No rule found for {}, trying to use the first.", name.c_str());
Debug::log(WARN, "No rule found for {}, trying to use the first.", name);

for (auto& r : m_dMonitorRules) {
if (r.name == "") {
Expand Down Expand Up @@ -1801,7 +1801,7 @@ std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow) {
std::string title = g_pXWaylandManager->getTitle(pWindow);
std::string appidclass = g_pXWaylandManager->getAppIDClass(pWindow);

Debug::log(LOG, "Searching for matching rules for {} (title: {})", appidclass.c_str(), title.c_str());
Debug::log(LOG, "Searching for matching rules for {} (title: {})", appidclass, title);

// since some rules will be applied later, we need to store some flags
bool hasFloating = pWindow->m_bIsFloating;
Expand All @@ -1824,7 +1824,7 @@ std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow) {
continue;
}
} catch (...) {
Debug::log(ERR, "Regex error at {}", rule.szValue.c_str());
Debug::log(ERR, "Regex error at {}", rule.szValue);
continue;
}
} else {
Expand Down Expand Up @@ -1884,13 +1884,13 @@ std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow) {
}
}
} catch (std::exception& e) {
Debug::log(ERR, "Regex error at {} ({})", rule.szValue.c_str(), e.what());
Debug::log(ERR, "Regex error at {} ({})", rule.szValue, e.what());
continue;
}
}

// applies. Read the rule and behave accordingly
Debug::log(LOG, "Window rule {} -> {} matched {:x} [{}]", rule.szRule.c_str(), rule.szValue.c_str(), (uintptr_t)pWindow, pWindow->m_szTitle.c_str());
Debug::log(LOG, "Window rule {} -> {} matched {:x} [{}]", rule.szRule, rule.szValue, (uintptr_t)pWindow, pWindow->m_szTitle);

returns.push_back(rule);

Expand Down
Loading