Xlib lateness effect of XGetWindowProperty() - Xwindows

This is a discussion on Xlib lateness effect of XGetWindowProperty() - Xwindows ; Hello, All! I need to get a contents of the XA_PRIMARY selection. If I select something and run my silly program, it's dumping what was in the XA_PRIMARY = OK. But, if I'm selecting something other & run my program ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Xlib lateness effect of XGetWindowProperty()

  1. Xlib lateness effect of XGetWindowProperty()

    Hello, All!

    I need to get a contents of the XA_PRIMARY selection.

    If I select something and run my silly program, it's dumping what was in
    the XA_PRIMARY = OK. But, if I'm selecting something other & run
    my program again, it's dumping the previous contents of selection

    Note: I'm not using any loop with XNextEvent(). May be that is a
    problem???

    ....
    Window selown;
    int format, result;
    long len, bytes_left, dummy;
    unsigned char* data;
    ....

    selown = XGetSelectionOwner(display, XA_PRIMARY);

    if (selown != NULL) {

    XConvertSelection(display, XA_PRIMARY, XA_STRING, NULL,
    selown, CurrentTime);

    XFlush(display);

    result = XGetWindowProperty(display, selown,
    XA_STRING,
    0, bytes_left,
    0,
    AnyPropertyType, &type, &format, &len, &dummy, &data);

    if (result == Success) printf("%s\n", data);
    }
    ....

    Interesting, that inserting sleep(2) before XGetWindowProperty() is
    helping.

    Sorry for my terrible english.

    --
    With best regards
    Templar



  2. Re: Xlib lateness effect of XGetWindowProperty()

    Hi Templar!

    On 12 Nov 03 at 00:14, "Templar" (Templar ) wrote to All:

    As XConvertSelection manual states,

    XConvertSelection requests that the specified selection be converted to
    the specified target type:

    o If the specified selection has an owner, the X server sends a
    SelectionRequest event to that owner.

    o If no owner for the specified selection exists, the X server gen-
    erates a SelectionNotify event to the requestor with property
    None.

    That means you have to wait for SelectionNotify before reading the
    property, which explains why you observe different results with sleep().

    Templar> Hello, All! I need to get a contents of the XA_PRIMARY
    Templar> selection.

    Templar> If I select something and run my silly program, it's dumping what
    Templar> was in the XA_PRIMARY = OK. But, if I'm selecting something other
    Templar> & run my program again, it's dumping the previous contents of
    Templar> selection

    Templar> Note: I'm not using any loop with XNextEvent(). May be that is a
    Templar> problem???

    Templar> ... Window selown; int format, result; long len, bytes_left,
    Templar> dummy; unsigned char* data; ...

    Templar> selown = XGetSelectionOwner(display, XA_PRIMARY);

    Templar> if (selown != NULL) {

    Templar> XConvertSelection(display, XA_PRIMARY, XA_STRING, NULL, selown,
    Templar> CurrentTime);

    Templar> XFlush(display);

    Templar> result = XGetWindowProperty(display, selown, XA_STRING, 0,
    Templar> bytes_left, 0, AnyPropertyType, &type, &format, &len, &dummy,
    Templar> &data);

    Templar> if (result == Success) printf("%s\n", data); } ...

    Templar> Interesting, that inserting sleep(2) before XGetWindowProperty()
    Templar> is helping.

    Templar> Sorry for my terrible english.

    Templar> -- With best regards Templar



    --
    Sincerely,
    Dmitry

    --- www.karasik.eu.org ---

    He who dies with most the toys wins

+ Reply to Thread