'Gtk4 GestureClick no released signal emitted

When I assign a Gtk.GestureClick to a Gtk.Scale there's no released signal emitted.

See code for example.

import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk

class Main():
    def on_activate(self, app):
        win = Gtk.ApplicationWindow(application=app)
        gesture = Gtk.GestureClick.new()
        gesture.connect("pressed", self.press)
        gesture.connect("released", self.release)
        scale = Gtk.Scale()
        win.set_child(scale)
        scale.add_controller(gesture)
        win.present()

    def press(self, *_):
        print("pressed")

    def release(self, *_):
        print("released")

app = Gtk.Application(application_id='com.example.GtkApplication')
runner = Main()
app.connect('activate', runner.on_activate)

app.run(None)


Solution 1:[1]

I actually took a look at the source code for the GTK "GestureClick" widget, and what I found in the code was that the "released" signal is only emitted at the end of the click event (gtk_gesture_click_end). That event is tied to the GTK Gesture widget's "end" signal. So, just as a test I revised the "self.release" function to utilize the widget's inherited "end" event as follows.

gesture.connect("end", self.release)

That then did print out the word "released" on the terminal immediately after printing "pressed", but it does so as a part of the click event and does not wait for the actual release of the mouse button.

You might try out my small code change just to see the effect. I am hesitant to call this a bug as I am still not too experienced with GTK gestures at this point. However, test this out. You possibly may need to just rely on the click event at this time.

Additional Findings.

To be brief, in reviewing other GTK4 click gesture examples, the "press" and "release" gestures both work with other widgets. Apparently, there is some peculiarity with the scale widget. I revised your sample code swapping in a label widget for the scale widget.

import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk

class Main():
    def on_activate(self, app):
        win = Gtk.ApplicationWindow(application=app)
        gesture = Gtk.GestureClick.new()
        gesture.connect("pressed", self.press)
        gesture.connect("released", self.release)
        label = Gtk.Label(label="This is a label widget")
        win.set_child(label)
        win.set_default_size(400, 200)
        label.add_controller(gesture)
        win.present()
        
    def press(self, *_):
        print("pressed")
    
    def release(self, *_):
        print("released")
    
app = Gtk.Application(application_id='com.example.GtkApplication')
runner = Main()
app.connect('activate', runner.on_activate)

app.run(None)

Following is a result of the terminal output for clicking and releasing the mouse button on the label widget.

Press and Release Label

FYI, just to confirm that this issue seems to be associated with the scale widget, I built a similar program in C testing out a scale widget versus other widgets. Again the scale widget would not emit a released signal. At least the scale widget peculiarity is consistent in different languages. So it looks like the bottom line is that scale widgets will not emit a released signal. I hope the extra information helps.

Regards.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1