ags icon indicating copy to clipboard operation
ags copied to clipboard

Listening to Hyprland's option changes

Open musjj opened this issue 1 year ago • 5 comments

Is there a way to listen to option changes in Hyprland? I wanted to react to gap changes so that I can adjust my bar's margins, but I couldn't figure out a good way to do it.

musjj avatar Feb 08 '24 17:02 musjj

There is no IPC event for config changes, You could monitor the config file, but there is no reliable way to do this. You might want to ask for this feature over at Hyprland

Aylur avatar Feb 08 '24 18:02 Aylur

there is this configreloaded 240212_11h07m01s_screenshot

EDIT: nvm it doesnt send the config changes but it should enough for your use case @musjj u just need to parse the entire hyprland config everytime it changes.

qxb3 avatar Feb 12 '24 03:02 qxb3

Unfortunately, the signal isn't triggered when you change your settings via hyprctl:

hyprctl keyword general:border_size

I wonder if listening to the changed signal would be enough here.

Another thing is that ags doesn't provide a way to retrieve an option's value in a structured way, like hyperctl -j:

$ hyprctl -j getoption general:border_size
{
    "option": "general:border_size",
    "int": 3,
    "float": -340282346638528859811704183484516925440.00000,
    "str": "",
    "data": "0x0",
    "set": true
}

Instead, you're getting the plain text format which you will then need to parse manually. Is there an equivalent to the -j flag in ags?

musjj avatar Feb 12 '24 08:02 musjj

the configreloaded signal is only emitted by Hyprland if the config file is reloaded. It won't be emitted when the config was modified using hyprctl. I think there is now way to detect this without polling using hyprctl getoption as of now. This would require a change in Hyprland.

Also note that this singal is not implemented in ags, you can however still connect to the event signal

Widget.Label(...).hook(Hyprland, (label, event, params) => {
  if(event === "configreloaded") {
    //config was reloaded
  }
}, "event")

Another thing is that ags doesn't provide a way to retrieve an option's value in a structured way, like hyperctl -j:

Hyprland.sendMessage() which is being replaced by Hyprland.message() and Hyprland.messageAsync() use the Hyprland socket directly. so to get the result as json you would have to do this:

const border_size = JSON.parse(Hyprland.message("j/keyword general:border_size"))

Another solution for your problem would be using ags to set hyprlands gap size with something like this:


function setGapSize(gap) {
  //update ags margins
  Hyprand.message(`keyword general:gap_in ${gap}`)
}

globalThis.setGapSize = setGapSize
ags -r "setGapSize(10)"

kotontrion avatar Feb 12 '24 08:02 kotontrion

Thanks for the tips! The globalThis method looks nice, I'll try it out!

musjj avatar Feb 13 '24 17:02 musjj