GtkGestureClick doesn't send release signal and stops after a click

Hi!

        let gesture_click = GestureClick::new();
        let pad = Arc::new(Pad {id: id, btn: btn, sample: sample, sample_player: sample_player});
        let cloned_pad = Arc::clone(&pad);
        gesture_click.connect_pressed(move |_gesture, _n_press, _x, _y| cloned_pad.on_click());
        gesture_click.connect_released(move |_gesture, _n_press, _x, _y| println!("I'm released"));
        gesture_click.connect_stopped(move |_a| println!("I'm gone."));
        pad.btn.add_controller(&gesture_click);

I have multiple buttons in my Rust (gtk4) program. I know that I can use the standard clicked signal of buttons but they respond when you click and release, I don’t want to wait for the release. So I used GtkGestureClick instead of the clicked signal. Basically, the first click works as it is supposed to, but after that, the stopped signal raises and I have no release signal and it doesn’t work anymore.

A short video of the problem:

(Btw I forgot to click the same button again. Simply nothing happens when you click it again since it sent the stopped signal)

use gtk::prelude::*;
use gtk::{Button, Application, ApplicationWindow, GestureClick};

fn main() {
    let app = Application::builder().application_id("org.reo.testingit").build();
    app.connect_activate(build_ui);
    app.run();
}

fn build_ui(app: &Application) {
    let b = Button::builder()
        .label("Press me")
        .build();

    let gesture_click = GestureClick::new();

    gesture_click.connect_pressed(move |_gesture, _n_press, _x, _y| println!("I'm clicked"));
    gesture_click.connect_released(move |_gesture, _n_press, _x, _y| println!("I'm released"));
    gesture_click.connect_stopped(move |_a| println!("I'm gone."));
    b.add_controller(&gesture_click);

    let window = ApplicationWindow::builder()
            .application(app)
            .title("testing")
            .child(&b)
            .build();


    window.present();
}

I just moved everything into a new file to make sure the problem was not in my UI file or specifically in my project. Output is still the same:

I'm clicked
I'm gone.

Can someone test this on their system too? And should I ask this in the rust community or here?

(Rust gtk4 version: 0.4.8)

Edit: Updated to gtk4 0.5.1 and nothing changed.

May it be related to GTK4: need button pressed and released signals ?
There the issue was, that gestures does not work well with widgets that have their own signals, e.g. gesture was working with a plain label, but not with a button.

Or maybe it is related with In GTK4 DND for a GtkButton stops working when button is clicked (#5265) · Issues · GNOME / gtk · GitLab ? That one is also funny, and seems to be hard for Mr. Clasen.

Well, I think I should learn some Rust myself.

1 Like

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