Description
Accessing modifier status on astal gtk4 widgets :
On gtk3 I'm using this to check for the pressed modifiers when a click (or other key, for now I also use it with onScroll)
is pressed.
const control_mask = Gdk.ModifierType.CONTROL_MASK
const shift_mask = Gdk.ModifierType.SHIFT_MASK
function handleClick(event: Astal.ClickEvent) {
const mods = event.modifier
if ((mods & shift_mask) == shift_mask) {
speaker.set_mute(!speaker.mute)
return
}
switchAudioProfile(device)
}
<button cssName="AudioButton"
onClick={(self, event) => handleClick(event)}>
...
</button>
But using gtk4 onClicked
only passes the widget instance. AFAIK astalify handles adding the evenControllers for the widgets and they are not made available for accessing from the widget instance.
Either passing the event when the signal triggers or make the controllers accessible to be able to get the events.
While writing this issue I found out about onButtonReleased
that sends an event so it becomes:
function handleClick(event: Gdk.ButtonEvent) {
if ((event.get_button() === 1)) {
const mods = event.get_modifier_state()
if ((mods & shift_mask) == shift_mask) {
speaker.set_mute(!speaker.mute)
return
}
switchAudioProfile(device)
}
}
return <button cssName="AudioButton"
onButtonReleased={(self, event) => handleClick(event)}
>
...
</button>
This could work for me but onButtonReleased is not triggering on left mouse click which I assume is 1
It triggers for the middle, right and side buttons.
I'm not sure if it's a bug or onClicked
is meant to be used to handle left clicks, in that case it's a feature request to also send the event.