mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 02:05:58 +01:00
binds: Add description to key binds (#6358)
--------- Co-authored-by: Yusuf Duran <firatyusuf.d@gmail.com>
This commit is contained in:
parent
21b9e31bf4
commit
e1b05f8eaf
3 changed files with 51 additions and 38 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include "helpers/varlist/VarList.hpp"
|
#include "helpers/varlist/VarList.hpp"
|
||||||
#include "../protocols/LayerShell.hpp"
|
#include "../protocols/LayerShell.hpp"
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -1957,15 +1958,16 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
|
||||||
// bind[fl]=SUPER,G,exec,dmenu_run <args>
|
// bind[fl]=SUPER,G,exec,dmenu_run <args>
|
||||||
|
|
||||||
// flags
|
// flags
|
||||||
bool locked = false;
|
bool locked = false;
|
||||||
bool release = false;
|
bool release = false;
|
||||||
bool repeat = false;
|
bool repeat = false;
|
||||||
bool mouse = false;
|
bool mouse = false;
|
||||||
bool nonConsuming = false;
|
bool nonConsuming = false;
|
||||||
bool transparent = false;
|
bool transparent = false;
|
||||||
bool ignoreMods = false;
|
bool ignoreMods = false;
|
||||||
bool multiKey = false;
|
bool multiKey = false;
|
||||||
const auto BINDARGS = command.substr(4);
|
bool hasDescription = false;
|
||||||
|
const auto BINDARGS = command.substr(4);
|
||||||
|
|
||||||
for (auto& arg : BINDARGS) {
|
for (auto& arg : BINDARGS) {
|
||||||
if (arg == 'l') {
|
if (arg == 'l') {
|
||||||
|
@ -1984,6 +1986,8 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
|
||||||
ignoreMods = true;
|
ignoreMods = true;
|
||||||
} else if (arg == 's') {
|
} else if (arg == 's') {
|
||||||
multiKey = true;
|
multiKey = true;
|
||||||
|
} else if (arg == 'd') {
|
||||||
|
hasDescription = true;
|
||||||
} else {
|
} else {
|
||||||
return "bind: invalid flag";
|
return "bind: invalid flag";
|
||||||
}
|
}
|
||||||
|
@ -1995,11 +1999,13 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
|
||||||
if (mouse && (repeat || release || locked))
|
if (mouse && (repeat || release || locked))
|
||||||
return "flag m is exclusive";
|
return "flag m is exclusive";
|
||||||
|
|
||||||
const auto ARGS = CVarList(value, 4);
|
const int numbArgs = hasDescription ? 5 : 4;
|
||||||
|
const auto ARGS = CVarList(value, numbArgs);
|
||||||
|
|
||||||
|
const int DESCR_OFFSET = hasDescription ? 1 : 0;
|
||||||
if ((ARGS.size() < 3 && !mouse) || (ARGS.size() < 3 && mouse))
|
if ((ARGS.size() < 3 && !mouse) || (ARGS.size() < 3 && mouse))
|
||||||
return "bind: too few args";
|
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";
|
return "bind: too many args";
|
||||||
|
|
||||||
std::set<xkb_keysym_t> KEYSYMS;
|
std::set<xkb_keysym_t> KEYSYMS;
|
||||||
|
@ -2018,12 +2024,11 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
|
||||||
|
|
||||||
const auto KEY = multiKey ? "" : ARGS[1];
|
const auto KEY = multiKey ? "" : ARGS[1];
|
||||||
|
|
||||||
auto HANDLER = ARGS[2];
|
const auto DESCRIPTION = hasDescription ? ARGS[2] : "";
|
||||||
|
|
||||||
const auto COMMAND = mouse ? HANDLER : ARGS[3];
|
auto HANDLER = ARGS[2 + DESCR_OFFSET];
|
||||||
|
|
||||||
if (mouse)
|
const auto COMMAND = mouse ? HANDLER : ARGS[3 + DESCR_OFFSET];
|
||||||
HANDLER = "mouse";
|
|
||||||
|
|
||||||
// to lower
|
// to lower
|
||||||
std::transform(HANDLER.begin(), HANDLER.end(), HANDLER.begin(), ::tolower);
|
std::transform(HANDLER.begin(), HANDLER.end(), HANDLER.begin(), ::tolower);
|
||||||
|
@ -2048,8 +2053,8 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
|
||||||
return "Invalid catchall, catchall keybinds are only allowed in submaps.";
|
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,
|
g_pKeybindManager->addKeybind(SKeybind{parsedKey.key, KEYSYMS, parsedKey.keycode, parsedKey.catchAll, MOD, MODS, HANDLER, COMMAND, locked, m_szCurrentSubmap, DESCRIPTION,
|
||||||
repeat, mouse, nonConsuming, transparent, ignoreMods, multiKey});
|
release, repeat, mouse, nonConsuming, transparent, ignoreMods, multiKey, hasDescription});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "HyprCtl.hpp"
|
#include "HyprCtl.hpp"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -28,6 +29,7 @@ using namespace Hyprutils::String;
|
||||||
#include "../devices/ITouch.hpp"
|
#include "../devices/ITouch.hpp"
|
||||||
#include "../devices/Tablet.hpp"
|
#include "../devices/Tablet.hpp"
|
||||||
#include "config/ConfigManager.hpp"
|
#include "config/ConfigManager.hpp"
|
||||||
|
#include "helpers/MiscFunctions.hpp"
|
||||||
|
|
||||||
static void trimTrailingComma(std::string& str) {
|
static void trimTrailingComma(std::string& str) {
|
||||||
if (!str.empty() && str.back() == ',')
|
if (!str.empty() && str.back() == ',')
|
||||||
|
@ -792,9 +794,11 @@ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) {
|
||||||
ret += "e";
|
ret += "e";
|
||||||
if (kb.nonConsuming)
|
if (kb.nonConsuming)
|
||||||
ret += "n";
|
ret += "n";
|
||||||
|
if (kb.hasDescription)
|
||||||
|
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,
|
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.keycode, kb.catchAll, kb.handler, kb.arg);
|
kb.key, kb.keycode, kb.catchAll, kb.description, kb.handler, kb.arg);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// json
|
// json
|
||||||
|
@ -808,17 +812,19 @@ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) {
|
||||||
"release": {},
|
"release": {},
|
||||||
"repeat": {},
|
"repeat": {},
|
||||||
"non_consuming": {},
|
"non_consuming": {},
|
||||||
|
"has_description": {},
|
||||||
"modmask": {},
|
"modmask": {},
|
||||||
"submap": "{}",
|
"submap": "{}",
|
||||||
"key": "{}",
|
"key": "{}",
|
||||||
"keycode": {},
|
"keycode": {},
|
||||||
"catch_all": {},
|
"catch_all": {},
|
||||||
|
"description": "{}",
|
||||||
"dispatcher": "{}",
|
"dispatcher": "{}",
|
||||||
"arg": "{}"
|
"arg": "{}"
|
||||||
}},)#",
|
}},)#",
|
||||||
kb.locked ? "true" : "false", kb.mouse ? "true" : "false", kb.release ? "true" : "false", kb.repeat ? "true" : "false", kb.nonConsuming ? "true" : "false",
|
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),
|
kb.hasDescription ? "true" : "false", kb.modmask, escapeJSONStrings(kb.submap), escapeJSONStrings(kb.key), kb.keycode, kb.catchAll ? "true" : "false",
|
||||||
escapeJSONStrings(kb.arg));
|
escapeJSONStrings(kb.description), escapeJSONStrings(kb.handler), escapeJSONStrings(kb.arg));
|
||||||
}
|
}
|
||||||
trimTrailingComma(ret);
|
trimTrailingComma(ret);
|
||||||
ret += "]";
|
ret += "]";
|
||||||
|
|
|
@ -14,23 +14,25 @@ class CPluginSystem;
|
||||||
class IKeyboard;
|
class IKeyboard;
|
||||||
|
|
||||||
struct SKeybind {
|
struct SKeybind {
|
||||||
std::string key = "";
|
std::string key = "";
|
||||||
std::set<xkb_keysym_t> sMkKeys = {};
|
std::set<xkb_keysym_t> sMkKeys = {};
|
||||||
uint32_t keycode = 0;
|
uint32_t keycode = 0;
|
||||||
bool catchAll = false;
|
bool catchAll = false;
|
||||||
uint32_t modmask = 0;
|
uint32_t modmask = 0;
|
||||||
std::set<xkb_keysym_t> sMkMods = {};
|
std::set<xkb_keysym_t> sMkMods = {};
|
||||||
std::string handler = "";
|
std::string handler = "";
|
||||||
std::string arg = "";
|
std::string arg = "";
|
||||||
bool locked = false;
|
bool locked = false;
|
||||||
std::string submap = "";
|
std::string submap = "";
|
||||||
bool release = false;
|
std::string description = "";
|
||||||
bool repeat = false;
|
bool release = false;
|
||||||
bool mouse = false;
|
bool repeat = false;
|
||||||
bool nonConsuming = false;
|
bool mouse = false;
|
||||||
bool transparent = false;
|
bool nonConsuming = false;
|
||||||
bool ignoreMods = false;
|
bool transparent = false;
|
||||||
bool multiKey = false;
|
bool ignoreMods = false;
|
||||||
|
bool multiKey = false;
|
||||||
|
bool hasDescription = false;
|
||||||
|
|
||||||
// DO NOT INITIALIZE
|
// DO NOT INITIALIZE
|
||||||
bool shadowed = false;
|
bool shadowed = false;
|
||||||
|
|
Loading…
Reference in a new issue