def run(self): self._setup() e = xlib.XEvent() t = 0 sleep_time = 0. self.dispatch_event('on_enter') while not self.has_exit: # Check for already pending events for display in displays: if xlib.XPending(display._display): pending_displays = (display, ) break else: # None found; select on all file descriptors or timeout iwtd = self.get_select_files() pending_displays, _, _ = select.select(iwtd, (), (), sleep_time) # Dispatch platform events for display in pending_displays: while xlib.XPending(display._display): xlib.XNextEvent(display._display, e) # Key events are filtered by the xlib window event # handler so they get a shot at the prefiltered event. if e.xany.type not in (xlib.KeyPress, xlib.KeyRelease): if xlib.XFilterEvent(e, e.xany.window): continue try: window = display._window_map[e.xany.window] except KeyError: continue window.dispatch_platform_event(e) # Dispatch resize events for window in windows: if window._needs_resize: window.switch_to() window.dispatch_event('on_resize', window._width, window._height) window.dispatch_event('on_expose') window._needs_resize = False sleep_time = self.idle() self.dispatch_event('on_exit')
def event_loop(dpy, win): while True: while xlib.XPending(dpy) > 0: event = xlib.XEvent() xlib.XNextEvent(dpy, event) if event.type == xlib.Expose: pass elif event.type == xlib.ConfigureNotify: reshape(event.xconfigure.width, event.xconfigure.height) elif event.type == xlib.KeyPress: pass # TODO #angle += 2.0 draw() glXSwapBuffers(dpy, win)
def dispatch_events(self): e = xlib.XEvent() while xlib.XPending(self._display): xlib.XNextEvent(self._display, e) # Key events are filtered by the xlib window event # handler so they get a shot at the prefiltered event. if e.xany.type not in (xlib.KeyPress, xlib.KeyRelease): if xlib.XFilterEvent(e, e.xany.window): continue try: window = self._window_map[e.xany.window] except KeyError: continue window.dispatch_platform_event(e)
def run(self): self._setup() e = xlib.XEvent() t = 0 sleep_time = 0. self.dispatch_event('on_enter') while not self.has_exit: # Check for already pending events for display in pyglet.app.displays: if xlib.XPending(display._display): pending_dispatchers = (display,) break else: # None found; select on all file descriptors or timeout iwtd = self.get_select_files() pending_dispatchers, _, _ = \ select.select(iwtd, (), (), sleep_time) # Dispatch platform events for dispatcher in pending_dispatchers: dispatcher.dispatch_events() # Dispatch resize events # XXX integrate into dispatchers? for window in pyglet.app.windows: if window._needs_resize: window.switch_to() window.dispatch_event('on_resize', window._width, window._height) window.dispatch_event('on_expose') window._needs_resize = False sleep_time = self.idle() self.dispatch_event('on_exit')