├── README ├── jqtouch.js ├── keyMapper.js ├── node_modules └── x11 │ ├── LICENSE │ ├── README.md │ ├── examples │ ├── .render.js.swo │ ├── kbdheatmap │ │ ├── coordinates.json │ │ ├── kbdheatmap.js │ │ ├── keyboard.jpg │ │ ├── keysyms.json │ │ └── node-jpg.js │ ├── render.js │ └── tetris.js │ ├── lib │ └── x11 │ │ ├── auth.js │ │ ├── corereqs.js │ │ ├── eventmask.js │ │ ├── ext │ │ ├── big-requests.js │ │ ├── glx.js │ │ ├── render.js │ │ └── xtest.js │ │ ├── handshake.js │ │ ├── hexy.js │ │ ├── index.js │ │ ├── keysyms.js │ │ ├── stdatoms.js │ │ ├── unpackbuffer.js │ │ ├── unpackstream.js │ │ ├── xcore.js │ │ ├── xerrors.js │ │ ├── xproto2js.pl │ │ └── xutil.js │ ├── package.json │ ├── roadmap.txt │ └── test │ ├── alloccolor.js │ ├── atom_benchmark_buffered.js │ ├── atom_benchmark_parallel.js │ ├── atoms.js │ ├── bmp.js │ ├── c-tests │ ├── Makefile │ ├── Xlib_JPEG_Example-8.tgz │ ├── Xlib_JPEG_Example-8 │ │ ├── Makefile │ │ ├── Xlib_JPEG_Example │ │ ├── Xlib_JPEG_Example.c │ │ ├── feh_003912_000001_keyboard.png │ │ ├── i01500.jpg │ │ ├── keyboard.jpg │ │ ├── keyboard.png │ │ ├── pod10_small.jpg │ │ └── rgb.jpg │ ├── a.out │ ├── keyboard.json │ └── simplewin.c │ ├── changeprop.js │ ├── color.c │ ├── copyarea.js │ ├── creategc.js │ ├── createwindow.js │ ├── genstdatoms.js │ ├── getkeyboardmapping.js │ ├── getprop.js │ ├── jpeg │ ├── Attachments_sidorares@yandex.ru_2011-09-09_17-23-48.zip │ ├── example.html │ ├── jpg.js │ ├── keyboard.jpg │ ├── node-jpg.js │ └── srvr.js │ ├── keyboard.jpg │ ├── listext.js │ ├── map_unmap.js │ ├── node-jpg.js │ ├── nodejs-black.bmp │ ├── pixmap.js │ ├── polyfillrect.js │ ├── polyline.js │ ├── polypoint.js │ ├── polytext8.js │ ├── putimage.js │ ├── putimage1.js │ ├── query_ext.js │ ├── query_pointer.js │ ├── query_pointer_benchmark_parallel.js │ ├── query_pointer_benchmark_sync.js │ ├── render-simplest.pl │ ├── render.h │ ├── rendertest.js │ ├── sendevent.js │ ├── sketch.js │ ├── subwindows.js │ ├── test_ext_render.js │ ├── testwnd.js │ ├── warppointer.js │ ├── wndwrap.js │ ├── xlsatoms.js │ └── xtesttest.js ├── package.json ├── remote-client.js ├── remote-server.js ├── remote.html ├── simpleServer.js ├── tests └── spiketest │ ├── q │ └── test.mapJSKeyToX.js └── xEventManager.js /README: -------------------------------------------------------------------------------- 1 | node-remote is a simple web server/webpage pair that allows you to remotely control the disply on the server by browsing to a webpage on any client machine. The page picks up mouse movements and keyboard presses and transmits them to the server via socket.io. Read more at 2 | 3 | RUNNING THE SERVER 4 | Start the server with the command node remote-server.js. Note you have to run this command from within the display that you want to be controlling, not a remote session. 5 | 6 | Then just have your client browse to port 8000 on the server. Note the client needs to support websockets, so either chrome or firefox is your best bet. 7 | -------------------------------------------------------------------------------- /keyMapper.js: -------------------------------------------------------------------------------- 1 | var exceptionKeys = { 2 | '190' : '46',//PERIOD CHROME 3 | '16' : '65506', //SHIFT CHROME 4 | '17' : '65507', //CTRL CHROME 5 | '18' : '65513', //ALT CHROME 6 | '34' : '65307', //ESC CHROME 7 | '191' : '47', //BACKSLASH CHROME 8 | '20' : '65509', //CAPS CHROME 9 | '9' : '65289', //TAB CHROME 10 | '189' : '45', //MINUS CHROME 11 | '187' : '61', //EQUALS CHROME 12 | '8' : '65288', //BACKSPACE CHROME 13 | '220' : '92', //FOWARD SLASH CHROME 14 | '13' : '65293', //ENTER CHROME 15 | '192' : '96', //TILDE CHROME 16 | '186' : '59', //SEMICOLON CHROME 17 | '222' : '34', //QUOTES CHROME 18 | '188' : '44', //COMMA CHROME 19 | '27' : '65307', //ESC CHROME 20 | '39' : '65363', //RIGHT ARROW CHROME 21 | '37' : '65361', //LEFT ARROW CHROME 22 | '38' : '65362', //UP ARROW CHROME 23 | '40' : '65364' //DOWN ARROW CHROME 24 | }; 25 | 26 | function buildASCIIToXKeyMap(XKeysMap,min){ 27 | asciiToX = {}; 28 | for(i=0; i 3) 75 | this.gc.polyLine(lastpoly.slice(-4)); 76 | } 77 | }, 78 | 79 | mousedown: function(ev) { 80 | if (ev.keycode == 1) { // left button 81 | this.pressed = true; 82 | pts.push([]); // start next polyline 83 | } 84 | }, 85 | 86 | mouseup: function(ev) { 87 | if (ev.keycode == 1) // left button 88 | this.pressed = false; 89 | }, 90 | 91 | expose: function(ev) { 92 | for (var i=0; i < pts.length ; ++i) 93 | this.gc.polyLine(pts[i]); 94 | } 95 | 96 | }) 97 | .map() 98 | .title = 'Hello, world!'; 99 | }); 100 | 101 | # Screenshots 102 | 103 | ![tetris game](https://lh6.googleusercontent.com/-RCRY9A7WwnA/Tlww0FHP7NI/AAAAAAAAAwo/nxfSxsw6xow/s400/tetris.png) 104 | ![XRENDER gradients](https://lh4.googleusercontent.com/-VS0BMYYmq6M/Tlww0Y1ij0I/AAAAAAAAAws/pVWsPZ63Yeo/s400/render-gradients.png) 105 | 106 | 107 | # Protocol documentation 108 | 109 | - http://www.x.org/releases/X11R7.6/doc/ 110 | - http://www.x.org/releases/X11R7.6/doc/xproto/x11protocol.pdf 111 | 112 | # Other implementations 113 | 114 | - C: XLib - http://codesearch.google.com/codesearch/p?hl=en#xEHUuo8Crmg/sites/ftp.x.org/pub/X11R7.2/src/update/everything/libX11-X11R7.2-1.1.1.tar.bz2%7CnOqwAyDlYlo/libX11-X11R7.2-1.1.1/src/OpenDis.c&q=XOpenDisplay&d=3 115 | - C: XCB - http://xcb.freedesktop.org/ 116 | - Python/twisted: https://launchpad.net/twisted-x11 117 | - Perl: http://search.cpan.org/~smccam/X11-Protocol-0.56/Protocol.pm 118 | -------------------------------------------------------------------------------- /node_modules/x11/examples/.render.js.swo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/examples/.render.js.swo -------------------------------------------------------------------------------- /node_modules/x11/examples/kbdheatmap/coordinates.json: -------------------------------------------------------------------------------- 1 | { 2 | "~": [35, 120], 3 | "`": [35, 120], 4 | "1": [90, 120], 5 | "!": [90, 120], 6 | "2": [144, 120], 7 | "@": [144, 120], 8 | "3": [198, 120], 9 | "#": [198, 120], 10 | "4": [253, 120], 11 | "$": [253, 120], 12 | "5": [307, 120], 13 | "%": [307, 120], 14 | "6": [361, 120], 15 | "^": [361, 120], 16 | "7": [415, 120], 17 | "&": [415, 120], 18 | "8": [469, 120], 19 | "*": [469, 120], 20 | "9": [524, 120], 21 | "(": [524, 120], 22 | "0": [579, 120], 23 | ")": [579, 120], 24 | "-": [630, 120], 25 | "_": [630, 120], 26 | "+": [685, 120], 27 | "=": [685, 120], 28 | "Q": [115, 174], 29 | "W": [169, 174], 30 | "E": [224, 174], 31 | "R": [278, 174], 32 | "T": [332, 174], 33 | "Y": [386, 174], 34 | "U": [440, 174], 35 | "I": [494, 174], 36 | "O": [548, 174], 37 | "P": [602, 174], 38 | "[": [656, 174], 39 | "{": [656, 174], 40 | "]": [710, 174], 41 | "}": [710, 174], 42 | "\\":[764, 174], 43 | "|": [764, 174], 44 | "A": [130, 225], 45 | "S": [184, 225], 46 | "D": [238, 225], 47 | "F": [292, 225], 48 | "G": [346, 225], 49 | "H": [400, 225], 50 | "J": [454, 225], 51 | "K": [508, 225], 52 | "L": [562, 225], 53 | ";": [616, 225], 54 | ":": [616, 225], 55 | "'": [670, 225], 56 | "\"": [670, 225], 57 | "Z": [158, 275], 58 | "X": [212, 275], 59 | "C": [266, 275], 60 | "V": [320, 275], 61 | "B": [374, 275], 62 | "N": [428, 275], 63 | "M": [482, 275], 64 | ",": [536, 275], 65 | "<": [536, 275], 66 | ".": [590, 275], 67 | ">": [590, 275], 68 | "/": [644, 275], 69 | "?": [644, 275], 70 | " ": [500, 300], 71 | "Left": [658, 345] 72 | } 73 | -------------------------------------------------------------------------------- /node_modules/x11/examples/kbdheatmap/kbdheatmap.js: -------------------------------------------------------------------------------- 1 | #!/home/laplace/node/node 2 | 3 | var Buffer = require('buffer').Buffer; 4 | var x11 = require('../../lib/x11'); 5 | 6 | var Exposure = x11.eventMask.Exposure; 7 | var KeyPress = x11.eventMask.KeyPress; 8 | var KeyRelease = x11.eventMask.KeyRelease; 9 | var ButtonPress = x11.eventMask.ButtonPress; 10 | var ButtonRelease = x11.eventMask.ButtonRelease; 11 | 12 | // image and coords file from http://www.patrick-wied.at/projects/heatmap-keyboard/ 13 | // TODO: add simple tool to use&tag coords in own keyboard photo 14 | // jpeg decoder is slightly modified version of https://github.com/notmasteryet/jpgjs 15 | var kbdImg = require('./node-jpg').readJpeg('./keyboard.jpg'); 16 | var keycoords = require('./coordinates'); 17 | 18 | // from https://github.com/substack/node-keysym 19 | var keysyms = require('./keysyms').records; 20 | var ks2name = {}; 21 | for (var k in keysyms) 22 | ks2name[keysyms[k].keysym] = keysyms[k].names; 23 | var kk2name = {}; 24 | 25 | 26 | x11.createClient(function(display) 27 | { 28 | var X = display.client; 29 | X.require('big-requests', function(BigReq) 30 | { 31 | X.require('render', function(Render) { 32 | X.Render = Render; 33 | BigReq.Enable(function(maxLen) 34 | { 35 | var min = display.min_keycode; 36 | var max = display.max_keycode; 37 | X.GetKeyboardMapping(min, max-min, function(list) 38 | { 39 | // map keycode to key name 40 | for (var i=0; i < list.length; ++i) 41 | { 42 | var name = kk2name[i+min] = []; 43 | var sublist = list[i]; 44 | for (var j =0; j < sublist.length; ++j) 45 | name.push(ks2name[sublist[j]]); 46 | 47 | } 48 | main(X); 49 | }); 50 | }); 51 | }); 52 | }); 53 | }); 54 | 55 | function main(X) 56 | { 57 | var display = X.display; 58 | var Render = X.Render; 59 | var root = display.screen[0].root; 60 | var white = display.screen[0].white_pixel; 61 | var black = display.screen[0].black_pixel; 62 | 63 | var win = X.AllocID(); 64 | X.CreateWindow( 65 | win, root, 66 | 0, 0, kbdImg.width, kbdImg.height, 67 | 1, 1, 0, 68 | { 69 | backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress 70 | } 71 | ); 72 | X.MapWindow(win); 73 | 74 | var win1 = X.AllocID(); 75 | X.CreateWindow( 76 | win1, root, 77 | 0, 0, kbdImg.width, kbdImg.height, 78 | 1, 1, 0, 79 | { 80 | backgroundPixel: white, eventMask: Exposure|KeyPress|ButtonPress 81 | } 82 | ); 83 | X.MapWindow(win1); 84 | 85 | var gc = X.AllocID(); 86 | X.CreateGC(gc, win); 87 | 88 | var picGrad = X.AllocID(); 89 | Render.RadialGradient(picGrad, [150/2,150/2], [150/2,150/2], 0, 150/2, 90 | [ 91 | [0, [0,0,0,0x15000 ] ], 92 | [1, [0, 0, 0, 0x0] ] 93 | ]); 94 | var pixmapHeatPush = X.AllocID(); 95 | X.CreatePixmap(pixmapHeatPush, win, 32, 150, 150); 96 | var picHeatPush = X.AllocID(); 97 | Render.CreatePicture(picHeatPush, pixmapHeatPush, Render.rgba32); 98 | Render.FillRectangles(1, picHeatPush, [0, 0, 0, 0], [0, 0, 150, 150]); 99 | Render.Composite(3, picGrad, 0, picHeatPush, 0, 0, 0, 0, 0, 0, 150, 150); 100 | 101 | var pixmapKbd = X.AllocID(); 102 | X.CreatePixmap(pixmapKbd, win, 24, kbdImg.width, kbdImg.height); 103 | var picKbd = X.AllocID(); 104 | X.PutImage(2, pixmapKbd, gc, kbdImg.width, kbdImg.height, 0, 0, 0, 24, kbdImg.data); 105 | Render.CreatePicture(picKbd, pixmapKbd, Render.rgb24); 106 | 107 | var pixmapHeat = X.AllocID(); 108 | X.CreatePixmap(pixmapHeat, win, 32, kbdImg.width, kbdImg.height); 109 | var picHeat = X.AllocID(); 110 | Render.CreatePicture(picHeat, pixmapHeat, Render.rgba32); 111 | 112 | var picWin = X.AllocID(); 113 | Render.CreatePicture(picWin, win, Render.rgb24); 114 | 115 | var picWin1 = X.AllocID(); 116 | Render.CreatePicture(picWin1, win1, Render.rgb24); 117 | 118 | X.on('event', function(ev) { 119 | if (ev.type == 12) // expose 120 | { 121 | Render.Composite(3, picKbd, 0, picWin, 0, 0, 0, 0, 0, 0, kbdImg.width, kbdImg.height); 122 | } if (ev.type == 4) { 123 | var x = ev.x; 124 | var y = ev.y; 125 | var mindist = 1e10; 126 | var minkey = ''; 127 | for (var k in keycoords) 128 | { 129 | var xdist = keycoords[k][0] - x; 130 | var ydist = keycoords[k][1] - y; 131 | var dist = xdist*xdist + ydist+ydist; 132 | if (dist < mindist) 133 | { 134 | minkey = k; 135 | mindist = dist; 136 | } 137 | } 138 | 139 | Render.Composite(3, picKbd, 0, picWin, 0, 0, 0, 0, 0, 0, kbdImg.width, kbdImg.height); 140 | Render.Composite(3, picHeatPush, 0, picWin, 0, 0, 0, 0, x -150/2, y-150/2, 150, 150); 141 | 142 | } if (ev.type == 2) { 143 | 144 | var name = kk2name[ev.keycode]; 145 | for (var n in name) 146 | { 147 | var pt = keycoords[name[n]]; 148 | if (pt) 149 | { 150 | Render.Composite(3, picHeatPush, 0, picWin, 0, 0, 0, 0, pt[0] -150/2, pt[1]-150/2, 150, 150); 151 | 152 | Render.Composite(3, picHeatPush, 0, picHeat, 0, 0, 0, 0, pt[0] -150/2, pt[1]-150/2, 150, 150); 153 | Render.Composite(3, picHeatPush, 0, picWin1, 0, 0, 0, 0, pt[0] -150/2, pt[1]-150/2, 150, 150); 154 | 155 | 156 | break; 157 | } else { 158 | //console.log(name); 159 | } 160 | } 161 | } else { 162 | //console.log(ev); 163 | } 164 | }) 165 | X.on('error', function(e) { 166 | console.error(e.message, ' error in request ', e.stack); 167 | process.exit(1); 168 | }); 169 | } 170 | -------------------------------------------------------------------------------- /node_modules/x11/examples/kbdheatmap/keyboard.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/examples/kbdheatmap/keyboard.jpg -------------------------------------------------------------------------------- /node_modules/x11/examples/tetris.js: -------------------------------------------------------------------------------- 1 | var figs = [ 2 | //[ 0, 0, 4, 0], 3 | 4 | // 0 0 5 | // 0 0 6 | [ 1, 1, 0, 1, 1, 0, 0, 0], 7 | // 0000 8 | [ -2, 0, -1, 0, 0, 0, 1, 0], 9 | // 00 10 | // 00 11 | [ -1, 0, 0, 0, 0, 1, 1, 1], 12 | // 00 13 | // 00 14 | [ 0, 0, 0, 1, -1, 1, 1, 0], 15 | // 0 16 | // 000 17 | [ 0, 0, 1, 0, 0, 1, -1, 0 ], 18 | // 0 19 | // 000 20 | [ 0, 0, -1, 0, -2, 0, 0, 1 ], 21 | [ 0, 0, -1, 0, -2, 0, 0, -1 ] 22 | ]; 23 | 24 | var Buffer = require('buffer').Buffer; 25 | 26 | var startpos = [4, 15]; 27 | var cupsize = [10, 20]; 28 | var cup = new Buffer(cupsize[0]*cupsize[1]); 29 | 30 | function clearCup() 31 | { 32 | for (var i=0; i = cupsize[0]) 59 | return true; 60 | if (y >= cupsize[1]) 61 | return true; 62 | if (cup[x + y*cupsize[0]]) 63 | return true; 64 | } 65 | return false; 66 | } 67 | 68 | function putfig(num, pos, angle) 69 | { 70 | angle %= 4; 71 | var fig = getTransformedFigure(num, angle, pos); 72 | for (var i=0; i < fig.length; i+= 2) 73 | { 74 | var x = fig[i]; 75 | var y = fig[i+1] 76 | var ind = x + y*cupsize[0]; 77 | cup[ind] = 1; 78 | } 79 | } 80 | 81 | function deleteLines() 82 | { 83 | for (var y=0; y < cupsize[1]; ++y) 84 | { 85 | var count = 0; 86 | for (var x=0; x < cupsize[0]; ++x) 87 | { 88 | var i = x + y*cupsize[0]; 89 | if (cup[i] == 1) 90 | count++; 91 | } 92 | if (count == cupsize[0]) // full line; 93 | { 94 | var count = 0; 95 | for (var yy=y; yy < cupsize[1] - 1; ++yy) 96 | { 97 | for (var xx=0; xx < cupsize[0]; ++xx) 98 | { 99 | var ii = xx + yy*cupsize[0]; 100 | cup[ii] = cup[ii+cupsize[0]]; 101 | } 102 | } 103 | y--; 104 | } 105 | } 106 | } 107 | 108 | var x11 = require('../lib/x11'); 109 | var Exposure = x11.eventMask.Exposure; 110 | var KeyPress = x11.eventMask.KeyPress; 111 | var sqsize = 50; 112 | var wid, cidBlack, cidWhite; 113 | var angle = 0; 114 | var gamestate = 'stopped'; 115 | var timer; 116 | var X; 117 | var pos = [4, 13]; 118 | var fignum = 0; 119 | 120 | function timerMove() 121 | { 122 | var newpos = [pos[0], pos[1]]; 123 | newpos[1]--; 124 | if (intersects(fignum, newpos, angle)) 125 | { 126 | putfig(fignum, pos, angle); 127 | 128 | deleteLines(); 129 | 130 | fignum = parseInt((Math.random()*100)%figs.length); 131 | pos[0] = startpos[0]; 132 | pos[1] = startpos[1]; 133 | angle = 0; 134 | if (intersects(fignum, pos, angle)) { 135 | process.exit(0); 136 | } 137 | draw(); 138 | } else { 139 | pos = newpos; 140 | draw(); 141 | } 142 | } 143 | 144 | function startGame() 145 | { 146 | // start timers set up cirrent + next figure, clear cup 147 | clearCup(); 148 | setInterval(timerMove, 200); 149 | } 150 | 151 | function getTransformedFigure(num, angle, pos) 152 | { 153 | var tfig = []; 154 | var fig = figs[num]; 155 | for (var i=0; i < fig.length; i+=2) 156 | { 157 | var figx = fig[i]; 158 | var figy = fig[i+1] 159 | var x = pos[0] + anglecoeff[angle*4]*figx + anglecoeff[angle*4+1]*figy; 160 | var y = pos[1] + anglecoeff[angle*4+2]*figx + anglecoeff[angle*4+3]*figy; 161 | tfig.push(x); 162 | tfig.push(y); 163 | } 164 | return tfig; 165 | } 166 | 167 | function draw() 168 | { 169 | var whiterects = []; 170 | var blackrects = []; 171 | for (var x=0; x < cupsize[0]; ++x) 172 | { 173 | for (var y=0; y < cupsize[1]; ++y) 174 | { 175 | var index = x + y*cupsize[0]; 176 | var rect = [x*sqsize, (cupsize[1]-1)*sqsize - y*sqsize, sqsize, sqsize]; 177 | if (cup[index] != 0) 178 | blackrects = blackrects.concat(rect); 179 | else 180 | whiterects = whiterects.concat(rect); 181 | } 182 | } 183 | var fig = getTransformedFigure(fignum, angle, pos); 184 | for (var i=0; i < fig.length; i+=2) 185 | { 186 | var x = fig[i]; 187 | var y = fig[i+1] 188 | blackrects = blackrects.concat([x*sqsize, (cupsize[1]-1)*sqsize - y*sqsize, sqsize, sqsize]); 189 | } 190 | X.PolyFillRectangle(wid, cidWhite, whiterects); 191 | X.PolyFillRectangle(wid, cidBlack, blackrects); 192 | } 193 | 194 | function rotate(v) 195 | { 196 | var newangle = angle + v; 197 | if (newangle < 0) 198 | newangle = 3; 199 | if (newangle >= 4) 200 | newangle = 0; 201 | if (intersects(fignum, pos, newangle)) 202 | return; 203 | 204 | angle = newangle; 205 | draw(); 206 | } 207 | 208 | function rotateUp() 209 | { 210 | rotate(1); 211 | } 212 | 213 | function rotateDown() 214 | { 215 | rotate(-1); 216 | } 217 | 218 | function moveX(v) 219 | { 220 | var newpos = [pos[0] + v, pos[1]]; 221 | if (intersects(fignum, newpos, angle)) 222 | return; 223 | pos = [newpos[0], newpos[1]]; 224 | draw(); 225 | } 226 | 227 | function moveLeft() 228 | { 229 | moveX(-1); 230 | } 231 | 232 | function moveRight() 233 | { 234 | moveX(1); 235 | } 236 | 237 | function drop() 238 | { 239 | var newpos = [pos[0], pos[1]]; 240 | while (!intersects(fignum, newpos, angle)) 241 | newpos[1]--; 242 | newpos[1]++; 243 | pos = [newpos[0], newpos[1]]; 244 | draw(); 245 | } 246 | 247 | 248 | x11.createClient(function(display) { 249 | X = display.client; 250 | var root = display.screen[0].root; 251 | var white = display.screen[0].white_pixel; 252 | var black = display.screen[0].black_pixel; 253 | wid = X.AllocID(); 254 | X.CreateWindow(wid, root, 0, 0, cupsize[0]*sqsize, cupsize[1]*sqsize, 1, 1, 0, { backgroundPixel: white, eventMask: KeyPress|Exposure }); 255 | cidBlack = X.AllocID(); 256 | cidWhite = X.AllocID(); 257 | X.CreateGC(cidBlack, wid, { foreground: black, background: white } ); 258 | X.CreateGC(cidWhite, wid, { foreground: white, background: black } ); 259 | X.MapWindow(wid); 260 | 261 | clearCup(); 262 | startGame(); 263 | 264 | 265 | var up = 111; 266 | var down = 116; 267 | var left = 113; 268 | var right = 114; 269 | 270 | //TODO keykode -> keysym 271 | /* 272 | var up = 98; 273 | var down = 104; 274 | var left = 100; 275 | var right = 102; 276 | */ 277 | X.on('event', function(ev) { 278 | switch(ev.type) { 279 | case 6: 280 | break; 281 | case 12: // expose 282 | draw(); break; 283 | case 2: 284 | //console.log('keycode', ev); 285 | //console.log(X.keymap[ev.keycode]); 286 | // 111, 113, 114, 116, 65 287 | switch(ev.keycode) { 288 | case up: rotateUp(); break; 289 | case down: rotateDown(); break; 290 | case left: moveLeft(); break; 291 | case right: moveRight(); break; 292 | case 65: drop(); break; 293 | } 294 | break; 295 | default: 296 | console.log('default event', ev); 297 | } 298 | }); 299 | }); 300 | -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/auth.js: -------------------------------------------------------------------------------- 1 | // TODO: http://en.wikipedia.org/wiki/X_Window_authorization 2 | 3 | var fs = require('fs'); 4 | var Buffer = require('buffer').Buffer; 5 | // add 'unpack' method for buffer 6 | require('./unpackbuffer').addUnpack(Buffer); 7 | 8 | function parseXauth( buf ) 9 | { 10 | var offset = 0; 11 | var auth = []; 12 | 13 | while (offset < buf.length) 14 | { 15 | var cookie = {}; 16 | var typeToName = { 17 | 256: 'Local', 18 | 65535: 'Wild', 19 | 254: 'Netname', 20 | 253: 'Krb5Principal', 21 | 252: 'LocalHost', 22 | 0: 'Internet', 23 | 1: 'DECnet', 24 | 2: 'Chaos', 25 | 5: 'ServerInterpreted', 26 | 6: 'InternetV6' 27 | }; 28 | cookie.type = buf.unpack('n')[0]; 29 | offset += 2; 30 | // TODO: rewrite following using loop (16bits length + string data) 31 | var addressLen = buf.unpack('n', offset)[0]; 32 | offset += 2; 33 | cookie.address = buf.unpackString(addressLen, offset); 34 | offset += addressLen; 35 | var displayNumLen = buf.unpack('n', offset)[0]; 36 | offset += 2; 37 | cookie.display = buf.unpackString(displayNumLen, offset); 38 | offset += displayNumLen; 39 | var authNameLen = buf.unpack('n', offset)[0]; 40 | offset += 2; 41 | cookie.authName = buf.unpackString(authNameLen, offset); 42 | offset += authNameLen; 43 | var authDataLen = buf.unpack('n', offset)[0]; 44 | offset += 2; 45 | cookie.authData = buf.unpackString(authDataLen, offset); 46 | offset += authDataLen; 47 | auth.push(cookie); 48 | } 49 | return auth; 50 | } 51 | 52 | module.exports = function( display, host, cb ) 53 | { 54 | var XAuthorityFile = process.env.XAUTHORITY; 55 | if (!XAuthorityFile) 56 | { 57 | if ( process.platform.match(/win/) ) { 58 | // http://www.straightrunning.com/XmingNotes/trouble.php 59 | // 60 | // The Xming magic cookie program, xauth (user-based), uses an 61 | // Xauthority file (not the traditional .Xauthority file) in 62 | // the %HOME% directory. To use xauth from Command Processor 63 | // e.g. on Windows machine 192.168.0.2 with user colin... 64 | XAuthorityFile = process.env.USERPROFILE + '\\Xauthority'; 65 | } else { 66 | XAuthorityFile = process.env.HOME + '/.Xauthority'; 67 | } 68 | } 69 | 70 | fs.readFile(XAuthorityFile, function (err, data) { 71 | 72 | if (err) 73 | { 74 | if (err.code == 'ENOENT') 75 | { 76 | cb('',''); 77 | return; 78 | } 79 | throw err; 80 | } 81 | 82 | var auth = parseXauth(data); 83 | for (cookieNum in auth) 84 | { 85 | var cookie = auth[cookieNum]; 86 | if (cookie.display == display && cookie.address == host) 87 | { 88 | cb( cookie.authName, cookie.authData ); 89 | return; 90 | } 91 | } 92 | // throw 'No auth cookie matching display=' + display + ' and host=' + host; 93 | cb( '', '' ); 94 | }); 95 | } -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/corereqs.js: -------------------------------------------------------------------------------- 1 | var xutil = require('./xutil'); 2 | var hexy = require('./hexy').hexy; 3 | 4 | var valueMask = { 5 | CreateWindow: { 6 | backgroundPixmap: 0x00000001, 7 | backgroundPixel : 0x00000002, 8 | borderPixmap : 0x00000004, 9 | borderPixel : 0x00000008, 10 | bitGravity : 0x00000010, 11 | winGravity : 0x00000020, 12 | backingStore : 0x00000040, 13 | backingPlanes : 0x00000080, 14 | backingPixel : 0x00000100, 15 | overrideRedirect: 0x00000200, 16 | saveUnder : 0x00000400, 17 | eventMask : 0x00000800, 18 | doNotPropagateMask: 0x00001000, 19 | colormap : 0x00002000, 20 | cursor : 0x00004000 21 | }, 22 | CreateGC: { 23 | 'function' : 0x00000001, // TODO: alias? _function? 24 | planeMask : 0x00000002, 25 | foreground : 0x00000004, 26 | background : 0x00000008, 27 | lineWidth : 0x00000010, 28 | lineStyle : 0x00000020, 29 | capStyle : 0x00000040, 30 | joinStyle : 0x00000080, 31 | fillStyle : 0x00000100, 32 | fillRule : 0x00000200, 33 | tile : 0x00000400, 34 | stipple : 0x00000800, 35 | tileStippleXOrigin: 0x00001000, 36 | tileStippleYOrigin: 0x00002000, 37 | font : 0x00004000, 38 | subwindowMode: 0x00008000, 39 | graphicsExposures: 0x00010000, 40 | clipXOrigin : 0x00020000, 41 | clipYOrigin : 0x00040000, 42 | clipMask : 0x00080000, 43 | dashOffset : 0x00100000, 44 | dashes : 0x00200000, 45 | arcMode : 0x00400000 46 | } 47 | }; 48 | 49 | var valueMaskName = {}; 50 | for (var req in valueMask) { 51 | var masks = valueMask[req]; 52 | var names = valueMaskName[req] = {}; 53 | for (var m in masks) 54 | names[masks[m]] = m; 55 | } 56 | 57 | function packValueMask(reqname, values) 58 | { 59 | var bitmask = 0; 60 | var masksList = []; 61 | var reqValueMask = valueMask[reqname]; 62 | var reqValueMaskName = valueMaskName[reqname]; 63 | 64 | if (!reqValueMask) 65 | throw new Error(reqname + ': no value mask description'); 66 | 67 | for (var v in values) 68 | { 69 | var valueBit = reqValueMask[v]; 70 | if (!valueBit) 71 | throw new Error(reqname + ': incorrect value param ' + v); 72 | masksList.push(valueBit); 73 | bitmask |= valueBit; 74 | } 75 | masksList.sort(); 76 | var args = []; 77 | for (m in masksList) 78 | { 79 | valueName = reqValueMaskName[masksList[m]]; 80 | args.push( values[valueName] ); 81 | } 82 | return [bitmask, args] 83 | } 84 | 85 | /* 86 | 87 | the way requests are described here 88 | 89 | - outgoing request 90 | 91 | 1) as function 92 | client.CreateWindow( params, params ) -> 93 | req = reqs.CreateWindow[0]( param, param ); 94 | pack_stream.pack(req[0], req[1]); 95 | 96 | 2) as array: [format, [opcode, request_length, additional known params]] 97 | 98 | client.MapWindow[0](id) -> 99 | req = reqs.MwpWindow; 100 | req[1].push(id); 101 | pack_stream.pack( req[0], req[1] ); 102 | 103 | - reply 104 | 105 | */ 106 | 107 | module.exports = { 108 | CreateWindow: [ 109 | // create request packet - function OR format string 110 | function(id, parentId, x, y, width, height, borderWidth, _class, visual, values) { 111 | 112 | // TODO: ??? there is depth field in xproto, but xlib just sets it to zero 113 | var depth = 0; 114 | 115 | var packetLength = 8 + (values ? Object.keys(values).length : 0); 116 | // TODO: should be CCSLLssSSSSLL - x,y are signed 117 | var format = 'CCSLLSSSSSSLL'; 118 | 119 | // create bitmask 120 | var bitmask = 0; 121 | // TODO: slice from function arguments? 122 | var args = [1, depth, packetLength, id, parentId, x, y, width, height, borderWidth, _class, visual]; 123 | 124 | // TODO: the code is a little bit mess 125 | // additional values need to be packed in the following way: 126 | // bitmask (bytes #24 to #31 in the packet) - 32 bit indicating what adittional arguments we supply 127 | // values list (bytes #32 .. #32+4*num_values) in order of corresponding bits TODO: it's actually not 4*num. Some values are 4b ytes, some - 1 byte 128 | 129 | 130 | // TODO: replace with packValueMask 131 | var masksList = []; 132 | for (var v in values) 133 | { 134 | var valueBit = valueMask['CreateWindow'][v]; 135 | if (!valueBit) 136 | { 137 | throw new Error('CreateWindow: incorrect value param ' + v); 138 | } 139 | masksList.push(valueBit); 140 | bitmask |= valueBit; 141 | format += 'L'; // TODO: not all values are 4 bytes CARD32!!! 142 | } 143 | // values packed in order of corresponding bit 144 | masksList.sort(); 145 | // set bits to indicate additional values we are sending in this request 146 | args.push(bitmask); 147 | // add values in the order of the bits 148 | // TODO: maybe it's better just to scan all 32 bits anstead of sorting parameters we are actually have? 149 | for (m in masksList) 150 | { 151 | valueName = valueMaskName['CreateWindow'][masksList[m]]; 152 | args.push( values[valueName] ); 153 | } 154 | return [format, args]; 155 | } 156 | 157 | ], 158 | 159 | MapWindow: [ 160 | // 8 - opcode, 2 - length, wid added as parameter 161 | [ 'CxSL', [8, 2] ] 162 | ], 163 | 164 | UnmapWindow: [ 165 | [ 'CxSL', [10, 2] ] 166 | ], 167 | 168 | // opcode 16 169 | InternAtom: [ 170 | function (returnOnlyIfExist, value) 171 | { 172 | var padded = xutil.padded_string(value); 173 | return ['CCSSxxa', [16, returnOnlyIfExist ? 1 : 0, 2+padded.length/4, value.length, padded] ]; 174 | }, 175 | 176 | function(buf) { 177 | var res = buf.unpack('L')[0]; 178 | return res; 179 | } 180 | ], 181 | 182 | GetAtomName: [ 183 | [ 'CxSL', [17, 2] ], 184 | function(buf) { 185 | var nameLen = buf.unpack('S')[0]; 186 | // Atom value starting from 24th byte in the buffer 187 | return buf.unpackString(nameLen, 24); 188 | } 189 | ], 190 | 191 | ChangeProperty: [ 192 | // mode: 0 replace, 1 prepend, 2 append 193 | // format: 8/16/32 194 | function(mode, wid, name, type, units, data) 195 | { 196 | var padded4 = (data.length + 3) >> 2; 197 | var pad = new Buffer( (padded4<<2) - data.length); 198 | var format = 'CCSLLLCxxxLaa'; 199 | var requestLength = 6 + padded4; 200 | var dataLenInFormatUnits = data.length / (units >> 3); 201 | return [format, [18, mode, requestLength, wid, name, type, units, dataLenInFormatUnits, data, pad] ]; 202 | } 203 | ], 204 | 205 | // TODO: test 206 | DeleteProperty: [ 207 | [ 'CxLLL', [19, 3] ] // wid, propNameAtom 208 | ], 209 | 210 | GetProperty: [ 211 | 212 | function(del, wid, name, type, longOffset, longLength) // - offest and maxLength in 4-byte units 213 | { 214 | return [ 'CCSLLLLL', [20, del, 6, wid, name, type, longOffset, longLength ] ]; 215 | }, 216 | 217 | function(buf, format) { 218 | var res = buf.unpack('LLL'); 219 | var prop = {}; 220 | prop.type = res[0]; 221 | prop.bytesAfter = res[1]; 222 | var len = res[2]*(format >> 3) 223 | prop.data = buf.slice(24, 24+len); 224 | return prop; 225 | } 226 | ], 227 | 228 | SendEvent: [ 229 | 230 | function(destination, propagate, eventMask, eventRawData) 231 | { 232 | return [ 'CCSLLa', [25, propagate, 11, destination, eventMask, eventRawData] ]; 233 | } 234 | ], 235 | 236 | QueryPointer: [ 237 | [ 'CxSL', [38, 2] ], 238 | function(buf) { 239 | var res = buf.unpack('LLSSSSS'); // TODO: should be unsigned 240 | // TODO pack array into named fields 241 | return res; 242 | } 243 | ], 244 | 245 | WarpPointer: [ 246 | 247 | function (srcWin, dstWin, srcX, srcY, srcWidth, srcHeight, dstX, dstY) 248 | { 249 | return [ 'CxSLLssSSss', [41, 6, srcWin, dstWin, srcX, srcY, srcWidth, srcHeight, dstX, dstY] ]; 250 | } 251 | ], 252 | 253 | CreatePixmap: [ 254 | function(pid, drawable, depth, width, height) { 255 | return [ 'CCSLLSS', [53, depth, 4, pid, drawable, width, height] ]; 256 | } 257 | ], 258 | 259 | // opcode 55 260 | CreateGC: [ 261 | function(cid, drawable, values) { 262 | var format = 'CxSLLL'; 263 | var packetLength = 4 + (values ? Object.keys(values).length : 0); 264 | var args = [55, packetLength, cid, drawable]; 265 | var vals = packValueMask('CreateGC', values); 266 | args.push(vals[0]); // values bitmask 267 | var valArr = vals[1]; 268 | for (v in valArr) 269 | { 270 | format += 'L'; // TODO: we know format string length in advance and += inefficient for string 271 | args.push(valArr[v]); 272 | } 273 | return [format, args]; 274 | } 275 | ], 276 | 277 | // 278 | CopyArea: [ 279 | function(srcDrawable, dstDrawable, gc, srcX, srcY, dstX, dstY, width, height) { 280 | return [ 'CxSLLLssssSS', [62, 7, srcDrawable, dstDrawable, gc, srcX, srcY, dstX, dstY, width, height] ]; 281 | } 282 | ], 283 | 284 | 285 | PolyPoint: [ 286 | function(coordMode, drawable, gc, points) 287 | { 288 | var format = 'CCSLL'; 289 | var args = [64, coordMode, 3+points.length/2, drawable, gc]; 290 | for (var i=0; i < points.length; ++i) 291 | { 292 | format += 'S'; 293 | args.push(points[i]); 294 | } 295 | return [format, args]; 296 | } 297 | ], 298 | 299 | PolyLine: [ 300 | // TODO: remove copy-paste - exectly same as PolyPoint, only differ with opcode 301 | function(coordMode, drawable, gc, points) 302 | { 303 | var format = 'CCSLL'; 304 | var args = [65, coordMode, 3+points.length/2, drawable, gc]; 305 | for (var i=0; i < points.length; ++i) 306 | { 307 | format += 'S'; 308 | args.push(points[i]); 309 | } 310 | return [format, args]; 311 | } 312 | 313 | ], 314 | 315 | PolyFillRectangle: [ 316 | function(drawable, gc, coords) { // x1, y1, w1, h1, x2, y2, w2, h2... 317 | var format = 'CxSLL'; 318 | var numrects4bytes = coords.length/2; 319 | var args = [70, 3+numrects4bytes, drawable, gc]; 320 | for (var i=0; i < coords.length; ++i) 321 | { 322 | format += 'S'; 323 | args.push(coords[i]); 324 | } 325 | return [format, args]; 326 | } 327 | ], 328 | 329 | PutImage: [ 330 | // format: 0 - Bitmap, 1 - XYPixmap, 2 - ZPixmap 331 | function(format, drawable, gc, width, height, dstX, dstY, leftPad, depth, data) { 332 | var padded = xutil.padded_length(data.length); 333 | var reqLen = 6 + padded/4; // (length + 3) >> 2 ??? 334 | var padLength = padded - data.length; 335 | var pad = new Buffer(padLength); // TODO: new pack format 'X' - skip amount of bytes supplied in numerical argument 336 | 337 | // TODO: move code to calculate reqLength and use BigReq if needed outside of corereq.js 338 | // NOTE: big req is used here (first 'L' in format, 0 and +1 in params), won't work if not enabled 339 | return [ 'CCSLLLSSssCCxxaa', [72, format, 0, 1+reqLen, drawable, gc, width, height, dstX, dstY, leftPad, depth, data, pad]]; 340 | } 341 | ], 342 | 343 | PolyText8: [ 344 | function(drawable, gc, x, y, items) { 345 | var format = 'CxSLLSS'; 346 | var numItems = items.length; 347 | var reqLen = 16; 348 | var args = [74, 0, drawable, gc, x, y]; 349 | for (var i=0; i < numItems; ++i) 350 | { 351 | var it = items[i]; 352 | if (typeof it == 'string') 353 | { 354 | if (it.length > 254) // TODO: split string in set of items 355 | throw 'not supported yet'; 356 | format += 'CCa'; 357 | args.push(it.length); 358 | args.push(0); // delta??? 359 | args.push(it); 360 | reqLen += 2 + it.length; 361 | } else { 362 | throw 'not supported yet'; 363 | } 364 | } 365 | var len4 = xutil.padded_length(reqLen)/4; 366 | var padLen = len4*4 - reqLen; 367 | args[1] = len4; // set request length to calculated value 368 | var pad = ''; 369 | for (var i=0; i < padLen; ++i) 370 | pad += String.fromCharCode(0); 371 | format += 'a'; 372 | args.push(pad); 373 | return [format, args]; 374 | } 375 | ], 376 | 377 | AllocColor: [ 378 | [ 'CxSLSSSxx', [84, 4] ], // params: colormap, red, green, blue 379 | 380 | function(buf) { 381 | var res = buf.unpack('SSSxL'); 382 | var color = {}; 383 | color.red = res[0]; 384 | color.blue = res[1]; 385 | color.green = res[2]; 386 | color.pixel = res[3]; 387 | return color; 388 | } 389 | ], 390 | 391 | QueryExtension: [ 392 | function(name) { 393 | var padded = xutil.padded_string(name); 394 | return ['CxSSxxa', [98, 2+padded.length/4, name.length, padded] ]; 395 | }, 396 | 397 | function(buf) { 398 | var res = buf.unpack('CCCC'); 399 | var ext = {}; 400 | ext.present = res[0]; 401 | ext.majorOpcode = res[1]; 402 | ext.firstEvent = res[2]; 403 | ext.firstError = res[3]; 404 | return ext; 405 | } 406 | 407 | ], 408 | 409 | ListExtensions: [ 410 | [ 'CxS', [99, 1] ], 411 | 412 | function(buf) { 413 | // TODO: move to buffer.unpackStringList 414 | var res = []; 415 | var off = 24; 416 | while (off < buf.length) 417 | { 418 | var len = buf[off++]; 419 | if (len == 0) 420 | break; 421 | if (off + len > buf.length) 422 | { 423 | len = buf.length - off; 424 | if (len <= 0) 425 | break; 426 | } 427 | res.push(buf.unpackString(len, off)); 428 | off += len; 429 | } 430 | return res; 431 | } 432 | ], 433 | 434 | GetKeyboardMapping: [ 435 | function(startCode, num) { 436 | return [ 'CxSCCxx', [101, 2, startCode, num] ] 437 | }, 438 | function(buff, listLength) { 439 | var res = []; 440 | var format = ''; 441 | for (var i=0; i < listLength; ++i) 442 | format += 'L'; 443 | for (var offset=24; offset < buff.length - 4*listLength; offset += 4*listLength) 444 | res.push(buff.unpack(format, offset)); 445 | return res; 446 | } 447 | ], 448 | 449 | GetGeometry: [ 450 | function(drawable){ 451 | return ['CxSL', [14, 2, drawable]] 452 | }, 453 | function(buff) 454 | { 455 | var res = buff.unpack('LSSSSSx'); 456 | ext = {}; 457 | ext.windowid = res[0] 458 | ext.xPos = res[1]; 459 | ext.yPos = res[2]; 460 | ext.width = res[3]; 461 | ext.height = res[4]; 462 | ext.borderWith = res[5]; 463 | return ext; 464 | } 465 | ] 466 | } 467 | -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/eventmask.js: -------------------------------------------------------------------------------- 1 | module.exports.eventMask = { 2 | KeyPress: 0x00000001, 3 | KeyRelease: 0x00000002, 4 | ButtonPress: 0x00000004, 5 | ButtonRelease: 0x00000008, 6 | EnterWindow: 0x00000010, 7 | LeaveWindow: 0x00000020, 8 | PointerMotion: 0x00000040, 9 | PointerMotionHint: 0x00000080, 10 | Button1Motion: 0x00000100, 11 | Button2Motion: 0x00000200, 12 | Button3Motion: 0x00000400, 13 | Button4Motion: 0x00000800, 14 | Button5Motion: 0x00001000, 15 | ButtonMotion: 0x00002000, 16 | KeymapState: 0x00004000, 17 | Exposure: 0x00008000, 18 | VisibilityChange: 0x00010000, 19 | StructureNotify: 0x00020000, 20 | ResizeRedirect: 0x00040000, 21 | SubstructureNotify: 0x00080000, 22 | SubstructureRedirect: 0x00100000, 23 | FocusChange: 0x00200000, 24 | PropertyChange: 0x00400000, 25 | ColormapChange: 0x00800000, 26 | OwnerGrabButton: 0x01000000 27 | // TODO: add more names for common masks combinations 28 | } 29 | -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/ext/big-requests.js: -------------------------------------------------------------------------------- 1 | // http://www.x.org/releases/X11R7.6/doc/bigreqsproto/bigreq.html 2 | 3 | // TODO: move to templates 4 | exports.requireExt = function(display, callback) 5 | { 6 | var X = display.client; 7 | X.QueryExtension('BIG-REQUESTS', function(ext) { 8 | 9 | if (!ext.present) 10 | callback(new Error('extension not available')); 11 | 12 | ext.Enable = function( cb ) 13 | { 14 | X.seq_num++; 15 | X.pack_stream.pack('CCS', [ext.majorOpcode, 0, 1]); 16 | X.replies[X.seq_num] = [ 17 | function(buf, opt) { 18 | return buf.unpack('L')[0]; 19 | }, 20 | cb 21 | ]; 22 | X.pack_stream.flush(); 23 | } 24 | callback(ext); 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/ext/glx.js: -------------------------------------------------------------------------------- 1 | /* 2 | second extension to try 3 | links to get started: 4 | 5 | http://cgit.freedesktop.org/xcb/proto/tree/src/glx.xml?id=HEAD 6 | http://cgit.freedesktop.org/mesa/mesa/tree/src/glx 7 | http://cgit.freedesktop.org/mesa/mesa/tree/src/glx/indirect.c 8 | 9 | http://www.opengl.org/wiki/Tutorial:_OpenGL_3.0_Context_Creation_(GLX) 10 | 11 | */ -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/ext/render.js: -------------------------------------------------------------------------------- 1 | // this will be eventually moved to lib/node-x11/extensions 2 | 3 | var x11 = require('..'); 4 | 5 | // adding XRender functions manually from 6 | // http://cgit.freedesktop.org/xcb/proto/tree/src/render.xml?id=HEAD 7 | // and http://www.x.org/releases/X11R7.6/doc/renderproto/renderproto.txt 8 | // TODO: move to templates 9 | exports.requireExt = function(display, callback) 10 | { 11 | var X = display.client; 12 | X.QueryExtension('RENDER', function(ext) { 13 | 14 | if (!ext.present) 15 | { 16 | callback(new Error('extension not available')); 17 | } 18 | 19 | ext.QueryVersion = function(clientMaj, clientMin, callback) 20 | { 21 | X.seq_num++; 22 | X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]); 23 | X.replies[X.seq_num] = [ 24 | function(buf, opt) { 25 | var res = buf.unpack('LL'); 26 | return res; 27 | }, 28 | callback 29 | ]; 30 | X.pack_stream.flush(); 31 | } 32 | 33 | ext.QueryPictFormat = function(callback) 34 | { 35 | X.seq_num++; 36 | X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]); 37 | X.replies[X.seq_num] = [ 38 | function (buf, opt) { 39 | var res = {}; 40 | var res1 = buf.unpack('LLLLL'); 41 | var num_formats = res1[0]; 42 | var num_screens = res1[1]; 43 | var num_depths = res1[2]; 44 | var num_visuals = res1[3]; 45 | var num_subpixel = res1[4]; 46 | // formats list: 47 | var offset = 24; 48 | res.formats = []; 49 | for (var i=0; i < num_formats; ++i) 50 | { 51 | var format = {}; 52 | var f = buf.unpack('LCCxxSSSSSSSSL', offset); 53 | res.formats.push(f); 54 | offset += 28; 55 | } 56 | return res; 57 | }, 58 | callback 59 | ]; 60 | X.pack_stream.flush(); 61 | } 62 | 63 | ext.QueryFilters = function(callback) 64 | { 65 | X.seq_num++; 66 | X.pack_stream.pack('CCSL', [ext.majorOpcode, 29, 2, display.screen[0].root]); 67 | X.replies[X.seq_num] = [ 68 | function(buf, opt) { 69 | var h = buf.unpack('LL'); 70 | var num_aliases = h[0]; 71 | var num_filters = h[1]; 72 | var aliases = []; 73 | var offset = 24; // LL + 16 bytes pad 74 | for (var i=0; i < num_aliases; ++i) 75 | { 76 | aliases.push(buf.unpack('S', offset)[0]); 77 | offset+=2; 78 | } 79 | var filters = []; 80 | for (var i=0; i < num_filters; ++i) 81 | { 82 | var len = buf.unpack('C', offset)[0]; 83 | //if (!len) break; 84 | offset++; 85 | filters.push(buf.toString('ascii', offset, offset+len)); 86 | offset+=len; 87 | } 88 | return [aliases, filters]; 89 | }, 90 | callback 91 | ]; 92 | X.pack_stream.flush(); 93 | } 94 | 95 | var valueList = [ 96 | ['repeat', 'C'], 97 | ['alphaMap', 'L'], 98 | ['alphaXOrigin', 's'], 99 | ['alphaYOrigin', 's'], 100 | ['clipXOrigin', 's'], 101 | ['clipYOrigin', 's'], 102 | ['clipMask', 'L'], 103 | ['graphicsExposures', 'C'], 104 | ['subwindowMode', 'C'], 105 | ['polyEdge', 'C'], 106 | ['polyMode', 'C'], 107 | ['dither', 'L'], 108 | ['componentAlpha', 'C'] 109 | ]; 110 | 111 | var argumentLength = { 112 | C: 1, 113 | S: 2, 114 | s: 2, 115 | L: 4, 116 | x: 1 117 | }; 118 | 119 | ext.CreatePicture = function(pid, drawable, pictformat, values) 120 | { 121 | X.seq_num++; 122 | var mask = 0; 123 | var reqLen = 5; // + (values + pad)/4 124 | var format = 'CCSLLLL'; 125 | var params = [ext.majorOpcode, 4, reqLen, pid, drawable, pictformat, mask]; 126 | 127 | if (values) 128 | { 129 | var valuesLength = 0; 130 | for (var i=0; i < valueList.length; ++i) 131 | { 132 | var val = values[valueList[i][0]]; 133 | if (val) { 134 | mask |= (1 << i); 135 | params.push(val); 136 | var valueFormat = valueList[i][1]; 137 | format += valueFormat; 138 | valuesLength += argumentLength[valueFormat]; 139 | } 140 | } 141 | var pad4 = (valuesLength + 3) >> 2; 142 | var toPad = (pad4 << 2) - valuesLength; 143 | for (var i=0; i < toPad; ++i) 144 | format += 'x'; 145 | reqLen += pad4; 146 | params[2] = reqLen; 147 | params[6] = mask; 148 | } 149 | X.pack_stream.pack(format, params); 150 | X.pack_stream.flush(); 151 | } 152 | 153 | function floatToFix(f) 154 | { 155 | return parseInt(f*65536); 156 | } 157 | 158 | // see example of blur filter here: https://github.com/richoH/rxvt-unicode/blob/master/src/background.C 159 | // TODO: not ready yet. 160 | ext.SetPictureFilter = function(pid, name, filterParams) 161 | { 162 | X.seq_num++; 163 | var reqLen = 2; //header + params + 1xStopfix+2xColors 164 | var format = 'CCSLa'; 165 | var params = [ext.majorOpcode, 30, reqLen, pid]; 166 | /* 167 | if (name == 'convolution') 168 | { 169 | reqLen += 2; 170 | format += 'L'; 171 | params.push(floatToFix(filterParams)); 172 | } else { 173 | throw 'Not implemented filter ' + name; 174 | } 175 | */ 176 | params[2] = reqLen; 177 | //console.log([format, params]); 178 | X.pack_stream.pack(format, params); 179 | X.pack_stream.flush(); 180 | } 181 | 182 | ext.RadialGradient = function(pid, p1, p2, r1, r2, stops) 183 | { 184 | // TODO: merge with linear gradient 185 | X.seq_num++; 186 | var reqLen = 9+stops.length*3; //header + params + 1xStopfix+2xColors 187 | var format = 'CCSLLLLLLLL'; 188 | var params = [ext.majorOpcode, 35, reqLen, pid]; 189 | params.push(floatToFix(p1[0])); // L 190 | params.push(floatToFix(p1[1])); 191 | params.push(floatToFix(p2[0])); 192 | params.push(floatToFix(p2[1])); // L 193 | params.push(floatToFix(r1)); // L 194 | params.push(floatToFix(r2)); // L 195 | params.push(stops.length); 196 | 197 | // [ [float stopDist, [float r, g, b, a] ], ...] 198 | // stop distances 199 | for (var i=0; i < stops.length; ++i) 200 | { 201 | format += 'L'; 202 | // TODO: we know total params length in advance. ? params[index] = 203 | params.push(floatToFix(stops[i][0])) 204 | } 205 | // colors 206 | for (var i=0; i < stops.length; ++i) 207 | { 208 | format += 'SSSS'; 209 | for (var j=0; j < 4; ++j) 210 | params.push(stops[i][1][j]); 211 | } 212 | //console.log([format, params]); 213 | X.pack_stream.pack(format, params); 214 | X.pack_stream.flush(); 215 | } 216 | 217 | ext.LinearGradient = function(pid, p1, p2, stops) 218 | { 219 | X.seq_num++; 220 | var reqLen = 7+stops.length*3; //header + params + 1xStopfix+2xColors 221 | var format = 'CCSLLLLLL'; 222 | var params = [ext.majorOpcode, 34, reqLen, pid]; 223 | params.push(floatToFix(p1[0])); // L 224 | params.push(floatToFix(p1[1])); 225 | params.push(floatToFix(p2[0])); 226 | params.push(floatToFix(p2[1])); // L 227 | 228 | params.push(stops.length); 229 | 230 | // [ [float stopDist, [float r, g, b, a] ], ...] 231 | // stop distances 232 | for (var i=0; i < stops.length; ++i) 233 | { 234 | format += 'L'; 235 | // TODO: we know total params length in advance. ? params[index] = 236 | params.push(floatToFix(stops[i][0])) 237 | } 238 | // colors 239 | for (var i=0; i < stops.length; ++i) 240 | { 241 | format += 'SSSS'; 242 | for (var j=0; j < 4; ++j) 243 | params.push(stops[i][1][j]); 244 | } 245 | //console.log([format, params]); 246 | X.pack_stream.pack(format, params); 247 | X.pack_stream.flush(); 248 | } 249 | 250 | ext.ConicalGradient = function(pid, center, angle, stops) 251 | { 252 | X.seq_num++; 253 | var reqLen = 6+stops.length*3; //header + params + 1xStopfix+2xColors 254 | var format = 'CCSLLLLL'; 255 | var params = [ext.majorOpcode, 36, reqLen, pid]; 256 | params.push(floatToFix(center[0])); // L 257 | params.push(floatToFix(center[1])); 258 | params.push(floatToFix(angle)); // L 259 | 260 | params.push(stops.length); 261 | 262 | // [ [float stopDist, [float r, g, b, a] ], ...] 263 | // stop distances 264 | for (var i=0; i < stops.length; ++i) 265 | { 266 | format += 'L'; 267 | // TODO: we know total params length in advance. ? params[index] = 268 | params.push(floatToFix(stops[i][0])) 269 | } 270 | // colors 271 | for (var i=0; i < stops.length; ++i) 272 | { 273 | format += 'SSSS'; 274 | for (var j=0; j < 4; ++j) 275 | params.push(stops[i][1][j]); 276 | } 277 | //console.log([format, params]); 278 | X.pack_stream.pack(format, params); 279 | X.pack_stream.flush(); 280 | } 281 | 282 | ext.FillRectangles = function(op, pid, color, rects) 283 | { 284 | X.seq_num++; 285 | var reqLen = 5+rects.length/2; 286 | var format = 'CCSCxxxLSSSS'; 287 | var params = [ext.majorOpcode, 26, reqLen, op, pid]; 288 | for (var j=0; j < 4; ++j) 289 | params.push(color[j]); 290 | for (var i=0; i < rects.length; i+=4) 291 | { 292 | format += 'ssSS'; 293 | params.push(rects[i*4]); 294 | params.push(rects[i*4 + 1]); 295 | params.push(rects[i*4 + 2]); 296 | params.push(rects[i*4 + 3]); 297 | } 298 | X.pack_stream.pack(format, params); 299 | X.pack_stream.flush(); 300 | } 301 | 302 | ext.Composite = function(op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height) 303 | { 304 | X.seq_num++; 305 | X.pack_stream.pack( 306 | 'CCSCxxxLLLssssssSS', 307 | [ext.majorOpcode, 8, 9, op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height] 308 | ) 309 | .flush(); 310 | } 311 | 312 | ext.Trapezoids = function(op, src, srcX, srcY, dst, maskFormat, trapz) 313 | { 314 | X.seq_num++; 315 | var format = 'CCSCxxxLLLss'; 316 | var params = [ext.majorOpcode, 10, 6+trapz.length, op, src, dst, maskFormat, srcX, srcY]; 317 | for (var i=0; i < trapz.length; i+=10) 318 | { 319 | format += 'llllllllll'; 320 | for (var j=0; j < 10; ++j) 321 | params.push(floatToFix(trapz[i*10 + j])); 322 | } 323 | //console.log([format, params]); 324 | X.pack_stream.pack(format, params); 325 | X.pack_stream.flush(); 326 | } 327 | 328 | ext.Triangles = function(op, src, srcX, srcY, dst, maskFormat, tris) 329 | { 330 | X.seq_num++; 331 | var format = 'CCSCxxxLLLss'; 332 | var params = [ext.majorOpcode, 11, 6+tris.length, op, src, dst, maskFormat, srcX, srcY]; 333 | for (var i=0; i < tris.length; i+=6) 334 | { 335 | format += 'llllll'; 336 | //TODO: Array.copy 337 | params.push(floatToFix(tris[i*6 + 0])); // x1 338 | params.push(floatToFix(tris[i*6 + 1])); // y1 339 | params.push(floatToFix(tris[i*6 + 2])); // x2 340 | params.push(floatToFix(tris[i*6 + 3])); // y2 341 | params.push(floatToFix(tris[i*6 + 4])); // x3 342 | params.push(floatToFix(tris[i*6 + 5])); // y3 343 | } 344 | X.pack_stream.pack(format, params); 345 | X.pack_stream.flush(); 346 | } 347 | 348 | ext.QueryPictFormat(function(formats) { 349 | for (var i=0; i < formats.formats.length; ++i) { 350 | var f = formats.formats[i]; 351 | if (f[2] == 1 && f[10] == 1) 352 | ext.mono1 = f[0] ; 353 | if (f[2] == 24 && f[3] == 16 && f[5] == 8 && f[7] == 0) 354 | ext.rgb24 = f[0]; 355 | if (f[2] == 32 && f[3] == 16 && f[5] == 8 && f[7] == 0 && f[9] == 24) 356 | ext.rgba32 = f[0] ; 357 | } 358 | callback(ext); 359 | }); 360 | }); 361 | } 362 | -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/ext/xtest.js: -------------------------------------------------------------------------------- 1 | // http://www.x.org/releases/X11R7.6/doc/xextproto/xtest.pdf 2 | 3 | var x11 = require('..'); 4 | // TODO: move to templates 5 | exports.requireExt = function(display, callback) 6 | { 7 | var X = display.client; 8 | X.QueryExtension('XTEST', function(ext) { 9 | 10 | if (!ext.present) 11 | callback(new Error('extension not available')); 12 | 13 | ext.QueryVersion = function(clientMaj, clientMin, callback) 14 | { 15 | X.seq_num++; 16 | X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]); 17 | X.replies[X.seq_num] = [ 18 | function(buf, opt) { 19 | var res = buf.unpack('LL'); 20 | return res; 21 | }, 22 | callback 23 | ]; 24 | X.pack_stream.flush(); 25 | } 26 | 27 | ext.KeyPress = 2; 28 | ext.KeyRelease = 3; 29 | ext.ButtonPress = 4; 30 | ext.ButtonRelease = 5; 31 | ext.MotionNotify = 6; 32 | 33 | ext.FakeInput = function( type, keycode, time, wid, x, y ) 34 | { 35 | X.seq_num++; 36 | X.pack_stream.pack('CCSCCxxLLxxxxxxxxssxxxxxxxx', [ext.majorOpcode, 2, 9, type, keycode, time, wid, x, y]); 37 | X.pack_stream.flush(); 38 | } 39 | 40 | callback(ext); 41 | }); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/handshake.js: -------------------------------------------------------------------------------- 1 | var getAuthString = require('./auth'); 2 | var xutil = require('./xutil'); 3 | 4 | function readVisuals(bl, visuals, n_visuals, cb) 5 | { 6 | if (n_visuals == 0) 7 | { 8 | cb(); 9 | return; 10 | } 11 | 12 | var visual = {}; 13 | bl.unpackTo( visual, 14 | [ 15 | 'L vid', 16 | 'C class', 17 | 'C bits_per_rgb', 18 | 'S map_ent', 19 | 'L red_mask', 20 | 'L green_mask', 21 | 'L blue_mask', 22 | 'xxxx' 23 | ], 24 | function() { 25 | var vid = visual.vid; 26 | // delete visual.vid; 27 | visuals[visual.vid] = visual; 28 | if (Object.keys(visuals).length == n_visuals) 29 | cb() 30 | else 31 | readVisuals(bl, visuals, n_visuals, cb); 32 | }); 33 | } 34 | 35 | function readDepths(bl, display, depths, n_depths, cb) 36 | { 37 | if (n_depths == 0) 38 | { 39 | cb(); 40 | return; 41 | } 42 | 43 | bl.unpack( 'CxSxxxx', function(res) { 44 | var dep = res[0]; 45 | var n_visuals = res[1]; 46 | var visuals = {}; 47 | readVisuals(bl, visuals, n_visuals, function() 48 | { 49 | depths[dep] = visuals; 50 | if (Object.keys(depths).length == n_depths) 51 | cb(); 52 | else 53 | readDepths(bl, display, depths, n_depths, cb); 54 | }); 55 | }); 56 | } 57 | 58 | function readScreens(bl, display, cbDisplayReady) 59 | { 60 | // for (i=0; i < display.screen_num; ++i) 61 | { 62 | var scr = {}; 63 | bl.unpackTo( scr, 64 | [ 65 | 'L root', 66 | 'L default_colormap', 67 | 'L white_pixel', 68 | 'L black_pixel', 69 | 'L input_masks', 70 | 'S pixel_with', 71 | 'S pixel_height', 72 | 'S mm_width', 73 | 'S mm_height', 74 | 'S min_installed_maps', 75 | 'S max_installed_maps', 76 | 'L root_visual', 77 | 'C root_depth', 78 | 'C backing_stores', 79 | 'C root_depth', 80 | 'C num_depths' 81 | ], 82 | function () { 83 | var depths = {}; 84 | readDepths(bl, display, depths, scr.num_depths, function() { 85 | 86 | scr.depths = depths; 87 | delete scr.num_depths; 88 | display.screen.push(scr); 89 | 90 | if (display.screen.length == display.screen_num) 91 | { 92 | delete display.screen_num; 93 | cbDisplayReady(display); 94 | return; 95 | } else { 96 | readScreens(bl, display, cbDisplayReady); 97 | } 98 | }); 99 | }); 100 | } 101 | } 102 | 103 | function readServerHello(bl, cb) 104 | { 105 | 106 | bl.unpack('C', function(res) { 107 | 108 | if (res[0] == 0) 109 | { 110 | // conection time error 111 | // unpack error (? TODO) 112 | var err = new Error; 113 | cb(err); // TODO: detect that this is error on xcore side 114 | // TODO: do we need to close stream from our side? 115 | // TODO: api to close source stream via attached unpackstream 116 | return; 117 | } 118 | 119 | var display = {}; 120 | bl.unpackTo( 121 | display, 122 | [ 123 | 'x', 124 | 'S major', 125 | 'S minor', 126 | 'S xlen', 127 | 'L release', 128 | 'L resource_base', 129 | 'L resource_mask', 130 | 'L motion_buffer_size', 131 | 'S vlen', 132 | 'S max_request_length', 133 | 'C screen_num', 134 | 'C format_num', 135 | 'C image_byte_order', 136 | 'C bitmap_bit_order', 137 | 'C bitmap_scanline_unit', 138 | 'C bitmap_scanline_pad', 139 | 'C min_keycode', 140 | 'C max_keycode', 141 | 'xxxx' 142 | ], 143 | 144 | function() 145 | { 146 | var pvlen = xutil.padded_length(display.vlen); 147 | 148 | // setup data to generate resource id 149 | // TODO: cleaunup code here 150 | var mask = display.resource_mask; 151 | display.rsrc_shift = 0; 152 | while (!( (mask >> display.rsrc_shift) & 1) ) 153 | display.rsrc_shift++; 154 | display.rsrc_id = 0; 155 | 156 | bl.get(pvlen, function(vendor) 157 | { 158 | display.vendor = vendor.toString().substr(0, display.vlen); // utf8 by default? 159 | 160 | display.format = {}; 161 | for (i=0; i < display.format_num; ++i) 162 | { 163 | bl.unpack('CCCxxxxx', function(fmt) { 164 | var depth = fmt[0]; 165 | display.format[depth] = {}; 166 | display.format[depth].bits_per_pixel = fmt[1]; 167 | display.format[depth].scanline_pad = fmt[2]; 168 | if (Object.keys(display.format).length == display.format_num) 169 | { 170 | delete display.format_num; 171 | display.screen = []; 172 | readScreens(bl, display, cb); 173 | } 174 | }); 175 | } 176 | }); 177 | } 178 | ); 179 | }); 180 | 181 | } 182 | 183 | function writeClientHello(stream, displayNum, authHost) 184 | { 185 | getAuthString( displayNum, authHost, function( authType, authData ) { 186 | authType = xutil.padded_string( authType ); 187 | authData = xutil.padded_string( authData ); 188 | var byte_order = 'l'.charCodeAt(0); // TODO: byteorder!!! 189 | var protocol_major = 11; // TODO: config? env? 190 | var protocol_minor = 0; 191 | stream.pack( 192 | 'CxSSSSxxaa', 193 | [ 194 | byte_order, 195 | protocol_major, 196 | protocol_minor, 197 | authType.length, 198 | authData.length, 199 | authType, 200 | authData 201 | ] 202 | ); 203 | stream.flush(); 204 | }); 205 | } 206 | 207 | module.exports.readServerHello = readServerHello; 208 | module.exports.writeClientHello = writeClientHello; -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/hexy.js: -------------------------------------------------------------------------------- 1 | //= hexy.js -- utility to create hex dumps 2 | // 3 | // `hexy` is a javascript (node) library that's easy to use to create hex 4 | // dumps from within node. It contains a number of options to configure 5 | // how the hex dumb will end up looking. 6 | // 7 | // It should create a pleasant looking hex dumb by default: 8 | // 9 | // var hexy = require('hexy.js'), 10 | // b = new Buffer("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789") 11 | // 12 | // console.log(hexy.hexy(b)) 13 | // 14 | // results in this dump: 15 | // 16 | // 0000000: 00 01 03 05 1f 0a 09 62 63 64 65 66 67 68 69 6a .......b cdefghij 17 | // 0000010: 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a klmnopqr stuvwxyz 18 | // 0000020: 30 31 32 33 34 35 36 37 38 39 01234567 89 19 | // 20 | // but it's also possible to configure: 21 | // 22 | // * Line numbering 23 | // * Line width 24 | // * Format 25 | // * Case of hex decimals 26 | // * Presence of the ASCII annotation in the right column. 27 | // 28 | // This mean you can do exciting dumps like: 29 | // 30 | // 0000000: 0001 0305 1f0a 0962 .... ...b 31 | // 0000008: 6364 6566 6768 696a cdef ghij 32 | // 0000010: 6b6c 6d6e 6f70 7172 klmn opqr 33 | // 0000018: 7374 7576 7778 797a stuv wxyz 34 | // 0000020: 3031 3233 3435 3637 0123 4567 35 | // 0000028: 3839 89 36 | // 37 | // or even: 38 | // 39 | // 0000000: 00 01 03 05 1f 0a 09 62 63 64 65 66 67 68 69 6a 40 | // 0000010: 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 41 | // 0000020: 30 31 32 33 34 35 36 37 38 39 42 | // 43 | // with hexy! 44 | // 45 | // Formatting options are configured by passing a `format` object to the `hexy` function: 46 | // 47 | // var format = {} 48 | // format.width = width // how many bytes per line, default 16 49 | // format.numbering = n // ["hex_bytes" | "none"], default "none" 50 | // format.format = f // ["fours"|"twos"|"none"], how many nibbles per group 51 | // // default "fours" 52 | // format.caps = c // ["lower"|"upper"], default lower 53 | // format.annotate=a // ["ascii"|"none"], ascii annotation at end of line? 54 | // // default "ascii" 55 | // format.prefix=p // something pretty to put in front of each line 56 | // // default "" 57 | // format.indent=i // number of spaces to indent 58 | // // default 0 59 | // 60 | // console.log(hexy.hexy(buffer, format)) 61 | // 62 | // In case you're really nerdy, you'll have noticed that the defaults correspond 63 | // to how `xxd` formats it's output. 64 | // 65 | // 66 | //== Installing 67 | // 68 | // Either use `npm`: 69 | // 70 | // npm install hexy 71 | // 72 | // This will install the lib which you'll be able to use like so: 73 | // 74 | // var hexy = require("hexy.js"), 75 | // buf = // get Buffer from somewhere, 76 | // str = hexy.hexy(buf) 77 | // 78 | // It will also install `hexy.js` into your path in case you're totally fed up 79 | // with using `xxd`. 80 | // 81 | // 82 | // If you don't like `npm`, grab the source from github: 83 | // 84 | // http://github.com/a2800276/hexy.js 85 | // 86 | //== TODOS 87 | // 88 | // The current version only pretty prints Buffers. Which probably means it 89 | // can only be used from within node. What's more important what it 90 | // doesn't support: Strings (which would be nice for the sake of 91 | // completeness) and Streams/series of Buffers which would be nice so you 92 | // don't have to collect the whole things you want to pretty print in 93 | // memory. `hexy` is probably most useful for debugging and getting binary 94 | // protocol stuff working, so that's probably not an too much of an issue. 95 | // 96 | //== History 97 | // 98 | // This is a fairly straightforward port of `hexy.rb` which does more or less the 99 | // same thing. You can find it here: 100 | // 101 | // http://github.com/a2800276/hexy 102 | // 103 | // in case these sorts of things interest you. 104 | // 105 | //== Mail 106 | // 107 | // In case you discover bugs, spelling errors, offer suggestions for 108 | // improvements or would like to help out with the project, you can contact 109 | // me directly (tim@kuriositaet.de). 110 | 111 | var hexy = function (buffer, config) { 112 | config = config || {} 113 | var h = new Hexy(buffer, config) 114 | return h.toString() 115 | } 116 | 117 | var Hexy = function (buffer, config) { 118 | var self = this 119 | 120 | self.buffer = buffer // magic string conversion here? 121 | self.width = config.width || 16 122 | self.numbering = config.numbering == "none" ? "none" : "hex_bytes" 123 | self.groupSpacing = config.groupSpacing || 0 124 | 125 | switch (config.format) { 126 | case "none": 127 | case "twos": 128 | self.format = config.format 129 | break 130 | default: 131 | self.format = "fours" 132 | } 133 | 134 | self.caps = config.caps == "upper" ? "upper" : "lower" 135 | self.annotate = config.annotate == "none" ? "none" : "ascii" 136 | self.prefix = config.prefix || "" 137 | self.indent = config.indent || 0 138 | 139 | for (var i = 0; i!=self.indent; ++i) { 140 | self.prefix = " "+prefix 141 | } 142 | 143 | var pos = 0 144 | 145 | this.toString = function () { 146 | var str = "" 147 | 148 | //split up into line of max `self.width` 149 | var line_arr = lines() 150 | 151 | //lines().forEach(function(hex_raw, i){ 152 | for (var i = 0; i!= line_arr.length; ++i) { 153 | var hex_raw = line_arr[i], 154 | hex = hex_raw[0], 155 | raw = hex_raw[1] 156 | //insert spaces every `self.format.twos` or fours 157 | var howMany = hex.length 158 | if (self.format === "fours") { 159 | howMany = 4 160 | } else if (self.format === "twos") { 161 | howMany = 2 162 | } 163 | 164 | var hex_formatted = "" 165 | var middle = Math.floor(self.width / 2)-1 166 | var groupSpaces = (new Array(self.groupSpacing+1)).join(' '); 167 | for (var j=0; j 0 ? groupSpaces : " ") 170 | } 171 | str += self.prefix 172 | 173 | if (self.numbering === "hex_bytes") { 174 | str += pad(i*self.width, 8) // padding... 175 | str += ": " 176 | } 177 | 178 | var padlen = 0 179 | switch(self.format) { 180 | case "fours": 181 | padlen = self.width*2 + self.width/2 182 | break 183 | case "twos": 184 | padlen = self.width*3 + 2 185 | break 186 | default: 187 | padlen = self * 2 188 | } 189 | 190 | str += rpad(hex_formatted, padlen) 191 | if (self.annotate === "ascii") { 192 | str+=" " 193 | str+=raw.replace(/[\000-\040\177-\377]/g, ".") 194 | } 195 | str += "\n" 196 | } 197 | return str 198 | } 199 | 200 | var lines = function() { 201 | var hex_raw = [] 202 | 203 | 204 | for (var i = 0; i= buffer.length ? buffer.length : i+self.width, 207 | slice = buffer.slice(begin, end), 208 | hex = self.caps === "upper" ? hexu(slice) : hexl(slice), 209 | raw = slice.toString('ascii') 210 | 211 | hex_raw.push([hex,raw]) 212 | } 213 | return hex_raw 214 | 215 | } 216 | 217 | var hexl = function (buffer) { 218 | var str = "" 219 | for (var i=0; i!=buffer.length; ++i) { 220 | str += pad(buffer[i], 2) 221 | } 222 | return str 223 | } 224 | var hexu = function (buffer) { 225 | return hexl(buffer).toUpperCase() 226 | } 227 | 228 | var pad = function(b, len) { 229 | var s = b.toString(16) 230 | 231 | while (s.length < len) { 232 | s = "0" + s 233 | } 234 | return s 235 | } 236 | var rpad = function(s, len) { 237 | while(s.length < len) { 238 | s += " " 239 | } 240 | return s 241 | } 242 | 243 | } 244 | /* 245 | var fs = require('fs'), 246 | file = process.argv[2] 247 | 248 | 249 | var data = fs.readFileSync(file) 250 | //console.log(hexy(data)) 251 | var format = {} 252 | //format.format = "fours" 253 | format.caps = "upper" 254 | format.annotate = "none" 255 | //format.numbering = "none" 256 | format.width = 8 257 | console.log(hexy(data, format)) 258 | console.log("doen") 259 | */ 260 | 261 | exports.hexy = hexy -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/index.js: -------------------------------------------------------------------------------- 1 | var core = require('./xcore'); 2 | var em = require('./eventmask').eventMask; 3 | var keysyms = require('./keysyms'); 4 | 5 | module.exports.createClient = core.createClient; 6 | module.exports.eventMask = em; 7 | module.exports.keySyms = keysyms; -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/stdatoms.js: -------------------------------------------------------------------------------- 1 | // pre-defined atoms. generated automatically with genstdatoms.js 2 | 3 | module.exports = { 4 | PRIMARY: 1, 5 | SECONDARY: 2, 6 | ARC: 3, 7 | ATOM: 4, 8 | BITMAP: 5, 9 | CARDINAL: 6, 10 | COLORMAP: 7, 11 | CURSOR: 8, 12 | CUT_BUFFER0: 9, 13 | CUT_BUFFER1: 10, 14 | CUT_BUFFER2: 11, 15 | CUT_BUFFER3: 12, 16 | CUT_BUFFER4: 13, 17 | CUT_BUFFER5: 14, 18 | CUT_BUFFER6: 15, 19 | CUT_BUFFER7: 16, 20 | DRAWABLE: 17, 21 | FONT: 18, 22 | INTEGER: 19, 23 | PIXMAP: 20, 24 | POINT: 21, 25 | RECTANGLE: 22, 26 | RESOURCE_MANAGER: 23, 27 | RGB_COLOR_MAP: 24, 28 | RGB_BEST_MAP: 25, 29 | RGB_BLUE_MAP: 26, 30 | RGB_DEFAULT_MAP: 27, 31 | RGB_GRAY_MAP: 28, 32 | RGB_GREEN_MAP: 29, 33 | RGB_RED_MAP: 30, 34 | STRING: 31, 35 | VISUALID: 32, 36 | WINDOW: 33, 37 | WM_COMMAND: 34, 38 | WM_HINTS: 35, 39 | WM_CLIENT_MACHINE: 36, 40 | WM_ICON_NAME: 37, 41 | WM_ICON_SIZE: 38, 42 | WM_NAME: 39, 43 | WM_NORMAL_HINTS: 40, 44 | WM_SIZE_HINTS: 41, 45 | WM_ZOOM_HINTS: 42, 46 | MIN_SPACE: 43, 47 | NORM_SPACE: 44, 48 | MAX_SPACE: 45, 49 | END_SPACE: 46, 50 | SUPERSCRIPT_X: 47, 51 | SUPERSCRIPT_Y: 48, 52 | SUBSCRIPT_X: 49, 53 | SUBSCRIPT_Y: 50, 54 | UNDERLINE_POSITION: 51, 55 | UNDERLINE_THICKNESS: 52, 56 | STRIKEOUT_ASCENT: 53, 57 | STRIKEOUT_DESCENT: 54, 58 | ITALIC_ANGLE: 55, 59 | X_HEIGHT: 56, 60 | QUAD_WIDTH: 57, 61 | WEIGHT: 58, 62 | POINT_SIZE: 59, 63 | RESOLUTION: 60, 64 | COPYRIGHT: 61, 65 | NOTICE: 62, 66 | FONT_NAME: 63, 67 | FAMILY_NAME: 64, 68 | FULL_NAME: 65, 69 | CAP_HEIGHT: 66, 70 | WM_CLASS: 67, 71 | WM_TRANSIENT_FOR: 68 72 | } -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/unpackbuffer.js: -------------------------------------------------------------------------------- 1 | // unpack for static buffer 2 | 3 | // TODO: use as fallback only if v0.5+ fuffer is not available 4 | // TODO: remove duplicate code 5 | var argument_length = {}; 6 | argument_length.C = 1; 7 | argument_length.S = 2; 8 | argument_length.s = 2; 9 | argument_length.L = 4; 10 | argument_length.x = 1; 11 | 12 | module.exports.addUnpack = function(Buffer) 13 | { 14 | Buffer.prototype.unpack = function(format, offset) 15 | { 16 | if (!offset) 17 | offset = 0; 18 | 19 | var data = []; 20 | var current_arg = 0; 21 | while (current_arg < format.length) 22 | { 23 | var arg = format[current_arg]; 24 | switch (arg) { 25 | case 'C': 26 | data.push(this[offset++]); 27 | break; 28 | case 'S': 29 | case 's': //TODO: 16bit signed unpack 30 | var b1 = this[offset++]; 31 | var b2 = this[offset++]; 32 | data.push(b2*256+b1); 33 | break; 34 | case 'n': 35 | var b1 = this[offset++]; 36 | var b2 = this[offset++]; 37 | data.push(b1*256+b2); 38 | break; 39 | case 'L': 40 | case 'l': //TODO: 32bit signed unpack 41 | var b1 = this[offset++]; 42 | var b2 = this[offset++]; 43 | var b3 = this[offset++]; 44 | var b4 = this[offset++]; 45 | data.push(((b4*256+b3)*256 + b2)*256 + b1); 46 | break; 47 | case 'x': 48 | offset++; 49 | break; 50 | } 51 | current_arg++; 52 | } 53 | return data; 54 | } 55 | 56 | /* 57 | Buffer.prototype.skip = function(n) 58 | { 59 | offset += n; 60 | } 61 | */ 62 | 63 | Buffer.prototype.unpackString = function(n, offset) 64 | { 65 | var res = ''; 66 | var end = offset + n; 67 | while(offset < end) 68 | res += String.fromCharCode(this[offset++]); 69 | return res; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/unpackstream.js: -------------------------------------------------------------------------------- 1 | var Buffer = require('buffer').Buffer; 2 | var EventEmitter = require('events').EventEmitter; 3 | var util = require('util'); 4 | var xutil = require('./xutil'); 5 | 6 | var argument_length = {}; 7 | argument_length.C = 1; 8 | argument_length.S = 2; 9 | argument_length.s = 2; 10 | argument_length.L = 4; 11 | argument_length.l = 4; 12 | argument_length.x = 1; 13 | 14 | function ReadFormatRequest(format, callback) 15 | { 16 | this.format = format; 17 | this.current_arg = 0; 18 | this.data = []; 19 | this.callback = callback; 20 | } 21 | 22 | function ReadFixedRequest(length, callback) 23 | { 24 | this.length = length; 25 | this.callback = callback; 26 | this.data = new Buffer(length); 27 | this.received_bytes = 0; 28 | } 29 | 30 | ReadFixedRequest.prototype.execute = function(bufferlist, aa, bb, cc, dd) 31 | { 32 | // TODO: this is a brute force version 33 | // replace with Buffer.slice calls 34 | var to_receive = this.length - this.received_bytes; 35 | for(var i=0 ; i < to_receive; ++i) 36 | { 37 | if (bufferlist.length == 0) 38 | return false; 39 | this.data[this.received_bytes++] = bufferlist.getbyte(); 40 | } 41 | this.callback(this.data); 42 | return true; 43 | } 44 | 45 | ReadFormatRequest.prototype.execute = function(bufferlist, tag1, tag2) 46 | { 47 | while (this.current_arg < this.format.length) 48 | { 49 | var arg = this.format[this.current_arg]; 50 | if (bufferlist.length < argument_length[arg]) 51 | return false; // need to wait for more data to prcess this argument 52 | 53 | // TODO: measure Buffer.readIntXXX performance and use them if faster 54 | // note: 4 and 2-byte values may cross chunk border & split. need to handle this correctly 55 | // maybe best approach is to wait all data required for format and then process fixed buffer 56 | // TODO: byte order!!! 57 | switch (arg) { 58 | case 'C': 59 | this.data.push(bufferlist.getbyte()); 60 | break; 61 | case 'S': 62 | case 's': 63 | var b1 = bufferlist.getbyte(); 64 | var b2 = bufferlist.getbyte(); 65 | this.data.push(b2*256+b1); 66 | break; 67 | case 'l': 68 | case 'L': 69 | var b1 = bufferlist.getbyte(); 70 | var b2 = bufferlist.getbyte(); 71 | var b3 = bufferlist.getbyte(); 72 | var b4 = bufferlist.getbyte(); 73 | this.data.push(((b4*256+b3)*256 + b2)*256 + b1); 74 | break; 75 | case 'x': 76 | bufferlist.getbyte(); 77 | break; 78 | } 79 | this.current_arg++; 80 | } 81 | this.callback(this.data); 82 | return true; 83 | } 84 | 85 | function UnpackStream() 86 | { 87 | EventEmitter.call(this); 88 | 89 | this.readlist = []; 90 | this.length = 0; 91 | this.offset = 0; 92 | this.read_queue = []; 93 | this.write_queue = []; 94 | this.write_length = 0; 95 | } 96 | util.inherits(UnpackStream, EventEmitter); 97 | 98 | UnpackStream.prototype.write = function(buf) 99 | { 100 | this.readlist.push(buf); 101 | this.length += buf.length; 102 | this.resume(); 103 | } 104 | 105 | UnpackStream.prototype.pipe = function(stream) 106 | { 107 | // TODO: ondrain & pause 108 | this.on('data', function(data) 109 | { 110 | stream.write(data); 111 | }); 112 | } 113 | 114 | UnpackStream.prototype.unpack = function(format, callback) 115 | { 116 | this.read_queue.push(new ReadFormatRequest(format, callback)); 117 | this.resume(); 118 | } 119 | 120 | UnpackStream.prototype.unpackTo = function(destination, names_formats, callback) 121 | { 122 | var names = []; 123 | var format = ''; 124 | 125 | for (var i=0; i < names_formats.length; ++i) 126 | { 127 | var off = 0; 128 | while(off < names_formats[i].length && names_formats[i][off] == 'x') 129 | { 130 | format += 'x'; 131 | off++; 132 | } 133 | 134 | if (off < names_formats[i].length) 135 | { 136 | format += names_formats[i][off]; 137 | var name = names_formats[i].substr(off+2); 138 | names.push(name); 139 | } 140 | } 141 | 142 | this.unpack(format, function(data) { 143 | if (data.length != names.length) 144 | throw 'Number of arguments mismatch, ' + names.length + ' fields and ' + data.length + ' arguments'; 145 | for (var fld = 0; fld < data.length; ++fld) 146 | { 147 | destination[names[fld]] = data[fld]; 148 | } 149 | callback(destination); 150 | }); 151 | } 152 | 153 | UnpackStream.prototype.get = function(length, callback) 154 | { 155 | this.read_queue.push(new ReadFixedRequest(length, callback)); 156 | this.resume(); 157 | } 158 | 159 | UnpackStream.prototype.resume = function() 160 | { 161 | if (this.resumed) 162 | return; 163 | this.resumed = true; 164 | // process all read requests until enough data in the buffer 165 | while(this.read_queue[0].execute(this)) 166 | { 167 | this.read_queue.shift(); 168 | if (this.read_queue.length == 0) 169 | return; 170 | } 171 | this.resumed = false; 172 | } 173 | 174 | UnpackStream.prototype.getbyte = function() 175 | { 176 | var res = 0; 177 | var b = this.readlist[0]; 178 | if (this.offset + 1 < b.length) 179 | { 180 | res = b[this.offset]; 181 | this.offset++; 182 | this.length--; 183 | 184 | } else { 185 | 186 | // last byte in current buffer, shift read list 187 | res = b[this.offset]; 188 | this.readlist.shift(); 189 | this.length--; 190 | this.offset = 0; 191 | } 192 | return res; 193 | } 194 | 195 | /* 196 | 197 | // write padded string 198 | // at the moment replaced with pack('p', [ 'padded_string' ]) 199 | UnpackStream.prototype.pstr = function(str) 200 | { 201 | var len = xutil.padded_length(str.length); 202 | if (len == 0) 203 | return; // nothing to write 204 | var buf = new Buffer(len); 205 | buf.write(str, 'binary'); 206 | this.write_queue.push(buf); 207 | } 208 | */ 209 | 210 | // TODO: measure node 0.5+ buffer serialisers performance 211 | UnpackStream.prototype.pack = function(format, args) 212 | { 213 | var packetlength = 0; 214 | 215 | var arg = 0; 216 | for (var i = 0; i < format.length; ++i) 217 | { 218 | var f = format[i]; 219 | if (f == 'x') 220 | { 221 | packetlength++; 222 | } else if (f == 'p') { 223 | packetlength += xutil.padded_length(args[arg++].length); 224 | } else if (f == 'a') { 225 | packetlength += args[arg].length; 226 | arg++; 227 | } else { 228 | // this is a fixed-length format, get length from argument_length table 229 | packetlength += argument_length[f]; 230 | arg++; 231 | } 232 | } 233 | 234 | var buf = new Buffer(packetlength); 235 | var offset = 0; 236 | var arg = 0; 237 | for (var i = 0; i < format.length; ++i) 238 | { 239 | switch(format[i]) 240 | { 241 | case 'x': 242 | buf[offset++] = 0; 243 | break; 244 | case 'C': 245 | var n = args[arg++]; 246 | buf[offset++] = n; 247 | break; 248 | case 's': // TODO: implement signed INT16!!! 249 | case 'S': 250 | var n = args[arg++]; 251 | buf[offset++] = n & 0xff; 252 | buf[offset++] = (n >> 8) & 0xff; 253 | break; 254 | case 'l': // TODO: implement signed INT32!!! 255 | case 'L': 256 | var n = args[arg++]; 257 | buf[offset++] = n & 0xff; 258 | buf[offset++] = (n >> 8) & 0xff; 259 | buf[offset++] = (n >> 16) & 0xff; 260 | buf[offset++] = (n >> 24) & 0xff; 261 | break; 262 | case 'a': // string or buffer 263 | var str = args[arg++]; 264 | if (Buffer.isBuffer(str)) 265 | { 266 | str.copy(buf, offset); 267 | offset += str.length; 268 | } else { 269 | // TODO: buffer.write could be faster 270 | for (var c = 0; c < str.length; ++c) 271 | buf[offset++] = str.charCodeAt(c); 272 | } 273 | break; 274 | case 'p': // padded string 275 | var str = args[arg++]; 276 | var len = padded(str); 277 | // TODO: buffer.write could be faster 278 | var c = 0; 279 | for (; c < str.length; ++c) 280 | buf[offset++] = str[c]; 281 | for (; c < len; ++c) 282 | buf[offset++] = 0; 283 | break; 284 | } 285 | } 286 | this.write_queue.push(buf); 287 | this.write_length += buf.length; 288 | return this; 289 | } 290 | 291 | UnpackStream.prototype.flush = function(stream) 292 | { 293 | // TODO: measure performance benefit of 294 | // creating and writing one big concatenated buffer 295 | 296 | // TODO: check write result 297 | // pause/resume streaming 298 | for (var i=0; i < this.write_queue.length; ++i) 299 | { 300 | //stream.write(this.write_queue[i]) 301 | this.emit('data', this.write_queue[i]); 302 | } 303 | this.write_queue = []; 304 | this.write_length = 0; 305 | } 306 | 307 | module.exports = UnpackStream; 308 | -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/xcore.js: -------------------------------------------------------------------------------- 1 | var util = require('util'); // util.inherits 2 | var net = require('net'); 3 | 4 | var handshake = require('./handshake'); 5 | //var xevents = require('./xevents'); 6 | 7 | var EventEmitter = require('events').EventEmitter; 8 | var PackStream = require('./unpackstream'); 9 | var coreRequestsTemplate = require('./corereqs'); 10 | var hexy = require('./hexy').hexy; 11 | 12 | var Buffer = require('buffer').Buffer; 13 | // add 'unpack' method for buffer 14 | require('./unpackbuffer').addUnpack(Buffer); 15 | 16 | var os = require('os'); 17 | 18 | var xerrors = require('./xerrors'); 19 | var coreRequests = require('./corereqs'); 20 | var stdatoms = require('./stdatoms'); 21 | 22 | function XClient(stream, displayNum, screenNum) 23 | { 24 | EventEmitter.call(this); 25 | this.stream = stream; 26 | 27 | this.core_requests = {}; 28 | this.ext_requests = {}; 29 | 30 | this.displayNum = displayNum; 31 | this.screenNum = screenNum; 32 | this.authHost = os.hostname(); 33 | 34 | pack_stream = new PackStream(); 35 | 36 | // data received from stream is dispached to 37 | // read requests set by calls to .unpack and .unpackTo 38 | //stream.pipe(pack_stream); 39 | 40 | // pack_stream write requests are buffered and 41 | // flushed to stream as result of call to .flush 42 | // TODO: listen for drain event and flush automatically 43 | //pack_stream.pipe(stream); 44 | 45 | pack_stream.on('data', function( data ) { 46 | //console.error(hexy(data, {prefix: 'from packer '})); 47 | //for (var i=0; i < data.length; ++i) 48 | // console.log('<<< ' + data[i]); 49 | stream.write(data); 50 | }); 51 | stream.on('data', function( data ) { 52 | //console.error(hexy(data, {prefix: 'to unpacker '})); 53 | //for (var i=0; i < data.length; ++i) 54 | // console.log('>>> ' + data[i]); 55 | pack_stream.write(data); 56 | }); 57 | 58 | this.pack_stream = pack_stream; 59 | 60 | this.rcrc_id = 0; // generated for each new resource 61 | this.seq_num = 0; // incremented in each request. (even if we don't expect reply) 62 | this.seq2stack = {}; // debug: map seq_num to stack at the moment request was issued 63 | 64 | // in/out packets indexed by sequence ID 65 | //this.requests = {}; 66 | this.replies = {}; 67 | //this.events = {}; 68 | this.atoms = stdatoms; 69 | this.event_consumers = {}; // maps window id to eventemitter TODO: bad name 70 | this.importRequestsFromTemplates(this, coreRequests); 71 | // TODO: this is potentially async and probably has to be synchronised with 'connect' event 72 | /* 73 | // import available extentions 74 | // TODO: lazy import on first call? 75 | this.ext = {}; 76 | this.ListExtensions( function(err, extentionsList ) { 77 | for (ext in extentionsList) { 78 | try { 79 | X.QueryExtension(ext, function(e) { 80 | var extRequests = require('./ext/' + extentionsList[ext]); 81 | importRequestsFromTemplates(this, extRequests); 82 | }); 83 | } catch (e) { 84 | // do not import if module not defined 85 | } 86 | } 87 | }); 88 | */ 89 | this.startHandshake(); 90 | } 91 | util.inherits(XClient, EventEmitter); 92 | 93 | // TODO: close() = set 'closing' flag, watch it in replies and writeQueue, terminate if empty 94 | XClient.prototype.terminate = function() 95 | { 96 | this.stream.end(); 97 | } 98 | 99 | XClient.prototype.importRequestsFromTemplates = function(target, reqs) 100 | { 101 | var client = this; 102 | for (r in reqs) 103 | { 104 | // r is request name 105 | target[r] = (function(reqName) { 106 | var reqFunc = function req_proxy() { 107 | client.seq_num++; // TODO: handle overflow (seq should be last 15 (?) bits of the number 108 | 109 | var err = new Error; 110 | err.name = r; 111 | Error.captureStackTrace(err, arguments.callee); 112 | client.seq2stack[client.seq_num] = err.stack; 113 | 114 | // is it fast? 115 | var args = Array.prototype.slice.call(req_proxy.arguments); 116 | 117 | var callback = args.length > 0 ? args[args.length - 1] : null; 118 | if (callback && callback.constructor.name != 'Function') 119 | callback = null; 120 | 121 | // TODO: see how much we can calculate in advance (not in each request) 122 | var reqReplTemplate = reqs[reqName]; 123 | var reqTemplate = reqReplTemplate[0]; 124 | var templateType = typeof reqTemplate; 125 | 126 | if (templateType == 'object') 127 | templateType = reqTemplate.constructor.name; 128 | 129 | if (templateType == 'function') 130 | { 131 | // call template with input arguments (not including callback which is last argument TODO currently with callback. won't hurt) 132 | //reqPack = reqTemplate.call(args); 133 | var reqPack = reqTemplate.apply(this, req_proxy.arguments); 134 | var format = reqPack[0]; 135 | var requestArguments = reqPack[1]; 136 | 137 | if (callback) 138 | this.replies[this.seq_num] = [reqReplTemplate[1], callback]; 139 | 140 | client.pack_stream.pack(format, requestArguments); 141 | var b = client.pack_stream.write_queue[0]; 142 | client.pack_stream.flush(); 143 | 144 | } else if (templateType == 'Array'){ 145 | var format = reqTemplate[0]; 146 | var requestArguments = []; 147 | 148 | for (a = 0; a < reqTemplate[1].length; ++a) 149 | requestArguments.push(reqTemplate[1][a]); 150 | for (a in args) 151 | requestArguments.push(args[a]); 152 | 153 | if (callback) 154 | this.replies[this.seq_num] = [reqReplTemplate[1], callback]; 155 | 156 | client.pack_stream.pack(format, requestArguments); 157 | client.pack_stream.flush(); 158 | } else { 159 | throw 'unknown request format - ' + templateType; 160 | } 161 | } 162 | return reqFunc; 163 | })(r); 164 | } 165 | } 166 | 167 | XClient.prototype.AllocID = function() 168 | { 169 | // TODO: handle overflow (XCMiscGetXIDRange from XC_MISC ext) 170 | // TODO: unused id buffer 171 | this.display.rsrc_id++; 172 | return (this.display.rsrc_id << this.display.rsrc_shift) + this.display.resource_base; 173 | } 174 | 175 | XClient.prototype.unpackEvent = function(type, seq, extra, code, raw) 176 | { 177 | var event = {}; // TODO: constructor & base functions 178 | event.type = type; 179 | event.seq = seq; 180 | 181 | if (type == 2 || type == 4 || type == 5 || type == 6) { // motion event 182 | var values = raw.unpack('LLLssssSC'); 183 | //event.raw = values; 184 | // TODO: use unpackTo??? 185 | event.time = extra; 186 | event.keycode = code; 187 | event.root = values[0]; 188 | event.wid = values[1]; 189 | event.child = values[2]; 190 | event.rootx = values[3]; 191 | event.rooty = values[4]; 192 | event.x = values[5]; 193 | event.y = values[6]; 194 | event.buttons = values[7]; 195 | event.sameScreen = values[8]; 196 | } else if (type == 12) { // Expose 197 | var values = raw.unpack('SSSSS'); 198 | event.wid = extra; 199 | event.x = values[0]; 200 | event.y = values[1]; 201 | event.width = values[2]; 202 | event.height = values[3]; 203 | event.count = values[4]; // TODO: ??? 204 | } else if (type == 16) { // CreateNotify 205 | var values = raw.unpack('LLSSSSS'); 206 | event.parent = extra; 207 | event.wid = values[0]; 208 | // x, y, width, height, border 209 | } else if (type == 19) { // MapNotify 210 | var values = raw.unpack('LLC'); 211 | //event.wid = extra; 212 | event.wid = values[0]; 213 | } 214 | return event; 215 | } 216 | 217 | XClient.prototype.expectReplyHeader = function() 218 | { 219 | // TODO: BigReq!!!! 220 | 221 | var client = this; 222 | client.pack_stream.get( 8, function(headerBuf) { 223 | var res = headerBuf.unpack('CCSL'); 224 | var type = res[0]; 225 | var seq_num = res[2]; 226 | 227 | if (type == 0) 228 | { 229 | var error_code = res[1]; 230 | var error = {}; 231 | error.error = error_code; 232 | error.seq = seq_num; 233 | error.message = xerrors.errorText[error_code]; 234 | error.stack = client.seq2stack[error.seq] 235 | 236 | // unpack error packet (32 bytes for all error types, 8 of them in CCSL header) 237 | client.pack_stream.get(24, function(buf) { 238 | // TODO: dispatch, use sequence number 239 | //TODO: add more generic way to read common values 240 | // if (error_code == 14) 241 | { 242 | var res = buf.unpack('LSC'); 243 | error.badParam = res[0]; // id: GC, WinID, Font, Atom etc; Value 244 | error.minorOpcode = res[1]; 245 | error.majorOpcode = res[2]; 246 | } 247 | var handler = client.replies[seq_num]; 248 | if (handler) { 249 | var callback = handler[1]; 250 | callback(error); 251 | if (!error.handled) 252 | client.emit('error', error); 253 | delete client.seq2stack[seq_num]; 254 | delete client.replies[seq_num]; 255 | } else 256 | client.emit('error', error); 257 | client.expectReplyHeader(); 258 | } ); 259 | return; 260 | } else if (type > 1) 261 | { 262 | client.pack_stream.get(24, function(buf) { 263 | var extra = res[3]; 264 | var code = res[1]; 265 | var ev = client.unpackEvent(type, seq_num, extra, code, buf); 266 | 267 | // raw event 32-bytes packet (primarily for use in SendEvent); 268 | // TODO: Event::pack based on event parameters, inverse to unpackEvent 269 | ev.rawData = new Buffer(32); 270 | headerBuf.copy(ev.rawData); 271 | buf.copy(ev.rawData, 8); 272 | 273 | client.emit('event', ev); 274 | var ee = client.event_consumers[ev.wid]; 275 | if (ee) { 276 | ee.emit('event', ev); 277 | } 278 | client.expectReplyHeader(); 279 | } ); 280 | return; 281 | } 282 | 283 | var opt_data = res[1]; 284 | var length_total = res[3]; // in 4-bytes units, _including_ this header 285 | var bodylength = 24 + length_total*4; // 24 is rest if 32-bytes header 286 | 287 | client.pack_stream.get( bodylength, function( data ) { 288 | 289 | var handler = client.replies[seq_num]; 290 | if (handler) { 291 | var unpack = handler[0]; 292 | var result = unpack( data, opt_data ); 293 | var callback = handler[1]; 294 | callback(result); 295 | // TODO: add multiple replies flag and delete handler only after last reply (eg ListFontsWithInfo) 296 | delete client.replies[seq_num]; 297 | } 298 | // wait for new packet from server 299 | client.expectReplyHeader(); 300 | }); 301 | } 302 | ); 303 | } 304 | 305 | XClient.prototype.startHandshake = function() 306 | { 307 | var client = this; 308 | 309 | handshake.writeClientHello(this.pack_stream, this.displayNum, this.authHost); 310 | handshake.readServerHello(this.pack_stream, function(display) 311 | { 312 | // TODO: readServerHello can set erro state in display 313 | // emit error in that case 314 | client.expectReplyHeader(); 315 | client.display = display; 316 | display.client = client; 317 | client.emit('connect', display); 318 | }); 319 | } 320 | 321 | XClient.prototype.require = function(extName, callback) 322 | { 323 | var ext = require('./ext/' + extName); 324 | ext.requireExt(this.display, callback); 325 | } 326 | 327 | var platformDefaultTransport = { 328 | win32: 'tcp', 329 | win64: 'tcp', 330 | cygwin: 'tcp', 331 | linux: 'unix' 332 | // TODO: check process.platform on SmartMachine solaris box 333 | } 334 | 335 | module.exports.createClient = function(initCb, display) 336 | { 337 | if (!display) 338 | display = process.env.DISPLAY; 339 | if (!display) 340 | display = ':0'; 341 | 342 | var displayMatch = display.match(/^(?:[^:]*?\/)?(.*):(\d+)(?:.(\d+))?$/); 343 | var host = displayMatch[1]; 344 | if (!host) 345 | host = '127.0.0.1'; 346 | var displayNum = displayMatch[2]; 347 | if (!displayNum) 348 | displayNum = 0; 349 | var screenNum = displayMatch[3]; 350 | if (!screenNum) 351 | screenNum = 0; 352 | 353 | // open stream 354 | var stream; 355 | var defaultTransportName = platformDefaultTransport[process.platform]; 356 | // use tcp if stated explicitly or if not defined at all 357 | if (!defaultTransportName || defaultTransportName == 'tcp' || host != '127.0.0.1') 358 | stream = net.createConnection(6000 + parseInt(displayNum), host); 359 | if (defaultTransportName == 'unix' && host == '127.0.0.1') 360 | stream = net.createConnection('/tmp/.X11-unix/X' + displayNum); 361 | 362 | var client = new XClient(stream, displayNum, screenNum); 363 | if (initCb) 364 | { 365 | client.on('connect', function(display) { 366 | initCb(display); 367 | }); 368 | } 369 | return client; 370 | } 371 | -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/xerrors.js: -------------------------------------------------------------------------------- 1 | module.exports.errorText = { 2 | 1: 'Bad request', 3 | 2: 'Bad param value', 4 | 3: 'Bad window', 5 | 4: 'Bad pixmap', 6 | 5: 'Bad atom', 7 | 6: 'Bad cursor', 8 | 7: 'Bad font', 9 | 8: 'Bad match', 10 | 9: 'Bad drawable', 11 | 10: 'Bad access', 12 | 11: 'Bad alloc', 13 | 12: 'Bad colormap', 14 | 13: 'Bad GContext', 15 | 14: 'Bad ID choice', 16 | 15: 'Bad name', 17 | 16: 'Bad length', 18 | 17: 'Bad implementation' 19 | }; 20 | -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/xproto2js.pl: -------------------------------------------------------------------------------- 1 | # convert X protocol docline 2 | # #x00000020 name 3 | # to JS line 4 | # name: x00000020 5 | while(<>) { 6 | my($line) = $_; 7 | chomp($line); 8 | if ($line =~ /(x[0-9]+)[ \t]+([^ ]+)/) 9 | { 10 | print "$2: 0$1,\n"; 11 | } 12 | } -------------------------------------------------------------------------------- /node_modules/x11/lib/x11/xutil.js: -------------------------------------------------------------------------------- 1 | function padded_length(len) 2 | { 3 | return ((len + 3) >> 2) << 2; 4 | /* 5 | var rem = len % 4; 6 | var pl = len; 7 | if (rem) 8 | return len + 4 - rem; 9 | return len; 10 | */ 11 | } 12 | 13 | // TODO: make it return buffer? 14 | // str += is slow 15 | function padded_string(str) 16 | { 17 | if (str.length == 0) 18 | return ''; 19 | 20 | var pad = padded_length(str.length) - str.length; 21 | var res = str; 22 | for (var i=0; i < pad; ++i) 23 | res += String.fromCharCode(0); 24 | 25 | return res; 26 | } 27 | 28 | module.exports.padded_length = padded_length; 29 | module.exports.padded_string = padded_string; 30 | -------------------------------------------------------------------------------- /node_modules/x11/package.json: -------------------------------------------------------------------------------- 1 | { "name" : "x11" 2 | , "author": "Andrey Sidorov " 3 | , "description": "A pure node.js JavaScript client implementing X Window (X11) protocol." 4 | , "keywords": ["X Window", "ui", "gui", "widgets", "desktop", "XWindow", "X"] 5 | , "homepage": "https://github.com/sidorares/node-x11" 6 | , "version" : "0.0.2" 7 | , "maintainers" : 8 | [ { "name": "Andrey Sidorov" 9 | , "email": "sidoares@yandex.ru" 10 | } 11 | ] 12 | , "bugs" : { "url" : "http://github.com/sidorares/node-x11/issues" } 13 | , "licenses" : [ { "type" : "MIT" } ] 14 | , "repositories" : 15 | [ { "type" : "git" 16 | , "url" : "http://github.com/sidorares/node-x11" 17 | } 18 | ] 19 | , "main" : "./lib/x11" 20 | , "engines" : { "node" : "*" } 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /node_modules/x11/roadmap.txt: -------------------------------------------------------------------------------- 1 | + 0) $DISPLAY parser 2 | + 0.1) basic connection setup, tcp/unix socket, unix/win 3 | + 1) x11 core protocol parser: handshake (no auth), request, reply, events, errors. Requests, replies and events queues. 4 | + 2) handwritten basic requests: CreateWindow, MapWindow, basic GC, simple examples 5 | 6 | 3) extensions support 7 | 3.5) XRender examples, FreeType or Xft wrapper (native module? ffi? https://github.com/rbranson/node-ffi/ http://www.freetype.org/freetype2/docs/tutorial/step1.html example) 8 | 9 | 4) tool to automatically generate requests from xcb xml description http://xcb.freedesktop.org/XmlXcb/ http://cgit.freedesktop.org/xcb/proto/tree/src?id=HEAD 10 | ( https://github.com/CrypticSwarm/XCBJS ) 11 | 12 | + 5) authorisation 13 | 6) examples: js implementation for basic X utilities: xev, xeyes, xclock, xclip, xauth, xkill, xlsatoms, glxgears etc. 14 | 7) vnc client using https://github.com/substack/node-rfb 15 | 8) rdesktop client using https://github.com/substack/node-rdesktop 16 | 9) widget implementing basic subset of html5 canvas api using https://github.com/learnboost/node-canvas or https://github.com/ajaxorg/node-o3-canvas 17 | 10) pdf viewer using https://github.com/andreasgal/pdf.js/, (ODF viewer? - http://webodf.org/demo/) 18 | 12) ICCCM library http://www.x.org/docs/ICCCM/icccm.pdf http://tronche.com/gui/x/icccm/ 19 | 11) pure js window manager 20 | 12) general purpose widgets set, layout managers, box model 21 | 13) pure js web browser :) -------------------------------------------------------------------------------- /node_modules/x11/test/alloccolor.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var Exposure = x11.eventMask.Exposure; 5 | var PointerMotion = x11.eventMask.PointerMotion; 6 | var pts = []; 7 | 8 | xclient.on('connect', function(display) { 9 | var X = this; 10 | var root = display.screen[0].root; 11 | var white = display.screen[0].white_pixel; 12 | var black = display.screen[0].black_pixel; 13 | 14 | var wid = X.AllocID(); 15 | X.CreateWindow( 16 | wid, root, 17 | 10, 10, 400, 300, 18 | 1, 1, 0, 19 | { 20 | backgroundPixel: white, eventMask: Exposure|PointerMotion 21 | } 22 | ); 23 | X.MapWindow(wid); 24 | 25 | var gc = X.AllocID(); 26 | X.AllocColor(display.screen[0].default_colormap, 0xffff, 0, 0, function(redcolor) { 27 | // todo: it is possible for PolyLine to be called before CreateGC! 28 | console.log(redcolor); 29 | X.CreateGC(gc, wid, { foreground: redcolor.pixel, background: white } ); 30 | }); 31 | 32 | X.on('event', function(ev) { 33 | if (ev.type == 12) 34 | { 35 | if (pts.length > 4) 36 | X.PolyLine(0, wid, gc, pts); 37 | } else if (ev.type == 6) { 38 | pts.push(ev.x); 39 | pts.push(ev.y); 40 | if (pts.length > 4) 41 | X.PolyLine(0, wid, gc, pts.slice(-4)); 42 | } 43 | }); 44 | 45 | X.on('error', function(e) { 46 | console.log(e); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /node_modules/x11/test/atom_benchmark_buffered.js: -------------------------------------------------------------------------------- 1 | // WinServ2008R2 64bit, Intel(R) Core(TM) i7 CPU 870 @2.93GHz, Xming 6.9.0.31 2 | // 0.4.3/cygwin 32bit: 12000 +/-1000 InternAtom/sec 3 | // 0.5.1/win32 : 12000 +/-1000 4 | 5 | // Ubuntu 11.04 32bit, Intel(R) Core(TM)2 Duo CPU T7250 @2.00GHz, XOrg 1:7.6+4ubuntu3.1 6 | // 0.4.9pre: 23300 +/-200 7 | 8 | 9 | var x11 = require('../lib/x11'); 10 | 11 | var xclient = x11.createClient(); 12 | var counter = 0; 13 | var t = +new Date(); 14 | var t0 = t; 15 | var num = 100000; 16 | xclient.on('connect', function(display) { 17 | console.log(display); 18 | process.exit(0); 19 | var X = this; 20 | for (var i=0; i < num; ++i) 21 | { 22 | var hello = 'Hello, node.js ' + i; 23 | X.InternAtom(false, hello, function(atomId) { 24 | if (counter == 0) 25 | { 26 | var t1 = +new Date(); 27 | console.log('first reply after sending %d atoms in %d ms', num, t1-t); 28 | t = t1; 29 | } 30 | //console.log('atom %d saved on server', atomId); 31 | 32 | if ((counter % 10000) == 0) 33 | { 34 | var t1 = +new Date(); 35 | console.log('received 10000 (up to %d) atom ids in %d ms', counter, t1 - t); 36 | t = t1; 37 | } 38 | 39 | counter++; 40 | if (counter == (num-1)) 41 | { 42 | var t1 = +new Date(); 43 | var delta = t1 - t0; 44 | console.log(delta); 45 | console.log('reqs/msec: ' + num/delta); 46 | console.log('msec per req: ' + delta/num); 47 | process.exit(0); // TODO: X.end() ? 48 | } 49 | }); 50 | } 51 | }); 52 | -------------------------------------------------------------------------------- /node_modules/x11/test/atom_benchmark_parallel.js: -------------------------------------------------------------------------------- 1 | // test results: 2 | 3 | // WinServ2008R2, Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz + Xming 6.9.0.31 4 | // 5 | // 0.4.3/cygwin 32bit : 8500 +/- 2000 InternAtom/sec 6 | // 0.5.1/win32 : N/A 7 | // 8 | // Ubuntu 11.04 32bit, Intel(R) Core(TM)2 Duo CPU T7250 @2.00GHz, XOrg 1:7.6+4ubuntu3.1 9 | // 0.4.9pre: 16700 +/-300 10 | 11 | 12 | var x11 = require('../lib/x11'); 13 | 14 | var xclient = x11.createClient(); 15 | var reqcounter = 0; 16 | var rescounter = 0; 17 | 18 | var num = 400000; 19 | var X; 20 | 21 | var t0 = +new Date(); 22 | 23 | function benchmarkAtoms() 24 | { 25 | if (reqcounter > num) 26 | return; 27 | 28 | X.InternAtom(false, 'test ' + reqcounter, function(atomId) { 29 | rescounter++; 30 | //console.log('%d received', rescounter); 31 | if ( (rescounter % 10000) == 0) 32 | { 33 | var t2 = X.t1; 34 | X.t1 = +new Date(); 35 | var delta = X.t1 - t2; 36 | console.log(reqcounter - rescounter); 37 | console.log('reqs/msec: ' + 10000/delta); 38 | console.log('msec per req: ' + delta/10000); 39 | } 40 | if (rescounter == (num-2)) 41 | { 42 | var t1 = +new Date(); 43 | var delta = t1 - t0; 44 | console.log(delta); 45 | console.log('reqs/msec: ' + num/delta); 46 | console.log('msec per req: ' + delta/num); 47 | 48 | process.exit(0); 49 | } 50 | }); 51 | 52 | reqcounter++; 53 | //console.log('%d sent', reqcounter); 54 | process.nextTick(benchmarkAtoms); 55 | } 56 | 57 | 58 | 59 | xclient.on('connect', function(display) { 60 | X = this; 61 | X.t1 = +new Date(); 62 | benchmarkAtoms(); 63 | }); 64 | -------------------------------------------------------------------------------- /node_modules/x11/test/atoms.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | 5 | xclient.on('connect', function(display) { 6 | var X = this; 7 | var hello = 'Hello, node.js'; 8 | X.InternAtom(false, hello, function(atomId) { 9 | X.GetAtomName(atomId, function(str) { 10 | console.log('Value for atom ' + atomId + ' is \"' + str + '\"'); 11 | }); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /node_modules/x11/test/bmp.js: -------------------------------------------------------------------------------- 1 | // http://atlc.sourceforge.net/bmp.html 2 | // Any better format documentation? 3 | 4 | var fs = require('fs'); 5 | var Pixmap = require('./pixmap').Pixmap; 6 | var Buffer = require('buffer').Buffer; 7 | require('../lib/x11/unpackbuffer').addUnpack(Buffer); 8 | 9 | var reversed = new Buffer(256); 10 | for (var i=0; i < 256; ++i) 11 | { 12 | var res = 0; 13 | for (b = 0; b < 8; ++b) 14 | { 15 | res += ((i & (1 << b) ) >> b) << (7-b); 16 | } 17 | reversed[i] = res; 18 | } 19 | 20 | module.exports.decodeBuffer = function(buffer) 21 | { 22 | var h = buffer.unpack('CCLxxxxLLLLSSLLLL'); 23 | var header = {}; 24 | header.filesize = h[2]; 25 | header.data_offset = h[3]; 26 | header.header_size = h[4]; 27 | header.width = h[5]; 28 | header.height = h[6]; 29 | header.num_planes = h[7]; 30 | header.bpp = h[8]; 31 | header.compression = h[9]; 32 | header.data_size = h[10]; 33 | header.hresolution = h[11]; // pixels per METER! 34 | header.vresolution = h[12]; 35 | // skipped: num colors, num important colors, palette 36 | var data = buffer.slice(header.data_offset, header.data_offset+header.data_size); 37 | // TODO: decode compressed bitmap 38 | //console.log(header); 39 | 40 | // mirror bits & invert 41 | for (var i=0; i < data.length; ++i) 42 | data[i] = 255 - reversed[data[i]]; 43 | 44 | return new Pixmap(header.bpp, header.width, header.height, data); 45 | } -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Makefile: -------------------------------------------------------------------------------- 1 | LDFLAGS=-lX11 2 | 3 | simplewin: simplewin.o 4 | -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Xlib_JPEG_Example-8.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/c-tests/Xlib_JPEG_Example-8.tgz -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc -g 2 | CINCLUDE=-I/usr/X11R6/include -I/usr/local/include 3 | CFLAGS=-Wall -g 4 | LFLAGS= -L/usr/local/lib /home/laplace/libX11-1.4.0/src/.libs/libX11.so.6.3.0 -ljpeg -lm 5 | #LFLAGS= -L/usr/local/lib /home/laplace/libX11-1.4.0/src/.libs/*.o /home/laplace/libX11-1.4.0/src/xcms/.libs/*.o /home/laplace/libX11-1.4.0/src/xlibi18n/.libs/*.o /home/laplace/libX11-1.4.0/src/xkb/.libs/*.o -ljpeg -lm 6 | 7 | all: Xlib_JPEG_Example 8 | 9 | Xlib_JPEG_Example: Xlib_JPEG_Example.c 10 | $(CC) $(CFLAGS) Xlib_JPEG_Example.c $(CINCLUDE) $(LFLAGS) -o Xlib_JPEG_Example 11 | 12 | clean: 13 | rm -f Xlib_JPEG_Example *.o *.core 14 | -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/Xlib_JPEG_Example: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/Xlib_JPEG_Example -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/Xlib_JPEG_Example.c: -------------------------------------------------------------------------------- 1 | /*Copyright George Peter Staplin 2003*/ 2 | 3 | /*You may use/copy/modify/distribute this software for any purpose 4 | *provided that I am given credit and you don't sue me for any bugs. 5 | */ 6 | 7 | /*Please contact me using GeorgePS@XMission.com if you like this, or 8 | *have questions. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #ifndef u_char 22 | #define u_char unsigned char 23 | #endif 24 | 25 | int get_byte_order (void) { 26 | union { 27 | char c[sizeof(short)]; 28 | short s; 29 | } order; 30 | 31 | order.s = 1; 32 | if ((1 == order.c[0])) { 33 | return LSBFirst; 34 | } else { 35 | return MSBFirst; 36 | } 37 | } 38 | 39 | void jpeg_error_exit (j_common_ptr cinfo) { 40 | cinfo->err->output_message (cinfo); 41 | exit (EXIT_FAILURE); 42 | } 43 | 44 | /*This returns an array for a 24 bit image.*/ 45 | u_char *decode_jpeg (char *filename, int *widthPtr, int *heightPtr) { 46 | register JSAMPARRAY lineBuf; 47 | struct jpeg_decompress_struct cinfo; 48 | struct jpeg_error_mgr err_mgr; 49 | int bytesPerPix; 50 | FILE *inFile; 51 | u_char *retBuf; 52 | 53 | inFile = fopen (filename, "rb"); 54 | if (NULL == inFile) { 55 | perror (NULL); 56 | return NULL; 57 | } 58 | 59 | cinfo.err = jpeg_std_error (&err_mgr); 60 | err_mgr.error_exit = jpeg_error_exit; 61 | 62 | jpeg_create_decompress (&cinfo); 63 | jpeg_stdio_src (&cinfo, inFile); 64 | jpeg_read_header (&cinfo, 1); 65 | cinfo.do_fancy_upsampling = 0; 66 | cinfo.do_block_smoothing = 0; 67 | jpeg_start_decompress (&cinfo); 68 | 69 | *widthPtr = cinfo.output_width; 70 | *heightPtr = cinfo.output_height; 71 | bytesPerPix = cinfo.output_components; 72 | 73 | lineBuf = cinfo.mem->alloc_sarray ((j_common_ptr) &cinfo, JPOOL_IMAGE, (*widthPtr * bytesPerPix), 1); 74 | retBuf = malloc (3 * (*widthPtr * *heightPtr)); 75 | 76 | if (NULL == retBuf) { 77 | perror (NULL); 78 | return NULL; 79 | } 80 | 81 | 82 | if (3 == bytesPerPix) { 83 | int lineOffset = (*widthPtr * 3); 84 | int x; 85 | int y; 86 | 87 | for (y = 0; y < cinfo.output_height; ++y) { 88 | jpeg_read_scanlines (&cinfo, lineBuf, 1); 89 | 90 | for (x = 0; x < lineOffset; ++x) { 91 | retBuf[(lineOffset * y) + x] = lineBuf[0][x]; 92 | ++x; 93 | retBuf[(lineOffset * y) + x] = lineBuf[0][x]; 94 | ++x; 95 | retBuf[(lineOffset * y) + x] = lineBuf[0][x]; 96 | } 97 | } 98 | } else if (1 == bytesPerPix) { 99 | unsigned int col; 100 | int lineOffset = (*widthPtr * 3); 101 | int lineBufIndex; 102 | int x ; 103 | int y; 104 | 105 | for (y = 0; y < cinfo.output_height; ++y) { 106 | jpeg_read_scanlines (&cinfo, lineBuf, 1); 107 | 108 | lineBufIndex = 0; 109 | for (x = 0; x < lineOffset; ++x) { 110 | col = lineBuf[0][lineBufIndex]; 111 | 112 | retBuf[(lineOffset * y) + x] = col; 113 | ++x; 114 | retBuf[(lineOffset * y) + x] = col; 115 | ++x; 116 | retBuf[(lineOffset * y) + x] = col; 117 | 118 | ++lineBufIndex; 119 | } 120 | } 121 | } else { 122 | fprintf (stderr, "Error: the number of color channels is %d. This program only handles 1 or 3\n", bytesPerPix); 123 | return NULL; 124 | } 125 | jpeg_finish_decompress (&cinfo); 126 | jpeg_destroy_decompress (&cinfo); 127 | fclose (inFile); 128 | 129 | return retBuf; 130 | } 131 | 132 | XImage *create_image_from_buffer (Display *dis, int screen, u_char *buf, int width, int height) { 133 | int depth; 134 | XImage *img = NULL; 135 | Visual *vis; 136 | double rRatio; 137 | double gRatio; 138 | double bRatio; 139 | int outIndex = 0; 140 | int i; 141 | int numBufBytes = (3 * (width * height)); 142 | 143 | depth = DefaultDepth (dis, screen); 144 | vis = DefaultVisual (dis, screen); 145 | 146 | rRatio = vis->red_mask / 255.0; 147 | gRatio = vis->green_mask / 255.0; 148 | bRatio = vis->blue_mask / 255.0; 149 | 150 | if (depth >= 24) { 151 | size_t numNewBufBytes = (4 * (width * height)); 152 | u_int32_t *newBuf = malloc (numNewBufBytes); 153 | 154 | for (i = 0; i < numBufBytes; ++i) { 155 | unsigned int r, g, b; 156 | r = (buf[i] * rRatio); 157 | ++i; 158 | g = (buf[i] * gRatio); 159 | ++i; 160 | b = (buf[i] * bRatio); 161 | 162 | r &= vis->red_mask; 163 | g &= vis->green_mask; 164 | b &= vis->blue_mask; 165 | 166 | newBuf[outIndex] = r | g | b; 167 | ++outIndex; 168 | } 169 | 170 | img = XCreateImage (dis, 171 | CopyFromParent, depth, 172 | ZPixmap, 0, 173 | (char *) newBuf, 174 | width, height, 175 | 32, 0 176 | ); 177 | 178 | } else if (depth >= 15) { 179 | size_t numNewBufBytes = (2 * (width * height)); 180 | u_int16_t *newBuf = malloc (numNewBufBytes); 181 | 182 | for (i = 0; i < numBufBytes; ++i) { 183 | unsigned int r, g, b; 184 | 185 | r = (buf[i] * rRatio); 186 | ++i; 187 | g = (buf[i] * gRatio); 188 | ++i; 189 | b = (buf[i] * bRatio); 190 | 191 | r &= vis->red_mask; 192 | g &= vis->green_mask; 193 | b &= vis->blue_mask; 194 | 195 | newBuf[outIndex] = r | g | b; 196 | ++outIndex; 197 | } 198 | 199 | img = XCreateImage (dis, 200 | CopyFromParent, depth, 201 | ZPixmap, 0, 202 | (char *) newBuf, 203 | width, height, 204 | 16, 0 205 | ); 206 | } else { 207 | fprintf (stderr, "This program does not support displays with a depth less than 15."); 208 | return NULL; 209 | } 210 | 211 | XInitImage (img); 212 | /*Set the client's byte order, so that XPutImage knows what to do with the data.*/ 213 | /*The default in a new X image is the server's format, which may not be what we want.*/ 214 | if ((LSBFirst == get_byte_order ())) { 215 | img->byte_order = LSBFirst; 216 | } else { 217 | img->byte_order = MSBFirst; 218 | } 219 | 220 | /*The bitmap_bit_order doesn't matter with ZPixmap images.*/ 221 | img->bitmap_bit_order = MSBFirst; 222 | 223 | return img; 224 | } 225 | 226 | void img2json(XImage *img) 227 | { 228 | int i=0; 229 | 230 | printf("{\n bitmap_bit_order: %d,\n", img->bitmap_bit_order); 231 | printf(" width: %d,", img->width); 232 | printf(" height: %d,", img->height); 233 | printf(" depth: %d,", img->depth); 234 | printf(" format: %d,", img->format); 235 | printf(" data: \""); 236 | for (i=0; i < img->width*img->height*4; ++i) 237 | printf("\\ux00%x", (unsigned char)img->data[i]); 238 | printf("\",\n"); 239 | printf("}"); 240 | exit(0); 241 | } 242 | 243 | Window create_window (Display *dis, int screen, int x, int y, int width, int height) { 244 | Window win; 245 | unsigned long windowMask; 246 | XSetWindowAttributes winAttrib; 247 | 248 | windowMask = CWBackPixel | CWBorderPixel; 249 | winAttrib.border_pixel = BlackPixel (dis, screen); 250 | winAttrib.background_pixel = BlackPixel (dis, screen); 251 | winAttrib.override_redirect = 0; 252 | 253 | win = XCreateWindow (dis, DefaultRootWindow (dis), 254 | x, y, 255 | width, height, 256 | 0, DefaultDepth (dis, screen), 257 | InputOutput, CopyFromParent, 258 | windowMask, &winAttrib 259 | ); 260 | 261 | return win; 262 | } 263 | 264 | int main (int argc, char *argv[]) { 265 | int imageWidth; 266 | int imageHeight; 267 | XImage *img; 268 | Window mainWin; 269 | int screen; 270 | Display *dis; 271 | u_char *buf; 272 | GC copyGC; 273 | 274 | if (2 != argc) { 275 | fprintf (stderr, "please specify a filename to %s\n", argv[0]); 276 | exit (EXIT_FAILURE); 277 | } 278 | 279 | buf = decode_jpeg (argv[1], &imageWidth, &imageHeight); 280 | 281 | if (NULL == buf) { 282 | fprintf (stderr, "unable to decode JPEG"); 283 | exit (EXIT_FAILURE); 284 | } 285 | 286 | dis = XOpenDisplay (NULL); 287 | screen = DefaultScreen (dis); 288 | 289 | img = create_image_from_buffer (dis, screen, buf, imageWidth, imageHeight); 290 | 291 | if (NULL == img) { 292 | exit (EXIT_FAILURE); 293 | } 294 | 295 | img2json(img); 296 | printf("Depth: %d Format: %d\n", img->depth, img->format); 297 | 298 | /*create_image_from_buffer creates a new buffer after translation, so we can free. 299 | */ 300 | free (buf); 301 | 302 | mainWin = create_window (dis, screen, 20, 20, imageWidth, imageHeight); 303 | copyGC = XCreateGC (dis, mainWin, 0, NULL); 304 | 305 | XMapRaised (dis, mainWin); 306 | 307 | XSelectInput(dis, mainWin, ExposureMask | KeyPressMask); 308 | 309 | while (1) { 310 | XEvent event; 311 | XNextEvent (dis, &event); 312 | switch (event.type) { 313 | case Expose: 314 | XPutImage (dis, mainWin, copyGC, img, 0, 0, 0, 0, imageWidth, imageHeight); 315 | XFlush (dis); 316 | break; 317 | case KeyPress: 318 | if (XK_q == XLookupKeysym (&event.xkey, 0)) { 319 | exit (EXIT_SUCCESS); 320 | } 321 | break; 322 | } 323 | } 324 | /*We shouldn't reach this point.*/ 325 | return EXIT_FAILURE; 326 | } 327 | -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/feh_003912_000001_keyboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/feh_003912_000001_keyboard.png -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/i01500.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/i01500.jpg -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/keyboard.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/keyboard.jpg -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/keyboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/keyboard.png -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/pod10_small.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/pod10_small.jpg -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/rgb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/c-tests/Xlib_JPEG_Example-8/rgb.jpg -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/c-tests/a.out -------------------------------------------------------------------------------- /node_modules/x11/test/c-tests/simplewin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | Display *d; 8 | Window w, w1; 9 | XEvent e; 10 | char *msg = "Hello, world!"; 11 | int s; 12 | 13 | d = XOpenDisplay(NULL); 14 | if (d == NULL) { 15 | fprintf(stderr, "Cannot open display\n"); 16 | exit(1); 17 | } 18 | 19 | s = DefaultScreen(d); 20 | w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, 21 | BlackPixel(d, s), WhitePixel(d, s)); 22 | 23 | w1 = XCreateSimpleWindow(d, RootWindow(d, s), 50, 50, 50, 50, 1, 24 | BlackPixel(d, s), WhitePixel(d, s)); 25 | XSelectInput(d, w, ExposureMask | KeyPressMask); 26 | XSelectInput(d, w1, ExposureMask); 27 | XMapWindow(d, w); 28 | XMapWindow(d, w1); 29 | 30 | while (1) { 31 | XNextEvent(d, &e); 32 | if (e.type == Expose) { 33 | XFillRectangle(e.xany.display, e.xany.window, DefaultGC(d, s), 20, 20, 10, 10); 34 | XDrawString(e.xany.display, e.xany.window, DefaultGC(d, s), 10, 50, msg, strlen(msg)); 35 | } 36 | if (e.type == KeyPress) 37 | break; 38 | } 39 | 40 | XCloseDisplay(d); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /node_modules/x11/test/changeprop.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var PointerMotion = x11.eventMask.PointerMotion; 5 | 6 | xclient.on('connect', function(display) { 7 | var X = this; 8 | var root = display.screen[0].root; 9 | var wid = X.AllocID(); 10 | var white = display.screen[0].white_pixel; 11 | var black = display.screen[0].black_pixel; 12 | 13 | X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: PointerMotion }); 14 | X.MapWindow(wid); 15 | 16 | // mode: 0 replace, 1 prepend, 2 append 17 | // mode, wid, name, type, format, data 18 | X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS'); 19 | setInterval(function() { 20 | X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS ' + new Date()); 21 | }, 100); 22 | }); -------------------------------------------------------------------------------- /node_modules/x11/test/color.c: -------------------------------------------------------------------------------- 1 | static char rcsid [] = 2 | "$Header: /u/04c/mnt/integ/tools/src/RCS/color.c,v 1.2 89/09/05 13:48:03 little Exp $"; 3 | 4 | /* 5 | $Log: color.c,v $ 6 | * Revision 1.2 89/09/05 13:48:03 little 7 | * this came from steve, not sure what he changed 8 | * 9 | */ 10 | 11 | 12 | #include "snap.h" 13 | 14 | 15 | /*--------------------------------------------------------------------------*\ 16 | | 17 | | Distribution: Approved for public release; distribution is unlimited. 18 | | 19 | | Copyright (c) 1989 by Carnegie Mellon University, Pittsburgh, PA. The 20 | | Software Engineering Institute (SEI) is a federally funded research and 21 | | development center established and operated by Carnegie Mellon University 22 | | (CMU). Sponsored by the U.S. Department of Defense under contract 23 | | F19628-85-C-0003, the SEI is supported by the services and defense 24 | | agencies, with the U.S. Air Force as the executive contracting agent. 25 | | 26 | | Permission to use, copy, modify, or distribute this software and its 27 | | documentation for any purpose and without fee is hereby granted, provided 28 | | that the above copyright notice appear in all copies and that both that 29 | | copyright notice and this permission notice appear in supporting 30 | | documentation. Further, the names Software Engineering Institute or 31 | | Carnegie Mellon University may not be used in advertising or publicity 32 | | pertaining to distribution of the software without specific, written prior 33 | | permission. CMU makes no claims or representations about the suitability 34 | | of this software for any purpose. This software is provided "as is" and no 35 | | warranty, express or implied, is made by the SEI or CMU, as to the 36 | | accuracy and functioning of the program and related program material, nor 37 | | shall the fact of distribution constitute any such warranty. No 38 | | responsibility is assumed by the SEI or CMU in connection herewith. 39 | | 40 | \*--------------------------------------------------------------------------*/ 41 | 42 | 43 | /* 44 | * Macros 45 | * 46 | * The ROUNDUP macro rounds up a quantity to the specified boundary. 47 | * 48 | * The XYNORMALIZE macro determines whether XY format data requires 49 | * normalization and calls a routine to do so if needed. The logic in 50 | * this module is designed for LSBFirst byte and bit order, so 51 | * normalization is done as required to present the data in this order. 52 | * 53 | * The ZNORMALIZE macro performs byte and nibble order normalization if 54 | * required for Z format data. 55 | * 56 | * The XYINDEX macro computes the index to the starting byte (char) boundary 57 | * for a bitmap_unit containing a pixel with coordinates x and y for image 58 | * data in XY format. 59 | * 60 | * The ZINDEX macro computes the index to the starting byte (char) boundary 61 | * for a pixel with coordinates x and y for image data in ZPixmap format. 62 | * 63 | */ 64 | 65 | #define ROUNDUP(nbytes, pad) ((((nbytes) + ((pad) - 1)) / (pad)) * (pad)) 66 | 67 | #define XYNORMALIZE(bp, nbytes, img) \ 68 | if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \ 69 | _normalizeimagebits((unsigned char *)(bp), (nbytes), img->byte_order, img->bitmap_unit, \ 70 | img->bitmap_bit_order) 71 | 72 | #define ZNORMALIZE(bp, nbytes, img) \ 73 | if (img->byte_order == MSBFirst) \ 74 | _normalizeimagebits((unsigned char *)(bp), (nbytes), MSBFirst, img->bits_per_pixel, \ 75 | LSBFirst) 76 | 77 | #define XYINDEX(x, y, img) \ 78 | ((y) * img->bytes_per_line) + \ 79 | (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3) 80 | 81 | #define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \ 82 | (((x) * img->bits_per_pixel) >> 3) 83 | 84 | 85 | extern unsigned char _reverse_byte[0x100]; /* found in XPutImage */ 86 | static char _lomask[0x09] = { 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; 87 | static char _himask[0x09] = { 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00 }; 88 | 89 | static _normalizeimagebits (bpt, nb, byteorder, unitsize, bitorder) 90 | unsigned char *bpt; /* beginning pointer to image bits */ 91 | int nb; /* number of bytes to normalize */ 92 | int byteorder; /* swap bytes if byteorder == MSBFirst */ 93 | int unitsize; /* size of the bitmap_unit or Zpixel */ 94 | int bitorder; /* swap bits if bitorder == MSBFirst */ 95 | { 96 | if ((byteorder==MSBFirst) && (byteorder!=bitorder)) { 97 | register char c; 98 | register unsigned char *bp = bpt; 99 | register unsigned char *ep = bpt + nb; 100 | register unsigned char *sp; 101 | switch (unitsize) { 102 | 103 | case 4: 104 | do { /* swap nibble */ 105 | *bp = ((*bp >> 4) & 0xF) | ((*bp << 4) & ~0xF); 106 | bp++; 107 | } 108 | while (bp < ep); 109 | break; 110 | 111 | case 16: 112 | do { /* swap short */ 113 | c = *bp; 114 | *bp = *(bp + 1); 115 | bp++; 116 | *bp = c; 117 | bp++; 118 | } 119 | while (bp < ep); 120 | break; 121 | 122 | case 24: 123 | do { /* swap three */ 124 | c = *(bp + 2); 125 | *(bp + 2) = *bp; 126 | *bp = c; 127 | bp += 3; 128 | } 129 | while (bp < ep); 130 | break; 131 | 132 | case 32: 133 | do { /* swap long */ 134 | sp = bp + 3; 135 | c = *sp; 136 | *sp = *bp; 137 | *bp++ = c; 138 | sp = bp + 1; 139 | c = *sp; 140 | *sp = *bp; 141 | *bp++ = c; 142 | bp += 2; 143 | } 144 | while (bp < ep); 145 | break; 146 | } 147 | } 148 | if (bitorder == MSBFirst) { 149 | do { 150 | *bpt = _reverse_byte[*bpt]; 151 | bpt++; 152 | } 153 | while (--nb > 0); 154 | } 155 | } 156 | 157 | 158 | static _putbits (src, dstoffset, numbits, dst) 159 | register char *src; /* address of source bit string */ 160 | long dstoffset; /* bit offset into destination; range is 0-31 */ 161 | register int numbits;/* number of bits to copy to destination */ 162 | register char *dst; /* address of destination bit string */ 163 | { 164 | register unsigned char chlo, chhi; 165 | int hibits; 166 | dst = dst + (dstoffset >> 3); 167 | dstoffset = dstoffset & 7; 168 | hibits = 8 - dstoffset; 169 | chlo = *dst & _lomask[dstoffset]; 170 | for (;;) { 171 | chhi = (*src << dstoffset) & _himask[dstoffset]; 172 | if (numbits <= hibits) { 173 | chhi = chhi & _lomask[dstoffset + numbits]; 174 | *dst = (*dst & _himask[dstoffset + numbits]) | chlo | chhi; 175 | break; 176 | } 177 | *dst = chhi | chlo; 178 | dst++; 179 | numbits = numbits - hibits; 180 | chlo = (unsigned char) (*src & _himask[hibits]) >> hibits; 181 | src++; 182 | if (numbits <= dstoffset) { 183 | chlo = chlo & _lomask[numbits]; 184 | *dst = (*dst & _himask[numbits]) | chlo; 185 | break; 186 | } 187 | numbits = numbits - dstoffset; 188 | } 189 | } 190 | 191 | 192 | 193 | unsigned long pixel_get(ximage, x, y) 194 | register XImage *ximage; 195 | int x, y; 196 | { 197 | unsigned long pixel, px; 198 | register char *src, *dst; 199 | register int i; 200 | int bits, nbytes; 201 | src = &ximage->data[ZINDEX(x, y, ximage)]; 202 | dst = (char *)&px; 203 | px = 0; 204 | nbytes = ROUNDUP(ximage->bits_per_pixel, 8) >> 3; 205 | for (i=0; i < nbytes; i++) *dst++ = *src++; 206 | ZNORMALIZE(&px, nbytes, ximage); 207 | pixel = 0; 208 | for (i=sizeof(unsigned long); --i >= 0; ) 209 | pixel = (pixel << 8) | ((unsigned char *)&px)[i]; 210 | if (ximage->bits_per_pixel == 4) { 211 | if (x & 1) 212 | pixel >>= 4; 213 | else 214 | pixel &= 0xf; 215 | } 216 | return pixel; 217 | } 218 | 219 | 220 | void pixel_put(ximage, x, y, pixel) 221 | register XImage *ximage; 222 | int x, y; 223 | unsigned long pixel; 224 | { 225 | unsigned long px; 226 | register char *src, *dst; 227 | register int i; 228 | int nbytes; 229 | 230 | src = &ximage->data[XYINDEX(x, y, ximage)]; 231 | dst = (char *)&px; 232 | px = 0; 233 | nbytes = ximage->bitmap_unit >> 3; 234 | for (i=0; i < nbytes; i++) *dst++ = *src++; 235 | XYNORMALIZE(&px, nbytes, ximage); 236 | i = ((x + ximage->xoffset) % ximage->bitmap_unit); 237 | _putbits ((char *)&pixel, i, 1, (char *)&px); 238 | XYNORMALIZE(&px, nbytes, ximage); 239 | src = (char *) &px; 240 | dst = &ximage->data[XYINDEX(x, y, ximage)]; 241 | for (i=0; i < nbytes; i++) *dst++ = *src++; 242 | } 243 | 244 | int b0[16] = { 245 | 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1}; 246 | int b1[16] = { 247 | 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1}; 248 | int b2[16] = { 249 | 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1}; 250 | int b3[16] = { 251 | 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1}; 252 | 253 | XImage *transform(ximage1) 254 | XImage *ximage1; 255 | { 256 | register unsigned long pixel; 257 | register int x, y; 258 | XColor cl; 259 | int r, index; 260 | int line; 261 | double f; 262 | XImage *ximage2; 263 | char *data; 264 | int white = 1, black = 0; 265 | 266 | if (ximage1->bits_per_pixel == 4) { 267 | if (reverse) { 268 | white = 0; 269 | black = 1; 270 | } 271 | line = ROUNDUP(ximage1->width, ximage1->bitmap_pad) >> 3; 272 | data = (char *)malloc(line * ximage1->height); 273 | line = line << 3; 274 | if (debug > 2) { 275 | printf("oldwidth = %d, newwidth = %d\n", 276 | ximage1->width, line); 277 | } 278 | ximage2 = XCreateImage(dpy, win_info.visual, 1, ZPixmap, 0, 279 | data, line, ximage1->height, 280 | ximage1->bitmap_pad, 0); 281 | 282 | for (y = 0; y < ximage1->height; y++) 283 | for (x = 0; x < line; x++) { 284 | if (x < ximage1->width) { 285 | pixel = pixel_get(ximage1, 2*x, 2*y); 286 | if (debug > 2) 287 | printf("=> (%d,%d): pixel = %d\n", x, y, pixel); 288 | if (pixel == XWhitePixel(dpy, 0)) index = white; 289 | else index = black; 290 | pixel_put(ximage2, x, y, index); 291 | } 292 | else 293 | pixel_put(ximage2, x, y, white); 294 | } 295 | } 296 | else { 297 | line = ROUNDUP(ximage1->width * 2, ximage1->bitmap_pad) >> 3; 298 | data = (char *)malloc(line * ximage1->height * 2); 299 | line = line << 3; 300 | if (debug > 2) { 301 | printf("oldwidth = %d, newwidth = %d\n", 302 | ximage1->width, line); 303 | } 304 | ximage2 = XCreateImage(dpy, win_info.visual, 1, ZPixmap, 0, 305 | data, line, ximage1->height * 2, 306 | ximage1->bitmap_pad, 0); 307 | line = line >> 1; 308 | 309 | for (y = 0; y < ximage1->height; y++) 310 | for (x = 0; x < line; x++) { 311 | if (x < ximage1->width) { 312 | pixel = pixel_get(ximage1, x, y); 313 | if (debug > 2) 314 | printf("=> (%d,%d): pixel = %d", x, y, pixel); 315 | if (pixel == XWhitePixel(dpy, 0)) index = 15; 316 | else if (pixel == XBlackPixel(dpy, 0)) index = 0; 317 | else { 318 | cl = color[pixel]; 319 | f = (0.3 * cl.red) + (0.59 * cl.green) + (0.11 * cl.blue); 320 | if (debug > 2) 321 | printf(" & intensity = %f\n", f); 322 | r = f; 323 | index = r >> 12; 324 | } 325 | pixel_put(ximage2, 2*x, 2*y, b0[index]); 326 | pixel_put(ximage2, 2*x+1, 2*y, b1[index]); 327 | pixel_put(ximage2, 2*x, 2*y+1, b2[index]); 328 | pixel_put(ximage2, 2*x+1, 2*y+1, b3[index]); 329 | } 330 | else { 331 | pixel_put(ximage2, 2*x, 2*y, 15); 332 | pixel_put(ximage2, 2*x+1, 2*y, 15); 333 | pixel_put(ximage2, 2*x, 2*y+1, 15); 334 | pixel_put(ximage2, 2*x+1, 2*y+1, 15); 335 | } 336 | 337 | } 338 | } 339 | return ximage2; 340 | } 341 | 342 | 343 | XImage *bit1_reverse(image1) 344 | XImage *image1; 345 | { 346 | register unsigned int *rev = (unsigned int *)image1->data; 347 | register int i, j; 348 | int lim = image1->bytes_per_line >> 2; 349 | 350 | for (i= 0; i < image1->height; i++) 351 | for (j = 0; j < lim; j++) { 352 | *rev = ~(*rev); 353 | rev++; 354 | } 355 | return image1; 356 | } 357 | 358 | 359 | void imagedump(ximage) 360 | XImage *ximage; 361 | { 362 | register int x, y; 363 | register unsigned long pixel; 364 | 365 | for (y = 0; y < ximage->height; y++) 366 | for (x = 0; x < ximage->width; x++) { 367 | pixel = XGetPixel(ximage, x, y); 368 | printf("=> (%d,%d): pixel = %d\n", x, y, pixel); 369 | } 370 | } 371 | 372 | void datadump(ximage) 373 | XImage *ximage; 374 | { 375 | register int i, j, limit, ret; 376 | register char *data; 377 | 378 | limit = ximage->bytes_per_line * ximage->height; 379 | ret = ximage->width / 8; 380 | j = 0; 381 | data = (char *)ximage->data; 382 | for (i = 0; i < limit; i++) { 383 | printf("%h", (unsigned long)(*data)); 384 | ++j; 385 | if (j >= ret) { 386 | printf("\n"); 387 | j = 0; 388 | } 389 | ++data; 390 | } 391 | } 392 | -------------------------------------------------------------------------------- /node_modules/x11/test/copyarea.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | var Window = require('./wndwrap'); 3 | 4 | x11.createClient(function(display) { 5 | 6 | var pts = []; 7 | new Window(display.client, 0, 0, 700, 500) 8 | .handle({ 9 | 10 | map: function(ev) { 11 | this.pixmap = this.createPixmap(700, 500); 12 | }, 13 | 14 | mousemove: function(ev) { 15 | if (this.pressed) 16 | { 17 | var lastpoly = pts[pts.length - 1]; 18 | lastpoly.push(ev.x); 19 | lastpoly.push(ev.y); 20 | if (lastpoly.length > 3) 21 | this.gc.polyLine(lastpoly.slice(-4)); 22 | } 23 | }, 24 | 25 | mousedown: function(ev) { 26 | if (ev.keycode == 1) // left button 27 | { 28 | this.pressed = true; 29 | pts.push([]); 30 | } 31 | }, 32 | 33 | mouseup: function(ev) { 34 | if (ev.keycode == 1) // left button 35 | this.pressed = false; 36 | }, 37 | 38 | expose: function(ev) { 39 | for (var i=0; i < pts.length ; ++i) { 40 | this.pixmap.gc.polyLine(pts[i]); 41 | } 42 | // todo: resize 43 | this.gc.copy(this.pixmap, 0, 0, 0, 0, 700, 500); 44 | } 45 | 46 | }) 47 | .map() 48 | .title = 'Hello, world!'; 49 | }).on('error', function(err) { 50 | console.error(err); 51 | }); 52 | -------------------------------------------------------------------------------- /node_modules/x11/test/creategc.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var PointerMotion = x11.eventMask.PointerMotion; 5 | var mapped = true; 6 | 7 | xclient.on('connect', function(display) { 8 | var X = this; 9 | var root = display.screen[0].root; 10 | var white = display.screen[0].white_pixel; 11 | var black = display.screen[0].black_pixel; 12 | 13 | var wid = X.AllocID(); 14 | X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: PointerMotion }); 15 | var cid = X.AllocID(); 16 | X.CreateGC(cid, wid); 17 | }); -------------------------------------------------------------------------------- /node_modules/x11/test/createwindow.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var PointerMotion = x11.eventMask.PointerMotion; 5 | var Button1Motion = x11.eventMask.Button1Motion; 6 | var Button2Motion = x11.eventMask.Button2Motion; 7 | var Button3Motion = x11.eventMask.Button3Motion; 8 | var Button4Motion = x11.eventMask.Button4Motion; 9 | var Button5Motion = x11.eventMask.Button5Motion; 10 | var ButtonPress = x11.eventMask.ButtonPress; 11 | var ButtonRelease = x11.eventMask.ButtonRelease; 12 | var EnterWindow = x11.eventMask.EnterWindow; 13 | var LeaveWindow = x11.eventMask.LeaveWindow; 14 | 15 | //var mask = PointerMotion|Button1Motion|Button2Motion|Button3Motion|Button4Motion|Button5Motion|ButtonPress|ButtonRelease; 16 | //var mask = Button1Motion|Button2Motion|Button3Motion|Button4Motion|Button5Motion|ButtonPress|ButtonRelease; 17 | var mask = Button1Motion|ButtonPress|EnterWindow|LeaveWindow; 18 | 19 | xclient.on('connect', function(display) { 20 | var X = this; 21 | var root = display.screen[0].root; 22 | var wid = X.AllocID(); 23 | var white = display.screen[0].white_pixel; 24 | var black = display.screen[0].black_pixel; 25 | 26 | X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: mask }); 27 | X.MapWindow(wid); 28 | }); 29 | 30 | xclient.on('event', function(ev) { 31 | console.log(ev); 32 | }); -------------------------------------------------------------------------------- /node_modules/x11/test/genstdatoms.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var atomId = 1; 5 | xclient.on('connect', function(display) { 6 | var X = this; 7 | function listAtoms() 8 | { 9 | function getAtom(a) 10 | { 11 | X.GetAtomName(a, function(str) { 12 | if (a == 1) 13 | console.log('module.exports = {') 14 | if (a != 68) 15 | console.log(' %s: %d,', str, a); 16 | else 17 | console.log(' %s: %d\n}', str, a); 18 | listAtoms(); 19 | }); 20 | } 21 | if (atomId <= 68) 22 | getAtom(atomId); 23 | else 24 | X.terminate(); 25 | atomId++; 26 | } 27 | listAtoms(); 28 | }); 29 | -------------------------------------------------------------------------------- /node_modules/x11/test/getkeyboardmapping.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var ks = x11.keySyms; 4 | var ks2Name = {}; 5 | for (var key in ks) 6 | ks2Name[ ks[key] ] = key; 7 | var kk2Name = {}; 8 | 9 | x11.createClient(function(display) { 10 | var X = display.client; 11 | var min = display.min_keycode; 12 | var max = display.max_keycode; 13 | console.log(min); 14 | X.GetKeyboardMapping(min, max-min, function(list) { 15 | for (var i=0; i < list.length; ++i) 16 | { 17 | var name = kk2Name[i+min] = []; 18 | var sublist = list[i]; 19 | for (var j =0; j < sublist.length; ++j) 20 | name.push(ks2Name[sublist[j]]); 21 | } 22 | 23 | var root = display.screen[0].root; 24 | var wid = X.AllocID(); 25 | var white = display.screen[0].white_pixel; 26 | var black = display.screen[0].black_pixel; 27 | X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: x11.eventMask.KeyPress}); 28 | X.MapWindow(wid); 29 | 30 | X.on('event', function(ev) { 31 | console.log(ev.keycode); 32 | console.log(kk2Name[ev.keycode]); 33 | }); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /node_modules/x11/test/getprop.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var PropertyChange = x11.eventMask.PropertyChange; 5 | 6 | xclient.on('connect', function(display) { 7 | var X = this; 8 | var root = display.screen[0].root; 9 | var wid = X.AllocID(); 10 | var white = display.screen[0].white_pixel; 11 | var black = display.screen[0].black_pixel; 12 | 13 | X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: PropertyChange }); 14 | X.MapWindow(wid); 15 | 16 | // mode: 0 replace, 1 prepend, 2 append 17 | // mode, wid, name, type, format, data 18 | X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS'); 19 | setInterval(function() { 20 | X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS ' + new Date()); 21 | }, 1000); 22 | 23 | xclient.on('event', function(ev) { 24 | X.GetProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 0, 10000000, function(prop) { 25 | if (prop.type == xclient.atoms.STRING) 26 | prop.data = prop.data.toString(); 27 | console.log(prop.data); 28 | }); 29 | }); 30 | }); -------------------------------------------------------------------------------- /node_modules/x11/test/jpeg/Attachments_sidorares@yandex.ru_2011-09-09_17-23-48.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/jpeg/Attachments_sidorares@yandex.ru_2011-09-09_17-23-48.zip -------------------------------------------------------------------------------- /node_modules/x11/test/jpeg/example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
baselineprogressivebaseline (gray)
34 | -------------------------------------------------------------------------------- /node_modules/x11/test/jpeg/keyboard.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/jpeg/keyboard.jpg -------------------------------------------------------------------------------- /node_modules/x11/test/jpeg/srvr.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var fs = require('fs'); 3 | var jpgData = fs.readFileSync('./keyboard.jpg'); 4 | var htmlData = fs.readFileSync('./example.html'); 5 | var jsData = fs.readFileSync('./jpg.js'); 6 | 7 | var s = http.createServer(function(req,res) { 8 | console.log(req.url); 9 | if(req.url == '/') 10 | res.end(htmlData); 11 | else if(req.url == '/jpg.js') 12 | res.end(jsData); 13 | else 14 | res.end(jpgData); 15 | 16 | }).listen(8080); -------------------------------------------------------------------------------- /node_modules/x11/test/keyboard.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/keyboard.jpg -------------------------------------------------------------------------------- /node_modules/x11/test/listext.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | var X = x11.createClient(); 3 | X.on('connect', function(display) { 4 | X.ListExtensions(function(list) { 5 | list.forEach(function(ext) { 6 | console.log(ext); 7 | }); 8 | X.terminate(); 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /node_modules/x11/test/map_unmap.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var PointerMotion = x11.eventMask.PointerMotion; 5 | var mapped = true; 6 | 7 | xclient.on('connect', function(display) { 8 | var X = this; 9 | var root = display.screen[0].root; 10 | var wid = X.AllocID(); 11 | var white = display.screen[0].white_pixel; 12 | var black = display.screen[0].black_pixel; 13 | 14 | X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: PointerMotion }); 15 | X.MapWindow(wid); 16 | setInterval(function() { 17 | if (!mapped) { 18 | X.MapWindow(wid); 19 | } else { 20 | X.UnmapWindow(wid); 21 | } 22 | mapped = !mapped; 23 | }, 1000); 24 | 25 | }); -------------------------------------------------------------------------------- /node_modules/x11/test/nodejs-black.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/nodejs-black.bmp -------------------------------------------------------------------------------- /node_modules/x11/test/pixmap.js: -------------------------------------------------------------------------------- 1 | function Pixmap(depth, width, height, buffer) 2 | { 3 | this.depth = depth; 4 | this.width = width; 5 | this.height = height; 6 | this.data = buffer; 7 | } 8 | 9 | module.exports.Pixmap = Pixmap; -------------------------------------------------------------------------------- /node_modules/x11/test/polyfillrect.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var Exposure = x11.eventMask.Exposure; 5 | var PointerMotion = x11.eventMask.PointerMotion; 6 | 7 | xclient.on('connect', function(display) { 8 | var X = this; 9 | var root = display.screen[0].root; 10 | var white = display.screen[0].white_pixel; 11 | var black = display.screen[0].black_pixel; 12 | 13 | var wid = X.AllocID(); 14 | X.CreateWindow( 15 | wid, root, 16 | 10, 10, 400, 300, 17 | 1, 1, 0, 18 | { 19 | backgroundPixel: white, eventMask: Exposure|PointerMotion 20 | } 21 | ); 22 | X.MapWindow(wid); 23 | 24 | var gc = X.AllocID(); 25 | X.CreateGC(gc, wid, { foreground: black, background: white } ); 26 | 27 | X.on('event', function(ev) { 28 | if (ev.type == 12) 29 | { 30 | X.PolyFillRectangle(wid, gc, [20, 30, 50, 90]); 31 | X.PolyFillRectangle(wid, gc, [40, 50, 90, 10]); 32 | X.PolyFillRectangle(wid, gc, [20, 80, 50, 30]); 33 | 34 | } else if (ev.type == 6) { 35 | //console.log(ev.x, ev.y); 36 | //console.log(X.replies); 37 | } 38 | }); 39 | 40 | X.on('error', function(e) { 41 | console.log(e); 42 | }); 43 | }); -------------------------------------------------------------------------------- /node_modules/x11/test/polyline.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var Exposure = x11.eventMask.Exposure; 5 | var PointerMotion = x11.eventMask.PointerMotion; 6 | var pts = [100, 1000, 10, 20, 10, 0, 0, 3]; 7 | 8 | var prevPoint; 9 | 10 | xclient.on('connect', function(display) { 11 | var X = this; 12 | var root = display.screen[0].root; 13 | var white = display.screen[0].white_pixel; 14 | var black = display.screen[0].black_pixel; 15 | 16 | var wid = X.AllocID(); 17 | X.CreateWindow( 18 | wid, root, 19 | 10, 10, 400, 300, 20 | 1, 1, 0, 21 | { 22 | backgroundPixel: white, eventMask: Exposure|PointerMotion 23 | } 24 | ); 25 | X.MapWindow(wid); 26 | 27 | var gc = X.AllocID(); 28 | X.CreateGC(gc, wid, { foreground: black, background: white } ); 29 | 30 | X.on('event', function(ev) { 31 | if (ev.type == 12) 32 | { 33 | if (pts.length > 4) 34 | X.PolyLine(0, wid, gc, pts); 35 | } else if (ev.type == 6) { 36 | pts.push(ev.x); 37 | pts.push(ev.y); 38 | if (pts.length > 4) 39 | X.PolyLine(0, wid, gc, pts.slice(-4)); 40 | } 41 | }); 42 | 43 | X.on('error', function(e) { 44 | console.log(e); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /node_modules/x11/test/polypoint.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var Exposure = x11.eventMask.Exposure; 5 | var PointerMotion = x11.eventMask.PointerMotion; 6 | var pts = []; 7 | 8 | xclient.on('connect', function(display) { 9 | var X = this; 10 | var root = display.screen[0].root; 11 | var white = display.screen[0].white_pixel; 12 | var black = display.screen[0].black_pixel; 13 | 14 | var wid = X.AllocID(); 15 | X.CreateWindow( 16 | wid, root, 17 | 10, 10, 400, 300, 18 | 1, 1, 0, 19 | { 20 | backgroundPixel: white, eventMask: Exposure|PointerMotion 21 | } 22 | ); 23 | X.MapWindow(wid); 24 | 25 | var gc = X.AllocID(); 26 | X.CreateGC(gc, wid, { foreground: black, background: white } ); 27 | 28 | X.on('event', function(ev) { 29 | if (ev.type == 12) 30 | { 31 | //X.PolyPoint(0, wid, gc, pts); 32 | } else if (ev.type == 6) { 33 | //pts.push(ev.x); 34 | //pts.push(ev.y); 35 | X.PolyPoint(0, wid, gc, [ev.x, ev.y]); 36 | } 37 | }); 38 | 39 | X.on('error', function(e) { 40 | console.log(e); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /node_modules/x11/test/polytext8.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var Exposure = x11.eventMask.Exposure; 5 | var PointerMotion = x11.eventMask.PointerMotion; 6 | 7 | xclient.on('connect', function(display) { 8 | var X = this; 9 | var root = display.screen[0].root; 10 | var white = display.screen[0].white_pixel; 11 | var black = display.screen[0].black_pixel; 12 | 13 | var wid = X.AllocID(); 14 | X.CreateWindow( 15 | wid, root, 16 | 10, 10, 400, 300, 17 | 1, 1, 0, 18 | { 19 | backgroundPixel: white, eventMask: Exposure|PointerMotion 20 | } 21 | ); 22 | X.MapWindow(wid); 23 | 24 | var gc = X.AllocID(); 25 | X.CreateGC(gc, wid, { foreground: black, background: white } ); 26 | 27 | X.on('event', function(ev) { 28 | if (ev.type == 12) 29 | { 30 | X.PolyText8(wid, gc, 50, 50, ['Hello, Node.JS!', ' Hello, world!']); 31 | } 32 | }); 33 | X.on('error', function(e) { 34 | console.log(e); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /node_modules/x11/test/putimage.js: -------------------------------------------------------------------------------- 1 | var Buffer = require('buffer').Buffer; 2 | var x11 = require('../lib/x11'); 3 | var fs = require('fs'); 4 | var logo1bit = fs.readFileSync('./nodejs-black.bmp'); 5 | var pixmap = require('./bmp').decodeBuffer(logo1bit); 6 | 7 | var xclient = x11.createClient(); 8 | var Exposure = x11.eventMask.Exposure; 9 | var PointerMotion = x11.eventMask.PointerMotion; 10 | 11 | var bitmap = new Buffer(128*128/8); // 16384 bits, 2048 bytes bitmap 12 | for (var i=0; i < bitmap.length; ++i) 13 | { 14 | bitmap[i] = i % 256; 15 | } 16 | 17 | xclient.on('connect', function(display) { 18 | var X = this; 19 | var root = display.screen[0].root; 20 | var white = display.screen[0].white_pixel; 21 | var black = display.screen[0].black_pixel; 22 | //console.log(display.screen[0]); 23 | 24 | var wid = X.AllocID(); 25 | X.CreateWindow( 26 | wid, root, 27 | 10, 10, 400, 300, 28 | 1, 1, 0, 29 | { 30 | backgroundPixel: white, eventMask: Exposure|PointerMotion 31 | } 32 | ); 33 | X.MapWindow(wid); 34 | 35 | var gc = X.AllocID(); 36 | X.CreateGC(gc, wid, { foreground: black, background: white } ); 37 | 38 | X.on('event', function(ev) { 39 | if (ev.type == 12) // expose 40 | { 41 | //X.PutImage(0, wid, gc, 128, 128, 20, 20, 0, 1, bitmap); 42 | X.PutImage(0, wid, gc, pixmap.width, pixmap.height, 20, 20, 0, pixmap.depth, pixmap.data); 43 | } 44 | }); 45 | X.on('error', function(e) { 46 | console.log(e); 47 | }); 48 | }); 49 | -------------------------------------------------------------------------------- /node_modules/x11/test/putimage1.js: -------------------------------------------------------------------------------- 1 | var Buffer = require('buffer').Buffer; 2 | var x11 = require('../lib/x11'); 3 | 4 | var xclient = x11.createClient(); 5 | var Exposure = x11.eventMask.Exposure; 6 | var PointerMotion = x11.eventMask.PointerMotion; 7 | 8 | var bitmap = new Buffer(128*128*4); // 16384 bits, 2048 bytes bitmap 9 | for (var i=0; i < bitmap.length; ++i) 10 | { 11 | var byteNum = i%4; 12 | if (byteNum == 0) 13 | bitmap[i] = parseInt((i/512)%256); 14 | if (byteNum == 1) 15 | bitmap[i] = parseInt((i/2048)%256); 16 | if (byteNum == 2) 17 | bitmap[i] = parseInt((i/256)%256); 18 | 19 | } 20 | 21 | xclient.on('connect', function(display) { 22 | 23 | var X = display.client; 24 | X.require('big-requests', function(BigReq) { 25 | 26 | BigReq.Enable(function(maxLen) { console.log( maxLen ); }); 27 | 28 | var root = display.screen[0].root; 29 | var white = display.screen[0].white_pixel; 30 | var black = display.screen[0].black_pixel; 31 | //console.log(display.screen[0]); 32 | 33 | var wid = X.AllocID(); 34 | X.CreateWindow( 35 | wid, root, 36 | 10, 10, 400, 300, 37 | 1, 1, 0, 38 | { 39 | backgroundPixel: white, eventMask: Exposure|PointerMotion 40 | } 41 | ); 42 | X.MapWindow(wid); 43 | 44 | var gc = X.AllocID(); 45 | X.CreateGC(gc, wid, { foreground: black, background: white } ); 46 | 47 | X.on('event', function(ev) { 48 | if (ev.type == 12) // expose 49 | { 50 | X.PutImage(2, wid, gc, 128, 128, 0, 0, 0, 24, bitmap); 51 | } 52 | }); 53 | X.on('error', function(e) { 54 | console.log(e); 55 | }); 56 | 57 | }); 58 | }); 59 | -------------------------------------------------------------------------------- /node_modules/x11/test/query_ext.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | var X = x11.createClient(); 3 | var numExt = 0; 4 | X.on('connect', function(display) { 5 | X.ListExtensions(function(list) { 6 | console.log(list); 7 | list.forEach(function(ext) { 8 | numExt++; 9 | X.QueryExtension(ext, function(e) { 10 | e.name = ext; 11 | console.log(e); 12 | if (--numExt == 0) 13 | X.terminate(); 14 | }); 15 | }); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /node_modules/x11/test/query_pointer.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | var X = x11.createClient(); 3 | 4 | X.on('connect', function(display) { 5 | 6 | var screen = display.screen[0]; 7 | var wid = X.AllocID(); 8 | X.CreateWindow(wid, screen.root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: screen.white_pixel }); 9 | X.MapWindow(wid); 10 | setInterval( function() { 11 | X.QueryPointer(wid, function(res) { 12 | console.log(res); 13 | }); 14 | }, 1000); 15 | 16 | }); 17 | 18 | X.on('error', function(err) { 19 | console.log(err); 20 | }); 21 | -------------------------------------------------------------------------------- /node_modules/x11/test/query_pointer_benchmark_parallel.js: -------------------------------------------------------------------------------- 1 | // test results: 2 | 3 | // WinServ2008R2, Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz + Xming 6.9.0.31 4 | // 5 | // 0.4.3/cygwin 32bit : 6900 +/- 200 req/sec 6 | // 0.5.1/win32 : 3700 +/- 200 req/sec 7 | // cygwin x11perf -sync -pointer : 2800 +/- 200 req/sec 8 | // cygwin x11perf -pointer : 5600 +/- 200 req/sec 9 | 10 | // 11 | // Ubuntu 11.04 32bit, Intel(R) Core(TM)2 Duo CPU T7250 @2.00GHz, XOrg 1:7.6+4ubuntu3.1 12 | // 0.4.9pre : 13 | // x11perf -sync -pointer : 14 | // x11perf -pointer : 15 | 16 | var x11 = require('../lib/x11'); 17 | var X = x11.createClient(); 18 | 19 | var total = 50000; 20 | var num_qp_resp_left = total; 21 | var num_qp_req_left = total; 22 | var start = +new Date(); 23 | var wid; 24 | 25 | function benchmarkQP() 26 | { 27 | num_qp_req_left--; 28 | X.QueryPointer(wid, function(res) { 29 | num_qp_resp_left--; 30 | if (num_qp_resp_left == 0) 31 | { 32 | var end = +new Date(); 33 | var delta = (end - start)/1000 34 | console.error( 'Finished ' + total + ' requests in ' + delta + ' sec, ' + total/delta + ' req/sec'); 35 | X.terminate(); 36 | } 37 | }); 38 | 39 | if (num_qp_req_left > 0) 40 | process.nextTick(benchmarkQP); 41 | } 42 | 43 | X.on('connect', function(display) { 44 | var screen = display.screen[0]; 45 | wid = X.AllocID(); 46 | X.CreateWindow(wid, screen.root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: screen.white_pixel }); 47 | X.MapWindow(wid); 48 | benchmarkQP(wid); 49 | }); 50 | 51 | X.on('error', function(err) { 52 | console.log(err); 53 | }); 54 | -------------------------------------------------------------------------------- /node_modules/x11/test/query_pointer_benchmark_sync.js: -------------------------------------------------------------------------------- 1 | // test results: 2 | 3 | // WinServ2008R2, Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz + Xming 6.9.0.31 4 | // 5 | // 0.4.3/cygwin 32bit : 2900 +/- 300 req/sec 6 | // 0.5.1/win32 : 5500 +/- 1000 req/sec 7 | // cygwin x11perf -sync -pointer : 2800 +/- 200 req/sec 8 | // cygwin x11perf -pointer : 5600 +/- 200 req/sec 9 | 10 | // 11 | // Ubuntu 11.04 32bit, Intel(R) Core(TM)2 Duo CPU T7250 @2.00GHz, XOrg 1:7.6+4ubuntu3.1 12 | // 0.4.9pre : 13 | // x11perf -sync -pointer : 14 | // x11perf -pointer : 15 | 16 | var x11 = require('../lib/x11'); 17 | var X = x11.createClient(); 18 | 19 | var total = 50000; 20 | var num_qp_left = total; 21 | var start = +new Date(); 22 | 23 | function benchmarkQP(wid) 24 | { 25 | X.QueryPointer(wid, function(res) { 26 | num_qp_left--; 27 | if (num_qp_left > 0) 28 | benchmarkQP(wid); 29 | else { 30 | var end = +new Date(); 31 | var delta = (end - start)/1000 32 | console.log( 'Finished ' + total + ' requests in ' + delta + ' sec, ' + total/delta + ' req/sec'); 33 | X.terminate(); 34 | } 35 | }); 36 | } 37 | 38 | X.on('connect', function(display) { 39 | var screen = display.screen[0]; 40 | var wid = X.AllocID(); 41 | X.CreateWindow(wid, screen.root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: screen.white_pixel }); 42 | X.MapWindow(wid); 43 | benchmarkQP(wid); 44 | }); 45 | 46 | X.on('error', function(err) { 47 | console.log(err); 48 | }); 49 | -------------------------------------------------------------------------------- /node_modules/x11/test/render-simplest.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use X11::Protocol; 4 | use strict; 5 | use IO::Select; 6 | my $X = new X11::Protocol; 7 | $X->init_extension("RENDER") or die; 8 | 9 | my($rgb24, $rgba32); 10 | 11 | $rgb24 = 71; 12 | $rgba32 = 69; 13 | 14 | my $win = $X->new_rsrc; 15 | $X->CreateWindow($win, $X->root, 'InputOutput', $X->root_depth, 16 | 'CopyFromParent', (0, 0), 500, 500, 4, 17 | 'event_mask' => $X->pack_event_mask('Exposure')); 18 | 19 | $X->MapWindow($win); 20 | my $picture = $X->new_rsrc; 21 | $X->RenderCreatePicture($picture, $win, $rgb24, 'poly_edge' => 'Smooth', 'poly_mode' => 'Precise'); 22 | 23 | my $pixmap = $X->new_rsrc; 24 | $X->CreatePixmap($pixmap, $win, 32, 1000, 1000); 25 | my $pix_pict = $X->new_rsrc; 26 | $X->RenderCreatePicture($pix_pict, $pixmap, $rgba32, 'poly_edge' => 'Smooth', 'poly_mode' => 'Precise'); 27 | $X->RenderFillRectangles('Src', $pix_pict, [0xffff, 0, 0, 0x8000], [0, 0, 1000, 1000]); 28 | 29 | $X->event_handler('queue'); 30 | #my $fds = IO::Select->new($X->connection->fh); 31 | 32 | sub draw { 33 | $X->RenderFillRectangles('Src', $picture, [(0xffff)x4], [0, 0, 500, 500]); 34 | 35 | $X->RenderSetPictureFilter($pix_pict, "nearest"); 36 | $X->RenderTriangles('Over', $pix_pict, 500, 500, $picture, 0, [(250, 100), (100, 350), (400, 350), (175, 100), (185, 100), (180, 0)]); 37 | #$X->RenderFillRectangles('Src', $picture, [(0xffff, 0, 0, 0xffff)], [10, 10, 50, 50]); 38 | } 39 | 40 | for (;;) { 41 | my %e; 42 | $X->handle_input; 43 | if (%e = $X->dequeue_event) { 44 | if ($e{'name'} eq "Expose") { 45 | draw(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /node_modules/x11/test/render.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndrewSwerlick/node-remote/3df1ff080a48c6392acb8ab50a9169566a186871/node_modules/x11/test/render.h -------------------------------------------------------------------------------- /node_modules/x11/test/rendertest.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | var PointerMotion = x11.eventMask.PointerMotion; 3 | 4 | var xclient = x11.createClient(function(display) { 5 | var X = display.client; 6 | var root = display.screen[0].root; 7 | display.client.require('render', function(Render) { 8 | console.log(Render); 9 | var wid = X.AllocID(); 10 | var white = display.screen[0].white_pixel; 11 | varblack = display.screen[0].black_pixel; 12 | X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: PointerMotion }); 13 | X.MapWindow(wid); 14 | 15 | var pict = X.AllocID(); 16 | Render.CreatePicture(pict, wid, Render.rgb24); 17 | var pictGrad = X.AllocID(); 18 | Render.RadialGradient(pictGrad, [26,26], [26,26], 0, 26, 19 | [ 20 | [0, [0,0,0,0x0fff ] ], 21 | [0.3, [0,0,0,0x0fff ] ], 22 | [0.997, [0xffff, 0xf, 0, 0x1] ], 23 | [1, [0xffff, 0xffff, 0, 0x0] ] 24 | ]); 25 | 26 | function draw(x, y) { 27 | Render.Composite(3, pictGrad, 0, pict, 0, 0, 0, 0, x-26, y-26, 52, 52); 28 | } 29 | 30 | X.on('event', function(ev) { 31 | draw(ev.x, ev.y); 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /node_modules/x11/test/sendevent.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var Exposure = x11.eventMask.Exposure; 5 | var PointerMotion = x11.eventMask.PointerMotion; 6 | var pts = []; 7 | 8 | xclient.on('connect', function(display) { 9 | var X = this; 10 | var root = display.screen[0].root; 11 | var white = display.screen[0].white_pixel; 12 | var black = display.screen[0].black_pixel; 13 | 14 | function createWindow() 15 | { 16 | 17 | var wid = X.AllocID(); 18 | X.CreateWindow( 19 | wid, root, 20 | 10, 10, 400, 300, 21 | 1, 1, 0, 22 | { 23 | backgroundPixel: white, eventMask: Exposure|PointerMotion 24 | } 25 | ); 26 | X.MapWindow(wid); 27 | return wid; 28 | } 29 | 30 | var wid = createWindow(); 31 | var wid1 = createWindow(); 32 | 33 | var gc = X.AllocID(); 34 | X.CreateGC(gc, wid, { foreground: black, background: white } ); 35 | 36 | X.on('event', function(ev) { 37 | //console.log(ev); 38 | if (ev.type == 12) 39 | { 40 | // expose 41 | } else if (ev.type == 6) { 42 | X.PolyPoint(0, ev.wid, gc, [ev.x, ev.y]); 43 | // send copy of event to the second window 44 | if (ev.wid == wid) // don't send it from second window 45 | { 46 | // set window in the event we are sending 47 | var n = wid1; 48 | var offset = 12; 49 | var buf = ev.rawData; 50 | buf[offset++] = n & 0xff; 51 | buf[offset++] = (n >> 8) & 0xff; 52 | buf[offset++] = (n >> 16) & 0xff; 53 | buf[offset++] = (n >> 24) & 0xff; 54 | 55 | X.SendEvent(wid1, 1, PointerMotion, ev.rawData); 56 | } else { 57 | console.log('GotData!'); 58 | } 59 | } 60 | }); 61 | 62 | X.on('error', function(e) { 63 | console.log(e); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /node_modules/x11/test/sketch.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | var Window = require('./wndwrap'); 3 | 4 | x11.createClient(function(display) { 5 | 6 | var pts = []; 7 | new Window(display.client, 0, 0, 700, 500) 8 | .handle({ 9 | 10 | mousemove: function(ev) { 11 | if (this.pressed) 12 | { 13 | var lastpoly = pts[pts.length - 1]; 14 | lastpoly.push(ev.x); 15 | lastpoly.push(ev.y); 16 | if (lastpoly.length > 3) 17 | this.gc.polyLine(lastpoly.slice(-4)); 18 | } 19 | }, 20 | 21 | mousedown: function(ev) { 22 | if (ev.keycode == 1) // left button 23 | { 24 | this.pressed = true; 25 | pts.push([]); 26 | } 27 | }, 28 | 29 | mouseup: function(ev) { 30 | if (ev.keycode == 1) // left button 31 | this.pressed = false; 32 | }, 33 | 34 | expose: function(ev) { 35 | for (var i=0; i < pts.length ; ++i) { 36 | this.gc.polyLine(pts[i]); 37 | } 38 | } 39 | 40 | }) 41 | .map() 42 | .title = 'Hello, world!'; 43 | }); 44 | -------------------------------------------------------------------------------- /node_modules/x11/test/subwindows.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | var Window = require('./wndwrap'); 3 | 4 | x11.createClient(function(display) { 5 | 6 | var pts = []; 7 | new Window(display.client, 0, 0, 600, 400, display.screen[0].white_pixel) 8 | .handle({ 9 | 10 | create: function(ev) { 11 | console.log(eve); 12 | }, 13 | 14 | map: function(ev) { 15 | console.log(ev); 16 | 17 | for (var i=0; i < 29; ++i) 18 | for (var j=0; j < 19; ++j) 19 | { 20 | new Window( this, 10+i*20, 10+j*20, 17, 17, display.screen[0].black_pixel) 21 | .handle({ 22 | mousemove: function() { 23 | var self = this; 24 | self.unmap(); 25 | setTimeout(function() { 26 | self.map(); 27 | }, 500); 28 | } 29 | 30 | }) 31 | .map(); 32 | } 33 | }, 34 | 35 | mousemove: function(ev) { 36 | if (this.pressed) 37 | { 38 | var lastpoly = pts[pts.length - 1]; 39 | lastpoly.push(ev.x); 40 | lastpoly.push(ev.y); 41 | if (lastpoly.length > 3) 42 | this.gc.polyLine(lastpoly.slice(-4)); 43 | } 44 | }, 45 | 46 | mousedown: function(ev) { 47 | if (ev.keycode == 1) // left button 48 | { 49 | this.pressed = true; 50 | pts.push([]); 51 | } 52 | }, 53 | 54 | mouseup: function(ev) { 55 | if (ev.keycode == 1) // left button 56 | this.pressed = false; 57 | }, 58 | 59 | expose: function(ev) { 60 | //for (var i=0; i < pts.length ; ++i) { 61 | // this.gc.polyLine(pts[i]); 62 | //} 63 | } 64 | 65 | }) 66 | .map() 67 | .title = 'Hello, world!'; 68 | }); 69 | -------------------------------------------------------------------------------- /node_modules/x11/test/test_ext_render.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | // adding XRender functions manually from 4 | // http://cgit.freedesktop.org/xcb/proto/tree/src/render.xml?id=HEAD 5 | // and http://www.x.org/releases/X11R7.6/doc/renderproto/renderproto.txt 6 | // TODO: move to templates 7 | x11.createClient( 8 | function(display) { 9 | var X = display.client; 10 | X.QueryExtension('RENDER', function(ext) { 11 | function RenderQueryVersion(clientMaj, clientMin, callback) 12 | { 13 | X.seq_num++; 14 | X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]); 15 | X.replies[X.seq_num] = [ 16 | function(buf, opt) { 17 | var res = buf.unpack('LL'); 18 | return res; 19 | }, 20 | callback 21 | ]; 22 | X.pack_stream.flush(); 23 | } 24 | 25 | function RenderQueryFilters(callback) 26 | { 27 | X.seq_num++; 28 | X.pack_stream.pack('CCSL', [ext.majorOpcode, 29, 2, display.screen[0].root]); 29 | X.replies[X.seq_num] = [ 30 | function(buf, opt) { 31 | var h = buf.unpack('LL'); 32 | var num_aliases = h[0]; 33 | var num_filters = h[1]; 34 | var aliases = []; 35 | var offset = 24; // LL + 16 bytes pad 36 | for (var i=0; i < num_aliases; ++i) 37 | { 38 | aliases.push(buf.unpack('S', offset)[0]); 39 | offset+=2; 40 | } 41 | var filters = []; 42 | for (var i=0; i < num_filters; ++i) 43 | { 44 | var len = buf.unpack('C', offset)[0]; 45 | //if (!len) break; 46 | offset++; 47 | filters.push(buf.toString('ascii', offset, offset+len)); 48 | offset+=len; 49 | } 50 | return [aliases, filters]; 51 | }, 52 | callback 53 | ]; 54 | X.pack_stream.flush(); 55 | } 56 | 57 | var valueList = [ 58 | ['repeat', 'C'], 59 | ['alphaMap', 'L'], 60 | ['alphaXOrigin', 's'], 61 | ['alphaYOrigin', 's'], 62 | ['clipMask', 'L'], 63 | ['graphicsExposures', 'C'], 64 | ['subwindowMode', 'C'], 65 | ['polyEdge', 'C'], 66 | ['polyMode', 'C'], 67 | ['dither', 'L'], 68 | ['componentAlpha', 'C'] 69 | ]; 70 | 71 | var argumentLength = { 72 | C: 1, 73 | S: 2, 74 | s: 2, 75 | L: 4, 76 | x: 1 77 | }; 78 | 79 | function RenderCreatePicture(pid, drawable, pictformat, values) 80 | { 81 | X.seq_num++; 82 | var mask = 0; 83 | var reqLen = 5; // + (values + pad)/4 84 | var format = 'CCSLLLL'; 85 | var params = [ext.majorOpcode, 4, reqLen, pid, drawable, pictformat, mask]; 86 | 87 | if (values) 88 | { 89 | var valuesLength = 0; 90 | for (var i=0; i < valueList.length; ++i) 91 | { 92 | var val = values[valueList[i][0]]; 93 | if (val) { 94 | mask |= (1 << i); 95 | params.push(val); 96 | var valueFormat = valueList[i][1]; 97 | format += valueFormat; 98 | valuesLength += argumentLength[valueFormat]; 99 | } 100 | } 101 | var pad4 = (valuesLength + 3) >> 2; 102 | var toPad = (pad4 << 2) - valuesLength; 103 | for (var i=0; i < toPad; ++i) 104 | format += 'x'; 105 | reqLen += pad4; 106 | params[2] = reqLen; 107 | params[6] = mask; 108 | } 109 | console.log([format, params]); 110 | X.pack_stream.pack(format, params); 111 | X.pack_stream.flush(); 112 | } 113 | 114 | function floatToFix(f) 115 | { 116 | return parseInt(f*(1<<16)); 117 | } 118 | 119 | function RenderLinearGradient(pid, p1, p2, stops) 120 | { 121 | X.seq_num++; 122 | var reqLen = 7+stops.length*3; //header + params + 1xStopfix+2xColors 123 | var format = 'CCSLLLLLL'; 124 | var params = [ext.majorOpcode, 34, reqLen, pid]; 125 | params.push(floatToFix(p1[0])); // L 126 | params.push(floatToFix(p1[1])); 127 | params.push(floatToFix(p2[0])); 128 | params.push(floatToFix(p2[1])); // L 129 | 130 | params.push(stops.length); 131 | 132 | // [ [float stopDist, [float r, g, b, a] ], ...] 133 | // stop distances 134 | for (var i=0; i < stops.length; ++i) 135 | { 136 | format += 'L'; 137 | // TODO: we know total params length in advance. ? params[index] = 138 | params.push(floatToFix(stops[i][0])) 139 | } 140 | // colors 141 | for (var i=0; i < stops.length; ++i) 142 | { 143 | format += 'SSSS'; 144 | for (var j=0; j < 4; ++j) 145 | params.push(stops[i][1][j]); 146 | } 147 | console.log([format, params]); 148 | X.pack_stream.pack(format, params); 149 | X.pack_stream.flush(); 150 | } 151 | 152 | function RenderFillRectangles(op, pid, color, rects) 153 | { 154 | X.seq_num++; 155 | var reqLen = 5+rects.length*2; 156 | var format = 'CCSCxxxLSSSS'; 157 | var params = [ext.majorOpcode, 26, reqLen, op, pid]; 158 | for (var j=0; j < 4; ++j) 159 | params.push(color[j]); 160 | for (var i=0; i < rects.length; i+=4) 161 | { 162 | format += 'ssSS'; 163 | params.push(rects[i*4]); 164 | params.push(rects[i*4 + 1]); 165 | params.push(rects[i*4 + 2]); 166 | params.push(rects[i*4 + 3]); 167 | } 168 | console.log([format, params]); 169 | X.pack_stream.pack(format, params); 170 | X.pack_stream.flush(); 171 | } 172 | 173 | //RenderQueryVersion(0,9, function(serverVersion) { console.log(serverVersion); }); 174 | //RenderQueryFilters(function(resp) { console.log(resp); }); 175 | 176 | var root = display.screen[0].root; 177 | var wid = X.AllocID(); 178 | var white = display.screen[0].white_pixel; 179 | var black = display.screen[0].black_pixel; 180 | X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: x11.eventMask.Exposure }); 181 | var pid = X.AllocID(); 182 | RenderCreatePicture(pid, wid, 71, { repeat: 1} ); 183 | var pidGrad = X.AllocID(); 184 | 185 | //RenderLinearGradient(pidGrad, [0,0], [100,100], [ [0, [0,0,0,0xffff]], [100, [0xffff, 0xffff, 0xffff, 0xffff]]]); 186 | 187 | X.MapWindow(wid); 188 | 189 | X.on('event', function(ev) { 190 | console.log(ev); 191 | //RenderFillRectangles(1, pid, [0, 0, 0, 0x8000], [0, 0, 400, 500]); 192 | RenderFillRectangles(1, pid, [0, 0x8000, 0, 0xffff], [100, 200, 400, 500]); 193 | }); 194 | }); 195 | } 196 | 197 | ).on('error', function(err) { 198 | console.log(err); 199 | }); 200 | -------------------------------------------------------------------------------- /node_modules/x11/test/testwnd.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | var Window = require('./wndwrap'); 3 | 4 | var width = 700; 5 | var height = 500; 6 | 7 | var xclient = x11.createClient(); 8 | var pts = []; 9 | 10 | xclient.on('connect', function(display) { 11 | 12 | var mainwnd = new Window(xclient, 0, 0, width, height); 13 | mainwnd.on('mousemove', function(ev) 14 | { 15 | pts.push(ev.x); 16 | pts.push(ev.y); 17 | this.gc.text(ev.x, ev.y, 'Hello, NodeJS!'); 18 | mainwnd.title = ev.x + ' ' + ev.y; 19 | }); 20 | mainwnd.on('expose', function(ev) { 21 | for (var i=0; i < pts.length/2 ; ++i) 22 | ev.gc.drawText(pts[i], pts[i+1], 'Hello, NodeJS!'); 23 | }); 24 | mainwnd.map(); 25 | 26 | }); 27 | -------------------------------------------------------------------------------- /node_modules/x11/test/warppointer.js: -------------------------------------------------------------------------------- 1 | var angle = 0; 2 | var x11 = require('../lib/x11').createClient(function(display) { 3 | setInterval(function() { 4 | var x = 500 + 100*Math.cos(angle); 5 | var y = 500 + 100*Math.sin(angle); 6 | display.client.WarpPointer(0, display.screen[0].root, 0, 0, 0, 0, parseInt(x), parseInt(y)); 7 | angle += 0.05; 8 | }, 100); 9 | }); 10 | -------------------------------------------------------------------------------- /node_modules/x11/test/wndwrap.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | var Exposure = x11.eventMask.Exposure; 3 | var PointerMotion = x11.eventMask.PointerMotion; 4 | var ButtonPress = x11.eventMask.ButtonPress; 5 | var ButtonRelease = x11.eventMask.ButtonRelease; 6 | var SubstructureNotify = x11.eventMask.SubstructureNotify; 7 | var StructureNotify = x11.eventMask.StructureNotify; 8 | 9 | var EventEmitter = require('events').EventEmitter; 10 | var util = require('util'); // util.inherits 11 | 12 | function GraphicContext(win) 13 | { 14 | this.win = win; 15 | this.xclient = win.xclient; 16 | this.id = this.xclient.AllocID(); 17 | var screen = this.xclient.display.screen[0]; 18 | //win.xclient.CreateGC(this.id, win.id, { foreground: screen.black_pixel, background: screen.white_pixel}); 19 | this.xclient.CreateGC(this.id, win.id, { foreground: screen.white_pixel, background: screen.black_pixel}); 20 | } 21 | 22 | GraphicContext.prototype.polyLine = function(points) 23 | { 24 | this.xclient.PolyLine(0, this.win.id, this.id, points); 25 | } 26 | 27 | GraphicContext.prototype.noop = function() 28 | { 29 | //testing triggering gc creation 30 | } 31 | 32 | GraphicContext.prototype.rectangles = function(x, y, xyWHpoints) 33 | { 34 | this.xclient.PolyFillRectangle(this.win.id, this.id, xyWHpoints); 35 | } 36 | 37 | GraphicContext.prototype.text = function(x, y, text) 38 | { 39 | this.xclient.PolyText8(this.win.id, this.id, x, y, [text]); 40 | } 41 | 42 | GraphicContext.prototype.polyLine = function(points, opts) 43 | { 44 | var coordinateMode = 0; 45 | if (opts && opts.coordinateMode === 'previous') 46 | coordinateMode = 1; 47 | this.xclient.PolyLine(coordinateMode, this.win.id, this.id, points); 48 | } 49 | 50 | GraphicContext.prototype.points = function(points, opts) 51 | { 52 | var coordinateMode = 0; 53 | if (opts && opts.coordinateMode === 'previous') 54 | coordinateMode = 1; 55 | this.xclient.PolyPoint(coordinateMode, this.win.id, this.id, points); 56 | } 57 | 58 | GraphicContext.prototype.copy = function(srcDrawable, srcX, srcY, dstX, dstY, width, height) 59 | { 60 | // CopyArea: srcDrawable, dstDrawable, gc, srcX, srcY, dstX, dstY, width, height 61 | this.xclient.CopyArea(srcDrawable.id, this.win.id, this.id, srcX, srcY, dstX, dstY, width, height); 62 | } 63 | 64 | function Window(parent, x, y, w, h, bg) 65 | { 66 | if (parent.constructor && parent.constructor.name == 'XClient') 67 | { 68 | this.xclient = parent; 69 | if (!this.xclient.rootWindow) 70 | { 71 | // quick hack 72 | var rootWnd = { 73 | id: this.xclient.display.screen[0].root, 74 | xclient: this.xclient 75 | }; 76 | rootWnd.parent = null; 77 | this.parent = this.xclient.rootWnd; 78 | this.xclient.rootWindow = rootWnd; 79 | } 80 | this.parent = this.xclient.rootWindow; 81 | } else { 82 | this.parent = parent; 83 | this.xclient = parent.xclient; 84 | } 85 | 86 | this.x = x; 87 | this.y = y; 88 | this.w = w; 89 | this.h = h; 90 | this.black = this.xclient.display.screen[0].black_pixel; 91 | this.white = this.xclient.display.screen[0].white_pixel; 92 | this.id = this.xclient.AllocID(); 93 | 94 | if (!bg) 95 | bg = this.white; 96 | 97 | var borderWidth = 1; 98 | var _class = 1; // InputOutput 99 | var visual = 0; // CopyFromParent 100 | this.xclient.CreateWindow( 101 | this.id, this.parent.id, this.x, this.y, this.w, this.h, 102 | borderWidth, _class, visual, 103 | { 104 | backgroundPixel: bg, 105 | eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease|SubstructureNotify|StructureNotify 106 | } 107 | ); 108 | 109 | //this.map(); 110 | var wnd = this; 111 | eventType2eventName = { 112 | 4: 'mousedown', 113 | 5: 'mouseup', 114 | 6: 'mousemove', 115 | 12: 'expose', 116 | 16: 'create', 117 | 19: 'map' 118 | }; 119 | 120 | var ee = new EventEmitter(); 121 | this.xclient.event_consumers[wnd.id] = ee; 122 | // TODO: do we need to have wnd as EventEmitter AND EventEmitter stored in event_consumers ? 123 | ee.on('event', function( ev ) 124 | { 125 | if (ev.type == 12) //Expose 126 | ev.gc = wnd.gc; 127 | wnd.emit(eventType2eventName[ev.type], ev); // convert to mousemove? (ev is already event-spacific) 128 | }); 129 | // TODO: track delete events and remove wmd from consumers list 130 | 131 | this.__defineSetter__('title', function(title) { 132 | this._title = title; 133 | this.xclient.ChangeProperty(0, this.id, this.xclient.atoms.WM_NAME, this.xclient.atoms.STRING, 8, title); 134 | }); 135 | 136 | this.__defineGetter__('title', function() { 137 | return this._title; 138 | }); 139 | 140 | this.__defineGetter__('gc', function() 141 | { 142 | if (!this._gc) 143 | { 144 | this._gc = new GraphicContext(this); 145 | } 146 | return this._gc; 147 | }); 148 | 149 | } 150 | util.inherits(Window, EventEmitter); 151 | 152 | Window.prototype.map = function() { 153 | this.xclient.MapWindow(this.id); 154 | return this; 155 | } 156 | 157 | Window.prototype.unmap = function() { 158 | this.xclient.UnmapWindow(this.id); 159 | return this; 160 | } 161 | 162 | Window.prototype.handle = function(handlers) { 163 | // TODO: compare event mask with events names and issue 164 | // one ChangeWindowAttributes request adding missing events 165 | for (var eventName in handlers) { 166 | this.on(eventName, handlers[eventName]); 167 | } 168 | return this; 169 | } 170 | 171 | Window.prototype.getProperty = function(name, cb) { 172 | this.xclient.InternAtom(true, nam, function(nameAtom) { 173 | this.xclient.GetProperty(0, this.id, nameAtom, 0, 1000000000, function(prop) { 174 | cb(prop); 175 | }); 176 | }); 177 | return this; 178 | } 179 | 180 | Window.prototype.createPixmap = function(width, height) 181 | { 182 | var pid = this.xclient.AllocID(); 183 | // function(depth, pid, drawable, width, height) { 184 | this.xclient.CreatePixmap( this.xclient.display.screen[0].root_depth, pid, this.id, width, height); 185 | var pixmap = {}; 186 | pixmap.id = pid; 187 | pixmap.__defineGetter__('gc', function() 188 | { 189 | if (!this._gc) 190 | { 191 | this._gc = new GraphicContext(this); 192 | } 193 | return this._gc; 194 | }); 195 | pixmap.xclient = this.xclient; 196 | return pixmap; 197 | } 198 | 199 | module.exports = Window; -------------------------------------------------------------------------------- /node_modules/x11/test/xlsatoms.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(); 4 | var atomId = 10; 5 | xclient.on('connect', function(display) { 6 | var X = this; 7 | function listAtoms() 8 | { 9 | function getAtom(a) 10 | { 11 | X.GetAtomName(a, function(str) { 12 | if (typeof str != 'string') // 'Bad atom' error 13 | { 14 | X.terminate(); 15 | return; 16 | } 17 | console.log(a + ' ' + str); 18 | listAtoms(); 19 | }); 20 | } 21 | getAtom(atomId); 22 | atomId++; 23 | } 24 | listAtoms(); 25 | }); 26 | -------------------------------------------------------------------------------- /node_modules/x11/test/xtesttest.js: -------------------------------------------------------------------------------- 1 | var x11 = require('../lib/x11'); 2 | 3 | var xclient = x11.createClient(function(display) { 4 | var X = display.client; 5 | var root = display.screen[0].root; 6 | display.client.require('xtest', function(Test) { 7 | console.log(Test); 8 | setInterval(function() { 9 | Test.FakeInput(Test.KeyPress, 65, 0, root, 0, 0); // space 10 | Test.FakeInput(Test.KeyRelease, 65, 0, root, 0, 0); // space 11 | console.log('click'); 12 | }, 1000); 13 | }); 14 | display.client.on('error', function(err) { console.log(err); }); 15 | }); 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "node-remote", 3 | "author" : "Andrew Swerlick ", 4 | "version" : "0.0.1", 5 | "dependencies" : { 6 | "socket.io" : "0.x.x" 7 | }, 8 | "devDependencies" :{ 9 | "vows" : "0.x.x" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /remote-client.js: -------------------------------------------------------------------------------- 1 | var socket = io.connect("http://10.17.63.101:8000"); 2 | 3 | $(document).mousemove( 4 | function(e){ 5 | socket.emit('move', { 6 | xPercent: (e.pageX / $(window).width()) * 100, 7 | yPercent: (e.pageY / $(window).height()) * 100, 8 | }); 9 | } 10 | ); 11 | 12 | 13 | $(document).keydown( 14 | function(e){ 15 | socket.emit('keyDown', { 16 | key: e.which 17 | }); 18 | $(document).keypress(); 19 | return false; 20 | } 21 | ); 22 | 23 | $(document).keyup( 24 | function(e){ 25 | socket.emit('keyUp', { 26 | key: e.which 27 | }); 28 | return false; 29 | } 30 | ); 31 | 32 | $(document).click( 33 | function(e){ 34 | socket.emit('click', { 35 | clickCode: e.which 36 | }); 37 | return false; 38 | } 39 | ); 40 | 41 | //Adding touch events after the page is loaded 42 | $(document).ready(function(){ 43 | $.jQTouch({ 44 | initializeTouch: 'body' 45 | }); 46 | $('.current').bind('drag' ,function(e, info){ 47 | socket.emit('moveRelative', { 48 | x: info.deltaX/10, 49 | y: info.deltaY/10, 50 | }); 51 | }); 52 | }); 53 | 54 | -------------------------------------------------------------------------------- /remote-server.js: -------------------------------------------------------------------------------- 1 | var io = require('socket.io'), 2 | xManager = require('./xEventManager.js'), 3 | server = require('./simpleServer').createServer(); 4 | 5 | 6 | sockets = io.listen(server).sockets, 7 | 8 | server.listen(8000); 9 | 10 | xManager.createXManager(function(manager) { 11 | sockets.on('connection', function(socket) { 12 | socket.on('move', function(data) { 13 | try{manager.move(data.xPercent, data.yPercent);} 14 | catch(err){} 15 | }); 16 | socket.on('moveRelative', function(data) { 17 | try{manager.moveRelative(data.x, data.y);} 18 | catch(err){} 19 | }); 20 | socket.on('keyUp', function(data){ 21 | try{manager.keyUp(data.key);} 22 | catch(err){} 23 | }); 24 | socket.on('keyDown', function(data){ 25 | try{manager.keyDown(data.key);} 26 | catch(err){} 27 | }); 28 | socket.on('keyPress', function(data){ 29 | try{manager.keyPress(data.key);} 30 | catch(err){} 31 | }); 32 | socket.on('click', function(data){ 33 | try{manager.click(data.clickCode);} 34 | catch(err){} 35 | }); 36 | }); 37 | 38 | }); 39 | 40 | -------------------------------------------------------------------------------- /remote.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | Move your mouse around to control the other computer 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /simpleServer.js: -------------------------------------------------------------------------------- 1 | var url = require('url'), 2 | http = require('http'), 3 | path = require('path'), 4 | fs = require('fs'); 5 | log = require('util').puts; 6 | 7 | module.exports.createServer = function() 8 | { 9 | server = http.createServer(function(request, response) { 10 | var uri = url.parse(request.url).pathname; 11 | if(uri == "/"){ 12 | uri = "/remote.html"; 13 | } 14 | 15 | var filename = path.join(process.cwd(), uri); 16 | log(filename); 17 | path.exists(filename, function(exists) { 18 | if(!exists) { 19 | response.writeHead(404, {"Content-Type": "text/plain"}); 20 | response.write("404 Not Found\n"); 21 | response.end(); 22 | return; 23 | } 24 | 25 | fs.readFile(filename, "binary", function(err, file){ 26 | response.writeHead(200); 27 | response.write(file, "binary"); 28 | response.end(); 29 | return; 30 | }); 31 | }); 32 | }); 33 | return server; 34 | } 35 | -------------------------------------------------------------------------------- /tests/spiketest/q: -------------------------------------------------------------------------------- 1 | var x11 = require('x11/lib/x11'); 2 | 3 | x11.createClient(function(display) { 4 | var X = display.client; 5 | var min = display.min_keycode; 6 | var max = display.max_keycode; 7 | X.GetKeyboardMapping(min, max-min, function(list) { 8 | asciiToX = {}; 9 | for(i=0; i