コード例 #1
0
 def destroy(self):
     """Destroy the global object"""
     if self._ptr is not None:
         # run and remove destructor on c data
         _global_destroy(self._display, self._ptr)
         ffi.gc(self._ptr, None)
         self._ptr = None
         self._display = None
コード例 #2
0
 def destroy(self):
     """Destroy the event loop"""
     if self._ptr is not None:
         for event_source in self.event_sources:
             event_source.remove()
         # destroy the pointer and remove the destructor
         lib.wl_event_loop_destroy(self._ptr)
         ffi.gc(self._ptr, None)
         self._ptr = None
コード例 #3
0
    def connect(self) -> None:
        """Connect to a Wayland display

        Connect to the Wayland display by name of fd.  An `int` parameter opens
        the connection using the file descriptor.  The :class:`Display` takes
        ownership of the fd and will close it when the display is destroyed.
        The fd will also be closed in case of failure.  A string will open the
        display of the given name.  If name is ``None``, its value will be
        replaced with the ``WAYLAND_DISPLAY`` environment variable if it is
        set, otherwise display ``"wayland-0"`` will be used.
        """
        if isinstance(self._name_or_fd, int):
            # argument passed is a file descriptor
            self._ptr = lib.wl_display_connect_to_fd(self._name_or_fd)
        else:
            # connect using string by name, or use default
            if self._name_or_fd is None:
                name: Union["NullCdata", bytes] = ffi.NULL
            else:
                name = self._name_or_fd.encode()
            self._ptr = lib.wl_display_connect(name)

        if self._ptr == ffi.NULL:
            raise ValueError("Unable to connect to display")

        self._ptr = ffi.gc(self._ptr, lib.wl_display_disconnect)
コード例 #4
0
    def __init__(self, ptr=None) -> None:
        if ptr is None:
            ptr = lib.wl_display_create()
            if ptr == ffi.NULL:
                raise MemoryError("Unable to create wl_display object")

        self._ptr = ffi.gc(ptr, lib.wl_display_destroy)
コード例 #5
0
    def __init__(self, display, version=None):
        if display._ptr is None or display._ptr == ffi.NULL:
            raise ValueError(
                "Display has been destroyed or couldn't initialize")

        if version is None:
            version = self.interface.version

        # we can't keep alive a handle to self without creating a reference
        # loop, so use this dict as the handle to pass to the global_bind_func
        # callback
        self._callback_info = {"interface": self.interface, "bind_func": None}
        self._handle = ffi.new_handle(self._callback_info)

        ptr = lib.wl_global_create(
            display._ptr,
            self.interface._ptr,
            version,
            self._handle,
            lib.global_bind_func,
        )
        destructor = functools.partial(_global_destroy, display)
        self._ptr = ffi.gc(ptr, destructor)
        self._display = display

        # this c data should keep the display alive
        weakkeydict[self._ptr] = display
コード例 #6
0
 def _destroy(self):
     """Frees the pointer associated with the Proxy"""
     if self._ptr is not None:
         if self._display._ptr is not None:
             ffi.release(self._ptr)
         else:
             self._ptr = ffi.gc(self._ptr, None)
         self._ptr = None
コード例 #7
0
    def __init__(self, display: Display, fd: int) -> None:
        if display.destroyed:
            raise ValueError("Display has been destroyed")

        ptr = lib.wl_client_create(display._ptr, fd)

        destructor = functools.partial(_client_destroy, display)
        self._ptr = ffi.gc(ptr, destructor)
        self._display = display
コード例 #8
0
    def __init__(self, display=None):
        if display:
            self._ptr = lib.wl_display_get_event_loop(display._ptr)
        else:
            # if we are creating an eventloop. we need to destroy it later
            ptr = lib.wl_event_loop_create()
            self._ptr = ffi.gc(ptr, lib.wl_event_loop_destroy)

        self.event_sources = WeakSet()
        self.callbacks = []
コード例 #9
0
    def __init__(self, display: Optional["Display"] = None) -> None:
        if display:
            self._ptr: Optional[
                "EventLoopCdata"] = lib.wl_display_get_event_loop(display._ptr)
        else:
            # if we are creating an eventloop. we need to destroy it later
            ptr = lib.wl_event_loop_create()
            self._ptr = ffi.gc(ptr, lib.wl_event_loop_destroy)

        self.event_sources: WeakSet[EventSource] = WeakSet()
        self._callback_handles: List = []
コード例 #10
0
ファイル: eventqueue.py プロジェクト: ydirson/pywayland
    def __init__(self, display: "Display") -> None:
        """Constructor for the EventQueue object"""
        # check that we attach to a valid display
        if display._ptr is None or display._ptr == ffi.NULL:
            raise ValueError("Display object not connected")

        ptr = lib.wl_display_create_queue(display._ptr)

        # create a destructor, save data and display
        destructor = functools.partial(_event_queue_destroy, display)
        self._ptr: Optional["QueueCdata"] = ffi.gc(ptr, destructor)
        self._display: Optional["Display"] = display

        display._children.add(self)

        weakkeydict[self._ptr] = display
コード例 #11
0
    def __init__(self, ptr, display=None):
        """Represents a protocol object on the client side.

        A :class:`Proxy` acts as a client side proxy to an object existing in
        the compositor.  Events coming from the compositor are also handled by
        the proxy, which will in turn call the handler set with
        :func:`Proxy.add_listener`.
        """
        self.user_data = None
        self.dispatcher = Dispatcher(self.interface.events)

        # This should only be true for wl_display proxies, as they will
        # initialize its pointer on a `.connect()` call
        if ptr is None:
            self._ptr = ptr
            self._display = self
            return

        self._display = display

        # parent display is the root-most client Display object, all proxies
        # should keep the display alive
        if display is None:
            raise ValueError(
                "Non-Display Proxy objects must be associated to a Display")
        display._children.add(self)

        if ptr == ffi.NULL:
            raise RuntimeError("Got a null pointer for the proxy")

        # note that even though we cast to a proxy here, the ptr may be a
        # wl_display, so the methods must still cast to 'struct wl_proxy *'
        ptr = ffi.cast('struct wl_proxy *', ptr)
        self._ptr = ffi.gc(ptr, lib.wl_proxy_destroy)

        self._handle = ffi.new_handle(self)
        lib.wl_proxy_add_dispatcher(self._ptr, lib.dispatcher_func,
                                    self._handle, ffi.NULL)

        self.interface.registry[self._ptr] = self