Question

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.

Was it helpful?

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);
    });
});

OTHER TIPS

It's possible but...

Here's what the Xlib manual says:

"Xlib implements a write-back cache for all elements of a GC that are not resource IDs to allow Xlib to implement the transparent coalescing of changes to GCs. For example, a call to XSetForeground of a GC followed by a call to XSetLineAttributes results in only a single-change GC protocol request to the server. GCs are neither expected nor encouraged to be shared between client applications, so this writeback caching should present no problems. Applications cannot share GCs without external synchronization. Therefore, sharing GCs between applications is highly discouraged."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top