diff --git a/wlroots/backend.py b/wlroots/backend.py index 8ddf5372..45ab6fa3 100644 --- a/wlroots/backend.py +++ b/wlroots/backend.py @@ -72,20 +72,19 @@ def destroy(self) -> None: self._ptr = None - def start(self) -> None: + def start(self) -> bool: """Start the backend This may signal new_input or new_output immediately, but may also wait until the display's event loop begins. """ - ret = lib.wlr_backend_start(self._ptr) - if not ret: - self.destroy() - raise RuntimeError("Unable to start backend") + return lib.wlr_backend_start(self._ptr) def __enter__(self) -> Backend: """Context manager to create and clean-up the backend""" - self.start() + if not self.start(): + self.destroy() + raise RuntimeError("Unable to start backend") return self def __exit__(self, exc_type, exc_value, exc_tb) -> None: diff --git a/wlroots/wlr_types/output.py b/wlroots/wlr_types/output.py index 21fac421..894345c0 100644 --- a/wlroots/wlr_types/output.py +++ b/wlroots/wlr_types/output.py @@ -160,7 +160,11 @@ def __enter__(self) -> Output: def __exit__(self, exc_type, exc_value, exc_tb) -> None: """Stop rendering frame, commit when exiting normally, otherwise rollback""" if exc_type is None: - self.commit() + if not self.test(): + self.rollback() + raise RuntimeError("Rendering on output failed") + if not self.commit(): + raise RuntimeError("Unable to commit output") else: self.rollback() @@ -187,17 +191,13 @@ def attach_render(self) -> None: if not lib.wlr_output_attach_render(self._ptr, ffi.NULL): raise RuntimeError("Unable to attach render") - def commit(self) -> None: + def commit(self) -> bool: """Commit the pending output state If `.attach_render` has been called, the pending frame will be submitted for display. """ - if not lib.wlr_output_test(self._ptr): - self.rollback() - raise RuntimeError("Rendering on output failed") - if not lib.wlr_output_commit(self._ptr): - raise RuntimeError("Unable to commit output") + return lib.wlr_output_commit(self._ptr) def rollback(self) -> None: """Discard the pending output state"""