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

Add description to key binds #6358

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
42 changes: 25 additions & 17 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "helpers/VarList.hpp"
#include "../protocols/LayerShell.hpp"

#include <cstddef>
#include <cstdint>
#include <string.h>
#include <string>
Expand Down Expand Up @@ -1953,15 +1954,16 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
// bind[fl]=SUPER,G,exec,dmenu_run <args>

// flags
bool locked = false;
bool release = false;
bool repeat = false;
bool mouse = false;
bool nonConsuming = false;
bool transparent = false;
bool ignoreMods = false;
bool multiKey = false;
const auto BINDARGS = command.substr(4);
bool locked = false;
bool release = false;
bool repeat = false;
bool mouse = false;
bool nonConsuming = false;
bool transparent = false;
bool ignoreMods = false;
bool multiKey = false;
bool has_description = false;
Moerliy marked this conversation as resolved.
Show resolved Hide resolved
const auto BINDARGS = command.substr(4);

for (auto& arg : BINDARGS) {
if (arg == 'l') {
Expand All @@ -1980,6 +1982,8 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
ignoreMods = true;
} else if (arg == 's') {
multiKey = true;
} else if (arg == 'd') {
has_description = true;
} else {
return "bind: invalid flag";
}
Expand All @@ -1991,11 +1995,13 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
if (mouse && (repeat || release || locked))
return "flag m is exclusive";

const auto ARGS = CVarList(value, 4);
const int numbArgs = has_description ? 5 : 4;
const auto ARGS = CVarList(value, numbArgs);

const int DESCR_OFFSET = has_description ? 1 : 0;
if ((ARGS.size() < 3 && !mouse) || (ARGS.size() < 3 && mouse))
return "bind: too few args";
else if ((ARGS.size() > 4 && !mouse) || (ARGS.size() > 3 && mouse))
else if ((ARGS.size() > (size_t)4 + DESCR_OFFSET && !mouse) || (ARGS.size() > (size_t)3 + DESCR_OFFSET && mouse))
return "bind: too many args";

std::set<xkb_keysym_t> KEYSYMS;
Expand All @@ -2014,12 +2020,14 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command

const auto KEY = multiKey ? "" : ARGS[1];

auto HANDLER = ARGS[2];
const auto DESCRIPTION = has_description ? ARGS[2] : "";

const auto COMMAND = mouse ? HANDLER : ARGS[3];
auto HANDLER = ARGS[2 + DESCR_OFFSET];

if (mouse)
HANDLER = "mouse";
const auto COMMAND = mouse ? HANDLER : ARGS[3 + DESCR_OFFSET];

// const auto HAS_DESCRIPTION = mouse ? ARGS.size() == 4 : ARGS.size() == 5;
Moerliy marked this conversation as resolved.
Show resolved Hide resolved
//

// to lower
std::transform(HANDLER.begin(), HANDLER.end(), HANDLER.begin(), ::tolower);
Expand All @@ -2044,8 +2052,8 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
return "Invalid catchall, catchall keybinds are only allowed in submaps.";
}

g_pKeybindManager->addKeybind(SKeybind{parsedKey.key, KEYSYMS, parsedKey.keycode, parsedKey.catchAll, MOD, MODS, HANDLER, COMMAND, locked, m_szCurrentSubmap, release,
repeat, mouse, nonConsuming, transparent, ignoreMods, multiKey});
g_pKeybindManager->addKeybind(SKeybind{parsedKey.key, KEYSYMS, parsedKey.keycode, parsedKey.catchAll, MOD, MODS, HANDLER, COMMAND, locked, m_szCurrentSubmap, DESCRIPTION,
release, repeat, mouse, nonConsuming, transparent, ignoreMods, multiKey, has_description});
}

return {};
Expand Down
15 changes: 11 additions & 4 deletions src/debug/HyprCtl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "HyprCtl.hpp"

#include <format>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -25,6 +26,7 @@
#include "../devices/ITouch.hpp"
#include "../devices/Tablet.hpp"
#include "config/ConfigManager.hpp"
#include "helpers/MiscFunctions.hpp"

static void trimTrailingComma(std::string& str) {
if (!str.empty() && str.back() == ',')
Expand Down Expand Up @@ -789,9 +791,12 @@ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) {
ret += "e";
if (kb.nonConsuming)
ret += "n";
if (kb.hasDescriptions) {
Moerliy marked this conversation as resolved.
Show resolved Hide resolved
ret += "d";
}

ret += std::format("\n\tmodmask: {}\n\tsubmap: {}\n\tkey: {}\n\tkeycode: {}\n\tcatchall: {}\n\tdispatcher: {}\n\targ: {}\n\n", kb.modmask, kb.submap, kb.key,
kb.keycode, kb.catchAll, kb.handler, kb.arg);
ret += std::format("\n\tmodmask: {}\n\tsubmap: {}\n\tkey: {}\n\tkeycode: {}\n\tcatchall: {}\n\tdescription: {}\n\tdispatcher: {}\n\targ: {}\n\n", kb.modmask, kb.submap,
kb.key, kb.keycode, kb.catchAll, kb.description, kb.handler, kb.arg);
}
} else {
// json
Expand All @@ -805,17 +810,19 @@ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) {
"release": {},
"repeat": {},
"non_consuming": {},
"has_description": {},
"modmask": {},
"submap": "{}",
"key": "{}",
"keycode": {},
"catch_all": {},
"description": "{}",
"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), escapeJSONStrings(kb.key), kb.keycode, kb.catchAll ? "true" : "false", escapeJSONStrings(kb.handler),
escapeJSONStrings(kb.arg));
kb.hasDescriptions ? "true" : "false", kb.modmask, escapeJSONStrings(kb.submap), escapeJSONStrings(kb.key), kb.keycode, kb.catchAll ? "true" : "false",
escapeJSONStrings(kb.description), escapeJSONStrings(kb.handler), escapeJSONStrings(kb.arg));
}
trimTrailingComma(ret);
ret += "]";
Expand Down
36 changes: 19 additions & 17 deletions src/managers/KeybindManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ class CPluginSystem;
class IKeyboard;

struct SKeybind {
std::string key = "";
std::set<xkb_keysym_t> sMkKeys = {};
uint32_t keycode = 0;
bool catchAll = false;
uint32_t modmask = 0;
std::set<xkb_keysym_t> sMkMods = {};
std::string handler = "";
std::string arg = "";
bool locked = false;
std::string submap = "";
bool release = false;
bool repeat = false;
bool mouse = false;
bool nonConsuming = false;
bool transparent = false;
bool ignoreMods = false;
bool multiKey = false;
std::string key = "";
std::set<xkb_keysym_t> sMkKeys = {};
uint32_t keycode = 0;
bool catchAll = false;
uint32_t modmask = 0;
std::set<xkb_keysym_t> sMkMods = {};
std::string handler = "";
std::string arg = "";
bool locked = false;
std::string submap = "";
std::string description = "";
bool release = false;
bool repeat = false;
bool mouse = false;
bool nonConsuming = false;
bool transparent = false;
bool ignoreMods = false;
bool multiKey = false;
bool hasDescriptions = false;
Moerliy marked this conversation as resolved.
Show resolved Hide resolved

// DO NOT INITIALIZE
bool shadowed = false;
Expand Down