linuxx11graphicscontext

Use GC (X11 graphics context) in another process


Is it possible to pass GC from process1 to process2 and use it there (I need to update clipping region)?

I've tried to pass GC via window property. But I've got SEGFAULT on XSetRegion call on that GC.


Solution

  • yes, it is possible. Here is example (sorry, in JavaScript, using node-x11) where you can create gc in one process and pass it as a command line parameter to another process. All changes to gc (foreground color in this example) are visible in another process. Note that GC is destroyed on server when first process exits and you'll see 'Bad GContext' error in second process if you try to continue using it.

    var x11 = require('x11');
    
    var gc;
    x11.createClient(function(display) {
        var X = display.client;
        var root = display.screen[0].root;
    
        var wid = X.AllocID();
        X.CreateWindow(wid, root, 0, 0, 400, 300);
    
        var _gc = parseInt(process.argv[2]);
        if (_gc != 0)
           gc = _gc;
        else {
           gc = X.AllocID();
           X.CreateGC(gc, root);
           console.log('GC created: ' + gc);
           setInterval(function() {
               X.ChangeGC(gc, { foreground: parseInt(Math.random()*0xffffff) });
               console.log('gc updated!');
           }, 500);
        }
        X.MapWindow(wid);
        setInterval(function() {
           X.PolyText8(wid, gc, 50, 50, ['Hello, Node.JS!', ' Hello, world!']);
           console.log(gc);
        }, 100);
        X.on('error', function(err) {
            console.log(err);
        });
    });