G_signal_handler_block vs GtkGesture

In old GTK3 applications we sometimes used g_signal_handler_block() to temporary block user input for Widgets, e.g. to block temporary mouse clicks in a drawing area. This worked for the old GdkEvents.

Currently I can not find out how we would do it for GtkGestures. For example, in https://gitlab.gnome.org/GNOME/gtk/-/blob/main/examples/drawing.c how would we temporary block button click user input?

g_signal_handler_block() didn’t do anything to events: it blocks a signal emission.

Since GtkGestures and event controllers emit signals, you can do precisely the same thing; the object is the only thing that changes from the widget to the event controller.

Unless, of course, you’re trying to block a signal on an existing widget that you don’t control/did not write; in that case, blocking signal emission was already a bad idea with GTK3. The typical solution is to have a boolean flag somewhere that you check in a signal handler. Of course, that still assumes you’re blocking a signal handler you’re adding yourself with g_signal_connect().

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.