示例#1
0
    def create(self):
        """Creates the window and gc"""
        if self.window:
            return

        visual_id = get_visual_id(self._screen, OverlayWindow.SCREEN_DEPTH)
        self._colormap = self._screen.root.create_colormap(
            visual_id, X.AllocNone)
        self.parent_window = self._display.create_resource_object(
            'window', self.parent_info.window_id)
        parent_size = None
        with xutil.get_display() as display:
            parent_window = display.create_resource_object(
                'window', self.parent_info.window_id)
            parent_size = parent_window.get_geometry()
        self._width, self._height = parent_size.width, parent_size.height

        self.window = self.parent_window.create_window(
            0,
            0,
            parent_size.width,
            parent_size.height,
            0,
            OverlayWindow.SCREEN_DEPTH,
            X.InputOutput,
            visual_id,
            background_pixmap=0,
            colormap=self._colormap,
            background_pixel=0,
            border_pixel=0,
            event_mask=X.ExposureMask)
        self.parent_window.change_attributes(event_mask=X.StructureNotifyMask)
        self._set_click_through()
        self._set_invisible()
        self._display.flush()
示例#2
0
def main(options):
    if options['--silent']:
        try:
            outfile = os.open(os.devnull, os.O_WRONLY)
            os.close(sys.stderr.fileno())
            os.dup2(outfile, sys.stderr.fileno())
        finally:
            os.close(outfile)

    display = xutil.get_display()
    screen = display.screen()
    window_infos = xutil.get_parent_window_infos()
    loop = asyncio.get_event_loop()
    executor = thread.DaemonThreadPoolExecutor(max_workers=2)
    parser_object = (parser.ParserOption(options['--parser'])
                     .parser_class())
    image_loader = (loading.ImageLoaderOption(options['--loader'])
                    .loader_class())
    error_handler = error_processor_factory(parser_object)
    view = View()
    tools = Tools(image_loader, parser_object, error_handler)
    window_factory = ui.OverlayWindow.Factory(display, view)
    windows = batch.BatchList(window_factory.create(*window_infos))
    image_loader.register_error_handler(error_handler)
    view.screen_width = screen.width_in_pixels
    view.screen_height = screen.height_in_pixels

    if tmux_util.is_used():
        atexit.register(setup_tmux_hooks())
        view.offset = tmux_util.get_offset()

    with windows, image_loader:
        loop.set_default_executor(executor)

        for sig in (signal.SIGINT, signal.SIGTERM):
            loop.add_signal_handler(
                sig, shutdown_factory(loop))

        loop.add_signal_handler(
            signal.SIGUSR1,
            lambda: asyncio.ensure_future(query_windows(
                window_factory, windows, view)))

        loop.add_signal_handler(
            signal.SIGWINCH,
            lambda: asyncio.ensure_future(
                reset_terminal_info(windows)))

        asyncio.ensure_future(process_xevents(loop, display, windows))
        asyncio.ensure_future(process_commands(
            loop, shutdown_factory(loop),
            windows, view, tools))

        try:
            loop.run_forever()
        finally:
            loop.close()
            executor.shutdown(wait=False)
示例#3
0
def main_layer(options):
    display = xutil.get_display()
    window_infos = xutil.get_parent_window_infos()
    loop = asyncio.get_event_loop()
    executor = futures.ThreadPoolExecutor(max_workers=2)
    shutdown_routine = shutdown(loop)  #pylint: disable=E1111
    parser_class = parser.ParserOption(options['--parser']).parser_class
    media = {}
    window_factory = ui.OverlayWindow.Factory(display, media)
    windows = batch.BatchList(window_factory.create(*window_infos))

    if tmux_util.is_used():
        atexit.register(setup_tmux_hooks())

    with windows:
        # this could lead to unexpected behavior,
        # but hey otherwise it breaks exiting the script..
        # as readline for example won't return till a line was read
        # and there's no (already integrated) way to
        # disable it only for a specific threadpoolexecutor
        # see: https://github.com/python/cpython/blob/master/Lib/concurrent/futures/thread.py#L33
        # -> TODO: reimplement ThreadPoolExecutor
        atexit.unregister(futures.thread._python_exit)  #pylint: disable=W0212
        loop.set_default_executor(executor)

        for sig in (signal.SIGINT, signal.SIGTERM):
            loop.add_signal_handler(
                sig, functools.partial(asyncio.ensure_future,
                                       shutdown_routine))

        loop.add_signal_handler(
            signal.SIGUSR1, lambda: asyncio.ensure_future(
                query_windows(window_factory, windows)))

        asyncio.ensure_future(main_xevents(loop, display, windows))
        asyncio.ensure_future(
            main_commands(loop, shutdown_routine, parser_class(), windows,
                          media))

        try:
            loop.run_forever()
        finally:
            loop.close()
            executor.shutdown(wait=False)
示例#4
0
def main_layer(options):
    display = xutil.get_display()
    window_infos = xutil.get_parent_window_infos()
    loop = asyncio.get_event_loop()
    executor = thread.DaemonThreadPoolExecutor(max_workers=2)
    parser_class = parser.ParserOption(options['--parser']).parser_class
    view = ui.View()
    window_factory = ui.OverlayWindow.Factory(display, view)
    windows = batch.BatchList(window_factory.create(*window_infos))

    if tmux_util.is_used():
        atexit.register(setup_tmux_hooks())
        view.offset = tmux_util.get_offset()

    if options['--silent']:
        sys.stderr = open('/dev/null', 'w')

    with windows:
        loop.set_default_executor(executor)

        for sig in (signal.SIGINT, signal.SIGTERM):
            loop.add_signal_handler(
                sig, shutdown_factory(loop))

        loop.add_signal_handler(
            signal.SIGUSR1,
            lambda: asyncio.ensure_future(query_windows(
                window_factory, windows, view)))

        asyncio.ensure_future(main_xevents(loop, display, windows))
        asyncio.ensure_future(main_commands(
            loop, shutdown_factory(loop), parser_class(),
            windows, view))

        try:
            loop.run_forever()
        finally:
            loop.close()
            executor.shutdown(wait=False)