Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 33 additions & 1 deletion hyprtester/plugin/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class CTestMouse : public IPointer {
};

SP<CTestMouse> g_mouse;
SP<CTestKeyboard> g_keyboard;

static SDispatchResult pressAlt(std::string in) {
g_pInputManager->m_lastMods = in == "1" ? HL_MODIFIER_ALT : 0;
Expand Down Expand Up @@ -220,6 +221,30 @@ static SDispatchResult scroll(std::string in) {
return {};
}

static SDispatchResult keybind(std::string in) {
CVarList data(in);
// 0 = release, 1 = press
bool press;
// See src/devices/IKeyboard.hpp : eKeyboardModifiers for modifier bitmasks
// 0 = none, eKeyboardModifiers is shifted to start at 1
uint32_t modifier;
// keycode
uint32_t key;
try {
press = std::stoul(data[0]) == 1;
modifier = std::stoul(data[1]);
key = std::stoul(data[2]) - 8; // xkb offset
} catch (...) { return {.success = false, .error = "invalid input"}; }

uint32_t modifierMask = 0;
if (modifier > 0)
modifierMask = 1 << (modifier - 1);
g_pInputManager->m_lastMods = modifierMask;
g_keyboard->sendKey(key, press);

return {};
}

APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
PHANDLE = handle;

Expand All @@ -229,15 +254,22 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:alt", ::pressAlt);
HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:gesture", ::simulateGesture);
HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:scroll", ::scroll);
HyprlandAPI::addDispatcherV2(PHANDLE, "plugin:test:keybind", ::keybind);

// init mouse
g_mouse = CTestMouse::create(false);
g_pInputManager->newMouse(g_mouse);

// init keyboard
g_keyboard = CTestKeyboard::create(false);
g_pInputManager->newKeyboard(g_keyboard);

return {"hyprtestplugin", "hyprtestplugin", "Vaxry", "1.0"};
}

APICALL EXPORT void PLUGIN_EXIT() {
g_mouse->destroy();
g_mouse.reset();
}
g_keyboard->destroy();
g_keyboard.reset();
}
14 changes: 2 additions & 12 deletions hyprtester/src/tests/main/exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ using namespace Hyprutils::Memory;
#define UP CUniquePointer
#define SP CSharedPointer

static std::string execAndGet(const std::string& cmd) {
CProcess proc("/bin/sh", {"-c", cmd});

if (!proc.runSync()) {
return "error";
}

return proc.stdOut();
}

static bool test() {
NLog::log("{}Testing process spawning", Colors::GREEN);

Expand All @@ -33,7 +23,7 @@ static bool test() {
OK(getFromSocket("/dispatch exec sleep 1"));

// Ensure that sleep is our child
const std::string sleepPidS = execAndGet("pgrep sleep");
const std::string sleepPidS = Tests::execAndGet("pgrep sleep");
pid_t sleepPid;
try {
sleepPid = std::stoull(sleepPidS);
Expand All @@ -42,7 +32,7 @@ static bool test() {
return false;
}

const std::string sleepParentComm = execAndGet("cat \"/proc/$(ps -o ppid:1= -p " + sleepPidS + ")/comm\"");
const std::string sleepParentComm = Tests::execAndGet("cat \"/proc/$(ps -o ppid:1= -p " + sleepPidS + ")/comm\"");
NLog::log("{}Expecting that sleep's parent is Hyprland", Colors::YELLOW);
EXPECT_CONTAINS(sleepParentComm, "Hyprland");

Expand Down
Loading
Loading