Skip to content

Commit

Permalink
Merge branch 'flacjacket:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
heuer authored Mar 13, 2024
2 parents a91c03d + 371ca85 commit 9e3f68f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
11 changes: 5 additions & 6 deletions wlroots/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 4 additions & 7 deletions wlroots/wlr_types/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ 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.commit():
raise RuntimeError("Unable to commit output")
else:
self.rollback()

Expand All @@ -187,17 +188,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"""
Expand Down

0 comments on commit 9e3f68f

Please sign in to comment.