mirror of
https://github.com/danbulant/node-x11
synced 2026-06-10 18:20:35 +00:00
Add DPMS extension
- Implemented all requests defined in: http://www.x.org/releases/X11R7.6/doc/xextproto/dpms.pdf - Tests added.
This commit is contained in:
parent
78a9977228
commit
c0dccec8bc
2 changed files with 212 additions and 0 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);
|
||||
});
|
||||
};
|
||||
|
||||
112
test/dpms.js
Normal file
112
test/dpms.js
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
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;
|
||||
// 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.
|
||||
X.require('dpms', function(ext) {
|
||||
if (util.isError(ext)) {
|
||||
done(ext);
|
||||
} else {
|
||||
dpms = ext;
|
||||
dpms.GetVersion(undefined, undefined, function(err, version) {
|
||||
if (err) return done(err);
|
||||
version.should.eql([1, 1]);
|
||||
dpms.Capable(function(err, capable) {
|
||||
if (!err) capable.should.eql([1]);
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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