Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
Hello everybody, i am using fedora core 6 for developement. i have done a simple c program using xlib apis. i have grab all the mouse and keyboard events using ...
  1. #1
    Just Joined!
    Join Date
    May 2008
    Location
    pune,India
    Posts
    9

    need help in xlib programming

    Hello everybody,
    i am using fedora core 6 for developement.
    i have done a simple c program using xlib apis.
    i have grab all the mouse and keyboard events using XGrabKeyboard and XGrabPointer.
    By this all the events generated by X server are sent to my simple c program.
    There are other windows on desktop.
    Is there any way in xlib to grab the events except for the one window specified by me.
    That means specified window should get all its event.And for all windows the events should go to my program where i grab the events.

    please if anyone can guide me in this or have any solution,that will be helpful for me.

    Thanks in advance.


    Regards,
    ~Sanjay

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    There are two issues here.

    The first issue: Please be sure that it's grabbing that you want. If you specify grabbing for a window that's owned by another application, then that application will not (normally) see the event; only your application will. Is this what you want? If so, you ought to be able to use XGrabKeyboard() and XGrabPointer() on any window you want.

    If that's the case, maybe you want to share with us why you need to do this. Grabbing the keyboard and the pointer should only be done when absolutely necessary, and maybe we can help with a reality check. :)

    The alternative is to receive events for a given window, even if the window isn't yours, but also to let the application owning that window to receive the event as well. In that case, simply use XSelectInput() in the usual manner. You don't have to be the owner of a given window to do this.

    The second issue: If you wish to get a list of windows that exist, XQueryTree() will be useful.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    May 2008
    Location
    pune,India
    Posts
    9
    Thanks to reply me.

    Actually the case is there are two windows created by me.

    One window which grabs all the events by using XGrabKeyboard and XGrabPointer.

    And second window is merely a window.

    Now my requirement is second window should get all of its event even though i have grabbed all the events in first window.


    In short except for the second window, first window should grab all the events.


    Regards,
    ~Sanjay

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Are both of these windows being managed by the same application and process?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just Joined!
    Join Date
    May 2008
    Location
    pune,India
    Posts
    9
    No both windows are are part of separate process

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    At first I would say that there's no way to do what you want to do.

    But before giving up, try this. Grab all events, even the ones for your second window, in the first window. Then for all events that were intended for the second window, do an XSendEvent() to the second window. You may have to play with the coordinates in the event structure to make them relative to the second window. You may have to experiment with XSendEvent()'s third parameter (propagate). And you may have to experiment with the send_event member of the event structure you're sending.

    If none of that works, and if you are at liberty to modify the code of the application associated with the second window, and if both applications are running on the same host, then have the first application communicate with the second application through other means. Send the event structure through some sort of interprocess communication, and have the second application wait for a message from the first application, rather than waiting for an X event. A POSIX message queue is one way to do this.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Just Joined!
    Join Date
    May 2008
    Location
    pune,India
    Posts
    9
    Thanks a lot.

    1. As u said in your first alternative htere is one problem.How would i come to know the event i recieved is meant for which window.
    Because i tried for printing the event types and their Window name(for which it is basically meant) by using the window handle comes with the event structure.
    And all the times i got the same window handle (window handle of the window in which i have grabs the events).

    2. Secondly you were talking abt some kind of IPC between two process.
    Basically my ultimate requirement is to have IPC between these two prcosess mentioned in the first post.And to do IPC between these two process
    i need to grabs all the events except for the second window.

    Hope the picture is clear now.

    Regards,
    ~Sanjay

  8. #8
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    And all the times i got the same window handle (window handle of the window in which i have grabs the events).
    An interesting problem. First, use XQueryTree() to get the coordinates of every window that exists. Then use XGetGeometry() to get the location of each window.

    Then, for the ButtonPress, ButtonRelease, KeyPress, and KeyRelease events, look at the x_root and y_root event structure members. Then go through your list of windows to determine which window is appropriate. You will have to do x and y coordinate translation for the window you find.

    Are there other events in which you're interested?

    And by the way: You may wish to consider using the root window as the one which grabs the events. I'm not sure that this will help, but it might, especially for events other than keyboard and mouse events.
    to do IPC between these two process i need to grabs all the events except for the second window.
    You can't grab all events except for those in the second window. Either you grab events for all windows or events for no windows.

    But this will actually help you, because eventually you'll have to figure out for your second program how it's going to wait for interprocess messages and for X events at the same time. It can't.

    So have it just wait for interprocess messages. Your first program can, if it wants, set a special flag for those events that are for the second process's window.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  9. #9
    Just Joined!
    Join Date
    May 2008
    Location
    pune,India
    Posts
    9
    Many thanks.

    As u suggest i will try to get geometry of the required window and for each mouse press and mouse release i will check with saved geometry.

    One thing i need to mention that i am already finding out the window handle of specific window before grabbing the events and saving it to the memeber variable.

    So i think i need not maintain list of all windows.am i right?

    Regards,
    ~Sanjay

  10. #10
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    One thing i need to mention that i am already finding out the window handle of specific window before grabbing the events and saving it to the memeber variable.
    Now I'm really confused. I would have lots of questions for you if I were learning how to grab events myself, but I'm not, and the yardwork won't wait. :)
    So i think i need not maintain list of all windows.am i right?
    You are right, as long as you can get the information you need for each event without one. You'll have to try it and see!
    --
    Bill

    Old age and treachery will overcome youth and skill.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...