Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Damage.Destroy not work? #108

Open
guodong opened this issue Oct 7, 2015 · 6 comments
Open

Damage.Destroy not work? #108

guodong opened this issue Oct 7, 2015 · 6 comments

Comments

@guodong
Copy link

guodong commented Oct 7, 2015

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?

@sidorares
Copy link
Owner

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

@sidorares
Copy link
Owner

@guodong
Copy link
Author

guodong commented Oct 7, 2015

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.

@sidorares
Copy link
Owner

can you post your code?

@guodong
Copy link
Author

guodong commented Oct 7, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants