Intermittent Gtk::GestureClick signals on mac M1 Ventura

In the HelloWolrd example. I’ve added a GestureClick controller to the Gtk::Button to get ‘pressed’ and ‘released’ events. In addition I’ve added ‘begin’, ‘end’, ‘state_changed’ signal handers. The results are very erratic. On the first click I get the start and end events, but after that nothing for a while. I get one or two ‘pressed’ events, but never a released event. The standard ‘clicked’ events seem to work fine.

I’m linking with: libglibmm-2.68.1.dylib,
libglibmm_generate_extra_defs-2.68.1.dylib,
libgiomm-2.68.1.dylib,
libgtk-4.0.0.dylib,
libcairomm.1.16.1.dylib,
libsigc-3.0.0.dylib.

Any clues?

#include “hello.hpp”
#include

HelloWorld::HelloWorld()
: m_button(“Hello World”)
{
Gtk::Fixed fixed;

fixed.set_size_request(200, 100);
Glib::RefPtr<Gtk::GestureClick> button_click_events(Gtk::GestureClick::create());

// Sets the border width of the window.
m_button.set_has_frame(true);
m_button.set_margin(10);
m_button.set_size_request(100,30);

fixed.put(m_button, 50, 35);

// When the button receives the "clicked" signal, it will call the
// on_button_clicked() method defined below.
m_button.signal_clicked().connect(sigc::mem_fun(*this,&HelloWorld::on_button_clicked));
m_button.add_controller(button_click_events);
button_click_events->signal_pressed().connect(sigc::mem_fun(*this, &HelloWorld::hello_button_pressed));
button_click_events->signal_released().connect(sigc::mem_fun(*this, &HelloWorld::hello_button_released));


// This packs the button into the Window (a container).
set_child(fixed);

}

HelloWorld::~HelloWorld()
{
}

void HelloWorld::on_button_clicked()
{
std::cout << “Hello World” << std::endl;
}

void HelloWorld::hello_button_pressed(int, double, double) {
std::cout << “Hello World PRESSED” << std::endl;

}
void HelloWorld::hello_button_released(int, double, double) {
std::cout << “Hello World RELEASED” << std::endl;

}

I get similar results on an Ubuntu/Linux system. The pressed signal handler is
called once, the released handler never.

I think this is because gtk’s code in gtkbutton.c adds a GtkGestureClick
controller, running in GTK_PHASE_CAPTURE. The click_released_cb() released
handler contains gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED).
I think this stops event propagation. The button events are not propagated in the
Bubble phase, where your event controller is executed by default. Both pressed
and released handlers are called, if I add

button_click_events->set_propagation_phase(Gtk::PropagationPhase::CAPTURE);

When I updated the description in the Event Signals section in the gtkmm tutorial
from gtkmm3 to gtkmm4, I seem to have overlooked some important details.

Thank you Kjell! That did the trick.

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