mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 15:25:58 +01:00
hyprctl: Add 'layouts' command (#3895)
* Add hyprctl 'layouts' command formatting * Add getAllLayoutNames(), move m_vLayouts back to private Formatting * clang-format
This commit is contained in:
parent
572fd554b8
commit
4729265284
4 changed files with 43 additions and 10 deletions
|
@ -52,6 +52,7 @@ commands:
|
||||||
notify
|
notify
|
||||||
globalshortcuts
|
globalshortcuts
|
||||||
instances
|
instances
|
||||||
|
layouts
|
||||||
|
|
||||||
flags:
|
flags:
|
||||||
-j -> output in JSON
|
-j -> output in JSON
|
||||||
|
@ -420,6 +421,8 @@ int main(int argc, char** argv) {
|
||||||
request(fullRequest, 2);
|
request(fullRequest, 2);
|
||||||
else if (fullRequest.contains("/hyprpaper"))
|
else if (fullRequest.contains("/hyprpaper"))
|
||||||
requestHyprpaper(fullRequest);
|
requestHyprpaper(fullRequest);
|
||||||
|
else if (fullRequest.contains("/layouts"))
|
||||||
|
request(fullRequest);
|
||||||
else if (fullRequest.contains("/--help"))
|
else if (fullRequest.contains("/--help"))
|
||||||
printf("%s", USAGE.c_str());
|
printf("%s", USAGE.c_str());
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -260,7 +260,7 @@ static std::string getWorkspaceRuleData(const SWorkspaceRule& r, HyprCtl::eHyprC
|
||||||
std::string result = std::format(R"#({{
|
std::string result = std::format(R"#({{
|
||||||
"workspaceString": "{}"{}{}{}{}{}{}{}{}
|
"workspaceString": "{}"{}{}{}{}{}{}{}{}
|
||||||
}})#",
|
}})#",
|
||||||
escapeJSONStrings(r.workspaceString), monitor, default_, persistent, gapsIn, gapsOut, borderSize, border, rounding, decorate, shadow);
|
escapeJSONStrings(r.workspaceString), monitor, default_, persistent, gapsIn, gapsOut, borderSize, border, rounding, decorate, shadow);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
|
@ -276,7 +276,7 @@ static std::string getWorkspaceRuleData(const SWorkspaceRule& r, HyprCtl::eHyprC
|
||||||
const std::string shadow = std::format("\tshadow: {}\n", (bool)(r.shadow) ? boolToString(r.shadow.value()) : "<unset>");
|
const std::string shadow = std::format("\tshadow: {}\n", (bool)(r.shadow) ? boolToString(r.shadow.value()) : "<unset>");
|
||||||
|
|
||||||
std::string result = std::format("Workspace rule {}:\n{}{}{}{}{}{}{}{}{}{}\n", escapeJSONStrings(r.workspaceString), monitor, default_, persistent, gapsIn, gapsOut,
|
std::string result = std::format("Workspace rule {}:\n{}{}{}{}{}{}{}{}{}{}\n", escapeJSONStrings(r.workspaceString), monitor, default_, persistent, gapsIn, gapsOut,
|
||||||
borderSize, border, rounding, decorate, shadow);
|
borderSize, border, rounding, decorate, shadow);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -423,6 +423,28 @@ std::string layersRequest(HyprCtl::eHyprCtlOutputFormat format) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string layoutsRequest(HyprCtl::eHyprCtlOutputFormat format) {
|
||||||
|
std::string result = "";
|
||||||
|
if (format == HyprCtl::FORMAT_JSON) {
|
||||||
|
result += "[";
|
||||||
|
|
||||||
|
for (auto& m : g_pLayoutManager->getAllLayoutNames()) {
|
||||||
|
result += std::format(
|
||||||
|
R"#(
|
||||||
|
"{}",)#",
|
||||||
|
m);
|
||||||
|
}
|
||||||
|
trimTrailingComma(result);
|
||||||
|
|
||||||
|
result += "\n]\n";
|
||||||
|
} else {
|
||||||
|
for (auto& m : g_pLayoutManager->getAllLayoutNames()) {
|
||||||
|
result += std::format("{}\n", m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
|
std::string devicesRequest(HyprCtl::eHyprCtlOutputFormat format) {
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
|
|
||||||
|
@ -1377,6 +1399,8 @@ std::string getReply(std::string request) {
|
||||||
return animationsRequest(format);
|
return animationsRequest(format);
|
||||||
else if (request == "rollinglog")
|
else if (request == "rollinglog")
|
||||||
return rollinglogRequest(format);
|
return rollinglogRequest(format);
|
||||||
|
else if (request == "layouts")
|
||||||
|
return layoutsRequest(format);
|
||||||
else if (request.starts_with("plugin"))
|
else if (request.starts_with("plugin"))
|
||||||
return dispatchPlugin(request);
|
return dispatchPlugin(request);
|
||||||
else if (request.starts_with("notify"))
|
else if (request.starts_with("notify"))
|
||||||
|
|
|
@ -51,3 +51,10 @@ bool CLayoutManager::removeLayout(IHyprLayout* layout) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> CLayoutManager::getAllLayoutNames() {
|
||||||
|
std::vector<std::string> results(m_vLayouts.size());
|
||||||
|
for (size_t i = 0; i < m_vLayouts.size(); ++i)
|
||||||
|
results[i] = m_vLayouts[i].first;
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
|
@ -7,16 +7,16 @@ class CLayoutManager {
|
||||||
public:
|
public:
|
||||||
CLayoutManager();
|
CLayoutManager();
|
||||||
|
|
||||||
IHyprLayout* getCurrentLayout();
|
IHyprLayout* getCurrentLayout();
|
||||||
|
|
||||||
void switchToLayout(std::string);
|
void switchToLayout(std::string);
|
||||||
|
|
||||||
bool addLayout(const std::string& name, IHyprLayout* layout);
|
bool addLayout(const std::string& name, IHyprLayout* layout);
|
||||||
bool removeLayout(IHyprLayout* layout);
|
bool removeLayout(IHyprLayout* layout);
|
||||||
|
std::vector<std::string> getAllLayoutNames();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum HYPRLAYOUTS
|
enum HYPRLAYOUTS {
|
||||||
{
|
|
||||||
LAYOUT_DWINDLE = 0,
|
LAYOUT_DWINDLE = 0,
|
||||||
LAYOUT_MASTER
|
LAYOUT_MASTER
|
||||||
};
|
};
|
||||||
|
@ -25,8 +25,7 @@ class CLayoutManager {
|
||||||
|
|
||||||
CHyprDwindleLayout m_cDwindleLayout;
|
CHyprDwindleLayout m_cDwindleLayout;
|
||||||
CHyprMasterLayout m_cMasterLayout;
|
CHyprMasterLayout m_cMasterLayout;
|
||||||
|
|
||||||
std::vector<std::pair<std::string, IHyprLayout*>> m_vLayouts;
|
std::vector<std::pair<std::string, IHyprLayout*>> m_vLayouts;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::unique_ptr<CLayoutManager> g_pLayoutManager;
|
inline std::unique_ptr<CLayoutManager> g_pLayoutManager;
|
||||||
|
|
Loading…
Reference in a new issue