Xlib sync on different instance of Xlib.display.Display()?

F

Ferry Boender

Hi,

I'm relatively new to Xlib programming, and I ran into a little problem.

I'm trying to insert keypress events into a X window. The following code
works:

--8<------------------------------------------------------------
#!/usr/bin/python

import Xlib.display
import Xlib.X
import Xlib.XK

import time

display = Xlib.display.Display()
screen = display.screen()
root = screen.root
input_focus = display.get_input_focus()
window = input_focus._data["focus"];

ev = Xlib.protocol.event.KeyPress(
time = int(time.time()), root = root, window = window,
same_screen = 0, child = Xlib.X.NONE, root_x = 0,
root_y = 0, event_x = 0, event_y = 0, state = 0,
detail = 104
)

window.send_event(ev, propagate = True)
#display = Xlib.display.Display()
display.sync()
--8<------------------------------------------------------------

But when I comment out the "#display = Xlib.display.Display()" line, it
stops working. (Naturally doing this in this situation is stupid, but in
the real code I tried to pass the window as a parameter to a object
which had its own instance of display)

My guess is that any events that get sent to a window are cached by the
display the window was gotten from. Since I'm sync()-ing on a different
instance of display() the events aren't there. I initially thought this
caching would've been handled on a lower level (somewhere in the X
internals; not in python) so that the instance wouldn't matter.

Is there any way around this, or will I be forced to pass the correct
display instance as a param?


Thanks for any help,


Ferry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top