can't get XSetSelectionOwner() to work - Xwindows

This is a discussion on can't get XSetSelectionOwner() to work - Xwindows ; I'm having trouble with XSetSelectionOwner(). It doesn't seem to be taking ownership of the selection, yet my error checking doesn't report that it didn't work. Here's what I have: XSetSelectionOwner (display, XA_PRIMARY, win, report.xbutton.time); if (XGetSelectionOwner (display, XA_PRIMARY) != win) ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: can't get XSetSelectionOwner() to work

  1. can't get XSetSelectionOwner() to work

    I'm having trouble with XSetSelectionOwner(). It doesn't seem to be
    taking ownership of the selection, yet my error checking doesn't report
    that it didn't work. Here's what I have:

    XSetSelectionOwner (display, XA_PRIMARY, win,
    report.xbutton.time);
    if (XGetSelectionOwner (display, XA_PRIMARY) != win)
    {
    fprintf (stderr, "Did not get selection ownership\n");
    return (report.xbutton.button);
    }

    If I select something in xterm and then select something in my app, the
    selection in xterm does not clear. Also my app never get the
    SelectionRequest event, so I'm sure that I'm not getting the selection
    ownership. Can anyone help?

    James Rich

    Vs lbh guvax bs argjbex frphevgl nf na vzzhar flfgrz, Jvaqbjf vf UVI.
    -- Wbr Cyhgn


  2. Re: can't get XSetSelectionOwner() to work

    In comp.windows.x, jimi

    wrote
    on Mon, 14 Jun 2004 13:03:05 -0600
    :
    > I'm having trouble with XSetSelectionOwner(). It doesn't seem to be
    > taking ownership of the selection, yet my error checking doesn't report
    > that it didn't work. Here's what I have:
    >
    > XSetSelectionOwner (display, XA_PRIMARY, win,
    > report.xbutton.time);
    > if (XGetSelectionOwner (display, XA_PRIMARY) != win)
    > {
    > fprintf (stderr, "Did not get selection ownership\n");
    > return (report.xbutton.button);
    > }
    >
    > If I select something in xterm and then select something in my app, the
    > selection in xterm does not clear. Also my app never get the
    > SelectionRequest event, so I'm sure that I'm not getting the selection
    > ownership. Can anyone help?


    A puzzling problem. What version of X are you using? Do you open
    the display yourself? If you're using a widget set such as Gtk,
    Qt, or Motif, be advised that they'll probably do most if not
    all of the selection management in their internals. I'd
    frankly have to look up the details.

    I'm assuming you're getting the printed out message; if not,
    you'll have to revisit your call to either the window creation
    (XSetWindowAttributes.event_mask) or XSelectInput() calls.
    Most likely you forgot to add ButtonPressMask thereto. :-)

    That's the simplest fix; check that first.

    If you do get the selection, you'll probably want to redraw at least
    part of your window to demonstrate to the world at large (or
    at least you, the programmer!) that it succeeded in doing so.

    >
    > James Rich
    >
    > Vs lbh guvax bs argjbex frphevgl nf na vzzhar flfgrz, Jvaqbjf vf UVI.
    > -- Wbr Cyhgn
    >



    --
    #191, ewill3@earthlink.net
    It's still legal to go .sigless.

  3. Re: can't get XSetSelectionOwner() to work

    On Tue, 15 Jun 2004 03:30:08 +0000, The Ghost In The Machine wrote:

    > In comp.windows.x, jimi
    >
    > wrote
    > on Mon, 14 Jun 2004 13:03:05 -0600
    > :
    >> I'm having trouble with XSetSelectionOwner(). It doesn't seem to be


    > I'm assuming you're getting the printed out message; if not,
    > you'll have to revisit your call to either the window creation
    > (XSetWindowAttributes.event_mask) or XSelectInput() calls.
    > Most likely you forgot to add ButtonPressMask thereto. :-)
    >
    > That's the simplest fix; check that first.


    I'm an idiot. Upon following your advice I found an errant return() that
    was right before the code in question! Turns out the code would have done
    the right thing if it hadn't return()'ed first.

    The thing that troubles me now is that upon receiving a SelectionClear
    event I understand that I'm supposed to do an XSetSelectionOwner to None,
    but that seems to interfere with other apps' normal selection process.
    Leaving the XSetSelectionOwner off makes things work the way I expect. Do
    I not need to call XSetSelectionOwner on SelectionClear events (to set the
    owner to None)?

    James Rich

    Vs lbh guvax bs argjbex frphevgl nf na vzzhar flfgrz, Jvaqbjf vf UVI.
    -- Wbr Cyhgn


  4. Re: can't get XSetSelectionOwner() to work

    In comp.windows.x, jimi

    wrote
    on Tue, 15 Jun 2004 13:37:25 -0600
    :
    > On Tue, 15 Jun 2004 03:30:08 +0000, The Ghost In The Machine wrote:
    >
    >> In comp.windows.x, jimi
    >>
    >> wrote
    >> on Mon, 14 Jun 2004 13:03:05 -0600
    >> :
    >>> I'm having trouble with XSetSelectionOwner(). It doesn't seem to be

    >
    >> I'm assuming you're getting the printed out message; if not,
    >> you'll have to revisit your call to either the window creation
    >> (XSetWindowAttributes.event_mask) or XSelectInput() calls.
    >> Most likely you forgot to add ButtonPressMask thereto. :-)
    >>
    >> That's the simplest fix; check that first.

    >
    > I'm an idiot. Upon following your advice I found an errant return() that
    > was right before the code in question! Turns out the code would have done
    > the right thing if it hadn't return()'ed first.


    Welcome to programming. :-) Sometimes the hardest bugs to find
    are the simplest.

    >
    > The thing that troubles me now is that upon receiving a SelectionClear
    > event I understand that I'm supposed to do an XSetSelectionOwner to None,
    > but that seems to interfere with other apps' normal selection process.
    > Leaving the XSetSelectionOwner off makes things work the way I expect. Do
    > I not need to call XSetSelectionOwner on SelectionClear events (to set the
    > owner to None)?


    No, you're merely being notified that you're no longer
    the owner. Proper response AFAIK is to simply set or
    clear an internal flag and redraw oneself. (The internal
    flag is application-specific. Presumably, if the prog
    has the selection, it sets something. If the prog does
    not, it clears that something and/or sets something else,
    or perhaps both.)

    >
    > James Rich
    >
    > Vs lbh guvax bs argjbex frphevgl nf na vzzhar flfgrz, Jvaqbjf vf UVI.
    > -- Wbr Cyhgn
    >



    --
    #191, ewill3@earthlink.net
    It's still legal to go .sigless.

+ Reply to Thread