From 6fc8d0137408ea20df90ba37b5582caf48cbf0c3 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 21 Jul 2025 23:02:37 +0200 Subject: [PATCH] Mon 21 Jul 22:43:21 CEST 2025 --- js/x11/core/examples/simple/alloccolor.js | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 js/x11/core/examples/simple/alloccolor.js diff --git a/js/x11/core/examples/simple/alloccolor.js b/js/x11/core/examples/simple/alloccolor.js new file mode 100644 index 0000000..13ba2fb --- /dev/null +++ b/js/x11/core/examples/simple/alloccolor.js @@ -0,0 +1,34 @@ +var x11 = require('../../lib'); + +var Exposure = x11.eventMask.Exposure; + +x11.createClient(function(err, display) { + var repaint; + 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, + 10, 10, 400, 300 + ); + X.MapWindow(wid); + + // parameters: colormap, red, green, blue + X.AllocColor(display.screen[0].default_colormap, 0xffff, 0xffff, 0, function(err, color) { + var gc = X.AllocID(); + X.CreateGC(gc, wid, { foreground: color.pixel, background: black } ); + repaint = setInterval(function() { + X.PolyFillRectangle(wid, gc, [100, 100, 200, 100]); + }, 1000); + }); + X.on('error', function(e) { + console.log(e); + }); + X.on('end', function() { + console.log('client destroyed'); + clearInterval(repaint); + }); +});