Exemplo n.º 1
0
def grabScreens(display, keyEvents, mouseEvents):
        screens = []
        for screen_id in xrange(0, display.screen_count()):
            if redirect_screen_events(display, screen_id):
                screens.append(screen_id)

        windowEventGrabber = WindowEventGrabber(mouseEvents)

        for screenId in screens:
            root = display.screen(screenId).root
            for keyEvent in keyEvents:
                codes = getCodes(display, keyEvent.sym)
                for code in codes:
                    grabKey(root, code, keyEvent.modifierMask)
            grabExistingWindowEvents(root, windowEventGrabber)

        if len(screens) == 0:
            raise NoUnmanagedScreens()
        return screens
Exemplo n.º 2
0
def defaultEventSetup(wm, keyEvents, mouseEvents):
    handleMappingNotify = HandleMappingNotify(wm.display)

    keycodeEvents = []
    for keyEvent in keyEvents:
        codes = getCodes(wm.display, keyEvent.sym)
        for code in codes:
            keycodeEvents.append(KeyEvent(keyEvent.sym, keyEvent.modifierMask, keyEvent.fn, code))

    keyEventHandler = KeyEventHandler(keycodeEvents)

    mouseEventHandler = MouseEventHandler(mouseEvents)

    wm.windowEventGrabber = WindowEventGrabber(mouseEvents)

    # mapRequestHandler = MapRequestHandler(windowEventGrabber)

    wm.eventDispatchTable = {
        Xlib.X.MapRequest: wm.handleMapRequest,
        Xlib.X.ConfigureRequest: wm.handle_configure_request,
        Xlib.X.EnterNotify: wm.handleEnterNotify,
        Xlib.X.LeaveNotify: wm.handleLeaveNotify,
        Xlib.X.MappingNotify: handleMappingNotify.fn,
        Xlib.X.DestroyNotify: wm.handleDestroyNotify,
        Xlib.X.MotionNotify: mouseEventHandler.motion,
        Xlib.X.ButtonPress: mouseEventHandler.press,
        Xlib.X.ButtonRelease: mouseEventHandler.release,
        Xlib.X.KeyPress: keyEventHandler.fn,
        # Xlib.X.KeyRelease: wm.handleKeyRelease,
    }

    wm.ignoreSet = {
        Xlib.X.UnmapNotify,
        Xlib.X.MapNotify,
        Xlib.X.ConfigureNotify,
        Xlib.X.CreateNotify,
        Xlib.X.ReparentNotify,
        Xlib.X.ClientMessage,
        Xlib.X.KeyRelease,
    }

    wm.display.set_error_handler(xErrorHandler)