mirror of
https://github.com/danbulant/node-x11
synced 2026-07-04 18:50:36 +00:00
some gradients + adopt to new CreateWindow parameter
This commit is contained in:
parent
3298795a7b
commit
fd81862722
1 changed files with 57 additions and 10 deletions
|
|
@ -1,17 +1,20 @@
|
||||||
var x11 = require('../../lib/x11');
|
var x11 = require('../../lib/x11');
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
var X, root;
|
var X, root, white;
|
||||||
var events = x11.eventMask.Button1Motion|x11.eventMask.ButtonPress|x11.eventMask.ButtonRelease|x11.eventMask.SubstructureNotify|x11.eventMask.SubstructureRedirect
|
var events = x11.eventMask.Button1Motion|x11.eventMask.ButtonPress|x11.eventMask.ButtonRelease|x11.eventMask.SubstructureNotify|x11.eventMask.SubstructureRedirect|x11.eventMask.Exposure;
|
||||||
var frames = {};
|
var frames = {};
|
||||||
var dragStart = null;
|
var dragStart = null;
|
||||||
|
|
||||||
function ManageWindow(wid)
|
function ManageWindow(wid)
|
||||||
{
|
{
|
||||||
X.GetWindowAttributes(wid, function(attrs) {
|
console.log("MANAGE WINDOW: " + wid);
|
||||||
|
X.GetWindowAttributes(wid, function(err, attrs) {
|
||||||
|
|
||||||
if (attrs[8])
|
if (attrs[8]) // override-redirect flag
|
||||||
{
|
{
|
||||||
|
// don't manage
|
||||||
|
console.log("don't manage");
|
||||||
X.MapWindow(wid);
|
X.MapWindow(wid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -22,18 +25,34 @@ function ManageWindow(wid)
|
||||||
winX = parseInt(Math.random()*300);
|
winX = parseInt(Math.random()*300);
|
||||||
winY = parseInt(Math.random()*300);
|
winY = parseInt(Math.random()*300);
|
||||||
|
|
||||||
X.GetGeometry(wid, function(clientGeom) {
|
X.GetGeometry(wid, function(err, clientGeom) {
|
||||||
|
|
||||||
|
console.log("window geometry: ", clientGeom);
|
||||||
var width = clientGeom.width + 4;
|
var width = clientGeom.width + 4;
|
||||||
var height = clientGeom.height + 24;
|
var height = clientGeom.height + 24;
|
||||||
X.CreateWindow(fid, root, winX, winY, width, height, 1, 1, 0,
|
console.log("CreateWindow", fid, root, winX, winY, width, height);
|
||||||
|
X.CreateWindow(fid, root, winX, winY, width, height, 0, 0, 0, 0,
|
||||||
{
|
{
|
||||||
backgroundPixel: 0xffffe0,
|
backgroundPixel: white,
|
||||||
eventMask: events
|
eventMask: events
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var bggrad = X.AllocID();
|
||||||
|
X.Render.LinearGradient(bggrad, [0,0], [0,24],
|
||||||
|
[
|
||||||
|
[0, [0,0,0xffff,0xffffff ] ],
|
||||||
|
[1, [0x00ff, 0xff00, 0, 0xffffff] ]
|
||||||
|
]);
|
||||||
|
|
||||||
|
var framepic = X.AllocID();
|
||||||
|
X.Render.CreatePicture(framepic, fid, X.Render.rgb24);
|
||||||
|
|
||||||
|
|
||||||
var ee = new EventEmitter();
|
var ee = new EventEmitter();
|
||||||
X.event_consumers[fid] = ee;
|
X.event_consumers[fid] = ee;
|
||||||
ee.on('event', function(ev)
|
ee.on('event', function(ev)
|
||||||
{
|
{
|
||||||
|
console.log(['event', ev]);
|
||||||
if (ev.type === 17) // DestroyNotify
|
if (ev.type === 17) // DestroyNotify
|
||||||
{
|
{
|
||||||
X.DestroyWindow(fid);
|
X.DestroyWindow(fid);
|
||||||
|
|
@ -45,10 +64,13 @@ function ManageWindow(wid)
|
||||||
winX = dragStart.winX + ev.rootx - dragStart.rootx;
|
winX = dragStart.winX + ev.rootx - dragStart.rootx;
|
||||||
winY = dragStart.winY + ev.rooty - dragStart.rooty;
|
winY = dragStart.winY + ev.rooty - dragStart.rooty;
|
||||||
X.MoveWindow(fid, winX, winY);
|
X.MoveWindow(fid, winX, winY);
|
||||||
|
} else if (ev.type == 12) {
|
||||||
|
X.Render.Composite(3, bggrad, 0, framepic, 0, 0, 0, 0, 0, 0, width, height);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
X.ChangeSaveSet(1, wid);
|
X.ChangeSaveSet(1, wid);
|
||||||
X.ReparentWindow(wid, fid, 1, 21);
|
X.ReparentWindow(wid, fid, 1, 21);
|
||||||
|
console.log("MapWindow", fid);
|
||||||
X.MapWindow(fid);
|
X.MapWindow(fid);
|
||||||
X.MapWindow(wid);
|
X.MapWindow(wid);
|
||||||
});
|
});
|
||||||
|
|
@ -58,18 +80,39 @@ function ManageWindow(wid)
|
||||||
|
|
||||||
x11.createClient(function(display) {
|
x11.createClient(function(display) {
|
||||||
X = display.client;
|
X = display.client;
|
||||||
|
X.require('render', function(Render) {
|
||||||
|
X.Render = Render;
|
||||||
|
|
||||||
root = display.screen[0].root;
|
root = display.screen[0].root;
|
||||||
|
white = display.screen[0].white_pixel;
|
||||||
console.log('root = ' + root);
|
console.log('root = ' + root);
|
||||||
X.ChangeWindowAttributes(root, { eventMask: x11.eventMask.SubstructureRedirect }, function(err) {
|
X.ChangeWindowAttributes(root, { eventMask: x11.eventMask.Exposure|x11.eventMask.SubstructureRedirect }, function(err) {
|
||||||
if (err.error == 10)
|
if (err.error == 10)
|
||||||
{
|
{
|
||||||
console.error('Error: another window manager already running.');
|
console.error('Error: another window manager already running.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
X.QueryTree(root, function(tree) {
|
X.QueryTree(root, function(err, tree) {
|
||||||
tree.children.forEach(ManageWindow);
|
tree.children.forEach(ManageWindow);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
X.bggrad = X.AllocID();
|
||||||
|
Render.LinearGradient(X.bggrad, [-10,0], [0,1000],
|
||||||
|
//RenderRadialGradient(pic_grad, [0,0], [1000,100], 10, 1000,
|
||||||
|
//RenderConicalGradient(pic_grad, [250,250], 360,
|
||||||
|
[
|
||||||
|
[0, [0,0,0,0xffffff ] ],
|
||||||
|
//[0.1, [0xfff, 0, 0xffff, 0x1000] ] ,
|
||||||
|
//[0.25, [0xffff, 0, 0xfff, 0x3000] ] ,
|
||||||
|
//[0.5, [0xffff, 0, 0xffff, 0x4000] ] ,
|
||||||
|
[1, [0xffff, 0xffff, 0, 0xffffff] ]
|
||||||
|
]);
|
||||||
|
|
||||||
|
X.rootpic = X.AllocID();
|
||||||
|
Render.CreatePicture(X.rootpic, root, Render.rgb24);
|
||||||
|
})
|
||||||
|
|
||||||
}).on('error', function(err) {
|
}).on('error', function(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}).on('event', function(ev) {
|
}).on('event', function(ev) {
|
||||||
|
|
@ -82,6 +125,10 @@ x11.createClient(function(display) {
|
||||||
} else if (ev.type === 23) // ConfigureRequest
|
} else if (ev.type === 23) // ConfigureRequest
|
||||||
{
|
{
|
||||||
X.ResizeWindow(ev.wid, ev.width, ev.height);
|
X.ResizeWindow(ev.wid, ev.width, ev.height);
|
||||||
|
} else if (ev.type === 12) {
|
||||||
|
console.log('EXPOSE', ev);
|
||||||
|
X.Render.Composite(3, X.bggrad, 0, X.rootpic, 0, 0, 0, 0, 0, 0, 1000, 1000);
|
||||||
}
|
}
|
||||||
console.log(ev);
|
console.log(ev);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue