Button remains in "pressed" state when used with GtkDragSource
Steps to reproduce
- Have a GtkButton with a GtkDragSource event controller attached
- Drag from a button
- The button will remain in "pressed" state and will not return to normal
Below example code exhibits the issue:
"""
This app shows an issue when dragging content from a button:
the button remains "pressed".
Steps to reproduce:
1. start this little app
2. Drag from a button
3. The button will remain in "pressed" state and will not return to normal
"""
import gi
gi.require_version("Gdk", "4.0")
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, GLib, Gio, GObject, Gdk
def buttons():
box = Gtk.Box.new(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
for i in range(2):
button = Gtk.Button.new_with_label(f"Drag me {i}")
drag_source = Gtk.DragSource.new()
drag_source.connect("prepare", _button_drag_prepare)
button.add_controller(drag_source)
box.append(button)
return box
def _button_drag_prepare(source: Gtk.DragSource, x: int, y: int):
v = GObject.Value(GObject.TYPE_STRING)
v.set_string("dragging")
source.set_state(Gtk.EventSequenceState.CLAIMED)
return Gdk.ContentProvider.new_for_value(v)
def window():
w = Gtk.Window.new()
w.set_default_size(640, 480)
e = buttons()
w.set_child(e)
w.show()
return w
def main():
app = Gtk.Application.new("org.gaphor.ToolboxTest", 0)
def activate(app):
win = window()
app.add_window(win)
app.connect("activate", activate)
app.run()
if __name__ == "__main__":
main()
Current behavior
The button you drag from will remain in a "pressed" state. It will not return to normal state, even when you click on it.
Expected outcome
The button should return to normal state when the drag starts or ends. The button should work as before the drag action.
Version information
- Gtk version: 4.4.1
- OS and version: Fedora 35 /
WaylandX11
Additional information
I'm using PyGObject, therefore the example is in Python. If needed I can translate it to C.
Edited by Arjan Molenaar