[Xcb] Advisable in this situation to swap Xlib with Xcb?

H. Dieter Wilhelm dieter at duenenhof-wilhelm.de
Sun Sep 7 13:09:51 PDT 2014


Hello Christian,

thanks a lot for your pointers!

Christian Linhart <chris at DemoRecorder.com>
writes:

> XCB will not give you any different functionality than Xlib.
> XCB is just another mechanism to access the functionality 
> that is provided by the XServer via the X-protocol.

:-( OK

> If you want to emulate user-input to X-Applications you could use 
> xdotool which is a commandline application for that purpose,
> to be used from shellscripts.
> or libxdo which is the underlying library of xdotool.
> I didn't use xdotool myself but the description looks good:
>     http://www.semicomplete.com/projects/xdotool/

I tried to emulate required functionality with xdotool and I'm running
into the very same problems:

    WIN=`xdotool getactivewindow`
    CMDW=`xdotool search --name "ANSYS Structural Utility Menu"`
    # CMDW accepts only keys when it has the input focus
    xdotool windowactivate  $CMDW
    # send the clipboard content
    xdotool key --window $CMDW "ctrl+v"
    # The interpreter needs a final "Return" to digest the input
    wait # does not help here
    sleep 3 # does not help, just prolongs the execution time
    xdotool key --window $CMDW "Return" "a" "b" "c"
    # return the input focus to the editor
    xdotool windowactivate $WIN

Frustratingly, when calling this script the Return key always appears in
the input window *before* the clipboard content!?

> If xdotool is not suitable, you may also look at the XTest extension.

I think I'll have a look. ;-)

> In any case you cannot send keyboard-input to applications other than emulating
> key-presses. xdotool makes this just more convenient.
> There is an exception: If an application has an extra API for doing that... 
> Maybe tcl/tk offers something in that direction. Since your receiving
> app seems to use tcl/tk, you might want to look at the tcl/tk docs,
> or ask in a tcl/tk forum.

Good idea, I'll ask in their mailing list...

Thanks again

       Dieter



> Hope this helps,
>
> Chris
>
> On 09/07/14 11:40, H. Dieter Wilhelm wrote:
>> Hello List,
>> 
>> my aim is to send script snippets (i. e. ASCII text from the Emacs
>> editor) to another input window (of an interpreter application called
>> ANSYS Classics in an tcl/tk window frame).  I'm a beginner of X
>> programming and my naive solution is to store text in Emacs into the
>> clipboard and using xlib calls to send the interpreter window the
>> "ctrl+v" key-combo.
>> 
>> Though working in principle, it is not very practical, mainly from the
>> fact, that I have to send an additional "Return" key so that the Ansys
>> interpreter is finally digesting its input.  Unfortunately I couldn't
>> yet solve this with one xlib program: One program has to send the
>> "Ctrl+v" combination, then Emacs must wait some 150 milli seconds,
>> otherwise the "Return" key is arriving before the clipboard content
>> before calling my other executable for sending the "Return" key!  This
>> is causing an annoying interruption and flickering, since both
>> executables have to give the other window temporarily the input focus.
>>                       
>> 1) Do you think it would be better here to switch to XCB, would it be
>> possible with XCB to receive a notification when the clipboard content
>> has been pasted and thus being able to do it in one executable?
>> 
>> 2) Or do you know a more elegant way of sending data to an input window
>> without using simulated key-presses?  Would you do it in a totally
>> different way?
>> 
>> I'm totally stuck, googling since 2 weeks, enquired the Xlib and Emacs
>> mailing lists -- in vain, could you please give me a hint?  Thanks for
>> your help!

-- 
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany



More information about the Xcb mailing list