mirror of
https://github.com/danbulant/node-x11
synced 2026-05-21 13:29:13 +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;
|
||||
}
|
||||
|
||||
XClient.prototype.unpackEvent = function(type, seq, extra, raw)
|
||||
XClient.prototype.unpackEvent = function(type, seq, extra, code, raw)
|
||||
{
|
||||
var event = {}; // TODO: constructor & base functions
|
||||
event.type = type;
|
||||
|
|
@ -167,6 +167,7 @@ XClient.prototype.unpackEvent = function(type, seq, extra, raw)
|
|||
//event.raw = values;
|
||||
// TODO: use unpackTo???
|
||||
event.time = extra;
|
||||
event.keycode = code;
|
||||
event.root = values[0];
|
||||
event.wid = values[1];
|
||||
event.child = values[2];
|
||||
|
|
@ -231,7 +232,8 @@ XClient.prototype.expectReplyHeader = function()
|
|||
{
|
||||
client.pack_stream.get(24, function(buf) {
|
||||
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);
|
||||
var ee = client.event_consumers[ev.wid];
|
||||
if (ee) {
|
||||
|
|
|
|||
|
|
@ -1,22 +1,42 @@
|
|||
var x11 = require('../lib/x11');
|
||||
var Window = require('./wndwrap');
|
||||
|
||||
var width = 700;
|
||||
var height = 500;
|
||||
x11.createClient(function(display) {
|
||||
|
||||
var xclient = x11.createClient(function(display) {
|
||||
|
||||
new Window(xclient, 0, 0, width, height)
|
||||
var pts = [];
|
||||
new Window(display.client, 0, 0, 700, 500)
|
||||
.handle({
|
||||
|
||||
mousemove: function(ev) {
|
||||
pts.push(ev.x);
|
||||
pts.push(ev.y);
|
||||
if (this.pressed)
|
||||
{
|
||||
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) {
|
||||
for (var i=0; i < pts.length/2 ; ++i)
|
||||
ev.gc.drawText(pts[i], pts[i+1], 'Hello, NodeJS!');
|
||||
for (var i=0; i < pts.length ; ++i) {
|
||||
this.gc.polyLine(pts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
.map()
|
||||
.title = 'Hello, world!';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
var x11 = require('../lib/x11');
|
||||
var Exposure = x11.eventMask.Exposure;
|
||||
var PointerMotion = x11.eventMask.PointerMotion;
|
||||
var ButtonPress = x11.eventMask.ButtonPress;
|
||||
var ButtonRelease = x11.eventMask.ButtonRelease;
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var util = require('util'); // util.inherits
|
||||
|
|
@ -87,13 +89,15 @@ function Window(parent, x, y, w, h)
|
|||
borderWidth, _class, visual,
|
||||
{
|
||||
backgroundPixel: this.white,
|
||||
eventMask: Exposure|PointerMotion
|
||||
eventMask: Exposure|PointerMotion|ButtonPress|ButtonRelease
|
||||
}
|
||||
);
|
||||
|
||||
//this.map();
|
||||
var wnd = this;
|
||||
eventType2eventName = {
|
||||
4: 'mousedown',
|
||||
5: 'mouseup',
|
||||
6: 'mousemove',
|
||||
12: 'expose'
|
||||
};
|
||||
|
|
@ -105,7 +109,6 @@ function Window(parent, x, y, w, h)
|
|||
{
|
||||
if (ev.type == 12) //Expose
|
||||
ev.gc = wnd.gc;
|
||||
|
||||
wnd.emit(eventType2eventName[ev.type], ev); // convert to mousemove? (ev is already event-spacific)
|
||||
});
|
||||
// TODO: track delete events and remove wmd from consumers list
|
||||
|
|
@ -142,9 +145,12 @@ Window.prototype.unmap = function() {
|
|||
}
|
||||
|
||||
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) {
|
||||
this.on(eventName, handlers[eventName]);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
Window.prototype.getProperty = function(name, cb) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue