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 _unmap(self): if not self._mapped: return xlib.XSelectInput(self._x_display, self._window, xlib.StructureNotifyMask) xlib.XUnmapWindow(self._x_display, self._window) e = xlib.XEvent() while True: xlib.XNextEvent(self._x_display, e) if e.type == xlib.UnmapNotify: break xlib.XSelectInput(self._x_display, self._window, self._default_event_mask) self._mapped = False
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 _map(self): if self._mapped: return # Map the window, wait for map event before continuing. xlib.XSelectInput(self._x_display, self._window, xlib.StructureNotifyMask) xlib.XMapRaised(self._x_display, self._window) e = xlib.XEvent() while True: xlib.XNextEvent(self._x_display, e) if e.type == xlib.MapNotify: break xlib.XSelectInput(self._x_display, self._window, self._default_event_mask) self._mapped = True if self._fullscreen: # Possibly an override_redirect issue. self.activate() self.dispatch_event('on_resize', self._width, self._height) self.dispatch_event('on_show') self.dispatch_event('on_expose')