In the documentation, it has been discouraged to use addOnActivate() function and it also has been suggested that the users should use addOnNotify(). In the D forum 5 years ago, it has recommended that switch signals be handled as follows:

Switch sw = new Switch();
sw.addOnNotify(&notify);

void notify(ParamSpec param, ObjectG obj)
{
	if(param.getName() == "active")
	{
		//Do stuff
	}
}

I am using this Switches like this:

        auto sw = new Switch();
        sw.addOnNotify(delegate void(ParamSpec p, ObjectG _y) {
            if (p.getName() == "active") {
                static bool on;
                on = sw.getActive();

                //do stuf
                import std.stdio : writeln;

                writeln(on ? "On" : "Off");
            }
        });

I have two questions -

  1. Is it still the latest way to connect activate signals to switches?
  2. How is it different that the code below:
        auto sw = new Switch();
        sw.addOnNotify(delegate void(ParamSpec _x, ObjectG _y) {
            if (sw.getActive()) {
                // Do stuff
            }
        });