hyprwm / Hyprland

Hyprland is an independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
https://hyprland.org
BSD 3-Clause "New" or "Revised" License
18.59k stars 773 forks source link

IPC: improve activelayout event #6298

Open cnt0 opened 1 month ago

cnt0 commented 1 month ago

Description

Hello. Hyprland IPC has the following event emitted on the layout change

activelayout>>KEYBOARDNAME,LAYOUTNAME

KEYBOARDNAME and LAYOUTNAME are separated by comma. The problem is that KEYBOARDNAME can contain commas as well. At least it does in my case, it starts with mistel-co.,ltd.-.

Such behavior complicates parsing, for example, shellevents can't correctly handle it right now.

I believe that instead of polluting IPC clients with workarounds we can fix the IPC itself. For example we can introduce the activelayoutv2>>LAYOUTNAME event, because who cares about keyboard names anyway. But I'd listen to suggestion first.

MahouShoujoMivutilde commented 1 month ago

~ 
❯ event_data='some,strange,name,layout' 

~ 
❯ echo "${event_data%,*}"                      
some,strange,name

~ 
❯ echo "${event_data#*,}" 
strange,name,layout

~ 
❯ echo "${event_data##*,}"
layout

But if we're talking about this - there are apparently layouts with commas too e.g.:

https://gist.github.com/MahouShoujoMivutilde/8a12c0d40e7b262f2c78ef6e01193542

because who cares about keyboard names anyway

I care*, because wtype, power button, my bluetooth headphones and possibly other unexpected things are "keyboards".

Here is wtype working:

activelayout>>cvirtualkeyboard,English (US)
activelayout>>cvirtualkeyboard,English (US)
activelayout>>cvirtualkeyboard,none
activelayout>>cvirtualkeyboard,error

* but it's obviously not mutually exclusive thing where we all have to settle to some ONE event to rule 'em all.

zjeffer commented 3 weeks ago

This is indeed a very annoying issue for IPC clients. I see the event is posted in InputManager.cpp:

https://github.com/hyprwm/Hyprland/blob/22138ac259b2f4253be29311f6b60fbd675074b4/src/managers/input/InputManager.cpp#L873-L874

and two other places in this file.

We could maybe replace the ',' in this line with something like a ;, but I feel this is not a very robust as some keyboard names or layout could contain a ; as well.

Maybe a better solution could be to escape the existing commas in the keyboard name and layout with a \? Does that make sense to do?