| 1 |
#include "tests.hpp" |
| 2 |
#include "../../shared.hpp" |
| 3 |
#include "../../hyprctlCompat.hpp" |
| 4 |
#include <cstdint> |
| 5 |
#include <string> |
| 6 |
#include <hyprutils/os/Process.hpp> |
| 7 |
#include <hyprutils/memory/WeakPtr.hpp> |
| 8 |
#include "../shared.hpp" |
| 9 |
|
| 10 |
using namespace Hyprutils::OS; |
| 11 |
using namespace Hyprutils::Memory; |
| 12 |
|
| 13 |
#define UP CUniquePointer |
| 14 |
#define SP CSharedPointer |
| 15 |
|
| 16 |
static std::string getCommandStdOut(std::string command) { |
| 17 |
CProcess process("bash", {"-c", command}); |
| 18 |
process.addEnv("HYPRLAND_INSTANCE_SIGNATURE", HIS); |
| 19 |
process.runSync(); |
| 20 |
|
| 21 |
const std::string& stdOut = process.stdOut(); |
| 22 |
|
| 23 |
// Remove trailing new line |
| 24 |
return stdOut.substr(0, stdOut.length() - 1); |
| 25 |
} |
| 26 |
|
| 27 |
static void setWindowProp(const std::string& selector, const std::string& prop, const std::string& value) { |
| 28 |
getFromSocket("/dispatch hl.dsp.window.set_prop({ window = '" + selector + "', prop = '" + prop + "', value = '" + value + "' })"); |
| 29 |
} |
| 30 |
|
| 31 |
TEST_CASE(hyprctlDevicesActiveLayoutIndex) { |
| 32 |
// configure layouts |
| 33 |
OK(getFromSocket("r/eval hl.config({ input = { kb_layout = \"us,pl,ua\" } })")); |
| 34 |
|
| 35 |
for (uint8_t i = 0; i < 3; i++) { |
| 36 |
// set layout |
| 37 |
getFromSocket("/switchxkblayout all " + std::to_string(i)); |
| 38 |
std::string devicesJson = getFromSocket("j/devices"); |
| 39 |
std::string expected = R"("active_layout_index": )" + std::to_string(i); |
| 40 |
// check layout index |
| 41 |
EXPECT_CONTAINS(devicesJson, expected); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
TEST_CASE(hyprctlGetprop) { |
| 46 |
if (!Tests::spawnKitty()) { |
| 47 |
FAIL_TEST("Could not spawn kitty"); |
| 48 |
} |
| 49 |
|
| 50 |
// animation |
| 51 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty animation"), "(unset)"); |
| 52 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty animation -j"), R"({"animation": ""})"); |
| 53 |
setWindowProp("class:kitty", "animation", "teststyle"); |
| 54 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty animation"), "teststyle"); |
| 55 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty animation -j"), R"({"animation": "teststyle"})"); |
| 56 |
|
| 57 |
// max_size |
| 58 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty max_size"), "inf inf"); |
| 59 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty max_size -j"), R"({"max_size": [null,null]})"); |
| 60 |
setWindowProp("class:kitty", "max_size", "200 150"); |
| 61 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty max_size"), "200 150"); |
| 62 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty max_size -j"), R"({"max_size": [200,150]})"); |
| 63 |
|
| 64 |
// min_size |
| 65 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty min_size"), "20 20"); |
| 66 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty min_size -j"), R"({"min_size": [20,20]})"); |
| 67 |
setWindowProp("class:kitty", "min_size", "100 50"); |
| 68 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty min_size"), "100 50"); |
| 69 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty min_size -j"), R"({"min_size": [100,50]})"); |
| 70 |
|
| 71 |
// expr-based min/max _size |
| 72 |
getFromSocket("/dispatch hl.dsp.window.float({ action = 'set', window = 'class:kitty' })"); // need to set floating for tests below |
| 73 |
setWindowProp("class:kitty", "max_size", "90+10 25*2"); // set max to the same as min above, forcing window to 100*50 |
| 74 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty max_size"), "100 50"); |
| 75 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty max_size -j"), R"({"max_size": [100,50]})"); |
| 76 |
setWindowProp("class:kitty", "min_size", "window_w*0.5 window_h-10"); |
| 77 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty min_size"), "50 40"); |
| 78 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty min_size -j"), R"({"min_size": [50,40]})"); |
| 79 |
getFromSocket("/dispatch hl.dsp.window.float({ action = 'unset', window = 'class:kitty' })"); // go back to tiled for consistency |
| 80 |
|
| 81 |
// opacity |
| 82 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity"), "1"); |
| 83 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity -j"), R"({"opacity": 1})"); |
| 84 |
setWindowProp("class:kitty", "opacity", "0.3"); |
| 85 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity"), "0.3"); |
| 86 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity -j"), R"({"opacity": 0.3})"); |
| 87 |
|
| 88 |
// opacity_inactive |
| 89 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_inactive"), "1"); |
| 90 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_inactive -j"), R"({"opacity_inactive": 1})"); |
| 91 |
setWindowProp("class:kitty", "opacity_inactive", "0.5"); |
| 92 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_inactive"), "0.5"); |
| 93 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_inactive -j"), R"({"opacity_inactive": 0.5})"); |
| 94 |
|
| 95 |
// opacity_fullscreen |
| 96 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_fullscreen"), "1"); |
| 97 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_fullscreen -j"), R"({"opacity_fullscreen": 1})"); |
| 98 |
setWindowProp("class:kitty", "opacity_fullscreen", "0.75"); |
| 99 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_fullscreen"), "0.75"); |
| 100 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_fullscreen -j"), R"({"opacity_fullscreen": 0.75})"); |
| 101 |
|
| 102 |
// opacity_override |
| 103 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_override"), "false"); |
| 104 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_override -j"), R"({"opacity_override": false})"); |
| 105 |
setWindowProp("class:kitty", "opacity_override", "true"); |
| 106 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_override"), "true"); |
| 107 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_override -j"), R"({"opacity_override": true})"); |
| 108 |
|
| 109 |
// opacity_inactive_override |
| 110 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_inactive_override"), "false"); |
| 111 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_inactive_override -j"), R"({"opacity_inactive_override": false})"); |
| 112 |
setWindowProp("class:kitty", "opacity_inactive_override", "true"); |
| 113 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_inactive_override"), "true"); |
| 114 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_inactive_override -j"), R"({"opacity_inactive_override": true})"); |
| 115 |
|
| 116 |
// opacity_fullscreen_override |
| 117 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_fullscreen_override"), "false"); |
| 118 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_fullscreen_override -j"), R"({"opacity_fullscreen_override": false})"); |
| 119 |
setWindowProp("class:kitty", "opacity_fullscreen_override", "true"); |
| 120 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_fullscreen_override"), "true"); |
| 121 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty opacity_fullscreen_override -j"), R"({"opacity_fullscreen_override": true})"); |
| 122 |
|
| 123 |
// active_border_color |
| 124 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty active_border_color"), "ee33ccff ee00ff99 45deg"); |
| 125 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty active_border_color -j"), R"({"active_border_color": "ee33ccff ee00ff99 45deg"})"); |
| 126 |
setWindowProp("class:kitty", "active_border_color", "rgb(abcdef)"); |
| 127 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty active_border_color"), "ffabcdef 0deg"); |
| 128 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty active_border_color -j"), R"({"active_border_color": "ffabcdef 0deg"})"); |
| 129 |
|
| 130 |
// bool window properties |
| 131 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty allows_input"), "false"); |
| 132 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty allows_input -j"), R"({"allows_input": false})"); |
| 133 |
setWindowProp("class:kitty", "allows_input", "true"); |
| 134 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty allows_input"), "true"); |
| 135 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty allows_input -j"), R"({"allows_input": true})"); |
| 136 |
|
| 137 |
// int window properties |
| 138 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty rounding"), "10"); |
| 139 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty rounding -j"), R"({"rounding": 10})"); |
| 140 |
setWindowProp("class:kitty", "rounding", "4"); |
| 141 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty rounding"), "4"); |
| 142 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty rounding -j"), R"({"rounding": 4})"); |
| 143 |
|
| 144 |
// float window properties |
| 145 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty rounding_power"), "2"); |
| 146 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty rounding_power -j"), R"({"rounding_power": 2})"); |
| 147 |
setWindowProp("class:kitty", "rounding_power", "1.25"); |
| 148 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty rounding_power"), "1.25"); |
| 149 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty rounding_power -j"), R"({"rounding_power": 1.25})"); |
| 150 |
|
| 151 |
// errors |
| 152 |
EXPECT(getCommandStdOut("hyprctl getprop"), "not enough args"); |
| 153 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty"), "not enough args"); |
| 154 |
EXPECT(getCommandStdOut("hyprctl getprop class:nonexistantclass animation"), "window not found"); |
| 155 |
EXPECT(getCommandStdOut("hyprctl getprop class:kitty nonexistantprop"), "prop not found"); |
| 156 |
} |
| 157 |
|
| 158 |
TEST_CASE(hyprctlSubmap) { |
| 159 |
EXPECT(getCommandStdOut("hyprctl submap"), "default\n"); |
| 160 |
EXPECT(getCommandStdOut("hyprctl submap -j | jq -r \".\""), "default"); |
| 161 |
} |
| 162 |
|
| 163 |
TEST_CASE(hyprctlJsonErrors) { |
| 164 |
CProcess jqProc("bash", {"-c", "hyprctl descriptions | jq"}); |
| 165 |
jqProc.addEnv("HYPRLAND_INSTANCE_SIGNATURE", HIS); |
| 166 |
jqProc.runSync(); |
| 167 |
EXPECT(jqProc.exitCode(), 0); |
| 168 |
} |
| 169 |
|
| 170 |
TEST_CASE(hyprctlBindsJson) { |
| 171 |
EXPECT(getFromSocket("/eval hl.bind('SUPER + F12', hl.dsp.exec_cmd('true'), { description = 'hyprctl binds JSON regression', allow_input_capture = false })"), "ok"); |
| 172 |
|
| 173 |
CProcess jqProc("bash", {"-c", R"(hyprctl -j binds | jq -e ' |
| 174 |
type == "array" and |
| 175 |
([.[] | select(.key == "F12")] | length == 1) and |
| 176 |
any(.[]; |
| 177 |
.key == "F12" and |
| 178 |
.has_description == true and |
| 179 |
(.description | type) == "string" and |
| 180 |
.description == "hyprctl binds JSON regression" and |
| 181 |
(.allow_input_capture | type) == "boolean" and |
| 182 |
.allow_input_capture == false |
| 183 |
) |
| 184 |
')"}); |
| 185 |
jqProc.addEnv("HYPRLAND_INSTANCE_SIGNATURE", HIS); |
| 186 |
jqProc.runSync(); |
| 187 |
EXPECT(jqProc.exitCode(), 0); |
| 188 |
|
| 189 |
EXPECT(getFromSocket("/eval hl.unbind('SUPER + F12')"), "ok"); |
| 190 |
} |
| 191 |
|
| 192 |
TEST_CASE(hyprctlREPL) { |
| 193 |
EXPECT(getCommandStdOut("hyprctl repl 'print(type(hl))'"), "table"); |
| 194 |
EXPECT(getCommandStdOut("hyprctl eval 'print(type(hl))'"), "ok"); |
| 195 |
} |