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
48 changed files with 671 additions and 655 deletions

View File

@@ -38,33 +38,33 @@ std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) {
continue;
result += getFormat(
R"#({
"id": %i,
"name": "%s",
"description": "%s",
"make": "%s",
"model": "%s",
"serial": "%s",
"width": %i,
"height": %i,
"refreshRate": %f,
"x": %i,
"y": %i,
"activeWorkspace": {
"id": %i,
"name": "%s"
},
"specialWorkspace": {
"id": %i,
"name": "%s"
},
"reserved": [%i, %i, %i, %i],
"scale": %.2f,
"transform": %i,
"focused": %s,
"dpmsStatus": %s,
"vrr": %s
},)#",
R"#({{
"id": {},
"name": "{}",
"description": "{}",
"make": "{}",
"model": "{}",
"serial": "{}",
"width": {},
"height": {},
"refreshRate": {:.5f},
"x": {},
"y": {},
"activeWorkspace": {{
"id": {},
"name": "{}"
}},
"specialWorkspace": {{
"id": {},
"name": "{}"
}},
"reserved": [{}, {}, {}, {}],
"scale": {:.2f},
"transform": {},
"focused": {},
"dpmsStatus": {},
"vrr": {}
}},)#",
m->ID, escapeJSONStrings(m->szName).c_str(), escapeJSONStrings(m->output->description ? m->output->description : "").c_str(),
(m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""), (m->output->serial ? m->output->serial : ""), (int)m->vecPixelSize.x,
(int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, m->activeWorkspace,
@@ -82,10 +82,10 @@ std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) {
if (!m->output)
continue;
result += getFormat("Monitor %s (ID %i):\n\t%ix%i@%f at %ix%i\n\tdescription: %s\n\tmake: %s\n\tmodel: %s\n\tserial: %s\n\tactive workspace: %i (%s)\n\tspecial "
"workspace: %i (%s)\n\treserved: %i "
"%i %i %i\n\tscale: %.2f\n\ttransform: "
"%i\n\tfocused: %s\n\tdpmsStatus: %i\n\tvrr: %i\n\n",
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.c_str(), 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.c_str(),
@@ -113,7 +113,7 @@ static std::string getGroupedData(CWindow* w, HyprCtl::eHyprCtlOutputFormat form
} while (curr != w);
const auto comma = isJson ? ", " : ",";
const auto fmt = isJson ? "\"0x%lx\"" : "%lx";
const auto fmt = isJson ? "\"0x{:x}\"" : "{:x}";
std::ostringstream result;
bool first = true;
@@ -123,7 +123,7 @@ static std::string getGroupedData(CWindow* w, HyprCtl::eHyprCtlOutputFormat form
else
result << comma;
result << getFormat(fmt, gw);
result << getFormat(fmt, (uintptr_t)gw);
}
return result.str();
@@ -132,57 +132,56 @@ 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(
R"#({
"address": "0x%lx",
"mapped": %s,
"hidden": %s,
"at": [%i, %i],
"size": [%i, %i],
"workspace": {
"id": %i,
"name": "%s"
},
"floating": %s,
"monitor": %i,
"class": "%s",
"title": "%s",
"initialClass": "%s",
"initialTitle": "%s",
"pid": %i,
"xwayland": %s,
"pinned": %s,
"fullscreen": %s,
"fullscreenMode": %i,
"fakeFullscreen": %s,
"grouped": [%s],
"swallowing": %s
},)#",
w, (w->m_bIsMapped ? "true" : "false"), (w->isHidden() ? "true" : "false"), (int)w->m_vRealPosition.goalv().x, (int)w->m_vRealPosition.goalv().y,
R"#({{
"address": "0x{:x}",
"mapped": {},
"hidden": {},
"at": [{}, {}],
"size": [{}, {}],
"workspace": {{
"id": {},
"name": "{}"
}},
"floating": {},
"monitor": {},
"class": "{}",
"title": "{}",
"initialClass": "{}",
"initialTitle": "{}",
"pid": {},
"xwayland": {},
"pinned": {},
"fullscreen": {},
"fullscreenMode": {},
"fakeFullscreen": {},
"grouped": [{}],
"swallowing": "0x{:x}"
}},)#",
(uintptr_t)w, (w->m_bIsMapped ? "true" : "false"), (w->isHidden() ? "true" : "false"), (int)w->m_vRealPosition.goalv().x, (int)w->m_vRealPosition.goalv().y,
(int)w->m_vRealSize.goalv().x, (int)w->m_vRealSize.goalv().y, w->m_iWorkspaceID,
escapeJSONStrings(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)))
.c_str(),
((int)w->m_bIsFloating == 1 ? "true" : "false"), w->m_iMonitorID, escapeJSONStrings(g_pXWaylandManager->getAppIDClass(w)).c_str(),
escapeJSONStrings(g_pXWaylandManager->getTitle(w)).c_str(), escapeJSONStrings(w->m_szInitialClass).c_str(), escapeJSONStrings(w->m_szInitialTitle).c_str(), w->getPID(),
std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID))),
((int)w->m_bIsFloating == 1 ? "true" : "false"), w->m_iMonitorID, escapeJSONStrings(g_pXWaylandManager->getAppIDClass(w)),
escapeJSONStrings(g_pXWaylandManager->getTitle(w)), escapeJSONStrings(w->m_szInitialClass), escapeJSONStrings(w->m_szInitialTitle), w->getPID(),
((int)w->m_bIsX11 == 1 ? "true" : "false"), (w->m_bPinned ? "true" : "false"), (w->m_bIsFullscreen ? "true" : "false"),
(w->m_bIsFullscreen ? (g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_efFullscreenMode : 0) : 0),
w->m_bFakeFullscreenState ? "true" : "false", getGroupedData(w, format).c_str(), (w->m_pSwallowed ? getFormat("\"0x%lx\"", w->m_pSwallowed).c_str() : "null"));
(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(
"Window %lx -> %s:\n\tmapped: %i\n\thidden: %i\n\tat: %i,%i\n\tsize: %i,%i\n\tworkspace: %i (%s)\n\tfloating: %i\n\tmonitor: %i\n\tclass: %s\n\ttitle: "
"%s\n\tinitialClass: %s\n\tinitialTitle: %s\n\tpid: "
"%i\n\txwayland: %i\n\tpinned: "
"%i\n\tfullscreen: %i\n\tfullscreenmode: %i\n\tfakefullscreen: %i\n\tgrouped: %s\n\tswallowing: %lx\n\n",
w, w->m_szTitle.c_str(), (int)w->m_bIsMapped, (int)w->isHidden(), (int)w->m_vRealPosition.goalv().x, (int)w->m_vRealPosition.goalv().y, (int)w->m_vRealSize.goalv().x,
(int)w->m_vRealSize.goalv().y, w->m_iWorkspaceID,
"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: "
"{}\n\tfullscreen: {}\n\tfullscreenmode: {}\n\tfakefullscreen: {}\n\tgrouped: {}\n\tswallowing: {:x}\n\n",
(uintptr_t)w, w->m_szTitle.c_str(), (int)w->m_bIsMapped, (int)w->isHidden(), (int)w->m_vRealPosition.goalv().x, (int)w->m_vRealPosition.goalv().y,
(int)w->m_vRealSize.goalv().x, (int)w->m_vRealSize.goalv().y, w->m_iWorkspaceID,
(w->m_iWorkspaceID == -1 ? "" :
g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName.c_str() :
std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID)).c_str()),
(int)w->m_bIsFloating, w->m_iMonitorID, g_pXWaylandManager->getAppIDClass(w).c_str(), g_pXWaylandManager->getTitle(w).c_str(), w->m_szInitialClass.c_str(),
w->m_szInitialTitle.c_str(), 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).c_str(), w->m_pSwallowed);
(int)w->m_bFakeFullscreenState, getGroupedData(w, format).c_str(), (uintptr_t)w->m_pSwallowed);
}
}
@@ -210,21 +209,21 @@ 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"#({
"id": %i,
"name": "%s",
"monitor": "%s",
"windows": %i,
"hasfullscreen": %s,
"lastwindow": "0x%lx",
"lastwindowtitle": "%s"
})#",
return getFormat(R"#({{
"id": {},
"name": "{}",
"monitor": "{}",
"windows": {},
"hasfullscreen": {},
"lastwindow": "0x{:x}",
"lastwindowtitle": "{}"
}})#",
w->m_iID, escapeJSONStrings(w->m_szName).c_str(), escapeJSONStrings(PMONITOR ? PMONITOR->szName : "?").c_str(),
g_pCompositor->getWindowsOnWorkspace(w->m_iID), ((int)w->m_bHasFullscreenWindow == 1 ? "true" : "false"), PLASTW,
g_pCompositor->getWindowsOnWorkspace(w->m_iID), ((int)w->m_bHasFullscreenWindow == 1 ? "true" : "false"), (uintptr_t)PLASTW,
PLASTW ? escapeJSONStrings(PLASTW->m_szTitle).c_str() : "");
} else {
return getFormat("workspace ID %i (%s) on monitor %s:\n\twindows: %i\n\thasfullscreen: %i\n\tlastwindow: 0x%lx\n\tlastwindowtitle: %s\n\n", w->m_iID, w->m_szName.c_str(),
PMONITOR ? PMONITOR->szName.c_str() : "?", g_pCompositor->getWindowsOnWorkspace(w->m_iID), (int)w->m_bHasFullscreenWindow, PLASTW,
return getFormat("workspace ID {} ({}) on monitor {}:\n\twindows: {}\n\thasfullscreen: {}\n\tlastwindow: 0x{:x}\n\tlastwindowtitle: {}\n\n", w->m_iID, w->m_szName.c_str(),
PMONITOR ? PMONITOR->szName.c_str() : "?", g_pCompositor->getWindowsOnWorkspace(w->m_iID), (int)w->m_bHasFullscreenWindow, (uintptr_t)PLASTW,
PLASTW ? PLASTW->m_szTitle.c_str() : "");
}
}
@@ -278,8 +277,8 @@ std::string layersRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& mon : g_pCompositor->m_vMonitors) {
result += getFormat(
R"#("%s": {
"levels": {
R"#("{}": {{
"levels": {{
)#",
escapeJSONStrings(mon->szName).c_str());
@@ -287,20 +286,20 @@ std::string layersRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& level : mon->m_aLayerSurfaceLayers) {
result += getFormat(
R"#(
"%i": [
"{}": [
)#",
layerLevel);
for (auto& layer : level) {
result += getFormat(
R"#( {
"address": "0x%lx",
"x": %i,
"y": %i,
"w": %i,
"h": %i,
"namespace": "%s"
},)#",
layer.get(), layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height, escapeJSONStrings(layer->szNamespace).c_str());
R"#( {{
"address": "0x{:x}",
"x": {},
"y": {},
"w": {},
"h": {},
"namespace": "{}"
}},)#",
(uintptr_t)layer.get(), layer->geometry.x, layer->geometry.y, layer->geometry.width, layer->geometry.height, escapeJSONStrings(layer->szNamespace).c_str());
}
trimTrailingComma(result);
@@ -324,14 +323,14 @@ std::string layersRequest(HyprCtl::eHyprCtlOutputFormat format) {
} else {
for (auto& mon : g_pCompositor->m_vMonitors) {
result += getFormat("Monitor %s:\n", mon->szName.c_str());
result += getFormat("Monitor {}:\n", mon->szName.c_str());
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 %i (%s):\n", layerLevel, levelNames[layerLevel].c_str());
result += getFormat("\tLayer level {} ({}):\n", layerLevel, levelNames[layerLevel].c_str());
for (auto& layer : level) {
result += getFormat("\t\tLayer %lx: xywh: %i %i %i %i, namespace: %s\n", layer.get(), layer->geometry.x, layer->geometry.y, layer->geometry.width,
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.c_str());
}
@@ -353,12 +352,12 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& m : g_pInputManager->m_lMice) {
result += getFormat(
R"#( {
"address": "0x%lx",
"name": "%s",
"defaultSpeed": %f
},)#",
&m, escapeJSONStrings(m.name).c_str(),
R"#( {{
"address": "0x{:x}",
"name": "{}",
"defaultSpeed": {:.5f}
}},)#",
(uintptr_t)&m, escapeJSONStrings(m.name).c_str(),
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);
}
@@ -369,18 +368,18 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& k : g_pInputManager->m_lKeyboards) {
const auto KM = g_pInputManager->getActiveLayoutForKeyboard(&k);
result += getFormat(
R"#( {
"address": "0x%lx",
"name": "%s",
"rules": "%s",
"model": "%s",
"layout": "%s",
"variant": "%s",
"options": "%s",
"active_keymap": "%s",
"main": %s
},)#",
&k, escapeJSONStrings(k.name).c_str(), escapeJSONStrings(k.currentRules.rules).c_str(), escapeJSONStrings(k.currentRules.model).c_str(),
R"#( {{
"address": "0x{:x}",
"name": "{}",
"rules": "{}",
"model": "{}",
"layout": "{}",
"variant": "{}",
"options": "{}",
"active_keymap": "{}",
"main": {}
}},)#",
(uintptr_t)&k, escapeJSONStrings(k.name).c_str(), escapeJSONStrings(k.currentRules.rules).c_str(), escapeJSONStrings(k.currentRules.model).c_str(),
escapeJSONStrings(k.currentRules.layout).c_str(), escapeJSONStrings(k.currentRules.variant).c_str(), escapeJSONStrings(k.currentRules.options).c_str(),
escapeJSONStrings(KM).c_str(), (k.active ? "true" : "false"));
}
@@ -392,34 +391,34 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& d : g_pInputManager->m_lTabletPads) {
result += getFormat(
R"#( {
"address": "0x%lx",
R"#( {{
"address": "0x{:x}",
"type": "tabletPad",
"belongsTo": {
"address": "0x%lx",
"name": "%s"
}
},)#",
&d, d.pTabletParent, escapeJSONStrings(d.pTabletParent ? d.pTabletParent->name : "").c_str());
"belongsTo": {{
"address": "0x{:x}",
"name": "{}"
}}
}},)#",
(uintptr_t)&d, (uintptr_t)d.pTabletParent, escapeJSONStrings(d.pTabletParent ? d.pTabletParent->name : "").c_str());
}
for (auto& d : g_pInputManager->m_lTablets) {
result += getFormat(
R"#( {
"address": "0x%lx",
"name": "%s"
},)#",
&d, escapeJSONStrings(d.name).c_str());
R"#( {{
"address": "0x{:x}",
"name": "{}"
}},)#",
(uintptr_t)&d, escapeJSONStrings(d.name).c_str());
}
for (auto& d : g_pInputManager->m_lTabletTools) {
result += getFormat(
R"#( {
"address": "0x%lx",
R"#( {{
"address": "0x{:x}",
"type": "tabletTool",
"belongsTo": "0x%lx"
},)#",
&d, d.wlrTabletTool ? d.wlrTabletTool->data : 0);
"belongsTo": "0x{:x}"
}},)#",
(uintptr_t)&d, d.wlrTabletTool ? d.wlrTabletTool->data : 0);
}
trimTrailingComma(result);
@@ -429,11 +428,11 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& d : g_pInputManager->m_lTouchDevices) {
result += getFormat(
R"#( {
"address": "0x%lx",
"name": "%s"
},)#",
&d, d.name.c_str());
R"#( {{
"address": "0x{:x}",
"name": "{}"
}},)#",
(uintptr_t)&d, d.name.c_str());
}
trimTrailingComma(result);
@@ -443,11 +442,11 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& d : g_pInputManager->m_lSwitches) {
result += getFormat(
R"#( {
"address": "0x%lx",
"name": "%s"
},)#",
&d, d.pWlrDevice ? d.pWlrDevice->name : "");
R"#( {{
"address": "0x{:x}",
"name": "{}"
}},)#",
(uintptr_t)&d, d.pWlrDevice ? d.pWlrDevice->name : "");
}
trimTrailingComma(result);
@@ -460,7 +459,7 @@ std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& m : g_pInputManager->m_lMice) {
result += getFormat(
"\tMouse at %lx:\n\t\t%s\n\t\t\tdefault speed: %f\n", &m, m.name.c_str(),
"\tMouse at {:x}:\n\t\t{}\n\t\t\tdefault speed: {:.5f}\n", (uintptr_t)&m, m.name.c_str(),
(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));
}
@@ -468,35 +467,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 %lx:\n\t\t%s\n\t\t\trules: r \"%s\", m \"%s\", l \"%s\", v \"%s\", o \"%s\"\n\t\t\tactive keymap: %s\n\t\t\tmain: %s\n", &k,
k.name.c_str(), k.currentRules.rules.c_str(), k.currentRules.model.c_str(), k.currentRules.layout.c_str(), k.currentRules.variant.c_str(),
k.currentRules.options.c_str(), KM.c_str(), (k.active ? "yes" : "no"));
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.c_str(), k.currentRules.rules.c_str(), k.currentRules.model.c_str(), k.currentRules.layout.c_str(),
k.currentRules.variant.c_str(), k.currentRules.options.c_str(), KM.c_str(), (k.active ? "yes" : "no"));
}
result += "\n\nTablets:\n";
for (auto& d : g_pInputManager->m_lTabletPads) {
result += getFormat("\tTablet Pad at %lx (belongs to %lx -> %s)\n", &d, d.pTabletParent, d.pTabletParent ? d.pTabletParent->name.c_str() : "");
result += getFormat("\tTablet Pad at {:x} (belongs to {:x} -> {})\n", (uintptr_t)&d, (uintptr_t)d.pTabletParent, d.pTabletParent ? d.pTabletParent->name.c_str() : "");
}
for (auto& d : g_pInputManager->m_lTablets) {
result += getFormat("\tTablet at %lx:\n\t\t%s\n", &d, d.name.c_str());
result += getFormat("\tTablet at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.name.c_str());
}
for (auto& d : g_pInputManager->m_lTabletTools) {
result += getFormat("\tTablet Tool at %lx (belongs to %lx)\n", &d, d.wlrTabletTool ? d.wlrTabletTool->data : 0);
result += getFormat("\tTablet Tool at {:x} (belongs to {:x})\n", (uintptr_t)&d, d.wlrTabletTool ? d.wlrTabletTool->data : 0);
}
result += "\n\nTouch:\n";
for (auto& d : g_pInputManager->m_lTouchDevices) {
result += getFormat("\tTouch Device at %lx:\n\t\t%s\n", &d, d.name.c_str());
result += getFormat("\tTouch Device at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.name.c_str());
}
result += "\n\nSwitches:\n";
for (auto& d : g_pInputManager->m_lSwitches) {
result += getFormat("\tSwitch Device at %lx:\n\t\t%s\n", &d, d.pWlrDevice ? d.pWlrDevice->name : "");
result += getFormat("\tSwitch Device at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.pWlrDevice ? d.pWlrDevice->name : "");
}
}
@@ -509,14 +508,14 @@ std::string animationsRequest(HyprCtl::eHyprCtlOutputFormat format) {
ret += "animations:\n";
for (auto& ac : g_pConfigManager->getAnimationConfig()) {
ret += getFormat("\n\tname: %s\n\t\toverriden: %i\n\t\tbezier: %s\n\t\tenabled: %i\n\t\tspeed: %.2f\n\t\tstyle: %s\n", ac.first.c_str(), (int)ac.second.overridden,
ret += getFormat("\n\tname: {}\n\t\toverriden: {}\n\t\tbezier: {}\n\t\tenabled: {}\n\t\tspeed: {:.2f}\n\t\tstyle: {}\n", ac.first.c_str(), (int)ac.second.overridden,
ac.second.internalBezier.c_str(), ac.second.internalEnabled, ac.second.internalSpeed, ac.second.internalStyle.c_str());
}
ret += "beziers:\n";
for (auto& bz : g_pAnimationManager->getAllBeziers()) {
ret += getFormat("\n\tname: %s\n", bz.first.c_str());
ret += getFormat("\n\tname: {}\n", bz.first.c_str());
}
} else {
// json
@@ -524,14 +523,14 @@ std::string animationsRequest(HyprCtl::eHyprCtlOutputFormat format) {
ret += "[[";
for (auto& ac : g_pConfigManager->getAnimationConfig()) {
ret += getFormat(R"#(
{
"name": "%s",
"overridden": %s,
"bezier": "%s",
"enabled": %s,
"speed": %.2f,
"style": "%s"
},)#",
{{
"name": "{}",
"overridden": {},
"bezier": "{}",
"enabled": {},
"speed": {:.2f},
"style": "{}"
}},)#",
ac.first.c_str(), ac.second.overridden ? "true" : "false", ac.second.internalBezier.c_str(), ac.second.internalEnabled ? "true" : "false",
ac.second.internalSpeed, ac.second.internalStyle.c_str());
}
@@ -542,9 +541,9 @@ std::string animationsRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& bz : g_pAnimationManager->getAllBeziers()) {
ret += getFormat(R"#(
{
"name": "%s"
},)#",
{{
"name": "{}"
}},)#",
bz.first.c_str());
}
@@ -561,15 +560,15 @@ 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("%s:%s -> %s\n", sh.appid.c_str(), sh.id.c_str(), sh.description.c_str());
ret += getFormat("{}:{} -> {}\n", sh.appid.c_str(), sh.id.c_str(), sh.description.c_str());
} else {
ret += "[";
for (auto& sh : SHORTCUTS) {
ret += getFormat(R"#(
{
"name": "%s",
"description": "%s"
},)#",
{{
"name": "{}",
"description": "{}"
}},)#",
escapeJSONStrings(sh.appid + ":" + sh.id).c_str(), escapeJSONStrings(sh.description).c_str());
}
trimTrailingComma(ret);
@@ -595,7 +594,7 @@ std::string bindsRequest(HyprCtl::eHyprCtlOutputFormat format) {
if (kb.nonConsuming)
ret += "n";
ret += getFormat("\n\tmodmask: %u\n\tsubmap: %s\n\tkey: %s\n\tkeycode: %d\n\tdispatcher: %s\n\targ: %s\n\n", kb.modmask, kb.submap.c_str(), kb.key.c_str(), kb.keycode,
ret += getFormat("\n\tmodmask: {}\n\tsubmap: {}\n\tkey: {}\n\tkeycode: {}\n\tdispatcher: {}\n\targ: {}\n\n", kb.modmask, kb.submap.c_str(), kb.key.c_str(), kb.keycode,
kb.handler.c_str(), kb.arg.c_str());
}
} else {
@@ -604,19 +603,19 @@ std::string bindsRequest(HyprCtl::eHyprCtlOutputFormat format) {
for (auto& kb : g_pKeybindManager->m_lKeybinds) {
ret += getFormat(
R"#(
{
"locked": %s,
"mouse": %s,
"release": %s,
"repeat": %s,
"non_consuming": %s,
"modmask": %u,
"submap": "%s",
"key": "%s",
"keycode": %i,
"dispatcher": "%s",
"arg": "%s"
},)#",
{{
"locked": {},
"mouse": {},
"release": {},
"repeat": {},
"non_consuming": {},
"modmask": {},
"submap": "{}",
"key": "{}",
"keycode": {},
"dispatcher": "{}",
"arg": "{}"
}},)#",
kb.locked ? "true" : "false", kb.mouse ? "true" : "false", kb.release ? "true" : "false", kb.repeat ? "true" : "false", kb.nonConsuming ? "true" : "false",
kb.modmask, escapeJSONStrings(kb.submap).c_str(), escapeJSONStrings(kb.key).c_str(), kb.keycode, escapeJSONStrings(kb.handler).c_str(),
escapeJSONStrings(kb.arg).c_str());
@@ -653,12 +652,12 @@ std::string versionRequest(HyprCtl::eHyprCtlOutputFormat format) {
return result;
} else {
std::string result = getFormat(
R"#({
"branch": "%s",
"commit": "%s",
"dirty": %s,
"commit_message": "%s",
"tag": "%s",
R"#({{
"branch": "{}",
"commit": "{}",
"dirty": {},
"commit_message": "{}",
"tag": "{}",
"flags": [)#",
GIT_BRANCH, GIT_COMMIT_HASH, (strcmp(GIT_DIRTY, "dirty") == 0 ? "true" : "false"), escapeJSONStrings(commitMsg).c_str(), GIT_TAG);
@@ -701,7 +700,7 @@ std::string dispatchRequest(std::string in) {
DISPATCHER->second(DISPATCHARG);
Debug::log(LOG, "Hyprctl: dispatcher %s : %s", DISPATCHSTR.c_str(), DISPATCHARG.c_str());
Debug::log(LOG, "Hyprctl: dispatcher {} : {}", DISPATCHSTR.c_str(), DISPATCHARG.c_str());
return "ok";
}
@@ -746,7 +745,7 @@ std::string dispatchKeyword(std::string in) {
}
}
Debug::log(LOG, "Hyprctl: keyword %s : %s", COMMAND.c_str(), VALUE.c_str());
Debug::log(LOG, "Hyprctl: keyword {} : {}", COMMAND.c_str(), VALUE.c_str());
if (retval == "")
return "ok";
@@ -783,13 +782,13 @@ std::string cursorPosRequest(HyprCtl::eHyprCtlOutputFormat format) {
const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal().floor();
if (format == HyprCtl::FORMAT_NORMAL) {
return getFormat("%i, %i", (int)CURSORPOS.x, (int)CURSORPOS.y);
return getFormat("{}, {}", (int)CURSORPOS.x, (int)CURSORPOS.y);
} else {
return getFormat(R"#(
{
"x": %i,
"y": %i
}
{{
"x": {},
"y": {}
}}
)#",
(int)CURSORPOS.x, (int)CURSORPOS.y);
}
@@ -1043,20 +1042,20 @@ std::string dispatchGetOption(std::string request, HyprCtl::eHyprCtlOutputFormat
return "no such option";
if (format == HyprCtl::eHyprCtlOutputFormat::FORMAT_NORMAL)
return getFormat("option %s\n\tint: %lld\n\tfloat: %f\n\tstr: \"%s\"\n\tdata: %lx", curitem.c_str(), PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue.c_str(),
PCFGOPT->data.get());
return getFormat("option {}\n\tint: {}\n\tfloat: {:.5f}\n\tstr: \"{}\"\n\tdata: {:x}", curitem, PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue,
(uintptr_t)PCFGOPT->data.get());
else {
return getFormat(
R"#(
{
"option": "%s",
"int": %lld,
"float": %f,
"str": "%s",
"data": "0x%lx"
}
{{
"option": "{}",
"int": {}
"float": {:.5f},
"str": "{}",
"data": "0x{:x}"
}}
)#",
curitem.c_str(), PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue.c_str(), PCFGOPT->data.get());
curitem, PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue, (uintptr_t)PCFGOPT->data.get());
}
}
@@ -1172,8 +1171,8 @@ std::string dispatchPlugin(std::string request) {
std::string list = "";
for (auto& p : PLUGINS) {
list += getFormat("\nPlugin %s by %s:\n\tHandle: %lx\n\tVersion: %s\n\tDescription: %s\n", p->name.c_str(), p->author.c_str(), p->m_pHandle, p->version.c_str(),
p->description.c_str());
list += getFormat("\nPlugin {} by {}:\n\tHandle: {:x}\n\tVersion: {}\n\tDescription: {}\n", p->name.c_str(), p->author.c_str(), (uintptr_t)p->m_pHandle,
p->version.c_str(), p->description.c_str());
}
return list;
@@ -1338,7 +1337,7 @@ int hyprCtlFDTick(int fd, uint32_t mask, void* data) {
try {
reply = getReply(request);
} catch (std::exception& e) {
Debug::log(ERR, "Error in request: %s", e.what());
Debug::log(ERR, "Error in request: {}", e.what());
reply = "Err: " + std::string(e.what());
}
@@ -1376,7 +1375,7 @@ void HyprCtl::startHyprCtlSocket() {
// 10 max queued.
listen(iSocketFD, 10);
Debug::log(LOG, "Hypr socket started at %s", socketPath.c_str());
Debug::log(LOG, "Hypr socket started at {}", socketPath.c_str());
wl_event_loop_add_fd(g_pCompositor->m_sWLEventLoop, iSocketFD, WL_EVENT_READABLE, hyprCtlFDTick, nullptr);
}