Automatically capture a screenshot from server x if window contents change

I am looking for a way to automatically take a screenshot of my X server if a window is created or the contents of the windows have changed.

I am currently achieving this by listening to X11 events, but not all changes are reported.

+5
source share
2 answers

Take a look at XDamageNotifyEvent, XDamageQueryExtension, XDamageCreate, XDamageSubtract from the Damage extension. This extension is used to track changes to the contents of a window. http://www.freedesktop.org/wiki/Software/XDamage

, . , (Compiz, metacity ..) .

( ).

+5

, . X11 , , XDamage . , , , X11, , Havoc, :

#include <stdio.h>
#include <stdlib.h>
#include <X11/extensions/Xdamage.h>
#include <X11/Xlib.h>
#include <signal.h>

int endnow = 0;

void cleanup(int SIGNUM){
    endnow = 1;
}

int main(){
    Display *display;
    display = XOpenDisplay(":0");
    if(!display){
        perror("could not open display");
        exit(1);
    }
    Window root = DefaultRootWindow(display);        

    int damage_event, damage_error, test;

    //this line is necessary to initialize things
    test = XDamageQueryExtension(display, &damage_event, &damage_error);
    /*The "event" output is apparently the integer that appears in the
    Xevent.type field when XNextEvent returns an XDamage event */
    printf("test = %d, event = %d, error = %d\n",test,damage_event, damage_error);

    //This is the handler for the XDamage interface
    //See the XDamage documentation for more damage report levels
    // http://www.freedesktop.org/wiki/Software/XDamage
    Damage damage = XDamageCreate(display, root, XDamageReportNonEmpty);

    signal(SIGINT,cleanup);

    // XCloseDisplay(display);
    while(endnow == 0){
        XEvent event;
        XNextEvent(display,&event);
        printf("event.type = %d\n",event.type);
        //this line resets the XDamage handler
        XDamageSubtract(display,damage,None,None);
    }
    XCloseDisplay(display);
    printf("done\n");
    exit(0);
}

, , :0, , , . , ssh .

+2

All Articles