copy/paste text buffer in X? - Xwindows

This is a discussion on copy/paste text buffer in X? - Xwindows ; I hava window in a game client which users type text into which is then displayed in another window. Does anyone know how I can make the window which is used for text be able to receive pasted text? For ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: copy/paste text buffer in X?

  1. copy/paste text buffer in X?

    I hava window in a game client which users type text into which is
    then displayed in another window. Does anyone know how I can make the
    window which is used for text be able to receive pasted text? For
    example cut from one application in X and paste it into the game
    client text entry box window. Any code example would be appreciated.
    Right now you can only manually type in text. Also my next question is
    how can I make the text in the other message window (where it is
    displayed) copyable? Right now I can't select it with my mouse if I
    try to select the text. This is just regular X functions but I'm
    asking in here since I can't find another newsgroup dealing with X
    programming that isn't idle. If the solution given is Motif that is
    also fine though I'd need to know how to setup my Makefile for Motif.

    Zach


  2. Re: copy/paste text buffer in X?

    On 2007-11-12, Zach wrote:
    >
    > I hava window in a game client which users type text into which is
    > then displayed in another window. Does anyone know how I can make the
    > window which is used for text be able to receive pasted text? For
    > example cut from one application in X and paste it into the game
    > client text entry box window. Any code example would be appreciated.


    Copying and pasting in X is done with the "selection" mechanism. I will
    not go into details, since everything is spelled out clearly in the
    ICCCM document (Inter-Client Communication Conventions Manual), which
    can be found all over the web.

    Generally, an application (in response to some user event, usually
    selection of a text range with the mouse), becomes the current
    "selection owner" by sending an appropriate request to the X server.

    When an application requires a "paste" (usually as a result of a
    middle-click event by the use), it needs to send a "convert selection"
    request to the X server which in turn notifies the current selection
    owner. It's then the selection owner's responsibility, to convert its
    selection to the required format (TEXT is generally supported, other
    targets may or may not be supported by many applications), and give it
    to the application that asked for it.

    I deliberately didn't mention all the details and possibilities, as that
    would be redundant. Consider the above as a guiding overview, and read
    the appropriate sections of the ICCCM for all the gory details.

    > Also my next question is
    > how can I make the text in the other message window (where it is
    > displayed) copyable? Right now I can't select it with my mouse if I
    > try to select the text.


    It's easy to grab the current selection ownership. Is your question
    about how to let the user specify a range of text to be considered as
    your "selection" ?
    That's up to you... the most common way is to handle mouse events, so as
    to let the user select an area of the text with a mouse. Put that into a
    buffer and keep it there until another X client asks for the selection.

    > If the solution given is Motif that is also fine though I'd need to
    > know how to setup my Makefile for Motif.


    Motif, or any other X toolkit (GTK, Qt, fltk, whatever), will handle all
    of the above automatically, in their text entry widgets. That's the idea
    of toolkits, they abstract the details, and let you create GUI programs
    from a much higher level.

    As for "how to setup your makefile" ... every toolkit has documentation
    that explains that. In general that's much simpler than learning how to
    use the toolkit though, so your question strikes me as a bit odd
    For the motif case, in general you'll have to link with X11, Xt, and
    motif like so: -lXm -lXt -lX11


    --
    John Tsiombikas (Nuclear / Mindlapse)
    http://nuclear.sdf-eu.org/

  3. Re: copy/paste text buffer in X?

    Thanks John.

    Zach


  4. Re: copy/paste text buffer in X?

    On Nov 11, 11:48 pm, Zach wrote:
    > I hava window in a game client which users type text into which is
    > then displayed in another window. Does anyone know how I can make the
    > window which is used for text be able to receive pasted text? For
    > example cut from one application in X and paste it into the game
    > client text entry box window. Any code example would be appreciated.



    How copy and paste works is defined by the ICCCM. In practice, this
    can be quite hard to follow and many contains cases that I have not
    seen "in the wild". I have an implementation of copy and paste here:

    http://mi.eng.cam.ac.uk/~er258/code/x11.html

    It's a pretty complete implementation of the ICCCM (the missing cases
    are documented) and XDnD, and it can copy/paste/drag/drop data of any
    type. It also prints out lots of information so you can see how the
    processing works. It's also very well documented

    > Right now you can only manually type in text.


    You have to figure out how to bind keys to paste, but once you have,
    the example code will get the text for you.

    > Also my next question is
    > how can I make the text in the other message window (where it is
    > displayed) copyable? Right now I can't select it with my mouse if I
    > try to select the text. This is just regular X functions but I'm
    > asking in here since I can't find another newsgroup dealing with X
    > programming that isn't idle.


    So you're not using a toolkit? If not, you'll have to figure out where
    the mouse it relative to the characters, and implement the "select
    text" bit by hand.


    -Ed


  5. Re: copy/paste text buffer in X?

    On Nov 14, 1:42 pm, Edward Rosten wrote:
    > On Nov 11, 11:48 pm, Zach wrote:

    ..>
    > How copy and paste works is defined by the ICCCM. In practice, this
    > can be quite hard to follow and many contains cases that I have not
    > seen "in the wild". I have an implementation of copy and paste here:
    >
    > http://mi.eng.cam.ac.uk/~er258/code/x11.html


    Hi Ed,

    Ah this is interesting.

    > It's a pretty complete implementation of the ICCCM (the missing cases
    > are documented) and XDnD, and it can copy/paste/drag/drop data of any


    What is XDnD?

    > type. It also prints out lots of information so you can see how the
    > processing works. It's also very well documented


    Cool.

    > You have to figure out how to bind keys to paste, but once you have,
    > the example code will get the text for you.


    Any hints where I can find how to do this? I googled "bind keys X
    programming" but didn't find anything useful. Is there a really good
    book on X programming you can recommend for the future as I learn
    more?

    > So you're not using a toolkit? If not, you'll have to figure out where
    > the mouse it relative to the characters, and implement the "select
    > text" bit by hand.


    The code was written by other people and they didn't use a toolkit.
    But once I get better understand of C and X perhaps in the future I
    could re-write the code to use GTK2 or Motif toolkits. Well the
    message area where text appears happens in 3 different windows, all of
    which can be placed wherever the user wants to put them (set in config
    file) so how will I find where the text is relative to the mouse? It
    would be cool if I could have it just start selecting and it will be
    assumed I am selecting text: so click left mouse button, hold, select
    text, release left mouse button, and then this is ready to be pasted
    into whatever application I want. I assumed X would have some standard
    way to do this a la clipboard the way MS Windows does so you can copy
    into or paste from applications easily. I should say this is my first
    foray into X programming :-)

    Zach


  6. Re: copy/paste text buffer in X?

    On Nov 14, 2:24 pm, Zach wrote:

    > Hi Ed,
    >
    > Ah this is interesting.
    >
    > > It's a pretty complete implementation of the ICCCM (the missing cases
    > > are documented) and XDnD, and it can copy/paste/drag/drop data of any

    >
    > What is XDnD?


    Drag 'n' drop. The XDnD protocol is the only one in wide use.


    > > You have to figure out how to bind keys to paste, but once you have,
    > > the example code will get the text for you.

    >
    > Any hints where I can find how to do this? I googled "bind keys X
    > programming" but didn't find anything useful. Is there a really good
    > book on X programming you can recommend for the future as I learn
    > more?


    Well, there's probably a big switch statement somewhere on Xevent
    types. The bit under KeyPress will then go and find what character
    corresponds to the key and insert it in to a buffer somewhere. In this
    case you can add a bit where if a certain key is pressed, you copy all
    the pasted text in to the buffer.

    Of course, they may have abstracted it somewhat and written
    essentially their own toolkit of sorts...

    > > So you're not using a toolkit? If not, you'll have to figure out where
    > > the mouse it relative to the characters, and implement the "select
    > > text" bit by hand.

    >
    > The code was written by other people and they didn't use a toolkit.
    > But once I get better understand of C and X perhaps in the future I
    > could re-write the code to use GTK2 or Motif toolkits. Well the
    > message area where text appears happens in 3 different windows, all of
    > which can be placed wherever the user wants to put them (set in config
    > file) so how will I find where the text is relative to the mouse?


    Well, you know where to draw the text, so you know what position it's
    in. That's all I can think of, really.

    > It
    > would be cool if I could have it just start selecting and it will be
    > assumed I am selecting text: so click left mouse button, hold, select
    > text, release left mouse button, and then this is ready to be pasted
    > into whatever application I want.


    > I assumed X would have some standard
    > way to do this a la clipboard the way MS Windows does so you can copy
    > into or paste from applications easily. I should say this is my first
    > foray into X programming :-)


    It sounds like you're programming in Xlib. That's very, very low
    level.

    -Ed







  7. Re: copy/paste text buffer in X?

    On Nov 12, 4:51 am, John Tsiombikas wrote:
    >
    > I deliberately didn't mention all the details and possibilities, as that
    > would be redundant. Consider the above as a guiding overview, and read
    > the appropriate sections of the ICCCM for all the gory details.


    I found someone who seems to love ICCCM ;-)
    http://lists.slug.org.au/archives/sl.../msg00054.html

    Zach

  8. Re: copy/paste text buffer in X?

    Hi Ed,

    Thanks for the feedback. Yeah I figure it is good to start from the
    ground up so I'm trying to learn X lib before moving on to some
    toolkit. What do you use?

    Zach

  9. Re: copy/paste text buffer in X?


    "Zach" ha scritto nel messaggio
    news:d3713695-35de-48a3-bf43-bd7291911f69@e23g2000prf.googlegroups.com...
    > Hi Ed,
    >
    > Thanks for the feedback. Yeah I figure it is good to start from the
    > ground up so I'm trying to learn X lib before moving on to some
    > toolkit. What do you use?
    >
    > Zach


    I use Xlib, and this could be interesting I think:

    http://michael.toren.net/mirrors/doc/X-copy+paste.txt



+ Reply to Thread