diff --git a/lib/x11/corereqs.js b/lib/x11/corereqs.js index 9e67cc9..4a08df1 100644 --- a/lib/x11/corereqs.js +++ b/lib/x11/corereqs.js @@ -201,10 +201,33 @@ module.exports = { } ], + DeleteProperty: [ + [ 'CxLLL', [19, 3] ] // wid, propNameAtom + ], + + GetProperty: [ + + function(del, wid, name, type, longOffset, longLength) // - offest and maxLength in 4-byte units + { + return [ 'CCSLLLLL', [20, del, 6, wid, name, type, longOffset, longLength ] ]; + }, + + function(buf, format) { + var res = buf.unpack('LLL'); + var prop = {}; + prop.type = res[0]; + prop.bytesAfter = res[1]; + var len = res[2]*(format >> 3) + prop.data = buf.slice(24, 24+len); + return prop; + } + ], + QueryPointer: [ [ 'CxSL', [38, 2] ], function(buf) { var res = buf.unpack('LLSSSSS'); // TODO: should be unsigned + // TODO pack array into named fields return res; } ], diff --git a/lib/x11/xcore.js b/lib/x11/xcore.js index ec821f4..77ea368 100644 --- a/lib/x11/xcore.js +++ b/lib/x11/xcore.js @@ -253,7 +253,7 @@ XClient.prototype.expectReplyHeader = function() var reqName = handler[0]; var req = coreRequests[reqName]; var unpack = req[1]; - var result = unpack( data ); + var result = unpack( data, opt_data ); var callback = handler[1]; callback(result); delete client.replies[seq_num]; diff --git a/test/changeprop.js b/test/changeprop.js index d2181f5..a70eb94 100644 --- a/test/changeprop.js +++ b/test/changeprop.js @@ -16,7 +16,6 @@ xclient.on('connect', function(display) { // mode: 0 replace, 1 prepend, 2 append // mode, wid, name, type, format, data X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS'); - setInterval(function() { X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS ' + new Date()); }, 100); diff --git a/test/getprop.js b/test/getprop.js new file mode 100644 index 0000000..b350d00 --- /dev/null +++ b/test/getprop.js @@ -0,0 +1,30 @@ +var x11 = require('../lib/x11'); + +var xclient = x11.createClient(); +var PropertyChange = x11.eventMask.PropertyChange; + +xclient.on('connect', function(display) { + var X = this; + var root = display.screen[0].root; + var wid = X.AllocID(); + var white = display.screen[0].white_pixel; + var black = display.screen[0].black_pixel; + + X.CreateWindow(wid, root, 10, 10, 400, 300, 1, 1, 0, { backgroundPixel: white, eventMask: PropertyChange }); + X.MapWindow(wid); + + // mode: 0 replace, 1 prepend, 2 append + // mode, wid, name, type, format, data + X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS'); + setInterval(function() { + X.ChangeProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 8, 'Hello, NodeJS ' + new Date()); + }, 1000); + + xclient.on('event', function(ev) { + X.GetProperty(0, wid, xclient.atoms.WM_NAME, xclient.atoms.STRING, 0, 10000000, function(prop) { + if (prop.type == xclient.atoms.STRING) + prop.data = prop.data.toString(); + console.log(prop.data); + }); + }); +}); \ No newline at end of file