flacjacket / pywlroots

Python binding to the wlroots library using cffi
University of Illinois/NCSA Open Source License
51 stars 12 forks source link

Remove exception from SceneOutput.commit: Should return boolean #164

Closed heuer closed 5 months ago

heuer commented 5 months ago

The RuntimeException is of little value because, in my opinion, a failed commit is not critical. Using the exception only requires more code to catch the exception.

See Qtile https://github.com/qtile/qtile/blob/9e1eaf2b3407d547fdcc4ba0a4a12f10cf8443eb/libqtile/backend/wayland/output.py#L98

    def _on_frame(self, _listener: Listener, _data: Any) -> None:
        try:
            self.scene_output.commit()
        except RuntimeError:
            # Failed to commit scene output; skip rendering.
            pass

        # Inform clients of the frame
        self.scene_output.send_frame_done(Timespec.get_monotonic_time())

In my code I use:

        try:
            self.scene_output.commit()
        except RuntimeError:
            return
        self.scene_output.send_frame_done(Timespec.get_monotonic_time())

The more elegant versions of both examples:

Qtile:

    def _on_frame(self, _listener: Listener, _data: Any) -> None:
        self.scene_output.commit()
        # Inform clients of the frame
        self.scene_output.send_frame_done(Timespec.get_monotonic_time())

Or, if you care about the result of the commit:

        if not self.scene_output.commit():
            return
        self.scene_output.send_frame_done(Timespec.get_monotonic_time())

Removing the exception and returning a boolean value also aligns nicely with #135.