mirror of
https://github.com/danbulant/node-x11
synced 2026-07-03 10:10:36 +00:00
Merge pull request #14 from santigimeno/add_dpms_extension
Add DPMS extension
This commit is contained in:
commit
39e85aa20c
4 changed files with 260 additions and 1 deletions
100
lib/x11/ext/dpms.js
Normal file
100
lib/x11/ext/dpms.js
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
// http://www.x.org/releases/X11R7.6/doc/xextproto/dpms.txt
|
||||||
|
|
||||||
|
var x11 = require('..');
|
||||||
|
// TODO: move to templates
|
||||||
|
exports.requireExt = function(display, callback)
|
||||||
|
{
|
||||||
|
var X = display.client;
|
||||||
|
X.QueryExtension('DPMS', function(err, ext) {
|
||||||
|
|
||||||
|
if (!ext.present)
|
||||||
|
return callback(new Error('extension not available'));
|
||||||
|
|
||||||
|
ext.GetVersion = function(clientMaj, clientMin, callback)
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCSSS', [ext.majorOpcode, 0, 2, clientMaj, clientMin]);
|
||||||
|
X.replies[X.seq_num] = [
|
||||||
|
function(buf, opt) {
|
||||||
|
var res = buf.unpack('SS');
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
];
|
||||||
|
X.pack_stream.flush();
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.Capable = function(callback)
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]);
|
||||||
|
X.replies[X.seq_num] = [
|
||||||
|
function(buf, opt) {
|
||||||
|
var res = buf.unpack('C');
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
];
|
||||||
|
X.pack_stream.flush();
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.GetTimeouts = function(callback)
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCS', [ext.majorOpcode, 2, 1]);
|
||||||
|
X.replies[X.seq_num] = [
|
||||||
|
function(buf, opt) {
|
||||||
|
var res = buf.unpack('SSS');
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
];
|
||||||
|
X.pack_stream.flush();
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.SetTimeouts = function(standby_t, suspend_t, off_t)
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCSSSSxx', [ext.majorOpcode, 3, 3, standby_t, suspend_t, off_t]);
|
||||||
|
X.pack_stream.flush();
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.Enable = function()
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCS', [ext.majorOpcode, 4, 1]);
|
||||||
|
X.pack_stream.flush();
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.Disable = function()
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCS', [ext.majorOpcode, 5, 1]);
|
||||||
|
X.pack_stream.flush();
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.ForceLevel = function(level) // 0 : On, 1 : Standby, 2 : Suspend, 3 : Off
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCSSxx', [ext.majorOpcode, 6, 2, level]);
|
||||||
|
X.pack_stream.flush();
|
||||||
|
};
|
||||||
|
|
||||||
|
ext.Info = function(callback)
|
||||||
|
{
|
||||||
|
X.seq_num++;
|
||||||
|
X.pack_stream.pack('CCS', [ext.majorOpcode, 7, 1]);
|
||||||
|
X.replies[X.seq_num] = [
|
||||||
|
function(buf, opt) {
|
||||||
|
var res = buf.unpack('SC');
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
];
|
||||||
|
X.pack_stream.flush();
|
||||||
|
};
|
||||||
|
|
||||||
|
callback(ext);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
"should": "*"
|
"should": "*"
|
||||||
}
|
}
|
||||||
, "scripts": {
|
, "scripts": {
|
||||||
"test": "mocha -t 80000",
|
"test": "node test-runner.js",
|
||||||
"prepublish" : "npm prune"
|
"prepublish" : "npm prune"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
58
test-runner.js
Normal file
58
test-runner.js
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
var x11 = require('./lib/x11');
|
||||||
|
var Mocha = require('mocha');
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
|
var mocha = new Mocha({
|
||||||
|
timeout : 80000
|
||||||
|
});
|
||||||
|
|
||||||
|
// To be able to perform the tests we need the server:
|
||||||
|
// 1 - to support the dpms extension.
|
||||||
|
// 2 - dpms version is 1.1.
|
||||||
|
// 3 - to be dpms capable.
|
||||||
|
var run_dpms_test = function(cb) {
|
||||||
|
var client = x11.createClient(function(dpy) {
|
||||||
|
var display = dpy;
|
||||||
|
var X = display.client;
|
||||||
|
X.require('dpms', function(ext) {
|
||||||
|
if (!util.isError(ext)) {
|
||||||
|
dpms = ext;
|
||||||
|
dpms.GetVersion(undefined, undefined, function(err, version) {
|
||||||
|
if (!err && version[0] === 1 && version[1] === 1) {
|
||||||
|
dpms.Capable(function(err, capable) {
|
||||||
|
if (!err && capable[0] == 1) cb(true);
|
||||||
|
else cb(false);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
cb(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
cb(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('error', function() {
|
||||||
|
cb(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add all files from test root directory
|
||||||
|
fs.readdirSync('./test').forEach(function(file) {
|
||||||
|
if (file === 'dpms.js') {
|
||||||
|
run_dpms_test(function(run) {
|
||||||
|
if (run) {
|
||||||
|
mocha.addFile(path.join('./test', file));
|
||||||
|
}
|
||||||
|
|
||||||
|
mocha.run(function(){
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
mocha.addFile(path.join('./test', file));
|
||||||
|
}
|
||||||
|
});
|
||||||
101
test/dpms.js
Normal file
101
test/dpms.js
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
var x11 = require('../lib/x11');
|
||||||
|
var should = require('should');
|
||||||
|
var assert = require('assert');
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
|
describe('DPMS extension', function() {
|
||||||
|
var display;
|
||||||
|
var X;
|
||||||
|
var dpms;
|
||||||
|
before(function(done) {
|
||||||
|
var client = x11.createClient(function(dpy) {
|
||||||
|
display = dpy;
|
||||||
|
X = display.client;
|
||||||
|
X.require('dpms', function(ext) {
|
||||||
|
if (util.isError(ext)) {
|
||||||
|
done(ext);
|
||||||
|
} else {
|
||||||
|
dpms = ext;
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('error', done);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Setting the DPMS timeouts to specific values', function() {
|
||||||
|
|
||||||
|
var prev_timeouts;
|
||||||
|
before(function(done) {
|
||||||
|
dpms.GetTimeouts(function(err, timeouts) {
|
||||||
|
prev_timeouts = timeouts;
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('GetTimeouts should return those values', function(done) {
|
||||||
|
dpms.SetTimeouts(110, 110, 110);
|
||||||
|
dpms.GetTimeouts(function(err, timeouts) {
|
||||||
|
if (!err) timeouts.should.eql([110, 110, 110]);
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
dpms.SetTimeouts(prev_timeouts[0], prev_timeouts[1], prev_timeouts[2]);
|
||||||
|
dpms.GetTimeouts(function(err, timeouts) {
|
||||||
|
if (!err) timeouts.should.eql(prev_timeouts);
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Changing status and level of DPMS', function() {
|
||||||
|
var prev_status;
|
||||||
|
var prev_level;
|
||||||
|
before(function(done) {
|
||||||
|
dpms.Info(function(err, info) {
|
||||||
|
if (!err) {
|
||||||
|
prev_level = info[0];
|
||||||
|
prev_status = info[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Info should return the correct values', function(done) {
|
||||||
|
if (prev_status === 0) dpms.Enable(); // for force level to work dpms must be enabled
|
||||||
|
var new_level = prev_level === 0 ? 1 : 0;
|
||||||
|
dpms.ForceLevel(new_level);
|
||||||
|
dpms.Info(function(err, info) {
|
||||||
|
if (!err) {
|
||||||
|
info[0].should.equal(new_level);
|
||||||
|
info[1].should.equal(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
dpms.ForceLevel(prev_level);
|
||||||
|
if (prev_status) dpms.Enable();
|
||||||
|
else dpms.Disable();
|
||||||
|
dpms.Info(function(err, info) {
|
||||||
|
if (!err) {
|
||||||
|
info[0].should.equal(prev_level);
|
||||||
|
info[1].should.equal(prev_status);
|
||||||
|
}
|
||||||
|
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
X.terminate();
|
||||||
|
X.on('end', done);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue