Last active
August 29, 2015 14:07
-
-
Save sidorares/adc2b2d94a3485cff943 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x11 = require('x11'); | |
var PNG = require('png-js'); | |
var bl = require('bl'); | |
require('child_process').exec('locate png | grep 48').stdout.pipe(bl(function(err, files) { | |
var pngNames = files.toString().split('\n'); | |
var pngIndex = 0; | |
x11.createClient(function(err, display) { | |
var X = display.client; | |
var root = display.screen[0].root; | |
var wid = X.AllocID(); | |
X.CreateWindow(wid, root, 10, 10, 300, 300); | |
X.MapWindow(wid); | |
function nextPng() { | |
pngIndex++; | |
if (pngIndex >= pngNames.length) | |
pngIndex = 0; | |
var pngData = require('fs').readFileSync(pngNames[pngIndex]); | |
var png = new PNG(pngData); | |
png.decode(function(pixels) { | |
var icon = new Buffer(pixels.length + 8); | |
icon.writeUInt32LE(png.width, 0); | |
icon.writeUInt32LE(png.height, 4); | |
for (var i = 0; i < pixels.length; i+= 4) { | |
// pixels in BGRA, icon needs to be ARGB (prefixed with 2 bytes w,h) | |
icon[i + 8] = pixels[i + 2]; | |
icon[i + 9] = pixels[i + 1]; | |
icon[i + 10] = pixels[i + 0]; | |
icon[i + 11] = pixels[i + 3]; | |
} | |
X.InternAtom(false, '_NET_WM_ICON', function(err, wmIconAtom) { | |
X.InternAtom(false, '_NET_WM_WINDOW_TYPE_NORMAL', function(err, wmTypeNormal) { | |
X.InternAtom(false, '_NET_WM_WINDOW_TYPE', function(err, wmType) { | |
X.ChangeProperty(0, wid, wmIconAtom, X.atoms.CARDINAL, 32, icon); | |
var prop = new Buffer(4); | |
prop.writeUInt32LE(wmTypeNormal, 0); | |
X.ChangeProperty(0, wid, wmType, X.atoms.ATOM, 32, prop); | |
}); | |
}); | |
}); | |
}); | |
} | |
setInterval(nextPng, 2000); | |
}); | |
})); // end of pipe(bl(function() {})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment