Hyprland
Hyprland copied to clipboard
`hyprctl -j` output is not conformant with regard to backslashes
Hyprland Version
System/Version info
Hyprland, built from branch main at commit 855a516596fa8a15aea7cf4b4068aba0293a9615 ().
Date: Mon Apr 22 05:48:18 2024
Tag: , commits: 4509
flags: (if any)
System Information:
System name: Linux
Node name: june-asahi
Release: 6.6.3-414.asahi.fc39.aarch64+16k
Version: #1 SMP PREEMPT_DYNAMIC Sun Mar 24 19:44:17 UTC 2024
GPU information:
os-release: NAME="Fedora Linux Asahi Remix"
VERSION="39 (Thirty Nine)"
ID=fedora-asahi-remix
ID_LIKE=fedora
VERSION_ID=39
VERSION_CODENAME=""
PLATFORM_ID="platform:f39"
PRETTY_NAME="Fedora Linux Asahi Remix 39 (Thirty Nine)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora-asahi-remix:39"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedora-asahi-remix.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f39/system-administrators-guide/"
SUPPORT_URL="https://discussion.fedoraproject.org/c/neighbors/asahi/asahi-help/94"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=39
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=39
plugins:
Bug or Regression?
Bug
Description
According to the JSON spec, all backslashes that are not escaping one of the specified escape characters must be themselves escaped, but output from hyprctl -j
does not do this.
How to reproduce
- Make a window whose title contains a backslash (e.g. open a kitty window, then run the command
fd '.*\.png'
) - Run
hyprctl clients -j | jq
and see that jq refuses to parse it due to the backslash within the first argument tofd
not being escaped correctly
This can be fixed in the short term by doing hyprctl clients -j | sed 's/\\[^"\\/bfnrtu]/\\&/g' | jq
to preserve (most; maybe all?) valid escapes while fixing unescaped backslashes.
Crash reports, logs, images, videos
No response
I have a similar issue with a monitor name when it is in KVM mode, and it causes some tools such as nwg-panel to crash :/
[jbal@mercury ~]$ hyprctl monitors -j
[{
"id": 0,
"name": "HDMI-A-1",
"description": "GIGA-BYTE TECHNOLOGY CO. LTD. M34WQ \\xa0FP0@:",
"make": "GIGA-BYTE TECHNOLOGY CO., LTD.",
"model": "M34WQ",
"serial": "\xa0FP0@:",
"width": 1720,
"height": 1440,
"refreshRate": 59.93600,
"x": 0,
"y": 0,
"activeWorkspace": {
"id": 2,
"name": "2"
},
"specialWorkspace": {
"id": 0,
"name": ""
},
"reserved": [0, 30, 0, 0],
"scale": 1.00,
"transform": 0,
"focused": true,
"dpmsStatus": true,
"vrr": false,
"activelyTearing": false,
"disabled": false,
"currentFormat": "XRGB8888",
"availableModes": ["[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"]
}]
[jbal@mercury ~]$ hyprctl monitors -j | jq .
jq: parse error: Invalid escape at line 7, column 25
[jbal@mercury ~]$ nwg-panel
Common settings {'restart-on-display': True, 'restart-delay': 500, 'processes-backgroud-only': True, 'processes-own-only': True}
Dependencies check: {'light': True, 'brightnessctl': True, 'ddcutil': False, 'pamixer': False, 'pactl': True, 'playerctl': True, 'wlr-randr': True, 'hyprctl': True, 'upower': True, 'swaync': True, 'python-requests': True}
Running on Hyprland
Traceback (most recent call last):
File "/usr/bin/nwg-panel", line 8, in <module>
sys.exit(main())
^^^^^^
File "/usr/lib/python3.11/site-packages/nwg_panel/main.py", line 570, in main
common.outputs = list_outputs(sway=sway, tree=tree)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/nwg_panel/tools.py", line 304, in list_outputs
monitors = json.loads(output)
^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Invalid \escape: line 7 column 16 (char 192)
[jbal@mercury ~]$
https://github.com/hyprwm/Hyprland/blob/01df3b73d815beaa892849ae7bd4eddc94642dc7/src/helpers/MiscFunctions.cpp#L173-L193
here's the code, I don't know much about json, feel free to tinker.
@itsjunetime Can you share the problematic output of hyprctl clients -j
?
closing per #5811
@itsjunetime Can you share the problematic output of hyprctl clients -j?
It's looking like this may actually be a weird shell variable issue, not a problem with hyprland. Specifically, if I run hyprctl clients -j
and store it in a variable (e.g. clients=$(hyprctl clients -j)
), then the backslash before a period isn't preserved for some reason, but only in zsh. If I do so in bash, it is preserved. To be more specific:
- Run
yes '\.'
in a terminal window, so that the title of the window becomes "yes '\.'" (kitty works for this) - Run
clients=$(hyprctl clients -j) && echo $clients | jq
in zsh. You'll see that jq complains about a parse error because the backslash in the window title isn't preserved. - Run the same command from step 2 in bash instead of zsh. You'll see that it works as expected.
This could be interesting to investigate, but the easy solution is to make my script run in bash instead of zsh, so I'm not really going to try to figure out what's going on.
@itsjunetime Can you share the problematic output of hyprctl clients -j?
It's looking like this may actually be a weird shell variable issue, not a problem with hyprland. Specifically, if I run
hyprctl clients -j
and store it in a variable (e.g.clients=$(hyprctl clients -j)
), then the backslash before a period isn't preserved for some reason, but only in zsh. If I do so in bash, it is preserved. To be more specific:1. Run `yes '\.'` in a terminal window, so that the title of the window becomes "yes '\.'" (kitty works for this) 2. Run `clients=$(hyprctl clients -j) && echo $clients | jq` in zsh. You'll see that jq complains about a parse error because the backslash in the window title isn't preserved. 3. Run the same command from step 2 in bash instead of zsh. You'll see that it works as expected.
This could be interesting to investigate, but the easy solution is to make my script run in bash instead of zsh, so I'm not really going to try to figure out what's going on.
I think I found a way, can you try this?
clients=$(hyprctl -j clients) && printf '%s\n' "$clients" | jq