var Buffer = require('buffer').Buffer;
var x11 = require('../../lib');

var xclient = x11.createClient();
var Exposure = x11.eventMask.Exposure;
var PointerMotion = x11.eventMask.PointerMotion;

var bitmap = new Buffer(128*128*4); // 16384 bits, 2048 bytes bitmap
for (var i=0; i < bitmap.length; ++i)
{
    var byteNum = i%4;
    if (byteNum == 0)
        bitmap[i] = parseInt((i/512)%256);
    if (byteNum == 1)
        bitmap[i] = parseInt((i/2048)%256);
    if (byteNum == 2)
        bitmap[i] = parseInt((i/256)%256);
    if (byteNum == 2)
        bitmap[i] = parseInt((i/1024)%256);
                
}

xclient.on('connect', function(err, display) {

    var X = display.client;   
    X.require('big-requests', function(BigReq) {
       
        BigReq.Enable(function(maxLen) { console.log( maxLen ); });

X.require('render', function(Render) {

    var root = display.screen[0].root;
    var white = display.screen[0].white_pixel;
    var black = display.screen[0].black_pixel;
    //console.log(display.screen[0]);

    var wid = X.AllocID();
    X.CreateWindow(
       wid, root, 
       10, 10, 400, 300, 
       1, 1, 0,
       { 
           backgroundPixel: white, eventMask: Exposure|PointerMotion  
       }
    );
    X.MapWindow(wid);
  
    var gc = X.AllocID();
    X.CreateGC(gc, wid, { foreground: black, background: white } );

    var pixmap1 = X.AllocID();
    X.CreatePixmap(pixmap1, wid, 32, 128, 128);
    var pic = X.AllocID(); 
    Render.CreatePicture(pic, pixmap1, Render.rgba32);
    

    var pic1 = X.AllocID();
    Render.CreatePicture(pic1, wid, Render.rgb24);

    X.on('event', function(ev) {
        if (ev.type == 12) // expose
        {
            X.PutImage(2, wid, gc, 128, 128, 0, 0, 0, 24, bitmap);
            X.PutImage(2, pixmap1, gc, 128, 128, 0, 0, 0, 32, bitmap);
            //Render.Composite(3, pic1, 0, pic, 0, 0, 0, 0, 30, 40, 128, 128);

        } 
    });
    X.on('error', function(e) {
        console.log(e);
    });

});

    });
});

@@ -69,42 +69,8 @@
 );%0A%0A
-var xclient = x11.createClient();%0A
 var 
@@ -552,50 +552,29 @@
 6);%0A
-                %0A%7D%0A%0Axclient.on('connect', 
+%0A%7D%0A%0Ax11.createClient(
 func
@@ -598,165 +598,60 @@
 ) %7B%0A
-%0A
     
-var X = display.client;   %0A    X.require('big-requests', function(BigReq) %7B%0A       %0A        BigReq.Enable(function(maxLen) %7B console.log( maxLen ); %7D);%0A
+if (err) throw err;%0A%0A    var X = display.client;
 %0AX.r
@@ -923,17 +923,16 @@
 d, root,
- 
 %0A       
@@ -948,17 +948,16 @@
 00, 300,
- 
 %0A       
@@ -973,17 +973,16 @@
        %7B
- 
 %0A       
@@ -1042,18 +1042,16 @@
 erMotion
-  
 %0A       
@@ -1081,18 +1081,16 @@
 w(wid);%0A
-  
 %0A    var
@@ -1282,17 +1282,16 @@
 locID();
- 
 %0A    Ren
@@ -1338,20 +1338,16 @@
 gba32);%0A
-    
 %0A%0A    va
@@ -1727,17 +1727,16 @@
        %7D
- 
 %0A    %7D);
@@ -1806,20 +1806,12 @@
 ;%0A%0A%7D);%0A%0A
-    %7D);%0A
 %7D);%0A

fix outdated code