mirror of
https://github.com/danbulant/node-x11
synced 2026-06-22 00:02:31 +00:00
Compare commits
169 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eeb9d58310 | ||
|
|
97e3600467 | ||
|
|
bf56aef5a4 | ||
|
|
7728cde55e | ||
|
|
89fd615f8f | ||
|
|
1db2cb54c3 | ||
|
|
4ece7f2b0b | ||
|
|
b50b222a74 | ||
|
|
9414ed788d | ||
|
|
c54dddd746 | ||
|
|
c41ad68e34 | ||
|
|
e17e8b04a1 | ||
|
|
3d6295f0df | ||
|
|
a16c1cb8eb | ||
|
|
8ed75f54e1 | ||
|
|
340432893d | ||
|
|
8500b1fc54 | ||
|
|
43a7e7375a | ||
|
|
f6547d3876 | ||
|
|
15c7149c6a | ||
|
|
4bddee6d5e | ||
|
|
8f322e5f8f | ||
|
|
5c46c4f1d3 | ||
|
|
29b454ee3d | ||
|
|
66bc53624d | ||
|
|
d1868d5ee8 | ||
|
|
2d7ffc2bcd | ||
|
|
4c6617c994 | ||
|
|
174cff9a9c | ||
|
|
2bb273993e | ||
|
|
d5c4103b1f | ||
|
|
d004af97fa | ||
|
|
ce51cefdad | ||
|
|
373b60b975 | ||
|
|
85905efeae | ||
|
|
ef001bd4fb | ||
|
|
6f535cb65d | ||
|
|
ed27aa84ff | ||
|
|
e87b183a8f | ||
|
|
fd09ef9848 | ||
|
|
4e84ae8e40 | ||
|
|
a97f7a179d | ||
|
|
bc9dceebd4 | ||
|
|
18cbbdf6ee | ||
|
|
da262fcb8d | ||
|
|
8049e70deb | ||
|
|
eb674cc41c | ||
|
|
f13247ec6d | ||
|
|
6598e75baf | ||
|
|
3ca322cecc | ||
|
|
97a582be5c | ||
|
|
7341a317bd | ||
|
|
37d0130b38 | ||
|
|
08a6ae573e | ||
|
|
0ad31e0ffe | ||
|
|
777becd99e | ||
|
|
77a94b1324 | ||
|
|
9b6492b34a | ||
|
|
562ed74562 | ||
|
|
9e967b9734 | ||
|
|
6293ab358b | ||
|
|
e3f6438e1a | ||
|
|
9ff1b645d1 | ||
|
|
77d1666c08 | ||
|
|
f2a118d034 | ||
|
|
7f39c65c93 | ||
|
|
f0b0bac336 | ||
|
|
e09c8b5429 | ||
|
|
8ed37aaa31 | ||
|
|
ba6d6f63a2 | ||
|
|
4f241ba2b3 | ||
|
|
f040f8bbba | ||
|
|
88370a111e | ||
|
|
b9bebe3a11 | ||
|
|
60f8b08037 | ||
|
|
1d77f21ec7 | ||
|
|
bbaf2a8654 | ||
|
|
7ed7e896e1 | ||
|
|
44f9982495 | ||
|
|
1f5e2310a6 | ||
|
|
a42f043768 | ||
|
|
c694394b6d | ||
|
|
e8883275bf | ||
|
|
edbe678f84 | ||
|
|
d327261c74 | ||
|
|
4fd0385911 | ||
|
|
27c70c7315 | ||
|
|
f21cdb187b | ||
|
|
86f977f9bd | ||
|
|
582bd1a1b2 | ||
|
|
e90c1fd239 | ||
|
|
ce238c7c0b | ||
|
|
70519cbb38 | ||
|
|
0d7346fbac | ||
|
|
7e22a439e8 | ||
|
|
72f79ea9f9 | ||
|
|
9a7adcefb1 | ||
|
|
62c6df1c6d | ||
|
|
f1e41dab05 | ||
|
|
97dba66197 | ||
|
|
7e8e972b24 | ||
|
|
6627fd5168 | ||
|
|
7f0b054dbc | ||
|
|
0ad17ed7e4 | ||
|
|
abde205593 | ||
|
|
b39672b9d3 | ||
|
|
84ecd7afe3 | ||
|
|
b635b3209d | ||
|
|
c473fe4f72 | ||
|
|
737ecc7b60 | ||
|
|
4a3f3f6075 | ||
|
|
21cc95a8bb | ||
|
|
a49c9adeb3 | ||
|
|
39a9931cbf | ||
|
|
fa9dbe2000 | ||
|
|
6ad3f94b93 | ||
|
|
d8cd686ea3 | ||
|
|
de2b73ca2b | ||
|
|
f21c8d3c2a | ||
|
|
5c72df00e5 | ||
|
|
c5fb01edaa | ||
|
|
63fbe2e671 | ||
|
|
6a69754e55 | ||
|
|
edd6126808 | ||
|
|
68e261dabe | ||
|
|
31785d9a5b | ||
|
|
51b03c5173 | ||
|
|
71599b100f | ||
|
|
dbe2d97bee | ||
|
|
3b18e43fe6 | ||
|
|
bd991fa6e3 | ||
|
|
28fdbadb0b | ||
|
|
573f83feab | ||
|
|
91ff5d451f | ||
|
|
f13a438e94 | ||
|
|
140960145b | ||
|
|
c00a790c2b | ||
|
|
2d7d6cbc8f | ||
|
|
fb817b8e2b | ||
|
|
39ec8aca60 | ||
|
|
472cdf5cfc | ||
|
|
90ea482119 | ||
|
|
749b877d99 | ||
|
|
fafa42e6e6 | ||
|
|
520be559e8 | ||
|
|
e7d9ba7cb4 | ||
|
|
dc90e2760d | ||
|
|
76f148345b | ||
|
|
20886399ed | ||
|
|
b0a926d3de | ||
|
|
33f953db32 | ||
|
|
45ab095ef2 | ||
|
|
28aa28eccb | ||
|
|
9b603d4375 | ||
|
|
a5cced0dbc | ||
|
|
ad59dbea4b | ||
|
|
ac450d184a | ||
|
|
2e7bf6cb18 | ||
|
|
b27831d1d2 | ||
|
|
b3ca6fb04b | ||
|
|
5e14ac2301 | ||
|
|
3e3f1805a2 | ||
|
|
ef2c30793a | ||
|
|
76ce6c4141 | ||
|
|
ea67111025 | ||
|
|
5e76aafd30 | ||
|
|
1d9c7f2f4b | ||
|
|
ff73173cd5 | ||
|
|
2f66f04d9f |
62 changed files with 5481 additions and 1919 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
*.log
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
node_modules
|
||||
15
.travis.yml
15
.travis.yml
|
|
@ -1,7 +1,16 @@
|
|||
before_script:
|
||||
- "export DISPLAY=:99.0"
|
||||
- "sh -e /etc/init.d/xvfb start"
|
||||
- "export XAUTHORITY=/tmp/.Xauthority-Xvfb"
|
||||
- "xauth add :99 . $(mcookie)"
|
||||
- "xauth add 127.0.0.2:99 . $(mcookie)"
|
||||
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -nolisten $NOLISTEN -auth $XAUTHORITY"
|
||||
- "sleep 1"
|
||||
|
||||
env:
|
||||
- NOLISTEN=tcp DISPLAY=:99.0
|
||||
# - NOLISTEN=unix DISPLAY=:99.0
|
||||
# - NOLISTEN=unix DISPLAY=127.0.0.2:99.0
|
||||
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.10
|
||||
- '12'
|
||||
- '14'
|
||||
|
|
|
|||
2
Changelog.md
Normal file
2
Changelog.md
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
1.0.3 - 19/02/2015
|
||||
- cleanup debug logs #83
|
||||
139
README.md
139
README.md
|
|
@ -1,47 +1,60 @@
|
|||
# About
|
||||
[](https://gitter.im/sidorares/node-x11?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
X11 protocol client for node.js
|
||||
# node-x11
|
||||
|
||||
Implements core X11 protocol, as well as Xrender, Damage, Composite, Big-Requests, Dpms, Screensaver, XFixes, Shape, XTest, XC-Misc, GLX and Apple-WM extensions.
|
||||
# install
|
||||
|
||||
`npm install x11`
|
||||
|
||||
Windows users:
|
||||
1) install [XMing](http://www.straightrunning.com/XmingNotes/) or [Cygwin/X](http://x.cygwin.com/)
|
||||
2) get node-x11 copy (using [git](http://code.google.com/p/msysgit/downloads/list?can=3) or from [Github](https://github.com/sidorares/node-x11/archives/master ))
|
||||
|
||||
#CI build status:
|
||||
X11 protocol client for Node.js: implements the core X11 protocol, as well as Xrender, Damage, Composite, Big-Requests, Dpms, Screensaver, XFixes, Shape, XTest, XC-Misc, GLX, and Apple-WM extensions.
|
||||
|
||||
[](https://gitter.im/sidorares/node-x11?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](http://travis-ci.org/sidorares/node-x11)
|
||||
|
||||
# example
|
||||
## Install
|
||||
|
||||
npm install x11
|
||||
|
||||
Windows users:
|
||||
|
||||
1. install [XMing](http://www.straightrunning.com/XmingNotes/) or [Cygwin/X](http://x.cygwin.com/)
|
||||
2. get node-x11 copy (using [git](http://code.google.com/p/msysgit/downloads/list?can=3) or from [Github](https://github.com/sidorares/node-x11/archives/master))
|
||||
|
||||
## Example
|
||||
|
||||
Core requests usage:
|
||||
|
||||
var x11 = require('x11');
|
||||
```js
|
||||
var x11 = require('x11');
|
||||
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
|
||||
x11.createClient(function(err, display) {
|
||||
x11.createClient(function(err, display) {
|
||||
if (!err) {
|
||||
var X = display.client;
|
||||
var root = display.screen[0].root;
|
||||
var wid = X.AllocID();
|
||||
X.CreateWindow(
|
||||
wid, root, // new window id, parent
|
||||
0, 0, 100, 100, // x, y, w, h
|
||||
0, 0, 0, 0, // border, depth, class, visual
|
||||
{ eventMask: Exposure|PointerMotion } // other parameters
|
||||
wid,
|
||||
root, // new window id, parent
|
||||
0,
|
||||
0,
|
||||
500,
|
||||
500, // x, y, w, h
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, // border, depth, class, visual
|
||||
{ eventMask: Exposure | PointerMotion } // other parameters
|
||||
);
|
||||
X.MapWindow(wid);
|
||||
var gc = X.AllocID();
|
||||
X.CreateGC(gc, wid);
|
||||
var white = display.screen[0].white_pixel;
|
||||
var black = display.screen[0].black_pixel;
|
||||
cidBlack = X.AllocID();
|
||||
cidWhite = X.AllocID();
|
||||
X.CreateGC(cidBlack, wid, { foreground: black, background: white });
|
||||
X.CreateGC(cidWhite, wid, { foreground: white, background: black });
|
||||
X.on('event', function(ev) {
|
||||
if (ev.type == 12)
|
||||
{
|
||||
X.PolyText8(wid, gc, 50, 50, ['Hello, Node.JS!']);
|
||||
if (ev.type == 12) {
|
||||
X.PolyFillRectangle(wid, cidWhite, [0, 0, 500, 500]);
|
||||
X.PolyText8(wid, cidBlack, 50, 50, ['Hello, Node.JS!']);
|
||||
}
|
||||
});
|
||||
X.on('error', function(e) {
|
||||
|
|
@ -50,43 +63,57 @@ Core requests usage:
|
|||
} else {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
# Screenshots
|
||||
## Screenshots
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
# In use
|
||||
- [ntk](https://github.com/sidorares/ntk) - higher level toolkit on top of X11
|
||||
- [node-remote](https://github.com/AndrewSwerlick/node-remote) - metia center controller
|
||||
- [tiles](https://github.com/dominictarr/tiles) - tiling window manager
|
||||
- [vnc](https://github.com/sidorares/node-vnc) - vnc client.
|
||||
- [node-ewmh](https://github.com/santigimeno/node-ewmh) - set of EWMH helpers.
|
||||
- [OdieWM](https://github.com/bu/OdieWM) - window manager
|
||||
- [Dbusmenu](https://github.com/sidorares/node-dbusmenu) - unity global menu client.
|
||||
## In use
|
||||
|
||||
# Protocol documentation
|
||||
- [ntk](https://github.com/sidorares/ntk) - higher level toolkit on top of X11
|
||||
- [node-remote](https://github.com/AndrewSwerlick/node-remote) - media center controller
|
||||
- [tiles](https://github.com/dominictarr/tiles) - tiling window manager
|
||||
- [vnc](https://github.com/sidorares/node-vnc) - vnc client.
|
||||
- [node-ewmh](https://github.com/santigimeno/node-ewmh) - set of EWMH helpers.
|
||||
- [OdieWM](https://github.com/bu/OdieWM) - window manager
|
||||
- [Dbusmenu](https://github.com/sidorares/node-dbusmenu) - unity global menu client.
|
||||
- [AirWM](https://github.com/AirWM/AirWM) - tiling window manager
|
||||
- [npdf](https://github.com/sidorares/npdf) - pdf viewer
|
||||
- [tinywm](https://github.com/Airblader/node-tinywm) The famous [TinyWM](https://github.com/mackstann/tinywm) written in node.js
|
||||
- [basedwm](https://github.com/anko/basedwm) Infinite-desktop panning X window manager in LiveScript
|
||||
|
||||
- http://www.x.org/releases/X11R7.6/doc/
|
||||
- http://www.x.org/releases/X11R7.6/doc/xproto/x11protocol.pdf
|
||||
- C Xlib to X11 request mapping table http://tronche.com/gui/x/xlib/appendix/a.html
|
||||
## X11 resources/documentation:
|
||||
|
||||
# Other implementations
|
||||
- [Xplain](https://github.com/magcius/xplain) - A series of articles to help explain the X Window System http://magcius.github.io/xplain/article/
|
||||
- [Official X11 docs](http://www.x.org/releases/X11R7.6/doc/)
|
||||
- [protocol specification](http://www.x.org/releases/X11R7.6/doc/xproto/x11protocol.pdf)
|
||||
- C Xlib to X11 request mapping table http://tronche.com/gui/x/xlib/appendix/a.html
|
||||
- [How to write composite manager](http://www.talisman.org/~erlkonig/misc/x11-composite-tutorial/)
|
||||
- [Extended Window Manager Hints specification](http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html)
|
||||
|
||||
- C: XLib - http://www.sbin.org/doc/Xlib/ http://www.tronche.com/gui/x/xlib/ http://www.x.org/docs/X11/xlib.pdf
|
||||
- C: XCB - http://xcb.freedesktop.org/
|
||||
- Python: http://sourceforge.net/projects/python-xlib/ ( github fork: https://github.com/Ademan/python-xlib-branch pypi: http://pypi.python.org/pypi/Python%20Xlib )
|
||||
- https://github.com/alexer/python-xlib-render
|
||||
- Python/twisted: https://launchpad.net/twisted-x11
|
||||
- Perl: http://search.cpan.org/~smccam/X11-Protocol-0.56/Protocol.pm
|
||||
- Go: https://github.com/BurntSushi/xgb
|
||||
- Java: https://github.com/xderoche/J11
|
||||
- Ruby: https://github.com/dj2/x-ruby-bindings
|
||||
- Clojure: https://github.com/noodlewiz/xcljb
|
||||
- Guile: https://github.com/mwitmer/guile-xcb
|
||||
## Other implementations
|
||||
|
||||
[](https://bitdeli.com/free "Bitdeli Badge")
|
||||
- C: XLib - http://www.sbin.org/doc/Xlib/ http://www.tronche.com/gui/x/xlib/ http://www.x.org/docs/X11/xlib.pdf
|
||||
- C: XCB - http://xcb.freedesktop.org/
|
||||
- Python: http://sourceforge.net/projects/python-xlib/ ( github fork: https://github.com/Ademan/python-xlib-branch pypi: http://pypi.python.org/pypi/Python%20Xlib )
|
||||
- https://github.com/alexer/python-xlib-render
|
||||
- Python/twisted: https://launchpad.net/twisted-x11
|
||||
- Perl: http://search.cpan.org/~smccam/X11-Protocol-0.56/Protocol.pm
|
||||
- Go: https://github.com/BurntSushi/xgb
|
||||
- Java: https://github.com/xderoche/J11
|
||||
- Ruby: https://github.com/dj2/x-ruby-bindings
|
||||
- Clojure: https://github.com/noodlewiz/xcljb
|
||||
- Guile: https://github.com/mwitmer/guile-xcb
|
||||
- Emacs lisp: https://github.com/ch11ng/xelb ( autogenerated from XCB XML )
|
||||
|
||||
## Server side (protocol + functionality) implementations for js + DOM
|
||||
|
||||
would be really great to make completely web based playground page, connecting node-x11 api to DOM based implementation
|
||||
|
||||
- https://github.com/GothAck/javascript-x-server
|
||||
- https://github.com/ttaubert/x-server-js
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ function genReq(req, last)
|
|||
if (req.body.length == 0)
|
||||
{
|
||||
result.push(' function() {');
|
||||
result.push(' return new Buffer([' + req.opcode + ', 0, 1, 0]);');
|
||||
result.push(' return Buffer.from([' + req.opcode + ', 0, 1, 0]);');
|
||||
} else {
|
||||
result.push(' function (args) {');
|
||||
result.push(' var extraLength = 0;');
|
||||
|
|
@ -287,10 +287,10 @@ function genReq(req, last)
|
|||
var reqLen4 = ((reqLen + 3) >> 2);
|
||||
|
||||
if (extraLength)
|
||||
result.push(' var data = new Buffer(' + reqLen + ' + extraLength);');
|
||||
result.push(' var data = Buffer.alloc(' + reqLen + ' + extraLength);');
|
||||
else {
|
||||
result.pop();
|
||||
result.push(' var data = new Buffer(' + reqLen + ');');
|
||||
result.push(' var data = Buffer.alloc(' + reqLen + ');');
|
||||
}
|
||||
result.push(' data[0] = ' + req.opcode + ';');
|
||||
if (req.body.length != 0) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ var ButtonRelease = x11.eventMask.ButtonRelease;
|
|||
// image and coords file from http://www.patrick-wied.at/projects/heatmap-keyboard/
|
||||
// TODO: add simple tool to use&tag coords in own keyboard photo
|
||||
// jpeg decoder is slightly modified version of https://github.com/notmasteryet/jpgjs
|
||||
var kbdImg = require('./node-jpg').readJpeg('./keyboard.jpg');
|
||||
var kbdImg = require('./node-jpg').readJpeg(__dirname+'/keyboard.jpg');
|
||||
var keycoords = require('./coordinates');
|
||||
|
||||
// from https://github.com/substack/node-keysym
|
||||
|
|
|
|||
|
|
@ -571,7 +571,7 @@ module.exports.readJpeg = function(path)
|
|||
var imageData = {};
|
||||
imageData.width = j.width;
|
||||
imageData.height = j.height;
|
||||
imageData.data = new Buffer(j.width*j.height*4);
|
||||
imageData.data = Buffer.from(j.width*j.height*4);
|
||||
j.copyToImageData(imageData);
|
||||
return imageData;
|
||||
}
|
||||
|
|
|
|||
69
examples/key-recognition.js
Normal file
69
examples/key-recognition.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
var x11 = require('..');
|
||||
|
||||
// The list provided by GetKeyboardMapping has sublists where each position
|
||||
// represents the result for some key composition.
|
||||
keyComposition = [
|
||||
'Key',
|
||||
'shift + Key',
|
||||
'modeSwitch + Key',
|
||||
'modeSwitch + shift + Key',
|
||||
'altGr + Key',
|
||||
'altGr + shift + Key'
|
||||
]
|
||||
|
||||
x11.createClient(function(err, display){
|
||||
if (err) throw err
|
||||
|
||||
var min = display.min_keycode, // TODO: explain min_keycode
|
||||
max = display.max_keycode, // TODO: explain max_keycode
|
||||
chr2Data = [], // allow us to find a char by the charcode
|
||||
key2Data = []; // associate chars to a keycode
|
||||
|
||||
// The keySyms is a hash of mnemonic char names, associated to an integer
|
||||
// charcode and its description.
|
||||
for (codeName in x11.keySyms) {
|
||||
keyData = x11.keySyms[codeName];
|
||||
chr2Data[keyData.code] = { codeName: codeName, description: keyData.description };
|
||||
}
|
||||
|
||||
var X = display.client,
|
||||
wid = X.AllocID(), // Get a free integer id to a new window.
|
||||
root = display.screen[0].root, // The mother window. Like your window manager.
|
||||
evKeyPress = x11.eventMask.KeyPress, // Allow to filter for KeyPress events.
|
||||
white = display.screen[0].white_pixel; // Will paint the window.
|
||||
|
||||
// Get the local key mapping to build key2Data.
|
||||
X.GetKeyboardMapping(min, max-min, function(err, list) {
|
||||
for (var i=0; i < list.length; ++i) {
|
||||
var name = key2Data[i+min] = [];
|
||||
var sublist = list[i];
|
||||
for (var j=0; j < sublist.length; ++j)
|
||||
name.push(chr2Data[sublist[j]]);
|
||||
}
|
||||
});
|
||||
|
||||
// Launch a window to listen by key events:
|
||||
X.CreateWindow(wid, root, 0, 0, 100, 100, 0, 0, 0, 0, { backgroundPixel: white, eventMask: evKeyPress });
|
||||
X.MapWindow(wid);
|
||||
|
||||
X.on('event', function(ev) {
|
||||
if (ev.type == 2) { // filter by KeyPress. Useful if you have a more open eventMask.
|
||||
var key = key2Data[ev.keycode]; // key is a list of chars related to the pressed key.
|
||||
if (key) {
|
||||
console.log('\n>> key pressed:', ev.keycode);
|
||||
for (var i=0; i<key.length; i++) // Describe each related char
|
||||
if (key[i])
|
||||
console.log(
|
||||
key[i].codeName, '\t', (
|
||||
key[i].description ? key[i].description : 'no description'
|
||||
), (
|
||||
keyComposition[i] ? '\t' + keyComposition[i] : ''
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
console.log('>> keyCode '+ ev.keycode +' was not recognized.');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -874,7 +874,7 @@ module.exports.readPng = function(path)
|
|||
var imageData = {};
|
||||
imageData.width = j.width;
|
||||
imageData.height = j.height;
|
||||
imageData.data = new Buffer(j.width*j.height*4);
|
||||
imageData.data = Buffer.alloc(j.width*j.height*4);
|
||||
j.render(imageData);
|
||||
return imageData;
|
||||
}
|
||||
|
|
|
|||
344
examples/png/png-decoder.js
Normal file
344
examples/png/png-decoder.js
Normal file
|
|
@ -0,0 +1,344 @@
|
|||
/*
|
||||
* Simple png decoder
|
||||
* https://github.com/b37t1td/png-decoder
|
||||
*/
|
||||
|
||||
var CRCTable = new Int32Array([
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
]);
|
||||
|
||||
var crc32 = function(buf) {
|
||||
var crc = -1;
|
||||
for (var i = 0; i < buf.length; i++) {
|
||||
crc = CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
|
||||
}
|
||||
return crc ^ -1;
|
||||
};
|
||||
|
||||
/*
|
||||
* BE byteArray implementation
|
||||
* by Svetlana Linuxenko <linuxenko@yahoo.com>
|
||||
*/
|
||||
|
||||
/* eslint no-undef: 0 */
|
||||
var byteArray = Uint8Array;
|
||||
|
||||
var cmp = function(a, b) {
|
||||
if (!b) b = a; a = this;
|
||||
return a.filter(function(c,i) { return c === b[i]; }).length === a.length;
|
||||
};
|
||||
|
||||
var toInt = function(a) {
|
||||
if (!a) a = this.slice(this.off, 4);
|
||||
return (a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3];
|
||||
//return a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);
|
||||
};
|
||||
|
||||
var toBytes = function(int) {
|
||||
return new byteArray([
|
||||
(int >> 24) & 0xff,
|
||||
(int >> 16) & 0xff,
|
||||
(int >> 8) & 0xff,
|
||||
int & 0xff
|
||||
]);
|
||||
};
|
||||
|
||||
var nextInt = function() {
|
||||
return this.toInt(this.slice(this.off, (this.off += 4)));
|
||||
};
|
||||
|
||||
var nextIntBytes = function() {
|
||||
return this.nextBytes(4);
|
||||
};
|
||||
|
||||
var nextBytes = function(size) {
|
||||
return this.slice(this.off, (this.off += size));
|
||||
};
|
||||
|
||||
var nextByte = function() {
|
||||
return this.nextBytes(1)[0];
|
||||
};
|
||||
|
||||
var insertInt = function(int) {
|
||||
this.insertBytes(this.toBytes(int));
|
||||
};
|
||||
|
||||
var insertBytes = function(bytes, length) {
|
||||
length = length || 4;
|
||||
this.set(bytes, this.off, length);
|
||||
this.off += length;
|
||||
};
|
||||
|
||||
var insertByte = function(byte) {
|
||||
this.set([byte], this.off, (this.off += 1));
|
||||
};
|
||||
|
||||
byteArray.prototype.cmp = cmp;
|
||||
byteArray.prototype.toInt = toInt;
|
||||
byteArray.prototype.nextInt = nextInt;
|
||||
byteArray.prototype.nextIntBytes = nextIntBytes;
|
||||
byteArray.prototype.toBytes = toBytes;
|
||||
byteArray.prototype.insertInt = insertInt;
|
||||
byteArray.prototype.insertBytes = insertBytes;
|
||||
byteArray.prototype.nextBytes = nextBytes;
|
||||
byteArray.prototype.nextByte = nextByte;
|
||||
byteArray.prototype.insertByte = insertByte;
|
||||
|
||||
Object.defineProperty(byteArray.prototype , 'off', {
|
||||
enumerable: false,
|
||||
configurable: false,
|
||||
writable: true,
|
||||
value : 0
|
||||
});
|
||||
|
||||
|
||||
var SIGNATURE = new byteArray([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
||||
var IHDR = new byteArray([0x49, 0x48, 0x44, 0x52]);
|
||||
var IDAT = new byteArray([0x49, 0x44, 0x41, 0x54]);
|
||||
var IEND = new byteArray([0x49, 0x45, 0x4e, 0x44]);
|
||||
|
||||
|
||||
/*
|
||||
* Decoder
|
||||
*/
|
||||
var zlib = require('zlib');
|
||||
|
||||
var inflateFunction = function(data) {
|
||||
return zlib.inflateSync(Buffer.from(data));
|
||||
};
|
||||
|
||||
|
||||
var Decoder = function() { };
|
||||
|
||||
Decoder.prototype.parse = function(data) {
|
||||
if (!(data instanceof byteArray)) {
|
||||
data = new byteArray(data);
|
||||
}
|
||||
|
||||
if (!SIGNATURE.cmp(data.nextBytes(SIGNATURE.length))) {
|
||||
throw new Error('Not png');
|
||||
}
|
||||
|
||||
while (data.off < data.length) {
|
||||
var len = data.nextInt();
|
||||
var hdr = data.nextBytes(len + 4);
|
||||
|
||||
if (crc32(hdr) !== data.nextInt()) {
|
||||
throw new Error('Crc error');
|
||||
}
|
||||
|
||||
if (IHDR.cmp(hdr)) {
|
||||
this._IHDR = this._chunkIHDR(hdr.slice(4, len + 4));
|
||||
|
||||
if (this._IHDR.palette !== 8) {
|
||||
throw new Error('Depth error');
|
||||
}
|
||||
|
||||
if (this._IHDR.compression !== 0) {
|
||||
throw new Error('Compression error');
|
||||
}
|
||||
|
||||
if (this._IHDR.filter !== 0) {
|
||||
throw new Error('Filter error');
|
||||
}
|
||||
|
||||
if (this._IHDR.interlace !== 0) {
|
||||
throw new Error('Interlace error');
|
||||
}
|
||||
|
||||
switch (this._IHDR.colorType){
|
||||
case 0: this.bpp = 1; break;
|
||||
case 2: this.bpp = 3; break;
|
||||
case 3: this.bpp = 1; break;
|
||||
case 4: this.bpp = 2; break;
|
||||
case 6: this.bpp = 4; break;
|
||||
default: throw new Error('ColorType error');
|
||||
}
|
||||
this.chunks = [];
|
||||
}
|
||||
|
||||
if (IDAT.cmp(hdr)) {
|
||||
if (!this._IHDR) {
|
||||
throw new Error('IHDR error');
|
||||
}
|
||||
|
||||
this._chunkIDAT(hdr.slice(4, len + 4));
|
||||
}
|
||||
|
||||
if (IEND.cmp(hdr)) {
|
||||
return this._chunkIEND();
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Data error');
|
||||
};
|
||||
|
||||
Decoder.prototype._chunkIEND = function() {
|
||||
var tmp = [];
|
||||
for (var i = 0; i < this.chunks.length; i++) {
|
||||
for (var j = 0; j < this.chunks[i].length; j++) {
|
||||
tmp.push(this.chunks[i][j]);
|
||||
}
|
||||
}
|
||||
return this.filter(inflateFunction(tmp));
|
||||
};
|
||||
|
||||
Decoder.prototype._chunkIDAT = function(chunk) {
|
||||
this.chunks.push(chunk);
|
||||
};
|
||||
|
||||
Decoder.prototype._chunkIHDR = function(chunk) {
|
||||
return {
|
||||
width : chunk.nextInt(),
|
||||
height : chunk.nextInt(),
|
||||
palette : chunk.nextByte(),
|
||||
colorType : chunk.nextByte(),
|
||||
compression : chunk.nextByte(),
|
||||
filter : chunk.nextByte(),
|
||||
interlace : chunk.nextByte()
|
||||
};
|
||||
};
|
||||
|
||||
Decoder.prototype.filter = function(data) {
|
||||
var bpp = this.bpp;
|
||||
var width = this._IHDR.width, height = this._IHDR.height;
|
||||
var pixels = new byteArray((width * height) * bpp);
|
||||
var filter, line, left, leftup, up, pixel;
|
||||
var lineWidth = width * bpp, byte, off;
|
||||
|
||||
for (var y = 0; y < height; y++) {
|
||||
|
||||
filter = data.nextByte();
|
||||
line = data.nextBytes(lineWidth);
|
||||
|
||||
for (var x = 0; x < lineWidth; x++) {
|
||||
|
||||
if (filter !== 0) {
|
||||
off = (y * lineWidth) + x;
|
||||
}
|
||||
|
||||
byte = line.nextByte();
|
||||
|
||||
switch(filter) {
|
||||
case 0: //None
|
||||
pixel = byte;
|
||||
break;
|
||||
case 1: // Sub Raw(x) + Raw(x - bpp)
|
||||
if (x < bpp) {
|
||||
pixel = byte;
|
||||
break;
|
||||
}
|
||||
pixel = pixels[off - bpp] + byte & 0xff;
|
||||
break;
|
||||
case 2: // Up(x) = Raw(x) + Prior(x)
|
||||
if (y === 0) {
|
||||
pixel = byte;
|
||||
break;
|
||||
}
|
||||
pixel = pixels[off - lineWidth] + byte & 0xff;
|
||||
break;
|
||||
case 3: // Average(x) = Raw(x) + floor((Raw(x-bpp)+Prior(x))/2)
|
||||
if (y === 0) {
|
||||
if (x < bpp) {
|
||||
pixel = byte;
|
||||
} else {
|
||||
pixel = (byte + (pixels[off - bpp] >> 1)) & 0xff;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (x < bpp) {
|
||||
pixel = (byte + (pixels[off - lineWidth] >> 1)) & 0xff;
|
||||
break;
|
||||
}
|
||||
|
||||
pixel = (byte + (pixels[off - bpp] + pixels[off - lineWidth] >> 1)) & 0xff;
|
||||
break;
|
||||
case 4: // Paeth
|
||||
if (y === 0) {
|
||||
if (x < bpp) {
|
||||
pixel = byte;
|
||||
} else {
|
||||
pixel = (byte + (pixels[off - bpp])) & 0xff;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (x < bpp) {
|
||||
pixel = (byte + (pixels[off - lineWidth])) & 0xff;
|
||||
break;
|
||||
}
|
||||
|
||||
up = pixels[off - lineWidth];
|
||||
left = pixels[off - bpp];
|
||||
leftup = pixels[(off - lineWidth) - bpp];
|
||||
|
||||
var p = left + up - leftup,
|
||||
pleft = Math.abs(p - left),
|
||||
pup = Math.abs(p - up),
|
||||
pleftup = Math.abs(p - leftup);
|
||||
|
||||
if (pleft <= pup && pleft <= pleftup){
|
||||
pixel = byte + left & 0xff;
|
||||
break;
|
||||
} else if (pup <= pleftup) {
|
||||
pixel = byte + up & 0xff;
|
||||
break;
|
||||
}
|
||||
|
||||
pixel = byte + leftup & 0xff;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Filter error: ' + filter);
|
||||
}
|
||||
|
||||
pixels.insertByte(pixel);
|
||||
}
|
||||
}
|
||||
|
||||
return pixels;
|
||||
};
|
||||
|
||||
module.exports = Decoder;
|
||||
BIN
examples/png/screen.png
Normal file
BIN
examples/png/screen.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
80
examples/png/test1.js
Normal file
80
examples/png/test1.js
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
//var logo = require('./node-png').readPng('./node-logo.png');
|
||||
var fs = require('fs');
|
||||
var Decoder = require('./png-decoder');
|
||||
var decoder = new Decoder();
|
||||
|
||||
var logo = {
|
||||
data : Buffer.from(decoder.parse(fs.readFileSync('./screen.png'))),
|
||||
width : decoder._IHDR.width,
|
||||
height : decoder._IHDR.height
|
||||
};
|
||||
|
||||
var x11 = require('../../lib');
|
||||
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
|
||||
x11.createClient(function(err, display)
|
||||
{
|
||||
var X = display.client;
|
||||
X.require('render', function(err, Render) {
|
||||
var root = display.screen[0].root;
|
||||
main(root, X, Render, display);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function main(root, X, Render, display) {
|
||||
|
||||
var win, picWin, pic, gc;
|
||||
|
||||
win = X.AllocID();
|
||||
X.CreateWindow(
|
||||
win, root,
|
||||
0, 0, logo.width, logo.height,
|
||||
0, 0, 0, 0,
|
||||
{ eventMask: Exposure }
|
||||
);
|
||||
X.MapWindow(win);
|
||||
|
||||
gc = X.AllocID();
|
||||
X.CreateGC(gc, win);
|
||||
|
||||
var logoPixmap = X.AllocID();
|
||||
X.CreatePixmap(logoPixmap, win, 24, logo.width, logo.height);
|
||||
|
||||
var rscreen = display.screen[0];
|
||||
var screen =
|
||||
rscreen.depths[rscreen.root_depth][
|
||||
Object.keys(rscreen.depths[rscreen.root_depth])[0]];
|
||||
|
||||
var rmask = parseInt(screen.red_mask, 10);
|
||||
var gmask = parseInt(screen.green_mask, 10);
|
||||
var bmask = parseInt(screen.blue_mask, 10);
|
||||
|
||||
for (var y = 0; y < logo.height; y++) {
|
||||
for (var x = 0; x < logo.width; x++) {
|
||||
var pixel = Buffer.from([
|
||||
logo.data[(x + logo.width * y) * 4],
|
||||
logo.data[(x + logo.width * y) * 4 + 1],
|
||||
logo.data[(x + logo.width * y) * 4 + 2], 0]).readInt32LE();
|
||||
|
||||
logo.data[(x + logo.width * y) * 4 ] = (pixel & rmask) >> 16;
|
||||
logo.data[(x + logo.width * y) * 4 + 1] = (pixel & gmask) >> 8;
|
||||
logo.data[(x + logo.width * y) * 4 + 2] = (pixel & bmask) >> 0;
|
||||
logo.data[(x + logo.width * y) * 4 + 3] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
X.PutImage(2, logoPixmap, gc, logo.width, logo.height, 0, 0, 0, 24, logo.data);
|
||||
|
||||
var logoPicture = X.AllocID();
|
||||
Render.CreatePicture(logoPicture, logoPixmap, Render.rgb24);
|
||||
var winPicture = X.AllocID();
|
||||
Render.CreatePicture(winPicture, win, Render.rgb24);
|
||||
|
||||
X.on('event', function(ev) {
|
||||
if (ev.name == 'Expose') {
|
||||
Render.Composite(3, logoPicture, 0, winPicture, 0, 0, 0, 0, 0, 0, logo.width, logo.height);
|
||||
}
|
||||
});
|
||||
}
|
||||
14
examples/screenshot.js
Executable file → Normal file
14
examples/screenshot.js
Executable file → Normal file
|
|
@ -11,13 +11,13 @@ x11.createClient(function(err, display) {
|
|||
X.CreateGC(gc, id);
|
||||
var width = 0;
|
||||
var hwight = 0;
|
||||
X.GetGeometry(id, function(clientGeom) {
|
||||
X.GetGeometry(id, function(err, clientGeom) {
|
||||
width = clientGeom.width;
|
||||
height = clientGeom.height;
|
||||
|
||||
|
||||
var dispwin = X.AllocID();
|
||||
X.CreateWindow(dispwin, root, 0, 0, width, height, 1, 1, 0, { eventMask: x11.eventMask.Exposure });
|
||||
X.CreateWindow(dispwin, root, 0, 0, width, height, 0, 0, 0, 0, { eventMask: x11.eventMask.Exposure });
|
||||
X.MapWindow(dispwin);
|
||||
//X.CopyArea(idScreenshot, dispwin, gc, 0, 0, 0, 0, width, height);
|
||||
|
||||
|
|
@ -35,10 +35,10 @@ x11.createClient(function(err, display) {
|
|||
if (win == dispwin)
|
||||
return drawWithKids(list, cb);
|
||||
|
||||
X.GetWindowAttributes(win, function(res) {
|
||||
X.GetWindowAttributes(win, function(err, res) {
|
||||
if (res[8] == 0)
|
||||
return drawWithKids(list, cb);
|
||||
X.GetGeometry(win, function(geom) {
|
||||
X.GetGeometry(win, function(err, geom) {
|
||||
// (srcDrawable, dstDrawable, gc, srcX, srcY, dstX, dstY, width, height)
|
||||
if (win != root)
|
||||
X.CopyArea(win, dispwin, gc, 0, 0, p.x + geom.xPos, p.y + geom.yPos, geom.width, geom.height);
|
||||
|
|
@ -71,7 +71,11 @@ x11.createClient(function(err, display) {
|
|||
|
||||
});
|
||||
*/
|
||||
X.GetImage(2, root, 0, 0, width, height, 0xffffffff, function(image) {
|
||||
X.GetImage(2, id, 0, 0, width, height, 0xffffffff, function(err, image) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(image);
|
||||
// format, drawable, gc, width, height, dstX, dstY, leftPad, depth, data
|
||||
X.PutImage(2, dispwin, gc, width, height, 0, 0, 0, 24, image.data);
|
||||
|
|
|
|||
36
examples/simple/gcinvert.js
Normal file
36
examples/simple/gcinvert.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* GCFunction usage example
|
||||
*/
|
||||
var x11 = require('../../lib');
|
||||
|
||||
x11.createClient(function(err, display) {
|
||||
var X = display.client;
|
||||
var root = display.screen[0].root;
|
||||
var white = display.screen[0].white_pixel;
|
||||
var black = display.screen[0].black_pixel;
|
||||
|
||||
var wid = X.AllocID();
|
||||
X.CreateWindow(wid, root, 0, 0, 400, 300, 0, 0, 0, 0, {
|
||||
backgroundPixel: black,
|
||||
eventMask: x11.eventMask.ButtonPress|x11.eventMask.Exposure });
|
||||
var gc = X.AllocID();
|
||||
X.CreateGC(gc, wid, {foreground : white, 'function' : x11.gcFunction.GXinvert});
|
||||
X.MapWindow(wid);
|
||||
|
||||
|
||||
X.on('event', function(ev) {
|
||||
|
||||
if (ev.type === 12) {
|
||||
X.PolyFillRectangle(wid, gc, [0, 0, 400, 300]);
|
||||
}
|
||||
|
||||
if (ev.type === 4) {
|
||||
var x = ev.x;
|
||||
var y = ev.y;
|
||||
|
||||
X.PolyFillRectangle(wid, gc, [x - 25, y - 25, 50, 50]);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -7,7 +7,7 @@ var xclient = x11.createClient(function(err, display) {
|
|||
display.client.require('render', function(err, Render) {
|
||||
var wid = X.AllocID();
|
||||
var white = display.screen[0].white_pixel;
|
||||
varblack = display.screen[0].black_pixel;
|
||||
var black = display.screen[0].black_pixel;
|
||||
X.CreateWindow(wid, root, 10, 10, 400, 300, 0, 0, 0, 0, { backgroundPixel: white, eventMask: PointerMotion });
|
||||
X.MapWindow(wid);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ function padWidth(buf, width) {
|
|||
return buf;
|
||||
else {
|
||||
var stride = (width+3)&~3;
|
||||
var res = new Buffer(height*stride);
|
||||
var res = Buffer.alloc(height*stride);
|
||||
res.fill(0);
|
||||
for (var y=0; y < height; ++y) {
|
||||
// memcpy(tmpbitmap+y*stride, bitmap->buffer+y*ginfo.width, ginfo.width);
|
||||
|
|
@ -42,7 +42,7 @@ var xclient = x11.createClient({ debug: true }, function(err, display) {
|
|||
display.client.require('render', function(err, Render) {
|
||||
var wid = X.AllocID();
|
||||
var white = display.screen[0].white_pixel;
|
||||
varblack = display.screen[0].black_pixel;
|
||||
var black = display.screen[0].black_pixel;
|
||||
X.CreateWindow(wid, root, 10, 10, 400, 300, 0, 0, 0, 0, { backgroundPixel: white, eventMask: Exposure|PointerMotion });
|
||||
X.MapWindow(wid);
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ var xclient = x11.createClient({ debug: true }, function(err, display) {
|
|||
var glyphFromCode = [];
|
||||
glyphs.forEach(function(g) {
|
||||
if (!g.image || (g.image.length == 0)) {
|
||||
g.image = new Buffer(64);
|
||||
g.image = Buffer.alloc(64);
|
||||
g.image.fill(0);
|
||||
g.width = 8;
|
||||
g.height = 8;
|
||||
|
|
|
|||
51
examples/smoketest/blur-convolution.js
Normal file
51
examples/smoketest/blur-convolution.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// the code is taken from https://github.com/mattlockyer/iat455/blob/6493c882f1956703133c1bffa1d7ee9a83741cbe/assignment1/assignment/effects/blur-effect-dyn.js
|
||||
// (c) Matt Lockyer, https://github.com/mattlockyer
|
||||
|
||||
function hypotenuse(x1, y1, x2, y2) {
|
||||
var xSquare = Math.pow(x1 - x2, 2);
|
||||
var ySquare = Math.pow(y1 - y2, 2);
|
||||
return Math.sqrt(xSquare + ySquare);
|
||||
}
|
||||
|
||||
/*
|
||||
* Generates a kernel used for the gaussian blur effect.
|
||||
*
|
||||
* @param dimension is an odd integer
|
||||
* @param sigma is the standard deviation used for our gaussian function.
|
||||
*
|
||||
* @returns an array with dimension^2 number of numbers, all less than or equal
|
||||
* to 1. Represents our gaussian blur kernel.
|
||||
*/
|
||||
function generateGaussianKernel(dimension, sigma) {
|
||||
if (!(dimension % 2) || Math.floor(dimension) !== dimension || dimension<3) {
|
||||
throw new Error(
|
||||
'The dimension must be an odd integer greater than or equal to 3'
|
||||
);
|
||||
}
|
||||
var kernel = [];
|
||||
|
||||
var twoSigmaSquare = 2 * sigma * sigma;
|
||||
var centre = (dimension - 1) / 2;
|
||||
|
||||
for (var i = 0; i < dimension; i++) {
|
||||
for (var j = 0; j < dimension; j++) {
|
||||
var distance = hypotenuse(i, j, centre, centre);
|
||||
|
||||
// The following is an algorithm that came from the gaussian blur
|
||||
// wikipedia page [1].
|
||||
//
|
||||
// http://en.wikipedia.org/w/index.php?title=Gaussian_blur&oldid=608793634#Mechanics
|
||||
var gaussian = (1 / Math.sqrt(
|
||||
Math.PI * twoSigmaSquare
|
||||
)) * Math.exp((-1) * (Math.pow(distance, 2) / twoSigmaSquare));
|
||||
|
||||
kernel.push(gaussian);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the unit vector of the kernel array.
|
||||
var sum = kernel.reduce(function (c, p) { return c + p; });
|
||||
return kernel.map(function (e) { return e / sum; });
|
||||
}
|
||||
|
||||
module.exports = generateGaussianKernel;
|
||||
|
|
@ -6,7 +6,7 @@ var Pixmap = require('./pixmap').Pixmap;
|
|||
var Buffer = require('buffer').Buffer;
|
||||
require('../../lib/unpackbuffer').addUnpack(Buffer);
|
||||
|
||||
var reversed = new Buffer(256);
|
||||
var reversed = Buffer.alloc(256);
|
||||
for (var i=0; i < 256; ++i)
|
||||
{
|
||||
var res = 0;
|
||||
|
|
|
|||
15
examples/smoketest/cleararea.js
Normal file
15
examples/smoketest/cleararea.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
var x11 = require('../../lib');
|
||||
var Window = require('./wndwrap');
|
||||
|
||||
x11.createClient(function(err, display) {
|
||||
var X = display.client;
|
||||
var w = new Window(X, 0, 0, 700, 500);
|
||||
w.map();
|
||||
|
||||
w.on('expose', function() {
|
||||
var gc = X.AllocID();
|
||||
X.CreateGC(gc, w.id, { foreground: w.black, background: w.white });
|
||||
X.PolyFillRectangle(w.id, gc, [50, 50, 600, 400]);
|
||||
X.ClearArea(w.id, 0, 0, 300, 300, 0);
|
||||
});
|
||||
});
|
||||
|
|
@ -5,7 +5,7 @@ var keysym = require('keysym');
|
|||
var ks = x11.keySyms;
|
||||
var ks2Name = {};
|
||||
for (var key in ks)
|
||||
ks2Name[ ks[key] ] = key;
|
||||
ks2Name[ ks[key].code ] = key;
|
||||
var kk2Name = {};
|
||||
|
||||
x11.createClient(function(err, display) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ var xclient = x11.createClient();
|
|||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
|
||||
var bitmap = new Buffer(128*128/8); // 16384 bits, 2048 bytes bitmap
|
||||
var bitmap = Buffer.alloc(128*128/8); // 16384 bits, 2048 bytes bitmap
|
||||
for (var i=0; i < bitmap.length; ++i)
|
||||
{
|
||||
bitmap[i] = i % 256;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ var x11 = require('../../lib');
|
|||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
|
||||
var bitmap = new Buffer(128*128*4); // 16384 bits, 2048 bytes bitmap
|
||||
var bitmap = Buffer.alloc(128*128*4); // 16384 bits, 2048 bytes bitmap
|
||||
for (var i=0; i < bitmap.length; ++i)
|
||||
{
|
||||
var byteNum = i%4;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
var x11 = require('../../lib');
|
||||
|
||||
var xclient = x11.createClient();
|
||||
var xclient = x11.createClient({debug: true});
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
var pts = [];
|
||||
|
||||
xclient.on('connect', function(err, display) {
|
||||
xclient.on('connect', function(display) {
|
||||
var X = this;
|
||||
var root = display.screen[0].root;
|
||||
var white = display.screen[0].white_pixel;
|
||||
|
|
@ -13,16 +13,14 @@ xclient.on('connect', function(err, display) {
|
|||
|
||||
function createWindow()
|
||||
{
|
||||
|
||||
var wid = X.AllocID();
|
||||
// id, parentId, x, y, width, height, borderWidth, depth, _class, visual, values
|
||||
X.CreateWindow(
|
||||
wid, root,
|
||||
10, 10, 400, 300,
|
||||
1, 1, 0,
|
||||
{
|
||||
0, 0, 0, 0, {
|
||||
backgroundPixel: white, eventMask: Exposure|PointerMotion
|
||||
}
|
||||
);
|
||||
});
|
||||
X.MapWindow(wid);
|
||||
return wid;
|
||||
}
|
||||
|
|
@ -59,7 +57,7 @@ xclient.on('connect', function(err, display) {
|
|||
}
|
||||
});
|
||||
|
||||
X.on('error', function(e) {
|
||||
console.log(e);
|
||||
});
|
||||
//X.on('error', function(e) {
|
||||
// console.log(e);
|
||||
//});
|
||||
});
|
||||
|
|
|
|||
22
examples/smoketest/shape-rectangles.js
Normal file
22
examples/smoketest/shape-rectangles.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
var x11 = require('../../lib');
|
||||
|
||||
var Expose = 12;
|
||||
|
||||
x11.createClient(function(err, display) {
|
||||
var X = display.client;
|
||||
var root = display.screen[0].root;
|
||||
X.require('shape', function(err, Shape) {
|
||||
var win = X.AllocID();
|
||||
X.CreateWindow(win, root, 0, 0, 200, 200);
|
||||
X.ChangeWindowAttributes(win, { backgroundPixel: display.screen[0].black_pixel });
|
||||
X.MapWindow(win);
|
||||
Shape.Rectangles(Shape.Op.Set, Shape.Kind.Bounding, win, 0, 0, [
|
||||
[40, 40, 40, 40], [120, 40, 40, 40],
|
||||
[0, 120, 20, 20], [180, 120, 20, 20],
|
||||
[20, 140, 30, 20], [150, 140, 30, 20],
|
||||
[50, 160, 100, 20]
|
||||
]);
|
||||
});
|
||||
X.on('error', function(err) { console.log(err); });
|
||||
|
||||
});
|
||||
|
|
@ -6,17 +6,22 @@ x11.createClient(function(err, display) {
|
|||
X.require('shape', function(err, Shape) {
|
||||
var win = X.AllocID();
|
||||
X.CreateWindow(win, root, 0, 0, 200, 200);
|
||||
var gc = X.AllocID();
|
||||
X.CreateGC(gc, win);
|
||||
//X.MapWindow(win);
|
||||
Shape.SelectInput(win, 1);
|
||||
X.ChangeWindowAttributes(win, { backgroundPixel: display.screen[0].white_pixel });
|
||||
X.MapWindow(win);
|
||||
X.ClearArea(win, 0, 0, 200, 200, false);
|
||||
|
||||
Shape.SelectInput(win, true);
|
||||
Shape.InputSelected(win, function(err, isSelected) {
|
||||
console.log("IsSelected: " + isSelected);
|
||||
});
|
||||
//var pid = X.AllocID();
|
||||
//X.CreatePixmap(pid, win, 2, 200, 200);
|
||||
//X.PolyText8(pid, gc, 0, 0, ['Hello, Node.JS!', ' Hello, world!']);
|
||||
//Shape.Mask(Shape.Op.Set, Shape.Kind.Input, win, 0, 0, pid);
|
||||
|
||||
var bitmap = X.AllocID();
|
||||
X.CreatePixmap(bitmap, win, 1, 200, 200);
|
||||
var gc = X.AllocID();
|
||||
X.CreateGC(gc, bitmap, { foreground: 1 });
|
||||
// X.PolyText8(bitmap, gc, 0, 0, ['Hello, Node.JS!', ' Hello, world!']);
|
||||
X.PolyFillArc(bitmap, gc, [0, 0, 200, 200, 0, 360 * 64]);
|
||||
Shape.Mask(Shape.Op.Set, Shape.Kind.Bounding, win, 0, 0, bitmap);
|
||||
|
||||
X.on('event', function(ev) {
|
||||
console.log(ev);
|
||||
|
|
|
|||
125
examples/smoketest/trapezoids.js
Normal file
125
examples/smoketest/trapezoids.js
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
var _ = require('underscore');
|
||||
var x11 = require('../../lib');
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
var ButtonPress = x11.eventMask.ButtonPress;
|
||||
|
||||
var draw;
|
||||
|
||||
var useConvo3 = true;
|
||||
|
||||
x11.createClient({ debug: true}, function(err, display) {
|
||||
|
||||
var X = display.client;
|
||||
var root = display.screen[0].root;
|
||||
|
||||
var wid = X.AllocID();
|
||||
X.CreateWindow(
|
||||
wid, root,
|
||||
0, 0, 800, 600,
|
||||
0, 0, 0, 0,
|
||||
{
|
||||
eventMask: Exposure|PointerMotion|ButtonPress
|
||||
}
|
||||
);
|
||||
X.MapWindow(wid);
|
||||
|
||||
|
||||
X.require('render', function(err, Render) {
|
||||
|
||||
Render.QueryFilters(console.log);
|
||||
|
||||
var pixMask = X.AllocID();
|
||||
X.CreatePixmap(pixMask, wid, 8, 600, 600);
|
||||
var pictTraps = X.AllocID();
|
||||
Render.CreatePicture(pictTraps, pixMask, Render.a8);
|
||||
|
||||
var pictWin = X.AllocID();
|
||||
Render.CreatePicture(pictWin, wid, Render.rgb24);
|
||||
|
||||
var pictSolid = X.AllocID();
|
||||
r = 0.2; g = 0.2; b = 0.2; a = 1;
|
||||
Render.CreateSolidFill(pictSolid, r, g, b, a);
|
||||
|
||||
var pixBuff = X.AllocID();
|
||||
X.CreatePixmap(pixBuff, wid, 24, 600, 600);
|
||||
var pictBuff = X.AllocID();
|
||||
Render.CreatePicture(pictBuff, pixBuff, Render.rgb24);
|
||||
|
||||
var convo5 = [ 5, 5, 0.0030, 0.0133, 0.0219, 0.0133, 0.0030,
|
||||
0.0133, 0.0596, 0.0983, 0.0596, 0.0133,
|
||||
0.0219, 0.0983, 0.1621, 0.0983, 0.0219,
|
||||
0.0133, 0.0596, 0.0983, 0.0596, 0.0133,
|
||||
0.0030, 0.0133, 0.0219, 0.0133, 0.0030];
|
||||
var convo3 = [3, 3, 0.01, 0.08, 0.01, 0.08, 0.64, 0.08, 0.01, 0.08, 0.01];
|
||||
|
||||
var convo5 = [21, 21].concat(require('./blur-convolution')(21, 11));
|
||||
|
||||
//Render.SetPictureFilter(pictBuff, 'convolution', convo3);
|
||||
//Render.SetPictureFilter(pictTraps, 'convolution', convo3);
|
||||
//Render.SetPictureFilter(pictBuff, 'bilinear', []);
|
||||
Render.SetPictureFilter(pictBuff, 'best', []);
|
||||
|
||||
draw1 = function(x, y) {
|
||||
console.log('draw 1', x, y);
|
||||
var r = 3 + 2*Math.floor(x / 100);
|
||||
var convo = [r, r].concat(require('./blur-convolution')(r, r));
|
||||
Render.SetPictureFilter(pictBuff, 'convolution', convo);
|
||||
|
||||
var a = (x-400)/500;
|
||||
var m = [
|
||||
Math.cos(a), Math.sin(a), 0,
|
||||
-Math.sin(a), Math.cos(a), 0,
|
||||
0, 0, 1
|
||||
];
|
||||
// Render.SetPictureTransform(pictTraps, m)
|
||||
|
||||
var r, g, b;
|
||||
|
||||
// fill window
|
||||
r = 1; g = 1; b = 1; a = 0.5;
|
||||
Render.FillRectangles(1, pictBuff, [r, g, b, a], [0, 0, 1000, 1000])
|
||||
|
||||
// fill traps
|
||||
r = 0; g = 0; b = 0; a = 0;
|
||||
Render.FillRectangles(1, pictTraps, [r, g, b, a], [0, 0, 1000, 1000])
|
||||
|
||||
Render.AddTraps(pictTraps, 0, 0, [
|
||||
x, 200, y,
|
||||
//150, 200, 50,
|
||||
5, 250, 300,
|
||||
110, 200, 310,
|
||||
50, 150, 500
|
||||
]);
|
||||
|
||||
|
||||
// (op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height)
|
||||
//Render.Composite(Render.PictOp.Over, pictSolid, pictTraps, pictWin, 0, 0, 0, 0, 0, 0, 800, 600);
|
||||
//Render.PictOp.Over
|
||||
|
||||
Render.Composite(Render.PictOp.Over, pictSolid, pictTraps, pictBuff, 0, 0, 0, 0, 0, 0, 800, 600);
|
||||
Render.Composite(Render.PictOp.Over, pictBuff, 0, pictWin, 0, 0, 0, 0, 0, 0, 800, 600);
|
||||
|
||||
};
|
||||
|
||||
draw = function(x, y) {
|
||||
var f = _.debounce(function() {
|
||||
draw1(x, y);
|
||||
}, 100);
|
||||
f();
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
}).on('error', function(err) {
|
||||
console.log(err);
|
||||
}).on('event', function(ev) {
|
||||
//console.log(ev);
|
||||
if (ev.name == 'MotionNotify') {
|
||||
draw(ev.x, ev.y);
|
||||
} else if (ev.name == 'ButtonPress') {
|
||||
useConvo3 = !useConvo3;
|
||||
draw(ev.x, ev.y);
|
||||
//console.log(ev);
|
||||
}
|
||||
});
|
||||
|
|
@ -25,7 +25,7 @@ var Buffer = require('buffer').Buffer;
|
|||
|
||||
var startpos = [4, 15];
|
||||
var cupsize = [10, 20];
|
||||
var cup = new Buffer(cupsize[0]*cupsize[1]);
|
||||
var cup = Buffer.alloc(cupsize[0]*cupsize[1]);
|
||||
var moveInterval;
|
||||
|
||||
function clearCup()
|
||||
|
|
@ -250,7 +250,7 @@ x11.createClient(function(err, display) {
|
|||
var ks = x11.keySyms;
|
||||
var ks2Name = {};
|
||||
for (var key in ks)
|
||||
ks2Name[ ks[key] ] = key;
|
||||
ks2Name[ ks[key].code ] = key;
|
||||
var kk2Name = {};
|
||||
var min = display.min_keycode;
|
||||
var max = display.max_keycode;
|
||||
|
|
|
|||
12
examples/vncviewer/d3des.js
vendored
12
examples/vncviewer/d3des.js
vendored
|
|
@ -56,8 +56,8 @@ var pc2 = [
|
|||
function deskey(key, edf)
|
||||
{
|
||||
var i, j, l, m, n;
|
||||
var pc1m = new Buffer(56);
|
||||
var pcr = new Buffer(56);
|
||||
var pc1m = Buffer.alloc(56);
|
||||
var pcr = Buffer.alloc(56);
|
||||
var kn = new Array(32);
|
||||
|
||||
for ( j = 0; j < 56; j++ ) {
|
||||
|
|
@ -388,17 +388,17 @@ function desfunc(block, keys)
|
|||
|
||||
module.exports.response = function(challenge, password)
|
||||
{
|
||||
var key = new Buffer(8);
|
||||
var key = Buffer.alloc(8);
|
||||
key.fill(0);
|
||||
key.write(password.substring(0,8));
|
||||
var in1 = challenge.slice(0,8);
|
||||
var in2 = challenge.slice(8,16);
|
||||
var res1 = new Buffer(8);
|
||||
var res2 = new Buffer(8);
|
||||
var res1 = Buffer.alloc(8);
|
||||
var res2 = Buffer.alloc(8);
|
||||
deskey(key, EN0);
|
||||
des(in1, res1);
|
||||
des(in2, res2);
|
||||
var resp = new Buffer(16);
|
||||
var resp = Buffer.alloc(16);
|
||||
res1.copy(resp);
|
||||
res2.copy(resp, 8);
|
||||
return resp;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
// It should create a pleasant looking hex dumb by default:
|
||||
//
|
||||
// var hexy = require('hexy.js'),
|
||||
// b = new Buffer("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789")
|
||||
// b = Buffer.from("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789")
|
||||
//
|
||||
// console.log(hexy.hexy(b))
|
||||
//
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@ RfbClient.prototype.readHextileTile = function(rect, cb)
|
|||
});
|
||||
return;
|
||||
}
|
||||
tile.buffer = new Buffer(tilebuflen);
|
||||
tile.buffer = Buffer.alloc(tilebuflen);
|
||||
|
||||
function solidBackground() {
|
||||
clog('solidBackground');
|
||||
|
|
@ -667,8 +667,8 @@ function createConnection(params)
|
|||
var wstream = fs.createWriteStream(params.rfbFileOut);
|
||||
wstream.write('FBS 001.001\n');
|
||||
stream.on('data', function(data) {
|
||||
var sizeBuf = new Buffer(4);
|
||||
var timeBuf = new Buffer(4);
|
||||
var sizeBuf = Buffer.alloc(4);
|
||||
var timeBuf = Buffer.alloc(4);
|
||||
var size = data.length;
|
||||
sizeBuf.writeInt32BE(size, 0);
|
||||
wstream.write(sizeBuf);
|
||||
|
|
@ -676,7 +676,7 @@ function createConnection(params)
|
|||
timeBuf.writeInt32BE(+new Date() - start, 0);
|
||||
wstream.write(timeBuf);
|
||||
var padding = 3 - ((size - 1) & 0x03);
|
||||
var pbuf = new Buffer(padding);
|
||||
var pbuf = Buffer.alloc(padding);
|
||||
wstream.write(pbuf);
|
||||
}).on('end', function() {
|
||||
wstream.end();
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ RfbServer.prototype.processSecurity = function()
|
|||
break;
|
||||
case rfb.security.VNC:
|
||||
// generate random 16 byte challenge
|
||||
serv.challenge = new Buffer(16);
|
||||
serv.challenge = Buffer.alloc(16);
|
||||
serv.challenge.write('1234567890abcdef');
|
||||
console.log(['sending challenge', serv.challenge]);
|
||||
serv.pack_stream.pack('a', [serv.challenge]).flush();
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ function ReadFixedRequest(length, callback)
|
|||
this.length = length;
|
||||
this.callback = callback;
|
||||
//clog(length);
|
||||
this.data = new Buffer(length);
|
||||
this.data = Buffer.alloc(length);
|
||||
this.received_bytes = 0;
|
||||
}
|
||||
|
||||
|
|
@ -328,7 +328,7 @@ UnpackStream.prototype.pack = function(format, args)
|
|||
}
|
||||
}
|
||||
|
||||
var buf = new Buffer(packetlength);
|
||||
var buf = Buffer.alloc(packetlength);
|
||||
var offset = 0;
|
||||
var arg = 0;
|
||||
for (var i = 0; i < format.length; ++i)
|
||||
|
|
|
|||
75
examples/xpm/node-logo.xpm
Normal file
75
examples/xpm/node-logo.xpm
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/* XPM */
|
||||
static char * node_logo_xpm[] = {
|
||||
"245 66 6 1",
|
||||
" c None",
|
||||
". c #FFFFFF",
|
||||
"+ c #8CC84B",
|
||||
"@ c #8DC84C",
|
||||
"# c #89C746",
|
||||
"$ c #8AC748",
|
||||
" .. ",
|
||||
" .... ",
|
||||
" ...... ",
|
||||
" ....... ",
|
||||
" ......... ",
|
||||
" ........... ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ",
|
||||
" ............ ++ ",
|
||||
" .... ++++ .. ............ .... ++++++ .. . .",
|
||||
" ........ ++++++++ ...... ............ ....... +++++++++ .. .",
|
||||
" ............ ++++++++++++ ....................... ........... ++++++ ++++++ ...",
|
||||
" ............... ++++++++++++++ ......................... .............. +++++++ ++++++ ",
|
||||
" .................. ++++++++++++++++++ .......................... .................. ++++++ ++++++ ",
|
||||
" ...................... ++++++++++++++++++++++ ............................ ..................... ++++++ ++++++ ",
|
||||
" .......................... +++++++++++++++++++++++++ .............................. ......................... ++++++ ++++++ ",
|
||||
" ............................. ++++++++++++++++++++++++++++ ................................ ............................ +++++++ ++++++ ",
|
||||
" ................................ ++++++++++++++++++++++++++++++++ ................................. ................................ ++++++ ++++++ ",
|
||||
" .................................... ++++++++++++++++++++++++++++++++++++ ................................... ................................... +++++ ++++++ ",
|
||||
" .................................... ++++++++++++++++++++++++++++++++++++ .................................... ..................................... ++++ ++++ ",
|
||||
" .................................... ++++++++++++++++++++++++++++++++++++ ..................................... ..................................... +++ +++ ",
|
||||
" .................................... ++++++++++++++++++++++++++++++++++++ ..................................... ..................................... +++ + ++++++++ +++ ",
|
||||
" .................................... ++++++++++++++++++++++++++++++++++++ ..................................... ..................................... +++ +++ ++++++++++++ +++ ",
|
||||
" ................ ................ ++++++++++++++++++++++++++++++++++++ .................. ................. ................. ................. +++ +++ ++++++++++++++ +++ ",
|
||||
" ............... ............... ++++++++++++++++++++++++++++++++++++ ................ ............... ................ ............... +++ +++ ++++ ++++ +++ ",
|
||||
" ............. ............. ++++++++++++++++++++++++++++++++++++ ............... .............. .............. .............. +++ +++ +++ +++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ............. ............ ............. ++@# ............ +++ +++ +++ +++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ............. ............ ............. #@+++++ .......... +++ +++ ++++++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ............. ............ ............. +++++++ ........ +++ +++ +++++++++++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ............. ............ ............. +++++++ ...... +++ +++ ++++++++++++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ............. ............ ............. +++++++ .... +++ +++ +++++++++++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ............. ............ ............. @++++++ ... +++ +++ +++++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ............. ............ ............. $+++ +++ +++ +++ +++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ............. ............. .............. +++ +++ ++++ +++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ............... .............. ............... +++ +++ ++++ ++++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ................. ................ ................. +++ +++ ++++++++++++++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ..................................... ................... +++ +++ +++++++++++++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ..................................... .................... +++ +++ +++++++++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ ..................................... ...................... +++ +++ +++ ",
|
||||
" ............ ............ ++++++++++++++++++++++++++++++++++++ .................................... ........................ +++++ +++ ++++ ",
|
||||
" ........... ........... ++++++++++++++++++++++++++++++++++++ .................................... ......................... ++++++ ++++ +++++ ",
|
||||
" ......... ......... ++++++++++++++++++++++++++++++++ .................................. ........................ ++++++++++++ ++++++ ",
|
||||
" ........ ........ ++++++++++++++++++++++++++++ .............................. ......................... +++++++++ ++++++ ",
|
||||
" ...... ...... ++++++++++++++++++++++++++ .......................... ........................ ++++++ ++++++ ",
|
||||
" .... .... ++++++++++++++++++++++ ...................... ...................... ++++++ ",
|
||||
" .. .. ++++++++++++++++++ .................... .................. ++++ ++++++ ",
|
||||
" ++++++++++++++ ................ ............... ++++++ ++++++ ",
|
||||
" ++++++++++++ ............ ........... ++++++++++++ ",
|
||||
" ++++++++ ......... ........ +++++++++ ",
|
||||
" ++++ ...... .... +++++ ",
|
||||
" .. "};
|
||||
151
examples/xpm/node-xpm.js
Normal file
151
examples/xpm/node-xpm.js
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
/* Extracted from https://github.com/klepthys/node-xpm
|
||||
* This code is available as a standalone module named xpm
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Sebastien Dumetz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
|
||||
function PixmapFromFile (path,options){
|
||||
if(!options && typeof path == "object"){
|
||||
this.options = path;
|
||||
path = null;
|
||||
}else{
|
||||
this.options = options||{};
|
||||
}
|
||||
if(path){
|
||||
return this.parse(fs.readFileSync(path, {encoding:"utf-8"}));
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {[type]} data utf-8 file data
|
||||
* @param {Function} callback optionnal callback.
|
||||
*/
|
||||
PixmapFromFile.prototype.parse = function (data) {
|
||||
if(!/^\/\*\s*XPM\s*\*\/$/m.test(data)){
|
||||
throw new Error("Not an XPM file");
|
||||
}
|
||||
var size = this.getSize(data);
|
||||
var content = this.getArray(data,size);
|
||||
var colors = this.mapColors(data,size);
|
||||
size.data = this.toBuffer(colors,content,size);
|
||||
return size;
|
||||
};
|
||||
PixmapFromFile.prototype.getSize = function(data){
|
||||
var match = /{\n?"([0-9\s]*)\s?"/.exec(data);
|
||||
if(!match){
|
||||
throw new Error("can't parse size infos");
|
||||
}
|
||||
var values = match[1].split(" ").map(function(i){return parseInt(i)});
|
||||
return {width:values[0],height:values[1],count:values[2],length:values[3]}
|
||||
}
|
||||
|
||||
PixmapFromFile.prototype.getArray = function(data,size){
|
||||
//var reg = new RegExp('"((?!(?:[0-9]+\\s?){4}).{'+size.length+'}(?!\\sc\\s).*)"',"g"); //Works also but much less simple
|
||||
var reg = new RegExp('"(.{'+size.width*size.length+'})"',"g");
|
||||
var res;
|
||||
var rows = [];
|
||||
while((res = reg.exec(data)) !== null){
|
||||
rows.push(res[1]);
|
||||
}
|
||||
if(rows.length != size.height){
|
||||
throw new Error("found : "+rows.length+" rows. Should have found :"+size.height+" rows.");
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
// return RGBA color
|
||||
PixmapFromFile.prototype.mapColors = function(content,size){
|
||||
var reg = new RegExp('"(.' + ((size.length > 1)? "{"+(size.length)+"}" : "") + ")\\s+c\\s+#?(None|[0-9a-fA-F]{6})\"","gm");
|
||||
var res;
|
||||
var colors = {};
|
||||
while((res = reg.exec(content)) !== null){
|
||||
if(res[2] === "None"){
|
||||
colors[res[1]] = "00000000"
|
||||
}else{
|
||||
colors[res[1]] = res[2]+"FF";//RGBA
|
||||
}
|
||||
|
||||
}
|
||||
if(Object.keys(colors).length != size.count){
|
||||
throw new Error("found : "+Object.keys(colors).length+" colors. Should have found :"+size.count+" colors.");
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
PixmapFromFile.prototype.toBuffer = function (colors,content,size) {
|
||||
var buf = Buffer.alloc(size.width*size.height*4);
|
||||
var offset = 0, byte,color;
|
||||
var copy;
|
||||
if( !this.options.format || this.options.format.toUpperCase() === "BGRA"){
|
||||
copy = this.copyBGRABuffer;
|
||||
}else if(this.options.format && this.options.format.toUpperCase() === "RGBA"){
|
||||
copy = this.copyRGBABuffer;
|
||||
}else{
|
||||
throw new Error("invalid format option : ",this.options.format," valid values are BGRA (default) or RGBA")
|
||||
}
|
||||
content.forEach(function(row){
|
||||
//console.log("parsing : ",row)
|
||||
while(row && row.length >0){
|
||||
var code = row.slice(0,size.length);
|
||||
row = row.slice(size.length);
|
||||
if(!colors[code]){
|
||||
throw new Error("unknown color : ",code);
|
||||
}
|
||||
offset = copy(buf,offset,colors[code]);;
|
||||
}
|
||||
});
|
||||
return buf;
|
||||
};
|
||||
|
||||
/**
|
||||
* Takes an array of rows. Each char/sequence represents a colored pixel
|
||||
* @param {[type]} content [description]
|
||||
* @return {Buffer} A 1d array of pixels in RGBA
|
||||
*/
|
||||
PixmapFromFile.prototype.copyBGRABuffer = function(buf, offset, color){
|
||||
[4,2,0,6].forEach(function(i){
|
||||
buf.writeUInt8(parseInt(color[i]+color[i+1],16),offset);
|
||||
offset ++;
|
||||
});
|
||||
return offset;
|
||||
}
|
||||
PixmapFromFile.prototype.copyRGBABuffer = function(buf, offset, color){
|
||||
buf.writeUInt32BE(parseInt(color,16),offset);
|
||||
return offset+4;
|
||||
}
|
||||
PixmapFromFile.prototype.open = function(path,callback){
|
||||
var self = this;
|
||||
fs.readFile(path, {encoding:"utf-8"}, function(err,data){
|
||||
if(err){
|
||||
return callback(err);
|
||||
}else{
|
||||
callback(null,self.parse(data));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = PixmapFromFile;
|
||||
53
examples/xpm/test.js
Normal file
53
examples/xpm/test.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var x11 = require('../../lib');
|
||||
var PixmapFromFile = require('./node-xpm.js');
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
|
||||
x11.createClient(function(err, display)
|
||||
{
|
||||
var X = display.client;
|
||||
X.require('render', function(err, Render) {
|
||||
var root = display.screen[0].root;
|
||||
var pixmap = new PixmapFromFile();
|
||||
pixmap.open("node-logo.xpm",function(err,logo){
|
||||
if(err){
|
||||
console.log(new Error().stack);
|
||||
return console.error("pixmap open Error : ",err);
|
||||
}
|
||||
main(root, X, Render,logo);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function main(root, X, Render, logo) {
|
||||
|
||||
var win, picWin, pic, gc;
|
||||
|
||||
win = X.AllocID();
|
||||
X.CreateWindow(
|
||||
win, root,
|
||||
0, 0, logo.width, logo.height,
|
||||
0, 0, 0, 0,
|
||||
{ eventMask: Exposure }
|
||||
);
|
||||
X.MapWindow(win);
|
||||
|
||||
gc = X.AllocID();
|
||||
X.CreateGC(gc, win);
|
||||
|
||||
var logoPixmap = X.AllocID();
|
||||
X.CreatePixmap(logoPixmap, win, 24, logo.width, logo.height);
|
||||
// TODO: add proper png pixel conversion here
|
||||
X.PutImage(2, logoPixmap, gc, logo.width, logo.height, 0, 0, 0, 24, logo.data);
|
||||
|
||||
var logoPicture = X.AllocID();
|
||||
Render.CreatePicture(logoPicture, logoPixmap, Render.rgb24);
|
||||
var winPicture = X.AllocID();
|
||||
Render.CreatePicture(winPicture, win, Render.rgb24);
|
||||
|
||||
X.on('event', function(ev) {
|
||||
if (ev.name == 'Expose')
|
||||
Render.Composite(3, logoPicture, 0, winPicture, 0, 0, 0, 0, 0, 0, logo.width, logo.height);
|
||||
});
|
||||
}
|
||||
127
lib/auth.js
127
lib/auth.js
|
|
@ -1,27 +1,12 @@
|
|||
// TODO: http://en.wikipedia.org/wiki/X_Window_authorization
|
||||
// TODO: differentiate between auth types (i.e., MIT-MAGIC-COOKIE-1 and XDM-AUTHORIZATION-1)
|
||||
// and choose the best based on the algorithm in libXau's XauGetBestAuthByAddr
|
||||
|
||||
var fs = require('fs');
|
||||
var Buffer = require('buffer').Buffer;
|
||||
// add 'unpack' method for buffer
|
||||
require('./unpackbuffer').addUnpack(Buffer);
|
||||
|
||||
function parseXauth( buf )
|
||||
{
|
||||
var offset = 0;
|
||||
var auth = [];
|
||||
var cookieProperties = ['address', 'display', 'authName', 'authData'];
|
||||
|
||||
function handleCookieProperty(property) {
|
||||
var length = buf.unpack('n', offset)[0];
|
||||
offset += 2;
|
||||
cookie[property] = buf.unpackString(length, offset);
|
||||
offset += length;
|
||||
}
|
||||
|
||||
while (offset < buf.length)
|
||||
{
|
||||
var cookie = {};
|
||||
var typeToName = {
|
||||
var typeToName = {
|
||||
256: 'Local',
|
||||
65535: 'Wild',
|
||||
254: 'Netname',
|
||||
|
|
@ -31,61 +16,95 @@ function parseXauth( buf )
|
|||
1: 'DECnet',
|
||||
2: 'Chaos',
|
||||
5: 'ServerInterpreted',
|
||||
6: 'InternetV6'
|
||||
};
|
||||
cookie.type = buf.unpack('n')[0];
|
||||
6: 'Internet6'
|
||||
};
|
||||
|
||||
function parseXauth( buf )
|
||||
{
|
||||
var offset = 0;
|
||||
var auth = [];
|
||||
var cookieProperties = ['address', 'display', 'authName', 'authData'];
|
||||
|
||||
while (offset < buf.length)
|
||||
{
|
||||
var cookie = {};
|
||||
cookie.type = buf.readUInt16BE(offset);
|
||||
if (!typeToName[cookie.type]) {
|
||||
console.warn('Unknown address type');
|
||||
}
|
||||
offset += 2;
|
||||
//JSHint becomes angry when handleCookieProperty is declared inside loop
|
||||
cookieProperties.forEach(handleCookieProperty);
|
||||
cookieProperties.forEach(function(property) {
|
||||
var length = buf.unpack('n', offset)[0];
|
||||
offset += 2;
|
||||
if (cookie.type === 0 && property == 'address') { // Internet
|
||||
// 4 bytes of ip addess, convert to w.x.y.z string
|
||||
cookie.address = [ buf[offset], buf[offset+1], buf[offset+2], buf[offset+3]]
|
||||
.map(function(octet) { return octet.toString(10) }).join('.');
|
||||
} else {
|
||||
cookie[property] = buf.unpackString(length, offset);
|
||||
}
|
||||
offset += length;
|
||||
});
|
||||
auth.push(cookie);
|
||||
}
|
||||
return auth;
|
||||
}
|
||||
|
||||
module.exports = function( display, host, cb )
|
||||
{
|
||||
var XAuthorityFile = process.env.XAUTHORITY;
|
||||
if (!XAuthorityFile)
|
||||
{
|
||||
if ( process.platform.match(/win/) ) {
|
||||
// http://www.straightrunning.com/XmingNotes/trouble.php
|
||||
//
|
||||
// The Xming magic cookie program, xauth (user-based), uses an
|
||||
// Xauthority file (not the traditional .Xauthority file) in
|
||||
// the %HOME% directory. To use xauth from Command Processor
|
||||
// e.g. on Windows machine 192.168.0.2 with user colin...
|
||||
XAuthorityFile = process.env.USERPROFILE + '\\Xauthority';
|
||||
var homedir = require('os').homedir;
|
||||
var path = require('path');
|
||||
|
||||
function readXauthority(cb) {
|
||||
var filename = process.env.XAUTHORITY || path.join(homedir(), '.Xauthority');
|
||||
fs.readFile(filename, function(err, data) {
|
||||
if (!err)
|
||||
return cb(null, data);
|
||||
if(err.code == 'ENOENT') {
|
||||
// Xming/windows uses %HOME%/Xauthority ( .Xauthority with no dot ) - try with this name
|
||||
filename = process.env.XAUTHORITY || path.join(homedir(), 'Xauthority');
|
||||
fs.readFile(filename, function (err, data) {
|
||||
if (err.code == 'ENOENT') {
|
||||
cb(null, null);
|
||||
} else {
|
||||
XAuthorityFile = process.env.HOME + '/.Xauthority';
|
||||
cb(err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
cb(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fs.readFile(XAuthorityFile, function (err, data) {
|
||||
|
||||
if (err)
|
||||
{
|
||||
if (err.code == 'ENOENT')
|
||||
{
|
||||
cb('','');
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
module.exports = function( display, host, socketFamily, cb )
|
||||
{
|
||||
var family;
|
||||
if (socketFamily === 'IPv4') {
|
||||
family = 0; // Internet
|
||||
} else if (socketFamily === 'IPv6') {
|
||||
family = 6; // Internet6
|
||||
} else {
|
||||
family = 256; // Local
|
||||
}
|
||||
readXauthority(function(err, data) {
|
||||
if(err) return cb(err);
|
||||
|
||||
if (!data) {
|
||||
return cb(null, {
|
||||
authName: '',
|
||||
authData: ''
|
||||
});
|
||||
}
|
||||
var auth = parseXauth(data);
|
||||
for (var cookieNum in auth)
|
||||
{
|
||||
var cookie = auth[cookieNum];
|
||||
if (cookie.display == display && cookie.address == host)
|
||||
{
|
||||
cb( cookie.authName, cookie.authData );
|
||||
return;
|
||||
if ((typeToName[cookie.family] === 'Wild' || (cookie.type === family && cookie.address === host)) &&
|
||||
(cookie.display.length === 0 || cookie.display === display))
|
||||
return cb( null, cookie );
|
||||
}
|
||||
}
|
||||
// throw 'No auth cookie matching display=' + display + ' and host=' + host;
|
||||
cb( '', '' );
|
||||
// If no cookie is found, proceed without authentication
|
||||
cb(null, {
|
||||
authName: '',
|
||||
authData: ''
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -213,14 +213,17 @@ function packValueMask(reqname, values)
|
|||
if (!reqValueMask)
|
||||
throw new Error(reqname + ': no value mask description');
|
||||
|
||||
for (var v in values)
|
||||
for (var value in values)
|
||||
{
|
||||
var valueBit = reqValueMask[v].mask;
|
||||
var v = reqValueMask[value];
|
||||
if (v) {
|
||||
var valueBit = v.mask;
|
||||
if (!valueBit)
|
||||
throw new Error(reqname + ': incorrect value param ' + v);
|
||||
throw new Error(reqname + ': incorrect value param ' + value);
|
||||
masksList.push(valueBit);
|
||||
bitmask |= valueBit;
|
||||
}
|
||||
}
|
||||
|
||||
/* numeric sort */
|
||||
masksList.sort(function(a, b) {
|
||||
|
|
@ -228,9 +231,10 @@ function packValueMask(reqname, values)
|
|||
});
|
||||
|
||||
var args = [];
|
||||
for (m in masksList)
|
||||
for (var i=0,length=masksList.length;i<length;i++)
|
||||
{
|
||||
var valueName = reqValueMaskName[masksList[m]];
|
||||
var value = masksList[i];
|
||||
var valueName = reqValueMaskName[value];
|
||||
format += reqValueMask[valueName].format
|
||||
args.push( values[valueName] );
|
||||
}
|
||||
|
|
@ -396,6 +400,11 @@ var templates = {
|
|||
}
|
||||
],
|
||||
|
||||
LowerWindow: [
|
||||
function(win) {
|
||||
return module.exports.ConfigureWindow[0](win, { stackMode : 1 });
|
||||
}
|
||||
],
|
||||
|
||||
QueryTree: [
|
||||
['CxSL', [15, 2]],
|
||||
|
|
@ -456,7 +465,7 @@ var templates = {
|
|||
function(mode, wid, name, type, units, data)
|
||||
{
|
||||
var padded4 = (data.length + 3) >> 2;
|
||||
var pad = new Buffer( (padded4<<2) - data.length);
|
||||
var pad = Buffer.alloc( (padded4<<2) - data.length);
|
||||
var format = 'CCSLLLCxxxLaa';
|
||||
var requestLength = 6 + padded4;
|
||||
var dataLenInFormatUnits = data.length / (units >> 3);
|
||||
|
|
@ -606,6 +615,12 @@ var templates = {
|
|||
}
|
||||
],
|
||||
|
||||
AllowEvents: [
|
||||
function(mode, ts) {
|
||||
return [ 'CCSL', [ 35, mode, 2, ts ] ];
|
||||
}
|
||||
],
|
||||
|
||||
GrabServer: [
|
||||
[ 'CxS', [36, 1]]
|
||||
],
|
||||
|
|
@ -712,12 +727,6 @@ var templates = {
|
|||
}
|
||||
],
|
||||
|
||||
FreePixmap: [
|
||||
function(pixmap) {
|
||||
return [ 'CxSL', [ 54, 2, pixmap ] ];
|
||||
}
|
||||
],
|
||||
|
||||
FreePixmap: [
|
||||
function (pixmap) {
|
||||
return [ 'CxSL', [54, 2, pixmap] ];
|
||||
|
|
@ -757,17 +766,19 @@ var templates = {
|
|||
var vals = packValueMask('CreateGC', values);
|
||||
var packetLength = 3 + (values ? vals[2].length : 0);
|
||||
var args = [56, packetLength, cid];
|
||||
args.push(vals[0]); // values bitmask
|
||||
var valArr = vals[1];
|
||||
for (var v in valArr)
|
||||
{
|
||||
format += 'L'; // TODO: we know format string length in advance and += inefficient for string
|
||||
args.push(valArr[v]);
|
||||
}
|
||||
format += vals[0]
|
||||
args.push(vals[1]); // values bitmask
|
||||
args = args.concat(vals[2])
|
||||
return [format, args];
|
||||
}
|
||||
],
|
||||
|
||||
ClearArea: [
|
||||
function(wid, x, y, width, height, exposures) {
|
||||
return [ 'CCSLssSS', [61, exposures, 4, wid, x, y, width, height] ];
|
||||
}
|
||||
],
|
||||
|
||||
//
|
||||
CopyArea: [
|
||||
function(srcDrawable, dstDrawable, gc, srcX, srcY, dstX, dstY, width, height) {
|
||||
|
|
@ -840,7 +851,7 @@ var templates = {
|
|||
var padded = xutil.padded_length(data.length);
|
||||
var reqLen = 6 + padded/4; // (length + 3) >> 2 ???
|
||||
var padLength = padded - data.length;
|
||||
var pad = new Buffer(padLength); // TODO: new pack format 'X' - skip amount of bytes supplied in numerical argument
|
||||
var pad = Buffer.alloc(padLength); // TODO: new pack format 'X' - skip amount of bytes supplied in numerical argument
|
||||
|
||||
// TODO: move code to calculate reqLength and use BigReq if needed outside of corereq.js
|
||||
// NOTE: big req is used here (first 'L' in format, 0 and +1 in params), won't work if not enabled
|
||||
|
|
@ -1010,6 +1021,12 @@ var templates = {
|
|||
}
|
||||
],
|
||||
|
||||
Bell: [
|
||||
function(percent) {
|
||||
return ["CxCs",[108,1]];
|
||||
}
|
||||
],
|
||||
|
||||
ForceScreenSaver: [
|
||||
function(activate) {
|
||||
return [ 'CCS', [115, activate?1:0, 1] ];
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ exports.requireExt = function(display, callback)
|
|||
ext.BindTexImage = function(ctx, drawable, buffer, attribs) {
|
||||
if (!attribs)
|
||||
attribs = [];
|
||||
var data = new Buffer(12 + attribs.length*4);
|
||||
var data = Buffer.alloc(12 + attribs.length*4);
|
||||
data.writeUInt32LE(drawable, 0);
|
||||
data.writeUInt32LE(buffer, 4);
|
||||
data.writeUInt32LE(attribs.length, 8);
|
||||
|
|
@ -268,7 +268,7 @@ exports.requireExt = function(display, callback)
|
|||
}
|
||||
|
||||
ext.ReleaseTexImage = function(ctx, drawable, buffer) {
|
||||
var data = new Buffer(8);
|
||||
var data = Buffer.alloc(8);
|
||||
data.writeUint32LE(drawable, 0);
|
||||
data.writeUint32LE(buffer, 4);
|
||||
ext.VendorPrivate(ctx, 1331, data);
|
||||
|
|
@ -287,7 +287,7 @@ exports.requireExt = function(display, callback)
|
|||
X.pack_stream.pack('CCSLSSL', [ext.majorOpcode, 2, length, ctx, requestNum, requestTotal, data.length]);
|
||||
|
||||
X.pack_stream.write_queue.push(data);
|
||||
var pad = new Buffer(padLength);
|
||||
var pad = Buffer.alloc(padLength);
|
||||
pad.fill(0);
|
||||
X.pack_stream.write_queue.push(pad);
|
||||
X.pack_stream.flush();
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ module.exports = function(GLX, ctx) {
|
|||
throw Error('Buffer too big. Make sure you are using RenderLarge for large commands');
|
||||
|
||||
currentLength += len;
|
||||
var res = Buffer(len);
|
||||
var res = Buffer.alloc(len);
|
||||
res.writeUInt16LE(len, 0);
|
||||
res.writeUInt16LE(opcode, 2);
|
||||
return res;
|
||||
|
|
@ -266,7 +266,7 @@ module.exports = function(GLX, ctx) {
|
|||
typeSize[constants.BYTE] = 1;
|
||||
typeSize[constants.UNSIGNED_BYTE] = 1;
|
||||
|
||||
var res = new Buffer(60 + data.length*typeSize[type]);
|
||||
var res = Buffer.alloc(60 + data.length*typeSize[type]);
|
||||
res.writeUInt32LE(res.length, 0);
|
||||
res.writeUInt32LE(110, 4);
|
||||
|
||||
|
|
|
|||
|
|
@ -204,7 +204,43 @@ exports.requireExt = function(display, callback)
|
|||
|
||||
X.pack_stream.flush();
|
||||
},
|
||||
ext.GetOutputInfo = function(output, ts, cb)
|
||||
{
|
||||
X.seq_num ++;
|
||||
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 9, 3, output, ts ]);
|
||||
X.replies[X.seq_num] = [
|
||||
function(buf, opt) {
|
||||
var i;
|
||||
var pos = 0;
|
||||
var res = buf.unpack('LLLLCCSSSSS');
|
||||
var info = {
|
||||
timestamp : res[0],
|
||||
crtc : res[1],
|
||||
mm_width : res[2],
|
||||
mm_height : res[3],
|
||||
connection : res[4],
|
||||
subpixelOrder : res[5],
|
||||
preferredModes: res[8]
|
||||
};
|
||||
|
||||
pos += 28;
|
||||
var format = Array(res[6] + 1).join('L');
|
||||
info.crtcs = buf.unpack(format, pos);
|
||||
pos += res[6] << 2;
|
||||
format = Array(res[7] + 1).join('L');
|
||||
info.modes = buf.unpack(format, pos);
|
||||
pos += res[7] << 2;
|
||||
format = Array(res[9] + 1).join('L');
|
||||
info.clones = buf.unpack(format, pos);
|
||||
pos += res[9] << 2;
|
||||
info.name = buf.slice(pos, pos + res_modes[10]).toString('binary');
|
||||
return info;
|
||||
},
|
||||
cb
|
||||
];
|
||||
|
||||
X.pack_stream.flush();
|
||||
},
|
||||
ext.GetCrtcInfo = function(crtc, configTs, cb) {
|
||||
X.seq_num ++;
|
||||
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 20, 3, crtc, configTs ]);
|
||||
|
|
|
|||
|
|
@ -5,19 +5,14 @@ var xutil = require('../xutil');
|
|||
// http://cgit.freedesktop.org/xcb/proto/tree/src/render.xml?id=HEAD
|
||||
// and http://www.x.org/releases/X11R7.6/doc/renderproto/renderproto.txt
|
||||
// TODO: move to templates
|
||||
exports.requireExt = function(display, callback)
|
||||
{
|
||||
|
||||
exports.requireExt = function(display, callback) {
|
||||
var X = display.client;
|
||||
X.QueryExtension('RENDER', function(err, ext) {
|
||||
|
||||
if (!ext.present)
|
||||
{
|
||||
if (!ext.present) {
|
||||
return callback(new Error('extension not available'));
|
||||
}
|
||||
|
||||
ext.QueryVersion = function(clientMaj, clientMin, callback)
|
||||
{
|
||||
ext.QueryVersion = function(clientMaj, clientMin, callback) {
|
||||
X.seq_num++;
|
||||
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 3, clientMaj, clientMin]);
|
||||
X.replies[X.seq_num] = [
|
||||
|
|
@ -28,14 +23,13 @@ exports.requireExt = function(display, callback)
|
|||
callback
|
||||
];
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
};
|
||||
|
||||
ext.QueryPictFormat = function(callback)
|
||||
{
|
||||
X.seq_num++;
|
||||
ext.QueryPictFormat = function(callback) {
|
||||
X.pack_stream.pack('CCS', [ext.majorOpcode, 1, 1]);
|
||||
X.seq_num++;
|
||||
X.replies[X.seq_num] = [
|
||||
function (buf, opt) {
|
||||
function(buf, opt) {
|
||||
var res = {};
|
||||
var res1 = buf.unpack('LLLLL');
|
||||
var num_formats = res1[0];
|
||||
|
|
@ -46,8 +40,7 @@ exports.requireExt = function(display, callback)
|
|||
// formats list:
|
||||
var offset = 24;
|
||||
res.formats = [];
|
||||
for (var i=0; i < num_formats; ++i)
|
||||
{
|
||||
for (var i = 0; i < num_formats; ++i) {
|
||||
var format = {};
|
||||
var f = buf.unpack('LCCxxSSSSSSSSL', offset);
|
||||
res.formats.push(f);
|
||||
|
|
@ -58,12 +51,11 @@ exports.requireExt = function(display, callback)
|
|||
callback
|
||||
];
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
};
|
||||
|
||||
ext.QueryFilters = function(callback)
|
||||
{
|
||||
X.seq_num++;
|
||||
ext.QueryFilters = function(callback) {
|
||||
X.pack_stream.pack('CCSL', [ext.majorOpcode, 29, 2, display.screen[0].root]);
|
||||
X.seq_num++;
|
||||
X.replies[X.seq_num] = [
|
||||
function(buf, opt) {
|
||||
var h = buf.unpack('LL');
|
||||
|
|
@ -71,26 +63,24 @@ exports.requireExt = function(display, callback)
|
|||
var num_filters = h[1];
|
||||
var aliases = [];
|
||||
var offset = 24; // LL + 16 bytes pad
|
||||
for (var i=0; i < num_aliases; ++i)
|
||||
{
|
||||
for (var i = 0; i < num_aliases; ++i) {
|
||||
aliases.push(buf.unpack('S', offset)[0]);
|
||||
offset+=2;
|
||||
offset += 2;
|
||||
}
|
||||
var filters = [];
|
||||
for (var i=0; i < num_filters; ++i)
|
||||
{
|
||||
for (var i = 0; i < num_filters; ++i) {
|
||||
var len = buf.unpack('C', offset)[0];
|
||||
//if (!len) break;
|
||||
offset++;
|
||||
filters.push(buf.toString('ascii', offset, offset+len));
|
||||
offset+=len;
|
||||
filters.push(buf.toString('ascii', offset, offset + len));
|
||||
offset += len;
|
||||
}
|
||||
return [aliases, filters];
|
||||
},
|
||||
callback
|
||||
];
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
};
|
||||
|
||||
var valueList = [
|
||||
['repeat', 'Cxxx'],
|
||||
|
|
@ -116,23 +106,19 @@ exports.requireExt = function(display, callback)
|
|||
x: 1
|
||||
};
|
||||
|
||||
ext.CreatePicture = function(pid, drawable, pictformat, values)
|
||||
{
|
||||
X.seq_num++;
|
||||
ext.CreatePicture = function(pid, drawable, pictformat, values) {
|
||||
var mask = 0;
|
||||
var reqLen = 5; // + (values + pad)/4
|
||||
var format = 'CCSLLLL';
|
||||
var params = [ext.majorOpcode, 4, reqLen, pid, drawable, pictformat, mask];
|
||||
|
||||
if (values)
|
||||
{
|
||||
if (values) {
|
||||
var valuesLength = 0;
|
||||
for (var i=0; i < valueList.length; ++i)
|
||||
{
|
||||
for (var i = 0; i < valueList.length; ++i) {
|
||||
var name = valueList[i][0];
|
||||
var val = values[name];
|
||||
if (val) {
|
||||
mask |= (1 << i);
|
||||
mask |= 1 << i;
|
||||
params.push(val);
|
||||
var valueFormat = valueList[i][1];
|
||||
format += valueFormat;
|
||||
|
|
@ -141,56 +127,114 @@ exports.requireExt = function(display, callback)
|
|||
}
|
||||
var pad4 = (valuesLength + 3) >> 2;
|
||||
var toPad = (pad4 << 2) - valuesLength;
|
||||
for (var i=0; i < toPad; ++i)
|
||||
format += 'x';
|
||||
for (var i = 0; i < toPad; ++i) format += 'x';
|
||||
reqLen += pad4;
|
||||
params[2] = reqLen;
|
||||
params[6] = mask;
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.FreePicture = function(pid) {
|
||||
X.pack_stream.pack('CCSL', [ext.majorOpcode, 7, 2, pid]);
|
||||
X.pack_stream.flush();
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
function floatToFix(f) {
|
||||
return parseInt(f * 65536);
|
||||
}
|
||||
|
||||
function floatToFix(f)
|
||||
{
|
||||
return parseInt(f*65536);
|
||||
function colorToFix(f) {
|
||||
if (f < 0) f = 0;
|
||||
if (f > 1) f = 1;
|
||||
return parseInt(f * 65535);
|
||||
}
|
||||
|
||||
ext.SetPictureTransform = function(pid, matrix) {
|
||||
var format = 'CCSLLLLLLLLLL';
|
||||
if (matrix.length !== 9)
|
||||
throw 'Render.SetPictureTransform: incorrect transform matrix. Must be array of 9 numbers';
|
||||
var params = [ext.majorOpcode, 28, 11, pid];
|
||||
for (var i = 0; i < 9; ++i) {
|
||||
if (typeof matrix[i] !== 'number')
|
||||
throw 'Render.SetPictureTransform: matrix element must be a number';
|
||||
params.push(floatToFix(matrix[i]));
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
// see example of blur filter here: https://github.com/richoH/rxvt-unicode/blob/master/src/background.C
|
||||
// TODO: not ready yet.
|
||||
ext.SetPictureFilter = function(pid, name, filterParams)
|
||||
{
|
||||
X.seq_num++;
|
||||
var reqLen = 2; //header + params + 1xStopfix+2xColors
|
||||
var format = 'CCSLa';
|
||||
var params = [ext.majorOpcode, 30, reqLen, pid];
|
||||
/*
|
||||
if (name == 'convolution')
|
||||
{
|
||||
reqLen += 2;
|
||||
format += 'L';
|
||||
params.push(floatToFix(filterParams));
|
||||
} else {
|
||||
throw 'Not implemented filter ' + name;
|
||||
ext.SetPictureFilter = function(pid, name, filterParams) {
|
||||
if (filterParams === 0) filterParams = [0];
|
||||
if (!filterParams) filterParams = [];
|
||||
if (!Array.isArray(filterParams)) filterParams = [filterParams];
|
||||
|
||||
var reqLen = 2;
|
||||
var format = 'CCSLSxxp';
|
||||
var params = [ext.majorOpcode, 30, reqLen, pid, name.length, name];
|
||||
reqLen += xutil.padded_length(name.length + 3) / 4 + filterParams.length;
|
||||
|
||||
if (
|
||||
name == 'nearest' ||
|
||||
name == 'bilinear' ||
|
||||
name == 'fast' ||
|
||||
name == 'good' ||
|
||||
name == 'best'
|
||||
) {
|
||||
if (filterParams.length !== 0) {
|
||||
throw 'Render.SetPictureFilter: "' + name + '" - unexpected parameters for filters';
|
||||
}
|
||||
} else if (name == 'convolution') {
|
||||
if (
|
||||
filterParams.length < 2 ||
|
||||
filterParams[0] * filterParams[1] + 2 !== filterParams.length
|
||||
) {
|
||||
throw 'Render.SetPictureFilter: "convolution" - incorrect matrix dimensions. Must be flat array [ w, h, elem1, elem2, ... ]';
|
||||
}
|
||||
for (var i = 0; i < filterParams.length; ++i) {
|
||||
format += 'L';
|
||||
params.push(floatToFix(filterParams[i]));
|
||||
}
|
||||
} else if (name == 'binomial' || name == 'gaussian') {
|
||||
if (filterParams.length !== 1) {
|
||||
throw 'Render.SetPictureFilter: "' +
|
||||
name +
|
||||
'" - incorrect number of parameters, must be exactly 1 number, instead got: ' +
|
||||
filterParams;
|
||||
}
|
||||
format += 'L';
|
||||
params.push(floatToFix(filterParams[0]));
|
||||
} else {
|
||||
throw 'Render.SetPictureFilter: unknown filter "' + name + '"';
|
||||
}
|
||||
*/
|
||||
params[2] = reqLen;
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.CreateSolidFill = function(pid, r, g, b, a)
|
||||
{
|
||||
X.seq_num++;
|
||||
X.pack_stream.pack('CCSLSSSS', [ext.majorOpcode, 33, 4, pid, floatToFix(r), floatToFix(g), floatToFix(b), floatToFix(a)]);
|
||||
ext.CreateSolidFill = function(pid, r, g, b, a) {
|
||||
X.pack_stream.pack('CCSLSSSS', [
|
||||
ext.majorOpcode,
|
||||
33,
|
||||
4,
|
||||
pid,
|
||||
colorToFix(r),
|
||||
colorToFix(g),
|
||||
colorToFix(b),
|
||||
colorToFix(a)
|
||||
]);
|
||||
X.pack_stream.flush();
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.RadialGradient = function(pid, p1, p2, r1, r2, stops)
|
||||
{
|
||||
// TODO: merge with linear gradient
|
||||
X.seq_num++;
|
||||
var reqLen = 9+stops.length*3; //header + params + 1xStopfix+2xColors
|
||||
ext.RadialGradient = function(pid, p1, p2, r1, r2, stops) {
|
||||
var reqLen = 9 + stops.length * 3; //header + params + 1xStopfix+2xColors
|
||||
var format = 'CCSLLLLLLLL';
|
||||
var params = [ext.majorOpcode, 35, reqLen, pid];
|
||||
params.push(floatToFix(p1[0])); // L
|
||||
|
|
@ -203,27 +247,23 @@ exports.requireExt = function(display, callback)
|
|||
|
||||
// [ [float stopDist, [float r, g, b, a] ], ...]
|
||||
// stop distances
|
||||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
for (var i = 0; i < stops.length; ++i) {
|
||||
format += 'L';
|
||||
// TODO: we know total params length in advance. ? params[index] =
|
||||
params.push(floatToFix(stops[i][0]))
|
||||
params.push(floatToFix(stops[i][0]));
|
||||
}
|
||||
// colors
|
||||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
for (var i = 0; i < stops.length; ++i) {
|
||||
format += 'SSSS';
|
||||
for (var j=0; j < 4; ++j)
|
||||
params.push(stops[i][1][j]);
|
||||
for (var j = 0; j < 4; ++j) params.push(colorToFix(stops[i][1][j]));
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.LinearGradient = function(pid, p1, p2, stops)
|
||||
{
|
||||
X.seq_num++;
|
||||
var reqLen = 7+stops.length*3; //header + params + 1xStopfix+2xColors
|
||||
ext.LinearGradient = function(pid, p1, p2, stops) {
|
||||
var reqLen = 7 + stops.length * 3; //header + params + 1xStopfix+2xColors
|
||||
var format = 'CCSLLLLLL';
|
||||
var params = [ext.majorOpcode, 34, reqLen, pid];
|
||||
params.push(floatToFix(p1[0])); // L
|
||||
|
|
@ -235,27 +275,23 @@ exports.requireExt = function(display, callback)
|
|||
|
||||
// [ [float stopDist, [float r, g, b, a] ], ...]
|
||||
// stop distances
|
||||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
for (var i = 0; i < stops.length; ++i) {
|
||||
format += 'L';
|
||||
// TODO: we know total params length in advance. ? params[index] =
|
||||
params.push(floatToFix(stops[i][0]))
|
||||
params.push(floatToFix(stops[i][0]));
|
||||
}
|
||||
// colors
|
||||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
for (var i = 0; i < stops.length; ++i) {
|
||||
format += 'SSSS';
|
||||
for (var j=0; j < 4; ++j)
|
||||
params.push(stops[i][1][j]);
|
||||
for (var j = 0; j < 4; ++j) params.push(colorToFix(stops[i][1][j]));
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
ext.ConicalGradient = function(pid, center, angle, stops)
|
||||
{
|
||||
X.seq_num++;
|
||||
var reqLen = 6+stops.length*3; //header + params + 1xStopfix+2xColors
|
||||
};
|
||||
|
||||
ext.ConicalGradient = function(pid, center, angle, stops) {
|
||||
var reqLen = 6 + stops.length * 3; //header + params + 1xStopfix+2xColors
|
||||
var format = 'CCSLLLLL';
|
||||
var params = [ext.majorOpcode, 36, reqLen, pid];
|
||||
params.push(floatToFix(center[0])); // L
|
||||
|
|
@ -266,108 +302,136 @@ exports.requireExt = function(display, callback)
|
|||
|
||||
// [ [float stopDist, [float r, g, b, a] ], ...]
|
||||
// stop distances
|
||||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
for (var i = 0; i < stops.length; ++i) {
|
||||
format += 'L';
|
||||
// TODO: we know total params length in advance. ? params[index] =
|
||||
params.push(floatToFix(stops[i][0]))
|
||||
params.push(floatToFix(stops[i][0]));
|
||||
}
|
||||
// colors
|
||||
for (var i=0; i < stops.length; ++i)
|
||||
{
|
||||
for (var i = 0; i < stops.length; ++i) {
|
||||
format += 'SSSS';
|
||||
for (var j=0; j < 4; ++j)
|
||||
params.push(stops[i][1][j]);
|
||||
for (var j = 0; j < 4; ++j) params.push(colorToFix(stops[i][1][j]));
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
ext.FillRectangles = function(op, pid, color, rects)
|
||||
{
|
||||
X.seq_num++;
|
||||
var reqLen = 5+rects.length/2;
|
||||
};
|
||||
|
||||
ext.FillRectangles = function(op, pid, color, rects) {
|
||||
var reqLen = 5 + rects.length / 2;
|
||||
var format = 'CCSCxxxLSSSS';
|
||||
var params = [ext.majorOpcode, 26, reqLen, op, pid];
|
||||
for (var j=0; j < 4; ++j)
|
||||
params.push(color[j]);
|
||||
for (var i=0; i < rects.length; i+=4)
|
||||
{
|
||||
for (var j = 0; j < 4; ++j) params.push(colorToFix(color[j]));
|
||||
for (var i = 0; i < rects.length; i += 4) {
|
||||
format += 'ssSS';
|
||||
params.push(rects[i*4]);
|
||||
params.push(rects[i*4 + 1]);
|
||||
params.push(rects[i*4 + 2]);
|
||||
params.push(rects[i*4 + 3]);
|
||||
params.push(rects[i * 4]);
|
||||
params.push(rects[i * 4 + 1]);
|
||||
params.push(rects[i * 4 + 2]);
|
||||
params.push(rects[i * 4 + 3]);
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
ext.Composite = function(op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height)
|
||||
{
|
||||
X.seq_num++;
|
||||
X.pack_stream.pack(
|
||||
'CCSCxxxLLLssssssSS',
|
||||
[ext.majorOpcode, 8, 9, op, src, mask, dst, srcX, srcY, maskX, maskY, dstX, dstY, width, height]
|
||||
)
|
||||
};
|
||||
|
||||
ext.Composite = function(
|
||||
op,
|
||||
src,
|
||||
mask,
|
||||
dst,
|
||||
srcX,
|
||||
srcY,
|
||||
maskX,
|
||||
maskY,
|
||||
dstX,
|
||||
dstY,
|
||||
width,
|
||||
height
|
||||
) {
|
||||
X.pack_stream
|
||||
.pack('CCSCxxxLLLssssssSS', [
|
||||
ext.majorOpcode,
|
||||
8,
|
||||
9,
|
||||
op,
|
||||
src,
|
||||
mask,
|
||||
dst,
|
||||
srcX,
|
||||
srcY,
|
||||
maskX,
|
||||
maskY,
|
||||
dstX,
|
||||
dstY,
|
||||
width,
|
||||
height
|
||||
])
|
||||
.flush();
|
||||
}
|
||||
|
||||
ext.Trapezoids = function(op, src, srcX, srcY, dst, maskFormat, trapz)
|
||||
{
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
// note that Trapezoids is considered deprecated by Render extension
|
||||
ext.Trapezoids = function(op, src, srcX, srcY, dst, maskFormat, trapz) {
|
||||
var format = 'CCSCxxxLLLss';
|
||||
var params = [ext.majorOpcode, 10, 6+trapz.length, op, src, dst, maskFormat, srcX, srcY];
|
||||
for (var i=0; i < trapz.length; i+=10)
|
||||
{
|
||||
var params = [ext.majorOpcode, 10, 6 + trapz.length, op, src, dst, maskFormat, srcX, srcY];
|
||||
for (var i = 0; i < trapz.length; i++) {
|
||||
format += 'llllllllll';
|
||||
for (var j=0; j < 10; ++j)
|
||||
params.push(floatToFix(trapz[i*10 + j]));
|
||||
for (var j = 0; j < 10; ++j) params.push(floatToFix(trapz[i * 10 + j]));
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
ext.Triangles = function(op, src, srcX, srcY, dst, maskFormat, tris)
|
||||
{
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.AddTraps = function(pic, offX, offY, trapList) {
|
||||
var format = 'CCSLss';
|
||||
var params = [ext.majorOpcode, 32, 3 + trapList.length, pic, offX, offY];
|
||||
for (var i = 0; i < trapList.length; i++) {
|
||||
format += 'l';
|
||||
params.push(floatToFix(trapList[i]));
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.Triangles = function(op, src, srcX, srcY, dst, maskFormat, tris) {
|
||||
var format = 'CCSCxxxLLLss';
|
||||
var params = [ext.majorOpcode, 11, 6+tris.length, op, src, dst, maskFormat, srcX, srcY];
|
||||
for (var i=0; i < tris.length; i+=6)
|
||||
{
|
||||
var params = [ext.majorOpcode, 11, 6 + tris.length, op, src, dst, maskFormat, srcX, srcY];
|
||||
for (var i = 0; i < tris.length; i += 6) {
|
||||
format += 'llllll';
|
||||
//TODO: Array.copy
|
||||
params.push(floatToFix(tris[i*6 + 0])); // x1
|
||||
params.push(floatToFix(tris[i*6 + 1])); // y1
|
||||
params.push(floatToFix(tris[i*6 + 2])); // x2
|
||||
params.push(floatToFix(tris[i*6 + 3])); // y2
|
||||
params.push(floatToFix(tris[i*6 + 4])); // x3
|
||||
params.push(floatToFix(tris[i*6 + 5])); // y3
|
||||
params.push(floatToFix(tris[i + 0])); // x1
|
||||
params.push(floatToFix(tris[i + 1])); // y1
|
||||
params.push(floatToFix(tris[i + 2])); // x2
|
||||
params.push(floatToFix(tris[i + 3])); // y2
|
||||
params.push(floatToFix(tris[i + 4])); // x3
|
||||
params.push(floatToFix(tris[i + 5])); // y3
|
||||
}
|
||||
X.pack_stream.pack(format, params);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.CreateGlyphSet = function(gsid, format) {
|
||||
X.seq_num++;
|
||||
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 17, 3, gsid, format]);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.ReferenceGlyphSet = function(gsid, existing) {
|
||||
X.seq_num++;
|
||||
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 18, 3, gsid, existing]);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.FreeGlyphSet = function(gsid) {
|
||||
X.seq_num++;
|
||||
X.pack_stream.pack('CCSL', [ext.majorOpcode, 19, 2, gsid]);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.AddGlyphs = function(gsid, glyphs) {
|
||||
X.seq_num++;
|
||||
var numGlyphs = glyphs.length;
|
||||
var imageBytes = 0;
|
||||
var glyphPaddedLength;
|
||||
|
|
@ -377,11 +441,11 @@ exports.requireExt = function(display, callback)
|
|||
for (var i = 0; i < numGlyphs; i++) {
|
||||
glyph = glyphs[i];
|
||||
if (glyph.width % 4 !== 0) {
|
||||
var stride = (glyph.width+3)&~3;
|
||||
var res = new Buffer(glyph.height*stride);
|
||||
var stride = (glyph.width + 3) & ~3;
|
||||
var res = Buffer.alloc(glyph.height * stride);
|
||||
res.fill(0);
|
||||
for (var y=0; y < glyph.height; ++y) {
|
||||
glyph.image.copy(res, y*stride, y*glyph.width, y*glyph.width + glyph.width);
|
||||
for (var y = 0; y < glyph.height; ++y) {
|
||||
glyph.image.copy(res, y * stride, y * glyph.width, y * glyph.width + glyph.width);
|
||||
}
|
||||
glyph.image = res;
|
||||
glyph.width = stride;
|
||||
|
|
@ -391,12 +455,12 @@ exports.requireExt = function(display, callback)
|
|||
glyph.offX = glyph.offX / 64;
|
||||
glyph.offY = glyph.offY / 64;
|
||||
}
|
||||
var len = numGlyphs * 4 + imageBytes/4 + 3;
|
||||
var len = numGlyphs * 4 + imageBytes / 4 + 3;
|
||||
// TODO: check length, use bigReq
|
||||
// X.pack_stream.pack('CCSLL', [ext.majorOpcode, 20, len, gsid, glyphs.length]);
|
||||
|
||||
// BigReq: S + [ length ] replaced with SL + [ 0, length+1 ]
|
||||
X.pack_stream.pack('CCSLLL', [ext.majorOpcode, 20, 0, len+1, gsid, glyphs.length]);
|
||||
X.pack_stream.pack('CCSLLL', [ext.majorOpcode, 20, 0, len + 1, gsid, glyphs.length]);
|
||||
|
||||
// glyph ids
|
||||
for (i = 0; i < numGlyphs; i++) {
|
||||
|
|
@ -404,19 +468,44 @@ exports.requireExt = function(display, callback)
|
|||
}
|
||||
// width + heiht + origin xy + advance xy
|
||||
for (i = 0; i < numGlyphs; i++) {
|
||||
X.pack_stream.pack('SSssss', [glyphs[i].width, glyphs[i].height, -glyphs[i].x, glyphs[i].y, glyphs[i].offX, glyphs[i].offY]);
|
||||
X.pack_stream.pack('SSssss', [
|
||||
glyphs[i].width,
|
||||
glyphs[i].height,
|
||||
-glyphs[i].x,
|
||||
glyphs[i].y,
|
||||
glyphs[i].offX,
|
||||
glyphs[i].offY
|
||||
]);
|
||||
}
|
||||
// image
|
||||
for (i = 0; i < numGlyphs; i++) {
|
||||
X.pack_stream.write_queue.push(glyphs[i].image);
|
||||
}
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
//AddGlyphsFromPicture, opcode=21 (not in spec)
|
||||
// FreeGlyps - opcode 22
|
||||
// gsid(L) , glyphs.length (L) + each glyph id (L)
|
||||
//
|
||||
// As far as I know this is not implemented in any X server and always retuen "Bad implementation"
|
||||
// Also documentation looks misleading as it's not mention glyph ids.
|
||||
ext.AddGlyphsFromPicture = function(gsid, src, glyphs) {
|
||||
var len = 3 + glyphs.length * 5;
|
||||
X.pack_stream.pack('CCSLLL', [ext.majorOpcode, 21, 0, len + 1, gsid, src]);
|
||||
for (i = 0; i < glyphs.length; i++) {
|
||||
X.pack_stream.pack('L', [glyphs[i].id]);
|
||||
}
|
||||
for (i = 0; i < glyphs.length; i++) {
|
||||
X.pack_stream.pack('SSssssss', [
|
||||
glyphs[i].width,
|
||||
glyphs[i].height,
|
||||
-glyphs[i].x,
|
||||
glyphs[i].y,
|
||||
glyphs[i].offX,
|
||||
glyphs[i].offY,
|
||||
glyphs[i].srcX,
|
||||
glyphs[i].srcY
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
// each GlyphEle:
|
||||
// 1 byte - number of glyphs
|
||||
|
|
@ -432,54 +521,160 @@ exports.requireExt = function(display, callback)
|
|||
// glyphs as input:
|
||||
// [ "just string (0,0) offset is used", [ 10, 10, "string offseted 10,10 from previous pen position" ], 1234567 ] 1234567 is glypfset id or FONT
|
||||
|
||||
|
||||
// TODO: pre-process input so strings larger than 254 chars are supported
|
||||
// (split them into multiple entries with 0,0 offset)
|
||||
|
||||
var formatFromBits = [,,,,,,,,'C',,,,,,,,'S',,,,,,,,,,,,,,,,'L'];
|
||||
var bufferWriteBits = [,,,,,,,,'writeUInt8',,,,,,,,'writeUInt16LE',,,,,,,,,,,,,,,,'writeUInt32LE'];
|
||||
var formatFromBits = [
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
'C',
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
'S',
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
'L'
|
||||
];
|
||||
var bufferWriteBits = [
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
'writeUInt8',
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
'writeUInt16LE',
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
'writeUInt32LE'
|
||||
];
|
||||
|
||||
// 8/16/32 bit string + 4-byte pad
|
||||
function wstring(bits, s) {
|
||||
var charLength = bits / 8;
|
||||
var dataLength = s.length*charLength;
|
||||
var res = new Buffer(xutil.padded_length(dataLength));
|
||||
var dataLength = s.length * charLength;
|
||||
var res = Buffer.alloc(xutil.padded_length(dataLength));
|
||||
debugger;
|
||||
var write = res[bufferWriteBits[bits]]
|
||||
var write = res[bufferWriteBits[bits]];
|
||||
res.fill(0);
|
||||
for(var i=0; i < s.length; i++)
|
||||
write.call(res, s.charCodeAt(i), i*charLength);
|
||||
for (var i = 0; i < s.length; i++) write.call(res, s.charCodeAt(i), i * charLength);
|
||||
return res;
|
||||
}
|
||||
|
||||
var compositeGlyphsOpcodeFromBits = [,,,,,,,,23,,,,,,,,24,,,,,,,,,,,,,,,,25];
|
||||
ext.CompositeGlyphs = function(glyphBits, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
|
||||
{
|
||||
var compositeGlyphsOpcodeFromBits = [
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
23,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
24,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
,
|
||||
25
|
||||
];
|
||||
ext.CompositeGlyphs = function(glyphBits, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs) {
|
||||
var opcode = compositeGlyphsOpcodeFromBits[glyphBits];
|
||||
var charFormat = formatFromBits[glyphBits];
|
||||
var charLength = glyphBits / 8;
|
||||
X.seq_num++;
|
||||
var length = 7;
|
||||
var glyphs_length_split = [];
|
||||
for (var i=0; i < glyphs.length; ++i) {
|
||||
for (var i = 0; i < glyphs.length; ++i) {
|
||||
var g = glyphs[i];
|
||||
switch (typeof g) {
|
||||
case 'string':
|
||||
length += xutil.padded_length(g.length*charLength)/4 + 2;
|
||||
length += xutil.padded_length(g.length * charLength) / 4 + 2;
|
||||
break;
|
||||
case 'object':
|
||||
length += xutil.padded_length(g[2].length*charLength)/4 + 2;
|
||||
length += xutil.padded_length(g[2].length * charLength) / 4 + 2;
|
||||
break;
|
||||
case 'number': // glyphset id
|
||||
length += 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
X.pack_stream.pack(
|
||||
'CCSCxxxLLLLss',
|
||||
[ext.majorOpcode, opcode, length, op, src, dst, maskFormat, gsid, srcX, srcY]
|
||||
);
|
||||
for (var i=0; i < glyphs.length; ++i) {
|
||||
X.pack_stream.pack('CCSCxxxLLLLss', [
|
||||
ext.majorOpcode,
|
||||
opcode,
|
||||
length,
|
||||
op,
|
||||
src,
|
||||
dst,
|
||||
maskFormat,
|
||||
gsid,
|
||||
srcX,
|
||||
srcY
|
||||
]);
|
||||
for (var i = 0; i < glyphs.length; ++i) {
|
||||
var g = glyphs[i];
|
||||
switch (typeof g) {
|
||||
case 'string':
|
||||
|
|
@ -494,20 +689,18 @@ exports.requireExt = function(display, callback)
|
|||
}
|
||||
}
|
||||
X.pack_stream.flush();
|
||||
X.seq_num++;
|
||||
};
|
||||
|
||||
ext.CompositeGlyphs8 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
|
||||
{
|
||||
ext.CompositeGlyphs8 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs) {
|
||||
return ext.CompositeGlyphs(8, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs);
|
||||
};
|
||||
|
||||
ext.CompositeGlyphs16 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
|
||||
{
|
||||
ext.CompositeGlyphs16 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs) {
|
||||
return ext.CompositeGlyphs(16, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs);
|
||||
};
|
||||
|
||||
ext.CompositeGlyphs32 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs)
|
||||
{
|
||||
ext.CompositeGlyphs32 = function(op, src, dst, maskFormat, gsid, srcX, srcY, glyphs) {
|
||||
return ext.CompositeGlyphs(32, op, src, dst, maskFormat, gsid, srcX, srcY, glyphs);
|
||||
};
|
||||
|
||||
|
|
@ -530,34 +723,145 @@ exports.requireExt = function(display, callback)
|
|||
// 11 - colormap or none
|
||||
|
||||
ext.QueryPictFormat(function(err, formats) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
for (var i=0; i < formats.formats.length; ++i) {
|
||||
if (err) return callback(err);
|
||||
for (var i = 0; i < formats.formats.length; ++i) {
|
||||
var f = formats.formats[i];
|
||||
if (f[2] == 1 && f[10] == 1)
|
||||
ext.mono1 = f[0] ;
|
||||
if (f[2] == 24 && f[3] == 16 && f[5] == 8 && f[7] == 0)
|
||||
ext.rgb24 = f[0];
|
||||
if (f[2] == 1 && f[10] == 1) ext.mono1 = f[0];
|
||||
if (f[2] == 24 && f[3] == 16 && f[5] == 8 && f[7] == 0) ext.rgb24 = f[0];
|
||||
// 1, 32, 16, 255, 8, 255, 0, 255, 24, 255, 0
|
||||
if (f[2] == 32 && f[3] == 16 && f[4] == 255 && f[5] == 8 && f[6] == 255 && f[7] == 0 && f[9] == 24)
|
||||
ext.rgba32 = f[0] ;
|
||||
if (f[2] == 8 && f[10] == 255)
|
||||
ext.a8 = f[0];
|
||||
if (
|
||||
f[2] == 32 &&
|
||||
f[3] == 16 &&
|
||||
f[4] == 255 &&
|
||||
f[5] == 8 &&
|
||||
f[6] == 255 &&
|
||||
f[7] == 0 &&
|
||||
f[9] == 24
|
||||
)
|
||||
ext.rgba32 = f[0];
|
||||
if (f[2] == 8 && f[10] == 255) ext.a8 = f[0];
|
||||
}
|
||||
callback(null, ext);
|
||||
});
|
||||
|
||||
[
|
||||
"PICTFORMAT argument does not name a defined PICTFORMAT",
|
||||
"PICTURE argument does not name a defined PICTURE",
|
||||
"PICTOP argument does not name a defined PICTOP",
|
||||
"GLYPHSET argument does not name a defined GLYPHSET",
|
||||
"GLYPH argument does not name a defined GLYPH in the glyphset"
|
||||
'PICTFORMAT argument does not name a defined PICTFORMAT',
|
||||
'PICTURE argument does not name a defined PICTURE',
|
||||
'PICTOP argument does not name a defined PICTOP',
|
||||
'GLYPHSET argument does not name a defined GLYPHSET',
|
||||
'GLYPH argument does not name a defined GLYPH in the glyphset'
|
||||
].forEach(function(desc, code) {
|
||||
X.errorParsers[ext.firstError + code] = function(err) {
|
||||
err.message = "XRender: a value for a " + desc;
|
||||
err.message = 'XRender: a value for a ' + desc;
|
||||
};
|
||||
});
|
||||
|
||||
ext.PictOp = {
|
||||
Minimum: 0,
|
||||
Clear: 0,
|
||||
Src: 1,
|
||||
Dst: 2,
|
||||
Over: 3,
|
||||
OverReverse: 4,
|
||||
In: 5,
|
||||
InReverse: 6,
|
||||
Out: 7,
|
||||
OutReverse: 8,
|
||||
Atop: 9,
|
||||
AtopReverse: 10,
|
||||
Xor: 11,
|
||||
Add: 12,
|
||||
Saturate: 13,
|
||||
Maximum: 13,
|
||||
|
||||
/*,
|
||||
* Operators only available in version 0.2,
|
||||
*/
|
||||
DisjointMinimum: 0x10,
|
||||
DisjointClear: 0x10,
|
||||
DisjointSrc: 0x11,
|
||||
DisjointDst: 0x12,
|
||||
DisjointOver: 0x13,
|
||||
DisjointOverReverse: 0x14,
|
||||
DisjointIn: 0x15,
|
||||
DisjointInReverse: 0x16,
|
||||
DisjointOut: 0x17,
|
||||
DisjointOutReverse: 0x18,
|
||||
DisjointAtop: 0x19,
|
||||
DisjointAtopReverse: 0x1a,
|
||||
DisjointXor: 0x1b,
|
||||
DisjointMaximum: 0x1b,
|
||||
|
||||
ConjointMinimum: 0x20,
|
||||
ConjointClear: 0x20,
|
||||
ConjointSrc: 0x21,
|
||||
ConjointDst: 0x22,
|
||||
ConjointOver: 0x23,
|
||||
ConjointOverReverse: 0x24,
|
||||
ConjointIn: 0x25,
|
||||
ConjointInReverse: 0x26,
|
||||
ConjointOut: 0x27,
|
||||
ConjointOutReverse: 0x28,
|
||||
ConjointAtop: 0x29,
|
||||
ConjointAtopReverse: 0x2a,
|
||||
ConjointXor: 0x2b,
|
||||
ConjointMaximum: 0x2b,
|
||||
|
||||
/*,
|
||||
* Operators only available in version 0.11,
|
||||
*/
|
||||
BlendMinimum: 0x30,
|
||||
Multiply: 0x30,
|
||||
Screen: 0x31,
|
||||
Overlay: 0x32,
|
||||
Darken: 0x33,
|
||||
Lighten: 0x34,
|
||||
ColorDodge: 0x35,
|
||||
ColorBurn: 0x36,
|
||||
HardLight: 0x37,
|
||||
SoftLight: 0x38,
|
||||
Difference: 0x39,
|
||||
Exclusion: 0x3a,
|
||||
HSLHue: 0x3b,
|
||||
HSLSaturation: 0x3c,
|
||||
HSLColor: 0x3d,
|
||||
HSLLuminosity: 0x3e,
|
||||
BlendMaximum: 0x3e
|
||||
};
|
||||
|
||||
ext.PolyEdge = {
|
||||
Sharp: 0,
|
||||
Smooth: 1
|
||||
};
|
||||
|
||||
ext.PolyMode = {
|
||||
Precise: 0,
|
||||
Imprecise: 1
|
||||
};
|
||||
|
||||
ext.Repeat = {
|
||||
None: 0,
|
||||
Normal: 1,
|
||||
Pad: 2,
|
||||
Reflect: 3
|
||||
};
|
||||
|
||||
ext.Subpixel = {
|
||||
Unknown: 0,
|
||||
HorizontalRGB: 1,
|
||||
HorizontalBGR: 2,
|
||||
VerticalRGB: 3,
|
||||
VerticalBGR: 4,
|
||||
None: 5
|
||||
};
|
||||
|
||||
ext.Filters = {
|
||||
Nearest: 'nearest',
|
||||
Bilinear: 'bilinear',
|
||||
Convolution: 'convolution',
|
||||
Fast: 'fast',
|
||||
Good: 'good',
|
||||
Best: 'best'
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -31,12 +31,19 @@ exports.requireExt = function(display, callback)
|
|||
Intersect: 2,
|
||||
Subtract: 3,
|
||||
Invert: 4
|
||||
}
|
||||
};
|
||||
|
||||
ext.Ordering = {
|
||||
Unsorted: 0,
|
||||
YSorted: 1,
|
||||
YXSorted: 2,
|
||||
YXBanded: 3
|
||||
};
|
||||
|
||||
ext.QueryVersion = function(cb)
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
// captureStack();
|
||||
X.pack_stream.pack('CCSLL', [ext.majorOpcode, 0, 1]);
|
||||
X.replies[X.seq_num] = [
|
||||
function(buf, opt) {
|
||||
|
|
@ -48,18 +55,36 @@ exports.requireExt = function(display, callback)
|
|||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
// Accepts rectangles as [[x, y, width, height]]
|
||||
ext.Rectangles = function( op, kind, window, x, y, rectangles, ordering /* = Ordering.Unsorted */ )
|
||||
{
|
||||
if (ordering === undefined)
|
||||
ordering = ext.Ordering.Unsorted;
|
||||
|
||||
var length = 4 + rectangles.length * 2;
|
||||
|
||||
X.seq_num++;
|
||||
// captureStack();
|
||||
X.pack_stream.pack('CCSCCCxLss', [ext.majorOpcode, 1, length, op, kind, ordering, window, x, y]);
|
||||
for (var i = 0; i < rectangles.length; ++i) {
|
||||
var r = rectangles[i];
|
||||
X.pack_stream.pack('ssSS', r);
|
||||
}
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
ext.Mask = function( op, kind, window, x, y, bitmap )
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
X.pack_stream.pack('CCSCCxxLssL', [ext.majorOpcode, 2, 5, op, kind, x, y, bitmap]);
|
||||
// captureStack();
|
||||
X.pack_stream.pack('CCSCCxxLssL', [ext.majorOpcode, 2, 5, op, kind, window, x, y, bitmap]);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
||||
ext.SelectInput = function( window, enable )
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
// captureStack();
|
||||
X.pack_stream.pack('CCSLCxxx', [ext.majorOpcode, 6, 3, window, enable ]);
|
||||
X.pack_stream.flush();
|
||||
}
|
||||
|
|
@ -67,7 +92,7 @@ exports.requireExt = function(display, callback)
|
|||
ext.InputSelected = function( window, cb )
|
||||
{
|
||||
X.seq_num++;
|
||||
captureStack();
|
||||
// captureStack();
|
||||
X.pack_stream.pack('CCSL', [ext.majorOpcode, 7, 2, window ]);
|
||||
X.replies[X.seq_num] = [
|
||||
function(buf, opt) {
|
||||
|
|
@ -87,5 +112,31 @@ exports.requireExt = function(display, callback)
|
|||
callback(null, ext);
|
||||
});
|
||||
*/
|
||||
|
||||
ext.events = {
|
||||
ShapeNotify: 0
|
||||
}
|
||||
|
||||
X.eventParsers[ext.firstEvent + ext.events.ShapeNotify] = function(type, seq, extra, code, raw)
|
||||
{
|
||||
var event = {};
|
||||
event.type = type;
|
||||
event.kind = code;
|
||||
event.seq = seq;
|
||||
|
||||
event.window = extra;
|
||||
|
||||
var values = raw.unpack('ssSSLC');
|
||||
|
||||
event.x = values[0];
|
||||
event.y = values[1];
|
||||
event.width = values[2];
|
||||
event.height = values[3];
|
||||
event.time = values[4];
|
||||
event.shaped = values[5];
|
||||
event.name = 'ShapeNotify';
|
||||
|
||||
return event;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
|||
22
lib/gcfunction.js
Normal file
22
lib/gcfunction.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* GCFunction named shortcuts
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
GXclear : 0x0,
|
||||
GXand : 0x1,
|
||||
GXandReverse : 0x2,
|
||||
GXcopy : 0x3,
|
||||
GXandInverted : 0x4,
|
||||
GXnoop : 0x5,
|
||||
GXxor : 0x6,
|
||||
GXor : 0x7,
|
||||
GXnor : 0x8,
|
||||
GXequiv : 0x9,
|
||||
GXinvert : 0xa,
|
||||
GXorReverse : 0xb,
|
||||
GXcopyInverted : 0xc,
|
||||
GXorInverted : 0xd,
|
||||
GXnand : 0xe,
|
||||
GXset : 0xf
|
||||
};
|
||||
|
|
@ -32,8 +32,11 @@ function readVisuals(bl, visuals, n_visuals, cb)
|
|||
});
|
||||
}
|
||||
|
||||
function readDepths(bl, display, depths, n_depths, cb)
|
||||
function readScreens(bl, display, cbDisplayReady)
|
||||
{
|
||||
var numParsedDepths = 0;
|
||||
var readDepths = function(bl, display, depths, n_depths, cb)
|
||||
{
|
||||
if (n_depths == 0)
|
||||
{
|
||||
cb();
|
||||
|
|
@ -46,17 +49,22 @@ function readDepths(bl, display, depths, n_depths, cb)
|
|||
var visuals = {};
|
||||
readVisuals(bl, visuals, n_visuals, function()
|
||||
{
|
||||
if (dep in depths) {
|
||||
for (var visual in visuals) {
|
||||
depths[dep][visual] = visuals[visual];
|
||||
}
|
||||
} else {
|
||||
depths[dep] = visuals;
|
||||
if (Object.keys(depths).length == n_depths)
|
||||
}
|
||||
numParsedDepths++;
|
||||
if (numParsedDepths == n_depths)
|
||||
cb();
|
||||
else
|
||||
readDepths(bl, display, depths, n_depths, cb);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function readScreens(bl, display, cbDisplayReady)
|
||||
{
|
||||
// for (i=0; i < display.screen_num; ++i)
|
||||
{
|
||||
var scr = {};
|
||||
|
|
@ -90,7 +98,7 @@ function readScreens(bl, display, cbDisplayReady)
|
|||
if (display.screen.length == display.screen_num)
|
||||
{
|
||||
delete display.screen_num;
|
||||
cbDisplayReady(display);
|
||||
cbDisplayReady(null, display);
|
||||
return;
|
||||
} else {
|
||||
readScreens(bl, display, cbDisplayReady);
|
||||
|
|
@ -108,9 +116,14 @@ bl.unpack('C', function(res) {
|
|||
if (res[0] == 0)
|
||||
{
|
||||
// conection time error
|
||||
// unpack error (? TODO)
|
||||
// unpack error
|
||||
bl.unpack('Cxxxxxx', function (rlen) {
|
||||
bl.get(rlen[0], function (reason) {
|
||||
var err = new Error;
|
||||
cb(err); // TODO: detect that this is error on xcore side
|
||||
err.message = 'X server connection failed: ' + reason.toString();
|
||||
cb(err);
|
||||
});
|
||||
});
|
||||
// TODO: do we need to close stream from our side?
|
||||
// TODO: api to close source stream via attached unpackstream
|
||||
return;
|
||||
|
|
@ -189,9 +202,12 @@ function getByteOrder() {
|
|||
}
|
||||
}
|
||||
|
||||
function writeClientHello(stream, displayNum, authHost)
|
||||
function writeClientHello(stream, displayNum, authHost, authFamily)
|
||||
{
|
||||
getAuthString( displayNum, authHost, function( authType, authData ) {
|
||||
getAuthString( displayNum, authHost, authFamily, function( err, cookie ) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
var byte_order = getByteOrder();
|
||||
var protocol_major = 11; // TODO: config? env?
|
||||
var protocol_minor = 0;
|
||||
|
|
@ -201,10 +217,10 @@ function writeClientHello(stream, displayNum, authHost)
|
|||
byte_order,
|
||||
protocol_major,
|
||||
protocol_minor,
|
||||
authType.length,
|
||||
authData.length,
|
||||
authType,
|
||||
authData
|
||||
cookie.authName.length,
|
||||
cookie.authData.length,
|
||||
cookie.authName,
|
||||
cookie.authData
|
||||
]
|
||||
);
|
||||
stream.flush();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
// It should create a pleasant looking hex dumb by default:
|
||||
//
|
||||
// var hexy = require('hexy.js'),
|
||||
// b = new Buffer("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789")
|
||||
// b = Buffer.alloc("\000\001\003\005\037\012\011bcdefghijklmnopqrstuvwxyz0123456789")
|
||||
//
|
||||
// console.log(hexy.hexy(b))
|
||||
//
|
||||
|
|
|
|||
11
lib/index.js
11
lib/index.js
|
|
@ -1,13 +1,20 @@
|
|||
var core = require('./xcore');
|
||||
var em = require('./eventmask').eventMask;
|
||||
var keysyms = require('./keysyms');
|
||||
var server = require('./xserver');
|
||||
|
||||
module.exports.createClient = core.createClient;
|
||||
module.exports.createServer = server.createServer;
|
||||
module.exports.eventMask = em;
|
||||
module.exports.keySyms = keysyms;
|
||||
|
||||
Object.defineProperty(module.exports, 'keySyms', {
|
||||
enumerable: true,
|
||||
get: function() { return require('./keysyms'); }
|
||||
});
|
||||
|
||||
Object.defineProperty(module.exports, 'gcFunction', {
|
||||
enumerable: true,
|
||||
get: function() { return require('./gcfunction'); }
|
||||
});
|
||||
|
||||
//TODO:
|
||||
// keepe everything in namespace for consistensy (eventMask, keySyms, class, destination ...
|
||||
|
|
|
|||
3503
lib/keysyms.js
3503
lib/keysyms.js
File diff suppressed because it is too large
Load diff
35
lib/keysyms.update.sh
Executable file
35
lib/keysyms.update.sh
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash -e
|
||||
|
||||
keysymdef_url=http://cgit.freedesktop.org/xorg/proto/xproto/plain/keysymdef.h
|
||||
keysymdef=$(mktemp)
|
||||
|
||||
wget $keysymdef_url -O $keysymdef
|
||||
|
||||
(
|
||||
echo "
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\\
|
||||
|
||||
This file is automatically translated from X.Org's xproto/keysymdef.h
|
||||
Please, do not update this file with your hands, run $(basename "$0").
|
||||
|
||||
\\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
module.exports = {
|
||||
"
|
||||
|
||||
sed -r '
|
||||
s/#ifdef\s+/\/\/ Group /
|
||||
s/#endif.*//
|
||||
s/#define\s+([^ ]+)(\s+)([^ ]+)\s*\/\*\s*([^\*]+[^ ])\s*\*\// \1:\2{ code: \3, description: "\4" },/
|
||||
s/(\b)U\+([0-9A-F]+)(\b)/\1(\\u\2)\3/i
|
||||
s/#define\s+([^ ]+)(\s+)([^ ]+)/ \1:\2{ code: \3, description: null },/
|
||||
#s/#define\s+([^ ]+)(\s+[^ ]+)/ \1:\2,/
|
||||
' $keysymdef
|
||||
|
||||
echo -n '
|
||||
NoSymbol: 0
|
||||
};'
|
||||
|
||||
) > "$(dirname "$0")/keysyms.js"
|
||||
|
||||
rm $keysymdef
|
||||
|
|
@ -23,7 +23,7 @@ function ReadFixedRequest(length, callback)
|
|||
{
|
||||
this.length = length;
|
||||
this.callback = callback;
|
||||
this.data = new Buffer(length);
|
||||
this.data = Buffer.alloc(length);
|
||||
this.received_bytes = 0;
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +201,7 @@ UnpackStream.prototype.pstr = function(str)
|
|||
var len = xutil.padded_length(str.length);
|
||||
if (len == 0)
|
||||
return; // nothing to write
|
||||
var buf = new Buffer(len);
|
||||
var buf = Buffer.alloc(len);
|
||||
buf.write(str, 'binary');
|
||||
this.write_queue.push(buf);
|
||||
}
|
||||
|
|
@ -231,7 +231,7 @@ UnpackStream.prototype.pack = function(format, args)
|
|||
}
|
||||
}
|
||||
|
||||
var buf = new Buffer(packetlength);
|
||||
var buf = Buffer.alloc(packetlength);
|
||||
var offset = 0;
|
||||
var arg = 0;
|
||||
for (var i = 0; i < format.length; ++i)
|
||||
|
|
@ -269,12 +269,14 @@ UnpackStream.prototype.pack = function(format, args)
|
|||
buf[offset++] = (n >> 16) & 0xff;
|
||||
buf[offset++] = (n >> 24) & 0xff;
|
||||
break;
|
||||
case 'a': // string or buffer
|
||||
case 'a': // string, buffer, or array
|
||||
var str = args[arg++];
|
||||
if (Buffer.isBuffer(str))
|
||||
{
|
||||
str.copy(buf, offset);
|
||||
offset += str.length;
|
||||
} else if(Array.isArray(str)) {
|
||||
for(var item of str) buf[offset++] = item;
|
||||
} else {
|
||||
// TODO: buffer.write could be faster
|
||||
for (var c = 0; c < str.length; ++c)
|
||||
|
|
|
|||
174
lib/xcore.js
174
lib/xcore.js
|
|
@ -6,7 +6,6 @@ var handshake = require('./handshake');
|
|||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var PackStream = require('./unpackstream');
|
||||
var coreRequestsTemplate = require('./corereqs');
|
||||
var hexy = require('./hexy').hexy;
|
||||
|
||||
var Buffer = require('buffer').Buffer;
|
||||
|
|
@ -20,10 +19,28 @@ var coreRequests = require('./corereqs');
|
|||
var stdatoms = require('./stdatoms');
|
||||
var em = require('./eventmask').eventMask;
|
||||
|
||||
function XClient(stream, displayNum, screenNum, options)
|
||||
function stash ()
|
||||
{
|
||||
require('./ext/apple-wm');
|
||||
require('./ext/big-requests');
|
||||
require('./ext/composite');
|
||||
require('./ext/damage');
|
||||
require('./ext/dpms');
|
||||
require('./ext/fixes');
|
||||
require('./ext/glxconstants');
|
||||
require('./ext/glx');
|
||||
require('./ext/glxrender');
|
||||
require('./ext/randr');
|
||||
require('./ext/render');
|
||||
require('./ext/screen-saver');
|
||||
require('./ext/shape');
|
||||
require('./ext/xc-misc');
|
||||
require('./ext/xtest');
|
||||
}
|
||||
|
||||
function XClient(displayNum, screenNum, options)
|
||||
{
|
||||
EventEmitter.call(this);
|
||||
this.stream = stream;
|
||||
this.options = options ? options : {};
|
||||
|
||||
// TODO: this is probably not used
|
||||
|
|
@ -32,7 +49,20 @@ function XClient(stream, displayNum, screenNum, options)
|
|||
|
||||
this.displayNum = displayNum;
|
||||
this.screenNum = screenNum;
|
||||
}
|
||||
util.inherits(XClient, EventEmitter);
|
||||
|
||||
XClient.prototype.init = function(stream)
|
||||
{
|
||||
this.stream = stream;
|
||||
|
||||
this.authHost = stream.remoteAddress;
|
||||
// Node v0.10.x does not have stream.remoteFamily, so dig in to find it
|
||||
this.authFamily = stream._getpeername ? stream._getpeername().family : stream.remoteFamily;
|
||||
if (!this.authHost || this.authHost === '127.0.0.1' || this.authHost === '::1') {
|
||||
this.authHost = os.hostname();
|
||||
this.authFamily = null;
|
||||
}
|
||||
|
||||
var pack_stream = new PackStream();
|
||||
|
||||
|
|
@ -102,13 +132,14 @@ function XClient(stream, displayNum, screenNum, options)
|
|||
this.event_consumers = {}; // maps window id to eventemitter TODO: bad name
|
||||
this.eventParsers = {};
|
||||
this.errorParsers = {};
|
||||
this._extensions = {};
|
||||
|
||||
this.importRequestsFromTemplates(this, coreRequests);
|
||||
|
||||
this.startHandshake();
|
||||
this._closing = false;
|
||||
this._unusedIds = [];
|
||||
}
|
||||
util.inherits(XClient, EventEmitter);
|
||||
|
||||
// TODO: close() = set 'closing' flag, watch it in replies and writeQueue, terminate if empty
|
||||
XClient.prototype.terminate = function()
|
||||
|
|
@ -236,12 +267,17 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
|
|||
|
||||
XClient.prototype.AllocID = function()
|
||||
{
|
||||
if (this._unusedIds.length > 0) {
|
||||
return this._unusedIds.pop();
|
||||
}
|
||||
// TODO: handle overflow (XCMiscGetXIDRange from XC_MISC ext)
|
||||
// TODO: unused id buffer
|
||||
this.display.rsrc_id++;
|
||||
return (this.display.rsrc_id << this.display.rsrc_shift) + this.display.resource_base;
|
||||
}
|
||||
};
|
||||
|
||||
XClient.prototype.ReleaseID = function(id) {
|
||||
this._unusedIds.push(id);
|
||||
};
|
||||
|
||||
// TODO: move core events unpackers to corereqs.js
|
||||
XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
||||
|
|
@ -275,8 +311,8 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
|||
event.y = values[6];
|
||||
event.buttons = values[7];
|
||||
event.sameScreen = values[8];
|
||||
} else if (type == 7) { //EnterNotify
|
||||
event.name = 'EnterNotify'
|
||||
} else if (type == 7 || type == 8) { //EnterNotify || LeaveNotify
|
||||
event.name = type === 7 ? 'EnterNotify' : 'LeaveNotify';
|
||||
var values = raw.unpack('LLLssssSC');
|
||||
event.root = values[0]
|
||||
event.wid = values[1]
|
||||
|
|
@ -286,7 +322,14 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
|||
event.x = values[5];
|
||||
event.y = values[6];
|
||||
event.values = values
|
||||
|
||||
} else if (type == 9) { // FocusIn
|
||||
event.name = "FocusIn";
|
||||
event.mode = raw.unpack('C')[0];
|
||||
event.wid = extra;
|
||||
} else if (type == 10) { // FocusOut
|
||||
event.name = "FocusOut";
|
||||
event.mode = raw.unpack('C')[0];
|
||||
event.wid = extra;
|
||||
} else if (type == 12) { // Expose
|
||||
var values = raw.unpack('SSSSS');
|
||||
event.name = 'Expose'
|
||||
|
|
@ -297,36 +340,36 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
|||
event.height = values[3];
|
||||
event.count = values[4]; // TODO: ???
|
||||
} else if (type == 16) { // CreateNotify
|
||||
var values = raw.unpack('LLssSSSc');
|
||||
var values = raw.unpack('LssSSSc');
|
||||
event.name = 'CreateNotify'
|
||||
event.parent = values[0];
|
||||
event.wid = values[1];
|
||||
event.x = values[2];
|
||||
event.y = values[3];
|
||||
event.width = values[4];
|
||||
event.height = values[5];
|
||||
event.borderWidth = values[6];
|
||||
event.overrideRedirect = values[7] ? true : false;
|
||||
event.parent = extra;
|
||||
event.wid = values[0];
|
||||
event.x = values[1];
|
||||
event.y = values[2];
|
||||
event.width = values[3];
|
||||
event.height = values[4];
|
||||
event.borderWidth = values[5];
|
||||
event.overrideRedirect = values[6] ? true : false;
|
||||
// x, y, width, height, border
|
||||
} else if (type == 17) { // destroy notify
|
||||
var values = raw.unpack('LL');
|
||||
var values = raw.unpack('L');
|
||||
event.name = 'DestroyNotify'
|
||||
event.event = extra;
|
||||
event.wid = values[0];
|
||||
} else if (type == 18) { // UnmapNotify
|
||||
var values = raw.unpack('LLC');
|
||||
var values = raw.unpack('LC');
|
||||
event.name = 'UnmapNotify'
|
||||
event.event = extra;
|
||||
event.wid = values[0];
|
||||
event.fromConfigure = values[1] ? true : false;
|
||||
} else if (type == 19) { // MapNotify
|
||||
var values = raw.unpack('LLC');
|
||||
var values = raw.unpack('LC');
|
||||
event.name = 'MapNotify'
|
||||
event.event = extra;
|
||||
event.wid = values[0];
|
||||
event.overrideRedirect = values[1] ? true : false;
|
||||
} else if (type == 20) {
|
||||
var values = raw.unpack('LL');
|
||||
var values = raw.unpack('L');
|
||||
event.name = 'MapRequest'
|
||||
event.parent = extra;
|
||||
event.wid = values[0];
|
||||
|
|
@ -400,7 +443,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
|||
event.name = 'ClientMessage';
|
||||
event.format = code;
|
||||
event.wid = extra;
|
||||
event.type = raw.readUInt32LE(0);
|
||||
event.message_type = raw.unpack('L')[0];
|
||||
var format = (code === 32) ? 'LLLLL' : (code === 16) ? 'SSSSSSSSSS' : 'CCCCCCCCCCCCCCCCCCCC';
|
||||
event.data = raw.unpack(format, 4);
|
||||
} else if (type == 34) {
|
||||
|
|
@ -408,9 +451,6 @@ XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)
|
|||
event.request = headerBuf[4];
|
||||
event.firstKeyCode = headerBuf[5];
|
||||
event.count = headerBuf[6];
|
||||
// TODO cleanup
|
||||
console.log(values);
|
||||
console.log(raw);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
|
@ -475,7 +515,7 @@ XClient.prototype.expectReplyHeader = function()
|
|||
|
||||
// raw event 32-bytes packet (primarily for use in SendEvent);
|
||||
// TODO: Event::pack based on event parameters, inverse to unpackEvent
|
||||
ev.rawData = new Buffer(32);
|
||||
ev.rawData = Buffer.alloc(32);
|
||||
headerBuf.copy(ev.rawData);
|
||||
buf.copy(ev.rawData, 8);
|
||||
|
||||
|
|
@ -520,15 +560,16 @@ XClient.prototype.expectReplyHeader = function()
|
|||
);
|
||||
}
|
||||
|
||||
XClient.prototype.startHandshake = function()
|
||||
{
|
||||
XClient.prototype.startHandshake = function() {
|
||||
var client = this;
|
||||
|
||||
handshake.writeClientHello(this.pack_stream, this.displayNum, this.authHost);
|
||||
handshake.readServerHello(this.pack_stream, function(display)
|
||||
handshake.writeClientHello(this.pack_stream, this.displayNum, this.authHost, this.authFamily);
|
||||
handshake.readServerHello(this.pack_stream, function(err, display)
|
||||
{
|
||||
// TODO: readServerHello can set error state in display
|
||||
// emit error in that case
|
||||
if (err) {
|
||||
client.emit('error', err);
|
||||
return;
|
||||
}
|
||||
client.expectReplyHeader();
|
||||
client.display = display;
|
||||
display.client = client;
|
||||
|
|
@ -538,9 +579,24 @@ XClient.prototype.startHandshake = function()
|
|||
|
||||
XClient.prototype.require = function(extName, callback)
|
||||
{
|
||||
var ext = require('./ext/' + extName);
|
||||
ext.requireExt(this.display, callback);
|
||||
}
|
||||
var self = this;
|
||||
var ext = this._extensions[extName];
|
||||
if (ext) {
|
||||
return process.nextTick(function() {
|
||||
callback(null, ext);
|
||||
});
|
||||
}
|
||||
|
||||
ext = require('./ext/' + extName);
|
||||
ext.requireExt(this.display, function(err, _ext) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
self._extensions[extName] = _ext;
|
||||
callback(null, _ext);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.createClient = function(options, initCb)
|
||||
{
|
||||
|
|
@ -560,8 +616,6 @@ module.exports.createClient = function(options, initCb)
|
|||
throw new Error("Cannot parse display");
|
||||
|
||||
var host = displayMatch[1];
|
||||
if (!host)
|
||||
host = '127.0.0.1';
|
||||
|
||||
var displayNum = displayMatch[2];
|
||||
if (!displayNum)
|
||||
|
|
@ -572,6 +626,8 @@ module.exports.createClient = function(options, initCb)
|
|||
|
||||
// open stream
|
||||
var stream;
|
||||
var connected = false;
|
||||
var cbCalled = false;
|
||||
var socketPath;
|
||||
|
||||
// try local socket on non-windows platforms
|
||||
|
|
@ -584,22 +640,38 @@ module.exports.createClient = function(options, initCb)
|
|||
{
|
||||
socketPath = display;
|
||||
}
|
||||
} else if(host == '127.0.0.1') //TODO check if it's consistent with xlib (DISPLAY=127.0.0.1:0 -> local unix socket or port 6000?)
|
||||
} else if(!host)
|
||||
socketPath = '/tmp/.X11-unix/X' + displayNum;
|
||||
}
|
||||
//socketPath = '/tmp/.X11-unix/X' + displayNum;
|
||||
if(socketPath)
|
||||
{
|
||||
var client = new XClient(displayNum, screenNum, options);
|
||||
|
||||
var connectStream = function() {
|
||||
if (socketPath) {
|
||||
stream = net.createConnection(socketPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
stream = net.createConnection(6000 + parseInt(displayNum), host);
|
||||
}
|
||||
var client = new XClient(stream, displayNum, screenNum, options);
|
||||
stream.on('connect', function() {
|
||||
connected = true;
|
||||
client.init(stream);
|
||||
});
|
||||
stream.on('error', function(err) {
|
||||
if (!connected && socketPath && err.code === 'ENOENT') {
|
||||
// Retry connection with TCP on localhost
|
||||
socketPath = null;
|
||||
host = 'localhost';
|
||||
connectStream();
|
||||
} else if (initCb && !cbCalled) {
|
||||
cbCalled = true;
|
||||
initCb(err);
|
||||
} else {
|
||||
client.emit('error', err);
|
||||
}
|
||||
});
|
||||
};
|
||||
connectStream();
|
||||
if (initCb)
|
||||
{
|
||||
var cbCalled = false;
|
||||
client.on('connect', function(display) {
|
||||
// opt-in BigReq
|
||||
if (!options.disableBigRequests) {
|
||||
|
|
@ -617,14 +689,6 @@ module.exports.createClient = function(options, initCb)
|
|||
initCb(undefined, display);
|
||||
}
|
||||
});
|
||||
stream.on('error', function(err) {
|
||||
if (cbCalled)
|
||||
client.emit('error', err);
|
||||
else {
|
||||
cbCalled = true;
|
||||
initCb(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
|
|
|||
15
package.json
15
package.json
|
|
@ -12,7 +12,7 @@
|
|||
"X"
|
||||
],
|
||||
"homepage": "https://github.com/sidorares/node-x11",
|
||||
"version": "1.0.2",
|
||||
"version": "2.3.0",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Andrey Sidorov",
|
||||
|
|
@ -40,14 +40,15 @@
|
|||
"node": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "*",
|
||||
"should": "*",
|
||||
"sax": "*",
|
||||
"async": "*",
|
||||
"sinon": "*"
|
||||
"async": "^3.0.1",
|
||||
"mocha": "^7.1.2",
|
||||
"sax": "^1.2.4",
|
||||
"should": "^13.2.1",
|
||||
"sinon": "^7.2.5"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test-runner.js",
|
||||
"prepublish": "npm prune"
|
||||
}
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
|
|
|||
103
test/allow-events.js
Normal file
103
test/allow-events.js
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
var x11 = require('../lib');
|
||||
var should = require('should');
|
||||
var assert = require('assert');
|
||||
|
||||
// This test was ported from X Test Suite @ http://cgit.freedesktop.org/xorg/test/xts/
|
||||
|
||||
function warp_pointer(wid, x, y, cb) {
|
||||
var self = this;
|
||||
this.X.QueryPointer(wid, function(err, old_pointer) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
self.X.WarpPointer(0,
|
||||
wid,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
x,
|
||||
y);
|
||||
|
||||
self.X.QueryPointer(wid, function(err, new_pointer) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
cb(undefined, {
|
||||
old_x : old_pointer.childX,
|
||||
old_y : old_pointer.childY,
|
||||
new_x : new_pointer.childX,
|
||||
new_y : new_pointer.childY
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function is_pointer_frozen(cb) {
|
||||
var self = this;
|
||||
warp_pointer.call(this, this.wid, 0, 0, function(err) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
warp_pointer.call(self, self.wid, 1, 1, function(err, data) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
cb(undefined, data.old_x === data.new_x);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe('AllowEvents', function() {
|
||||
before(function(done) {
|
||||
var self = this;
|
||||
var client = x11.createClient(function(err, dpy) {
|
||||
should.not.exist(err);
|
||||
self.X = dpy.client;
|
||||
self.screen = dpy.screen[0];
|
||||
self.root = self.screen.root;
|
||||
self.wid = self.X.AllocID();
|
||||
self.X.CreateWindow(self.wid,
|
||||
self.root,
|
||||
0,
|
||||
0,
|
||||
self.screen.pixel_width,
|
||||
self.screen.pixel_height);
|
||||
self.X.MapWindow(self.wid);
|
||||
done();
|
||||
});
|
||||
|
||||
client.on('error', function (err) {
|
||||
console.error('Error : ', err);
|
||||
});
|
||||
});
|
||||
|
||||
it('if pointer is frozen by the client calling AllowEvents with AsyncPointer should resume the processing', function(done) {
|
||||
var self = this;
|
||||
this.X.GrabPointer(
|
||||
this.wid,
|
||||
false,
|
||||
x11.eventMask.PointerMotion,
|
||||
0, // sync
|
||||
1, // async
|
||||
0, // None
|
||||
0, // None
|
||||
0
|
||||
);
|
||||
|
||||
is_pointer_frozen.call(this, function(err, frozen) {
|
||||
should.not.exist(err);
|
||||
frozen.should.equal(true);
|
||||
self.X.AllowEvents(0, 0);
|
||||
is_pointer_frozen.call(self, function(err, frozen) {
|
||||
should.not.exist(err);
|
||||
frozen.should.equal(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -63,7 +63,7 @@ describe('Atoms and atom names cache', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should be used after the first request for non-std atom_names', function(done) {
|
||||
xit('should be used after the first request for non-std atom_names', function(done) {
|
||||
var self = this;
|
||||
var my_name;
|
||||
/*
|
||||
|
|
@ -94,7 +94,7 @@ describe('Atoms and atom names cache', function() {
|
|||
function(err) {
|
||||
should.not.exist(err);
|
||||
should.exist(my_name);
|
||||
self.spy.reset();
|
||||
self.spy.resetHistory();
|
||||
self.X.InternAtom(true, my_name, function(err, atom) {
|
||||
should.not.exist(err);
|
||||
my_atom.should.equal(atom);
|
||||
|
|
|
|||
34
test/cache-extensions.js
Normal file
34
test/cache-extensions.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
var x11 = require('../lib');
|
||||
var should = require('should');
|
||||
|
||||
describe('requiring an X11 extension on same connection', function() {
|
||||
before(function(done) {
|
||||
var self = this;
|
||||
var client = x11.createClient(function(err, dpy) {
|
||||
should.not.exist(err);
|
||||
self.X = dpy.client;
|
||||
done();
|
||||
});
|
||||
|
||||
client.on('error', function (err) {
|
||||
console.error('Error : ', err);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be cached', function(done) {
|
||||
var self = this;
|
||||
this.X.require('xtest', function(err, randr) {
|
||||
should.not.exist(err);
|
||||
self.X.require('xtest', function(err, randr1) {
|
||||
should.not.exist(err);
|
||||
randr.should.equal(randr1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
this.X.terminate();
|
||||
this.X.on('end', done);
|
||||
});
|
||||
});
|
||||
|
|
@ -27,7 +27,7 @@ describe('ChangeProperty', function() {
|
|||
var self = this;
|
||||
this.X.InternAtom(false, TEST_PROPERTY, function(err, atom) {
|
||||
should.not.exist(err);
|
||||
var raw = new Buffer(4);
|
||||
var raw = Buffer.alloc(4);
|
||||
raw.writeUInt32LE(self.wid, 0);
|
||||
self.X.ChangeProperty(0, self.wid, atom, self.X.atoms.WINDOW, 32, raw);
|
||||
self.X.once('event', function(ev) {
|
||||
|
|
@ -47,7 +47,7 @@ describe('ChangeProperty', function() {
|
|||
var self = this;
|
||||
this.X.InternAtom(false, TEST_PROPERTY, function(err, atom) {
|
||||
should.not.exist(err);
|
||||
var raw = new Buffer(new Array(8));
|
||||
var raw = Buffer.from(new Array(8));
|
||||
raw.writeUInt32LE(self.wid, 0);
|
||||
raw.writeUInt32LE(self.wid_helper, 4);
|
||||
self.X.ChangeProperty(0, self.wid, atom, self.X.atoms.ATOM, 32, raw);
|
||||
|
|
@ -69,7 +69,7 @@ describe('ChangeProperty', function() {
|
|||
var self = this;
|
||||
this.X.InternAtom(false, TEST_PROPERTY, function(err, atom) {
|
||||
should.not.exist(err);
|
||||
var raw = new Buffer(0);
|
||||
var raw = Buffer.alloc(0);
|
||||
self.X.ChangeProperty(0, self.wid, atom, self.X.atoms.WINDOW, 32, raw);
|
||||
self.X.once('event', function(ev) {
|
||||
ev.type.should.equal(28);
|
||||
|
|
|
|||
54
test/changeGC.js
Normal file
54
test/changeGC.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
var x11 = require('../lib');
|
||||
var should = require('should');
|
||||
|
||||
describe('CreateGC', function() {
|
||||
before(function(done) {
|
||||
var self = this;
|
||||
this.client = x11.createClient(function(err, dpy) {
|
||||
should.not.exist(err);
|
||||
self.X = dpy.client;
|
||||
self.root = dpy.screen[0].root;
|
||||
self.white = dpy.screen[0].white_pixel;
|
||||
self.black = dpy.screen[0].black_pixel;
|
||||
self.wid = self.X.AllocID();
|
||||
self.X.CreateWindow(self.wid, self.root, 0, 0, 1, 1); // 1x1 pixel window
|
||||
self.X.MapWindow(self.wid);
|
||||
self.X.QueryTree(self.root, function(err, list) {
|
||||
should.not.exist(err);
|
||||
list.children.indexOf(self.wid).should.not.equal(-1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a Graphic Context correctly', function() {
|
||||
var self = this;
|
||||
this.client.on('error', function(err) {
|
||||
should.not.exist(err);
|
||||
});
|
||||
|
||||
this.gc = this.X.AllocID();
|
||||
this.X.CreateGC(this.gc,
|
||||
this.wid,
|
||||
{
|
||||
foreground: this.black,
|
||||
background: this.white,
|
||||
lineStyle : 0
|
||||
}
|
||||
);
|
||||
|
||||
this.X.ChangeGC(this.gc,
|
||||
{
|
||||
foreground: 0xffff00,
|
||||
background: 0x0000ff,
|
||||
lineStyle : 2
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
this.X.DestroyWindow(this.wid);
|
||||
this.X.on('end', done);
|
||||
this.X.terminate();
|
||||
});
|
||||
});
|
||||
114
test/client-message.js
Normal file
114
test/client-message.js
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
var x11 = require('../lib');
|
||||
var UnpackStream = require('../lib/unpackstream.js');
|
||||
var should = require('should');
|
||||
|
||||
//Used Atoms
|
||||
var ATOM = {};
|
||||
|
||||
describe('ClientMessage', function() {
|
||||
before(function(done) {
|
||||
var self = this;
|
||||
var client = x11.createClient(function(err, dpy) {
|
||||
should.not.exist(err);
|
||||
self.X = dpy.client;
|
||||
self.wid = self.X.AllocID();
|
||||
self.X.CreateWindow(self.wid, dpy.screen[0].root, 0, 0, 1, 1); // 1x1 pixel window
|
||||
|
||||
self.X.InternAtom(false, 'TEST_ATOM_1', function(err, atom) {
|
||||
should.not.exist(err);
|
||||
ATOM['TEST_ATOM_1'] = atom;
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
client.on('error', done);
|
||||
});
|
||||
|
||||
it('should receive client message with format=8', function(done) {
|
||||
var self = this;
|
||||
|
||||
var client = x11.createClient(function(err, dpy) {
|
||||
should.not.exist(err);
|
||||
self.X.once('event', function(ev) {
|
||||
ev.name.should.equal('ClientMessage');
|
||||
ev.wid.should.equal(self.wid);
|
||||
ev.message_type.should.equal(ATOM.TEST_ATOM_1);
|
||||
ev.data.should.be.an.Array();
|
||||
ev.data.length.should.equal(20);
|
||||
done();
|
||||
});
|
||||
|
||||
var X = dpy.client;
|
||||
var eventData = Buffer.alloc(32);
|
||||
eventData.writeInt8(33, 0); //Event Type 33 = ClientMessage
|
||||
eventData.writeInt8(8, 1); //Format
|
||||
eventData.writeInt32LE(self.wid, 4); //Window ID
|
||||
eventData.writeInt32LE(ATOM.TEST_ATOM_1, 8); //Message Type
|
||||
|
||||
X.SendEvent(self.wid, false, 0, eventData);
|
||||
});
|
||||
|
||||
client.on('error', done);
|
||||
});
|
||||
|
||||
it('should receive client message with format=16', function(done) {
|
||||
var self = this;
|
||||
|
||||
var client = x11.createClient(function(err, dpy) {
|
||||
should.not.exist(err);
|
||||
self.X.once('event', function(ev) {
|
||||
ev.name.should.equal('ClientMessage');
|
||||
ev.wid.should.equal(self.wid);
|
||||
ev.message_type.should.equal(ATOM.TEST_ATOM_1);
|
||||
ev.data.should.be.an.Array();
|
||||
ev.data.length.should.equal(10);
|
||||
done();
|
||||
});
|
||||
|
||||
var X = dpy.client;
|
||||
var eventData = Buffer.alloc(32);
|
||||
eventData.writeInt8(33, 0); //Event Type 33 = ClientMessage
|
||||
eventData.writeInt8(16, 1); //Format
|
||||
eventData.writeInt32LE(self.wid, 4); //Window ID
|
||||
eventData.writeInt32LE(ATOM.TEST_ATOM_1, 8); //Message Type
|
||||
|
||||
X.SendEvent(self.wid, false, 0, eventData);
|
||||
});
|
||||
|
||||
client.on('error', done);
|
||||
});
|
||||
|
||||
it('should receive client message with format=32', function(done) {
|
||||
var self = this;
|
||||
|
||||
var client = x11.createClient(function(err, dpy) {
|
||||
should.not.exist(err);
|
||||
self.X.once('event', function(ev) {
|
||||
ev.name.should.equal('ClientMessage');
|
||||
ev.wid.should.equal(self.wid);
|
||||
ev.message_type.should.equal(ATOM.TEST_ATOM_1);
|
||||
ev.data.should.be.an.Array();
|
||||
ev.data.length.should.equal(5);
|
||||
done();
|
||||
});
|
||||
|
||||
var X = dpy.client;
|
||||
var eventData = Buffer.alloc(32);
|
||||
eventData.writeInt8(33, 0); //Event Type 33 = ClientMessage
|
||||
eventData.writeInt8(32, 1); //Format
|
||||
eventData.writeInt32LE(self.wid, 4); //Window ID
|
||||
eventData.writeInt32LE(ATOM.TEST_ATOM_1, 8); //Message Type
|
||||
|
||||
X.SendEvent(self.wid, false, 0, eventData);
|
||||
});
|
||||
|
||||
client.on('error', done);
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
this.X.DestroyWindow(this.wid);
|
||||
this.X.on('end', done);
|
||||
this.X.terminate();
|
||||
});
|
||||
});
|
||||
|
|
@ -72,7 +72,29 @@ describe('ConfigureWindow', function() {
|
|||
this.X.RaiseWindow(this.wid);
|
||||
});
|
||||
|
||||
it('should LowerWindow correctly', function(done) {
|
||||
var self = this;
|
||||
this.X.once('event', function(ev) {
|
||||
ev.type.should.equal(22); /* ConfigureNotify */
|
||||
ev.aboveSibling.should.equal(0); /* 0 -> no window below this */
|
||||
done();
|
||||
});
|
||||
this.X.LowerWindow(this.wid);
|
||||
});
|
||||
|
||||
it('should ignore invalid mask values', function(done) {
|
||||
this.X.once('event', function(ev) {
|
||||
ev.x.should.equal(0);
|
||||
done();
|
||||
});
|
||||
|
||||
this.X.ConfigureWindow(this.wid, { foo : 3, x : 0 }, function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
this.X.removeAllListeners('event');
|
||||
this.X.DestroyWindow(this.wid);
|
||||
this.X.DestroyWindow(this.wid_helper);
|
||||
this.X.on('end', done);
|
||||
|
|
|
|||
|
|
@ -57,4 +57,47 @@ describe('CreateWindow request', function() {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit CreateNotify event when', function(done) {
|
||||
var wid = X.AllocID();
|
||||
var root = display.screen[0].root;
|
||||
X.ChangeWindowAttributes(root, { eventMask: x11.eventMask.SubstructureNotify });
|
||||
X.on('event', function(ev) {
|
||||
switch (ev.name) {
|
||||
case 'CreateNotify':
|
||||
ev.parent.should.equal(root);
|
||||
ev.wid.should.equal(wid);
|
||||
ev.x.should.equal(0);
|
||||
ev.y.should.equal(0);
|
||||
ev.width.should.equal(1);
|
||||
ev.height.should.equal(1);
|
||||
ev.borderWidth.should.equal(0);
|
||||
ev.overrideRedirect.should.equal(false);
|
||||
break;
|
||||
|
||||
case 'MapNotify':
|
||||
ev.event.should.equal(root);
|
||||
ev.wid.should.equal(wid);
|
||||
ev.overrideRedirect.should.equal(false);
|
||||
X.UnmapWindow(wid);
|
||||
break;
|
||||
|
||||
case 'UnmapNotify':
|
||||
ev.event.should.equal(root);
|
||||
ev.wid.should.equal(wid);
|
||||
ev.fromConfigure.should.equal(false);
|
||||
X.DestroyWindow(wid);
|
||||
break;
|
||||
|
||||
case 'DestroyNotify':
|
||||
ev.event.should.equal(root);
|
||||
ev.wid.should.equal(wid);
|
||||
done();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
X.CreateWindow(wid, root, 0, 0, 1, 1); // 1x1 pixel window
|
||||
X.MapWindow(wid);
|
||||
})
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,43 +8,41 @@ describe('KillKlient request', function() {
|
|||
var X;
|
||||
beforeEach(function(done) {
|
||||
var client = x11.createClient(function(err, dpy) {
|
||||
if (!err) {
|
||||
should.not.exist(err);
|
||||
display = dpy;
|
||||
X = display.client;
|
||||
}
|
||||
var root = display.screen[0].root;
|
||||
var eventMask = x11.eventMask.SubstructureNotify;
|
||||
X.ChangeWindowAttributes(root, { eventMask: eventMask });
|
||||
done();
|
||||
});
|
||||
|
||||
done(err);
|
||||
});
|
||||
client.on('error', function(err) {
|
||||
done(err);
|
||||
});
|
||||
client.on('error', done);
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
X.terminate();
|
||||
X.on('end', done);
|
||||
X = null;
|
||||
display = null;
|
||||
X.terminate();
|
||||
});
|
||||
|
||||
it('should exist as client member', function(done) {
|
||||
it('should exist as client member', function() {
|
||||
should.exist(X.KillKlient);
|
||||
assert.equal(typeof X.KillKlient, 'function');
|
||||
done();
|
||||
});
|
||||
|
||||
it('should terminate other client connection', function(done) {
|
||||
x11.createClient(function(err, dpy) {
|
||||
if (!err) {
|
||||
should.not.exist(err);
|
||||
var otherclient = dpy.client;
|
||||
var wnd = otherclient.AllocID();
|
||||
otherclient.CreateWindow(wnd, dpy.screen[0].root, 0, 0, 1, 1);
|
||||
otherclient.on('end', done);
|
||||
X.once('event', function(ev) {
|
||||
ev.name.should.equal('CreateNotify');
|
||||
ev.wid.should.equal(wnd);
|
||||
X.KillKlient(wnd);
|
||||
} else {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
otherclient.CreateWindow(wnd, dpy.screen[0].root, 0, 0, 1, 1);
|
||||
otherclient.on('end', done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
var x11 = require('../lib');
|
||||
var async = require('async');
|
||||
var should = require('should');
|
||||
var assert = require('assert');
|
||||
var util = require('util');
|
||||
|
|
@ -12,7 +13,7 @@ describe('RANDR extension', function() {
|
|||
self.screen = dpy.screen[0];
|
||||
self.root = self.screen.root;
|
||||
self.X.require('randr', function(err, ext) {
|
||||
err.should.equal(null);
|
||||
should.not.exist(err);
|
||||
self.randr = ext;
|
||||
/* We HAVE to QueryVersion before using it. Otherwise it does not work as expected */
|
||||
self.randr.QueryVersion(1, 2, done);
|
||||
|
|
@ -35,6 +36,26 @@ describe('RANDR extension', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('GetScreenResources && GetOutputInfo', function(done) {
|
||||
var self = this;
|
||||
this.randr.GetScreenResources(this.root, function(err, resources) {
|
||||
should.not.exist(err);
|
||||
should.exist(resources);
|
||||
async.each(
|
||||
resources.outputs,
|
||||
function(output, cb) {
|
||||
self.randr.GetOutputInfo(output, 0, function(err, info) {
|
||||
should.not.exist(err);
|
||||
should.exist(info);
|
||||
cb();
|
||||
});
|
||||
},
|
||||
done
|
||||
);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
this.X.terminate();
|
||||
this.X.on('end', done);
|
||||
|
|
|
|||
16
test/smoke-require-ext.js
Normal file
16
test/smoke-require-ext.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
var fs = require('fs');
|
||||
var assert = require('assert');
|
||||
|
||||
describe('all extension modules', function() {
|
||||
it('should not throw when require\'d', function(done) {
|
||||
var extFolder = __dirname + '/../lib/ext';
|
||||
fs.readdir(extFolder, function(err, list) {
|
||||
assert.ifError(err);
|
||||
list.forEach(function(name) {
|
||||
var m = require(extFolder + '/' + name);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
Loading…
Reference in a new issue