node-x11 icon indicating copy to clipboard operation
node-x11 copied to clipboard

Damage.Destroy not work?

Open guodong opened this issue 9 years ago • 6 comments

I use Damage.Create when receiving mapnotify, and use Damage.Destroy(damageId) later, but after that, I can still receive DamageNotify on that damage, or I shoud use other ways to destroy a damage? And, I found that if I restart program, the damage seems not exists. So, how to destroy a damage in program to prevent receive DamageNotify?

guodong avatar Oct 07 '15 01:10 guodong

I think you need to DamageSubtract your region to stop updates but not 100% sure

sidorares avatar Oct 07 '15 01:10 sidorares

https://github.com/sidorares/node-x11/blob/master/examples/smoketest/damagetest.js#L12

sidorares avatar Oct 07 '15 01:10 sidorares

http://www.x.org/releases/X11R7.7/doc/damageproto/damageproto.txt

sidorares avatar Oct 07 '15 01:10 sidorares

en, I have already add substract on event callback. I see the Destroys damage has no detail about it in protocol, and I don't understand why damages all removed when I restart my program.

guodong avatar Oct 07 '15 01:10 guodong

can you post your code?

sidorares avatar Oct 07 '15 01:10 sidorares

the main process is get window info when start it, just like a window manager. bellow is used to recover windows state when start, remove damage created previously and attach new damage to window(uses old damage not work, just like I said damages not work when reconnect to it, so I must recreate damages):

function recover(cwconn){
    var X = cwconn.display.client;
    X.require('damage', function(err, Damage){
        for(var i in cwconn.damages){
            console.log('deleting damages');
            Damage.Destroy(cwconn.damages[i]);
        }
        cwconn.damages = [];
        X.QueryTree(cwconn.display.screen[0].root, function(err, tree) {
            tree.children.forEach(function(subwin) {
                var damage = X.AllocID();
                Damage.Create(damage, subwin, Damage.ReportLevel.DeltaRectangles);
                cwconn.damages.push(damage);
                X.GetGeometry(subwin, function(err, geom) {
                    ...
                });
            });
        });
    });
}

bellow is event handle:

X.require('composite', function(err, Composite){
            Composite.RedirectSubwindows(root, Composite.Redirect.Automatic);
            X.require('damage', function(err, Damage){
                var windows = cwconn.windows;
                X.on('event', function(ev){
                    console.log(ev);
                    if(ev.type == 19){ // MapNotify
                        var damage = X.AllocID();
                        Damage.Create(damage, ev.wid, Damage.ReportLevel.DeltaRectangles);
                        cwconn.damages.push(damage);

                    }
                    if(ev.name == 'DamageNotify'){

                        Damage.Subtract(ev.damage, 0, 0);
                    }
                   ....other events
                });

                // after init event listeners, recover rendered windows, and register damage
                recover(cwconn);
            })
        })
    }).on('error', function(err) {
        //console.log(err);
    });

guodong avatar Oct 07 '15 01:10 guodong