mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 00:25:57 +01:00
Added hyprctl keyword
This commit is contained in:
parent
b618fc1caa
commit
07080498fd
4 changed files with 68 additions and 27 deletions
|
@ -23,6 +23,7 @@ usage: hyprctl [command] [(opt)args]
|
||||||
activewindow
|
activewindow
|
||||||
layers
|
layers
|
||||||
dispatch
|
dispatch
|
||||||
|
keyword
|
||||||
)#";
|
)#";
|
||||||
|
|
||||||
void request(std::string arg) {
|
void request(std::string arg) {
|
||||||
|
@ -109,6 +110,17 @@ void dispatchRequest(int argc, char** argv) {
|
||||||
request(rq);
|
request(rq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void keywordRequest(int argc, char** argv) {
|
||||||
|
if (argc < 4) {
|
||||||
|
std::cout << "keyword requires 2 params";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string rq = "keyword " + std::string(argv[2]) + " " + std::string(argv[3]);
|
||||||
|
|
||||||
|
request(rq);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
int bflag = 0, sflag = 0, index, c;
|
int bflag = 0, sflag = 0, index, c;
|
||||||
|
|
||||||
|
@ -123,6 +135,7 @@ int main(int argc, char** argv) {
|
||||||
else if (!strcmp(argv[1], "activewindow")) request("activewindow");
|
else if (!strcmp(argv[1], "activewindow")) request("activewindow");
|
||||||
else if (!strcmp(argv[1], "layers")) request("layers");
|
else if (!strcmp(argv[1], "layers")) request("layers");
|
||||||
else if (!strcmp(argv[1], "dispatch")) dispatchRequest(argc, argv);
|
else if (!strcmp(argv[1], "dispatch")) dispatchRequest(argc, argv);
|
||||||
|
else if (!strcmp(argv[1], "keyword")) keywordRequest(argc, argv);
|
||||||
else {
|
else {
|
||||||
printf(USAGE.c_str());
|
printf(USAGE.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -253,6 +253,41 @@ void CConfigManager::handleDefaultWorkspace(const std::string& command, const st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std::string& VALUE, bool dynamic) {
|
||||||
|
if (dynamic)
|
||||||
|
parseError = "";
|
||||||
|
|
||||||
|
if (COMMAND == "exec") {
|
||||||
|
if (isFirstLaunch) {
|
||||||
|
firstExecRequests.push_back(VALUE);
|
||||||
|
} else {
|
||||||
|
handleRawExec(COMMAND, VALUE);
|
||||||
|
}
|
||||||
|
} else if (COMMAND == "exec-once") {
|
||||||
|
if (isFirstLaunch) {
|
||||||
|
firstExecRequests.push_back(VALUE);
|
||||||
|
}
|
||||||
|
} else if (COMMAND == "monitor") {
|
||||||
|
handleMonitor(COMMAND, VALUE);
|
||||||
|
} else if (COMMAND == "bind") {
|
||||||
|
handleBind(COMMAND, VALUE);
|
||||||
|
} else if (COMMAND == "workspace") {
|
||||||
|
handleDefaultWorkspace(COMMAND, VALUE);
|
||||||
|
} else if (COMMAND == "windowrule") {
|
||||||
|
handleWindowRule(COMMAND, VALUE);
|
||||||
|
} else {
|
||||||
|
configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dynamic) {
|
||||||
|
std::string retval = parseError;
|
||||||
|
parseError = "";
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseError;
|
||||||
|
}
|
||||||
|
|
||||||
void CConfigManager::parseLine(std::string& line) {
|
void CConfigManager::parseLine(std::string& line) {
|
||||||
// first check if its not a comment
|
// first check if its not a comment
|
||||||
const auto COMMENTSTART = line.find_first_of('#');
|
const auto COMMENTSTART = line.find_first_of('#');
|
||||||
|
@ -298,33 +333,7 @@ void CConfigManager::parseLine(std::string& line) {
|
||||||
const auto VALUE = removeBeginEndSpacesTabs(line.substr(EQUALSPLACE + 1));
|
const auto VALUE = removeBeginEndSpacesTabs(line.substr(EQUALSPLACE + 1));
|
||||||
//
|
//
|
||||||
|
|
||||||
if (COMMAND == "exec") {
|
parseKeyword(COMMAND, VALUE);
|
||||||
if (isFirstLaunch) {
|
|
||||||
firstExecRequests.push_back(VALUE);
|
|
||||||
} else {
|
|
||||||
handleRawExec(COMMAND, VALUE);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else if (COMMAND == "exec-once") {
|
|
||||||
if (isFirstLaunch) {
|
|
||||||
firstExecRequests.push_back(VALUE);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else if (COMMAND == "monitor") {
|
|
||||||
handleMonitor(COMMAND, VALUE);
|
|
||||||
return;
|
|
||||||
} else if (COMMAND == "bind") {
|
|
||||||
handleBind(COMMAND, VALUE);
|
|
||||||
return;
|
|
||||||
} else if (COMMAND == "workspace") {
|
|
||||||
handleDefaultWorkspace(COMMAND, VALUE);
|
|
||||||
return;
|
|
||||||
} else if (COMMAND == "windowrule") {
|
|
||||||
handleWindowRule(COMMAND, VALUE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConfigManager::loadConfigLoadVars() {
|
void CConfigManager::loadConfigLoadVars() {
|
||||||
|
|
|
@ -58,6 +58,8 @@ public:
|
||||||
void performMonitorReload();
|
void performMonitorReload();
|
||||||
bool m_bWantsMonitorReload = false;
|
bool m_bWantsMonitorReload = false;
|
||||||
|
|
||||||
|
std::string parseKeyword(const std::string&, const std::string&, bool dynamic = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, SConfigValue> configValues;
|
std::unordered_map<std::string, SConfigValue> configValues;
|
||||||
time_t lastModifyTime = 0; // for reloading the config if changed
|
time_t lastModifyTime = 0; // for reloading the config if changed
|
||||||
|
|
|
@ -88,6 +88,22 @@ std::string dispatchRequest(std::string in) {
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string dispatchKeyword(std::string in) {
|
||||||
|
// get rid of the keyword keyword
|
||||||
|
in = in.substr(in.find_first_of(' ') + 1);
|
||||||
|
|
||||||
|
const auto COMMAND = in.substr(0, in.find_first_of(' '));
|
||||||
|
|
||||||
|
const auto VALUE = in.substr(in.find_first_of(' ') + 1);
|
||||||
|
|
||||||
|
std::string retval = g_pConfigManager->parseKeyword(COMMAND, VALUE, true);
|
||||||
|
|
||||||
|
if (retval == "")
|
||||||
|
return "ok";
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
void HyprCtl::startHyprCtlSocket() {
|
void HyprCtl::startHyprCtlSocket() {
|
||||||
std::thread([&]() {
|
std::thread([&]() {
|
||||||
uint16_t connectPort = 9187;
|
uint16_t connectPort = 9187;
|
||||||
|
@ -149,6 +165,7 @@ void HyprCtl::startHyprCtlSocket() {
|
||||||
else if (request == "activewindow") reply = activeWindowRequest();
|
else if (request == "activewindow") reply = activeWindowRequest();
|
||||||
else if (request == "layers") reply = layersRequest();
|
else if (request == "layers") reply = layersRequest();
|
||||||
else if (request.find("dispatch") == 0) reply = dispatchRequest(request);
|
else if (request.find("dispatch") == 0) reply = dispatchRequest(request);
|
||||||
|
else if (request.find("keyword") == 0) reply = dispatchKeyword(request);
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
Debug::log(ERR, "Error in request: %s", e.what());
|
Debug::log(ERR, "Error in request: %s", e.what());
|
||||||
reply = "Err: " + std::string(e.what());
|
reply = "Err: " + std::string(e.what());
|
||||||
|
|
Loading…
Reference in a new issue