How come no g_signal_connect wrapper? #207
Closed
Comments
It's not wrapped because it's a macro, and not a function. That means it's not available in the gir files used by the generator, and would need to be added manually. In this case the macro calls g_signal_connect_data with null as the destroyNotify callback. |
Please add connection to custom signals to widget! Need for situation like this. Temporary workaround, maybe helpful for somebody import gtk.Widget;
import gdk.Event;
import gobject.ObjectG;
import gobject.Signals;
class CustomSignals
{
this() {}
void connect(Widget widget, string signal, bool delegate(Event, Widget) dlg)
{
auto wrapper = new Wrapper(widget, dlg);
Signals.connectData(widget, signal,
cast(GCallback)&callback,
cast(void*)wrapper,
cast(GClosureNotify)&destroyCallback,
cast(ConnectFlags)0
);
}
protected:
class Wrapper
{
Widget widget;
bool delegate(Event, Widget) dlg;
this(Widget widget, bool delegate(Event, Widget) dlg)
{
this.widget = widget;
this.dlg = dlg;
wrappers ~= this;
}
bool opCall(Event e) { return dlg(e, widget); }
void selfRemove()
{
import std.algorithm : filter;
import std.array : array;
wrappers = wrappers.filter!(a => this !is a).array;
}
}
Wrapper[] wrappers;
extern(C) static int callback(void* widgetStruct, GdkEvent* event, Wrapper wrapper)
{ return wrapper(ObjectG.getDObject!Event(event)); }
extern(C) static void destroyCallback(Wrapper wrapper, void* closure)
{ wrapper.selfRemove(); }
} Using: auto csig = new CustomSignals;
csig.connect(myWidget, "some-signal", (Event e, Widget w) { /+ do something +/ }); |
MikeWey
added a commit
that referenced
this issue
Aug 13, 2017
master now has a overload of gobject.Signals.Signals.connect that allows connecting D delegates, functions, or even structs/classes with an 'opCall' defined. So you could do this for the example above: Signals.connect(myWidget, "some-signal", (Event e, Widget w) { /+ do something +/ }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is a Signals.connectData but no Signals.connect, is there any reason for this?
The text was updated successfully, but these errors were encountered: