开发者

X11, sending an event with XSendEvent(3)

I embedded a X11 app (xterm) in a Motif window. All seems to work fine, bu开发者_StackOverflow中文版t if I press a key when the pointer isn't above the embedded app, it doesn't get it. Trying to fix this, I changed the main loop of the main app. Now it's like this:

  XEvent ev;
  for (;;)
    {
      XtAppNextEvent (app, &ev);

      /* If the event is a keypress, send it to
       * the xterm window. Else, dispatch it.
       */
      Window *xtW = NULL, parent, _root;
      unsigned int noC;

      if (ev.type == KeyPress || ev.type == KeyRelease)
   {
#ifdef DEBUG
     fprintf (stderr, "Key event\n");
#endif
     while (xtW == NULL)
       XQueryTree (XtDisplay (drawW), XtWindow (drawW), &_root,
         &parent, &xtW, &noC);

     XSendEvent (XtDisplay (drawW), *xtW, True,
            (KeyPressMask | KeyReleaseMask), &ev);
     XFlush (XtDisplay (drawW));
#ifdef DEBUG
     fprintf (stderr, "sent key event\n");
#endif
   }
      else
     XtDispatchEvent (&ev);
    }

When I press a key outside embedded xterm the debug line being printed, but xterm doesn't print the key I sent.

How can I fix this? If needed, I'll post the code.

--mghis


Well to start with you are assuming the XQueryTree will only return one child window - maybe it is returning more than one and you are passing the event on to the wrong one?

I'm not sure what that while loop around the XQueryTree call is for either.

You should also be calling XFree to free the child window list once you're done with it, or you will be leaking memory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜