I’m trying to prevent a button reacting to (mouse) events if certain condition is set, but without setting sensitive
to false for the button, to allow it to take the focus and look the same.
What I did is to add a GestureClick
or SingleGesture
to the parent window and set the state to CLAIMED
in the begin
event:
const gesture_click = new Gtk.GestureSingle();
gesture_click.propagation_phase = Gtk.PropagationPhase.CAPTURE;
window.add_controller(gesture_click);
gesture_click.connect("begin", () => {
if (condition) {
gesture_click.set_state(Gtk.EventSequenceState.CLAIMED);
}
});
The result is that the button doesn’t fire the clicked
event when the condition is set, but the button still behaves visually like normal. Is there a way to prevent it?