mirror of
https://github.com/danbulant/node-x11
synced 2026-05-24 12:35:39 +00:00
pass correctly mouse button (and keyboard) code in unpackEvent
This commit is contained in:
parent
d8764635e7
commit
1cfab85500
3 changed files with 41 additions and 13 deletions
|
|
@ -156,7 +156,7 @@ XClient.prototype.AllocID = function()
|
||||||
return (this.display.rsrc_id << this.display.rsrc_shift) + this.display.resource_base;
|
return (this.display.rsrc_id << this.display.rsrc_shift) + this.display.resource_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
XClient.prototype.unpackEvent = function(type, seq, extra, raw)
|
XClient.prototype.unpackEvent = function(type, seq, extra, code, raw)
|
||||||
{
|
{
|
||||||
var event = {}; // TODO: constructor & base functions
|
var event = {}; // TODO: constructor & base functions
|
||||||
event.type = type;
|
event.type = type;
|
||||||
|
|
@ -167,6 +167,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, raw)
|
||||||
//event.raw = values;
|
//event.raw = values;
|
||||||
// TODO: use unpackTo???
|
// TODO: use unpackTo???
|
||||||
event.time = extra;
|
event.time = extra;
|
||||||
|
event.keycode = code;
|
||||||
event.root = values[0];
|
event.root = values[0];
|
||||||
event.wid = values[1];
|
event.wid = values[1];
|
||||||
event.child = values[2];
|
event.child = values[2];
|
||||||
|
|
@ -231,7 +232,8 @@ XClient.prototype.expectReplyHeader = function()
|
||||||
{
|
{
|
||||||
client.pack_stream.get(24, function(buf) {
|
client.pack_stream.get(24, function(buf) {
|
||||||
var extra = res[3];
|
var extra = res[3];
|
||||||
var ev = client.unpackEvent(type, seq_num, extra, buf);
|
var code = res[1];
|
||||||
|
var ev = client.unpackEvent(type, seq_num, extra, code, buf);
|
||||||
client.emit('event', ev);
|
client.emit('event', ev);
|
||||||
var ee = client.event_consumers[ev.wid];
|
var ee = client.event_consumers[ev.wid];
|
||||||
if (ee) {
|
if (ee) {
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,42 @@
|
||||||
var x11 = require('../lib/x11');
|
var x11 = require('../lib/x11');
|
||||||
var Window = require('./wndwrap');
|
var Window = require('./wndwrap');
|
||||||
|
|
||||||
var width = 700;
|
x11.createClient(function(display) {
|
||||||
var height = 500;
|
|
||||||
|
|
||||||
var xclient = x11.createClient(function(display) {
|
var pts = [];
|
||||||
|
new Window(display.client, 0, 0, 700, 500)
|
||||||
new Window(xclient, 0, 0, width, height)
|
|
||||||
.handle({
|
.handle({
|
||||||
|
|
||||||
mousemove: function(ev) {
|
mousemove: function(ev) {
|
||||||
pts.push(ev.x);
|
if (this.pressed)
|
||||||
pts.push(ev.y);
|
{
|
||||||
|
var lastpoly = pts[pts.length - 1];
|
||||||
|
lastpoly.push(ev.x);
|
||||||
|
lastpoly.push(ev.y);
|
||||||
|
if (lastpoly.length > 3)
|
||||||
|
this.gc.polyLine(lastpoly.slice(-4));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mousedown: function(ev) {
|
||||||
|
if (ev.keycode == 1) // left button
|
||||||
|
{
|
||||||
|
this.pressed = true;
|
||||||
|
pts.push([]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
mouseup: function(ev) {
|
||||||
|
if (ev.keycode == 1) // left button
|
||||||
|
this.pressed = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
expose: function(ev) {
|
expose: function(ev) {
|
||||||
for (var i=0; i < pts.length/2 ; ++i)
|
for (var i=0; i < pts.length ; ++i) {
|
||||||
ev.gc.drawText(pts[i], pts[i+1], 'Hello, NodeJS!');
|
this.gc.polyLine(pts[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.map()
|
.map()
|
||||||
.title = 'Hello, world!';
|
.title = 'Hello, world!';
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
var x11 = require('../lib/x11');
|
var x11 = require('../lib/x11');
|
||||||
var Exposure = x11.eventMask.Exposure;
|
var Exposure = x11.eventMask.Exposure;
|
||||||
var PointerMotion = x11.eventMask.PointerMotion;
|
var PointerMotion = x11.eventMask.PointerMotion;
|
||||||
|
var ButtonPress = x11.eventMask.ButtonPress;
|
||||||
|
var ButtonRelease = x11.eventMask.ButtonRelease;
|
||||||
|
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var util = require('util'); // util.inherits
|
var util = require('util'); // util.inherits
|
||||||
|
|
@ -87,13 +89,15 @@ function Window(parent, x, y, w, h)
|
||||||
borderWidth, _class, visual,
|
borderWidth, _class, visual,
|
||||||
{
|
{
|
||||||
backgroundPixel: this.white,
|
backgroundPixel: this.white,
|
||||||
eventMask: Exposure|PointerMotion
|
eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
//this.map();
|
//this.map();
|
||||||
var wnd = this;
|
var wnd = this;
|
||||||
eventType2eventName = {
|
eventType2eventName = {
|
||||||
|
4: 'mousedown',
|
||||||
|
5: 'mouseup',
|
||||||
6: 'mousemove',
|
6: 'mousemove',
|
||||||
12: 'expose'
|
12: 'expose'
|
||||||
};
|
};
|
||||||
|
|
@ -105,7 +109,6 @@ function Window(parent, x, y, w, h)
|
||||||
{
|
{
|
||||||
if (ev.type == 12) //Expose
|
if (ev.type == 12) //Expose
|
||||||
ev.gc = wnd.gc;
|
ev.gc = wnd.gc;
|
||||||
|
|
||||||
wnd.emit(eventType2eventName[ev.type], ev); // convert to mousemove? (ev is already event-spacific)
|
wnd.emit(eventType2eventName[ev.type], ev); // convert to mousemove? (ev is already event-spacific)
|
||||||
});
|
});
|
||||||
// TODO: track delete events and remove wmd from consumers list
|
// TODO: track delete events and remove wmd from consumers list
|
||||||
|
|
@ -142,9 +145,12 @@ Window.prototype.unmap = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Window.prototype.handle = function(handlers) {
|
Window.prototype.handle = function(handlers) {
|
||||||
|
// TODO: compare event mask with events names and issue
|
||||||
|
// one ChangeWindowAttributes request adding missing events
|
||||||
for (var eventName in handlers) {
|
for (var eventName in handlers) {
|
||||||
this.on(eventName, handlers[eventName]);
|
this.on(eventName, handlers[eventName]);
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window.prototype.getProperty = function(name, cb) {
|
Window.prototype.getProperty = function(name, cb) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue