3
0
mirror of https://github.com/hyprwm/Hyprland.git synced 2026-02-04 13:15:38 +00:00

config: add automatic closing to submaps (#11760)

* Allow submaps to auto reset to parent.

* Really should be a stack instead.

If hyprlang would allow for { } i would be so happy.

* Fixed: Somewhat better way to do it..

Lets you define what submap you want to go to instead.

* squash! Fixed: Somewhat better way to do it..

* God i hate cf..

* Force clang-format on the whole thing..

* Removed {}.

* Added tests

Tests and reset fix.
This commit is contained in:
ItsOhen
2025-10-11 02:40:18 +02:00
committed by GitHub
parent 6a01c399a9
commit d599513d4a
8 changed files with 102 additions and 26 deletions

View File

@ -205,9 +205,9 @@ static SDispatchResult vkb(std::string in) {
}
static SDispatchResult scroll(std::string in) {
int by;
double by;
try {
by = std::stoi(in);
by = std::stod(in);
} catch (...) { return SDispatchResult{.success = false, .error = "invalid input"}; }
Debug::log(LOG, "tester: scrolling by {}", by);
@ -272,4 +272,4 @@ APICALL EXPORT void PLUGIN_EXIT() {
g_mouse.reset();
g_keyboard->destroy();
g_keyboard.reset();
}
}

View File

@ -1,4 +1,5 @@
#include <filesystem>
#include <linux/input-event-codes.h>
#include <thread>
#include "../../shared.hpp"
#include "../../hyprctlCompat.hpp"
@ -11,7 +12,19 @@ using namespace Hyprutils::Memory;
static int ret = 0;
static std::string flagFile = "/tmp/hyprtester-keybinds.txt";
static void clearFlag() {
// Because i don't feel like changing someone elses code.
enum eKeyboardModifierIndex : uint8_t {
MOD_SHIFT = 1,
MOD_CAPS,
MOD_CTRL,
MOD_ALT,
MOD_MOD2,
MOD_MOD3,
MOD_META,
MOD_MOD5
};
static void clearFlag() {
std::filesystem::remove(flagFile);
}
@ -394,6 +407,41 @@ static void testShortcutRepeatKeyRelease() {
Tests::killAllWindows();
}
static void testSubmap() {
const auto press = [](const uint32_t key, const uint32_t mod = 0) {
// +8 because udev -> XKB keycode.
getFromSocket("/dispatch plugin:test:keybind 1," + std::to_string(mod) + "," + std::to_string(key + 8));
getFromSocket("/dispatch plugin:test:keybind 0," + std::to_string(mod) + "," + std::to_string(key + 8));
};
NLog::log("{}Testing submaps", Colors::GREEN);
// submap 1 no resets
press(KEY_U, MOD_META);
EXPECT_CONTAINS(getFromSocket("/submap"), "submap1");
press(KEY_O);
Tests::waitUntilWindowsN(1);
EXPECT_CONTAINS(getFromSocket("/submap"), "submap1");
// submap 2 resets to submap 1
press(KEY_U);
EXPECT_CONTAINS(getFromSocket("/submap"), "submap2");
press(KEY_O);
Tests::waitUntilWindowsN(2);
EXPECT_CONTAINS(getFromSocket("/submap"), "submap1");
// submap 3 resets to default
press(KEY_I);
EXPECT_CONTAINS(getFromSocket("/submap"), "submap3");
press(KEY_O);
Tests::waitUntilWindowsN(3);
EXPECT_CONTAINS(getFromSocket("/submap"), "default");
// submap 1 reset via keybind
press(KEY_U, MOD_META);
EXPECT_CONTAINS(getFromSocket("/submap"), "submap1");
press(KEY_P);
EXPECT_CONTAINS(getFromSocket("/submap"), "default");
Tests::killAllWindows();
}
static bool test() {
NLog::log("{}Testing keybinds", Colors::GREEN);
@ -414,6 +462,8 @@ static bool test() {
testShortcutRepeat();
testShortcutRepeatKeyRelease();
testSubmap();
clearFlag();
return !ret;
}

View File

@ -297,6 +297,23 @@ bindl = , XF86AudioPause, exec, playerctl play-pause
bindl = , XF86AudioPlay, exec, playerctl play-pause
bindl = , XF86AudioPrev, exec, playerctl previous
bind = $mainMod, u, submap, submap1
submap = submap1
bind = , u, submap, submap2
bind = , i, submap, submap3
bind = , o, exec, $terminal
bind = , p, submap, reset
submap = submap2, submap1
bind = , o, exec, $terminal
submap = submap3, reset
bind = , o, exec, $terminal
submap = reset
##############################
### WINDOWS AND WORKSPACES ###
##############################