package org.westmalle.wayland.core;


import javax.annotation.Nonnull;
import javax.inject.Inject;

public class PointerDeviceFactory {

    @Nonnull
    private final PrivatePointerDeviceFactory privatePointerDeviceFactory;
    @Nonnull
    private final RenderPlatform              renderPlatform;
    @Nonnull
    private final FiniteRegionFactory         finiteRegionFactory;

    @Inject
    PointerDeviceFactory(@Nonnull final PrivatePointerDeviceFactory privatePointerDeviceFactory,
                         @Nonnull final RenderPlatform renderPlatform,
                         @Nonnull final FiniteRegionFactory finiteRegionFactory) {
        this.privatePointerDeviceFactory = privatePointerDeviceFactory;
        this.renderPlatform = renderPlatform;
        this.finiteRegionFactory = finiteRegionFactory;
    }

    PointerDevice create() {
        final FiniteRegion outputsRegion = this.finiteRegionFactory.create();
        this.renderPlatform.getRenderOutputs()
                           .forEach(renderOutput ->
                                            outputsRegion.add(renderOutput.getWlOutput()
                                                                          .getOutput()
                                                                          .getRegion()));
        //listen for add/removal of outputs
        this.renderPlatform.getRenderOutputNewSignal()
                           .connect(event ->
                                            outputsRegion.add(event.getRenderOutput()
                                                                   .getWlOutput()
                                                                   .getOutput()
                                                                   .getRegion()));
        this.renderPlatform.getRenderOutputDestroyedSignal()
                           .connect(event ->
                                            outputsRegion.remove(event.getRenderOutput()
                                                                      .getWlOutput()
                                                                      .getOutput()
                                                                      .getRegion()));

        return this.privatePointerDeviceFactory.create(outputsRegion);
    }
}

@@ -874,16 +874,17 @@
 eRegion 
+ 
 outputsR
@@ -926,16 +926,117 @@
 eate();%0A
+        final PointerDevice pointerDevice = this.privatePointerDeviceFactory.create(outputsRegion);%0A%0A
         
@@ -1384,32 +1384,33 @@
 .getRegion()));%0A
+%0A
         //listen
@@ -1407,23 +1407,78 @@
   //
-listen for add/
+FIXME we need to add these listeners in a (new) wlpointer factory, as 
 remo
@@ -1484,23 +1484,111 @@
 oval of 
+an 
 output
-s
+ requires warping%0A        //the pointer, which in turns requires wl pointer resources.
 %0A       
@@ -2480,62 +2480,21 @@
 urn 
-this.privatePointerDeviceFactory.create(outputsRegion)
+pointerDevice
 ;%0A  

add FIXME for output removal