Skip to content

Commit

Permalink
Tiny + Wlroots: Fix SceneOutputLayout API
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijenbergh committed May 10, 2024
1 parent e2d5413 commit 9f29208
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
4 changes: 3 additions & 1 deletion tiny/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
DataDeviceManager,
OutputLayout,
Scene,
SceneOutputLayout,
Seat,
XCursorManager,
XdgShell,
Expand All @@ -39,7 +40,7 @@ def main(argv) -> None:
display, "seat0"
) as seat:
scene = Scene()
scene.attach_output_layout(output_layout)
scene_layout = scene.attach_output_layout(output_layout)
tinywl_server = TinywlServer( # noqa: F841
display=display,
backend=backend,
Expand All @@ -51,6 +52,7 @@ def main(argv) -> None:
cursor_manager=xcursor_manager,
seat=seat,
output_layout=output_layout,
scene_layout=scene_layout,
)

socket = display.add_socket()
Expand Down
10 changes: 8 additions & 2 deletions tiny/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
SceneBuffer,
SceneNodeType,
SceneOutput,
SceneOutputLayout,
SceneSurface,
SceneTree,
Seat,
Expand Down Expand Up @@ -83,6 +84,7 @@ def __init__(
cursor_manager: XCursorManager,
seat: Seat,
output_layout: OutputLayout,
scene_layout: SceneOutputLayout,
) -> None:
# elements that we need to hold on to
self._display = display
Expand Down Expand Up @@ -118,6 +120,7 @@ def __init__(
self.resize_edges: Edges = Edges.NONE

self._output_layout = output_layout
self._scene_layout = scene_layout
self.outputs: list[Output] = []

xdg_shell.new_surface_event.add(Listener(self.server_new_xdg_surface))
Expand Down Expand Up @@ -349,7 +352,6 @@ def server_new_xdg_surface(self, listener, xdg_surface: XdgSurface) -> None:
# output and frame handling callbacks

def server_new_output(self, listener, output: Output) -> None:
SceneOutput.create(self._scene, output)
output.init_render(self._allocator, self._renderer)

state = OutputState()
Expand All @@ -361,13 +363,17 @@ def server_new_output(self, listener, output: Output) -> None:
state.finish()

self.outputs.append(output)
if not self._output_layout.add_auto(output):
l_output = self._output_layout.add_auto(output)
if not l_output:
logging.warning("Failed to add output to layout.")
return

output.frame_event.add(Listener(self.output_frame))
output.request_state_event.add(Listener(self.output_request_state))

scene_output = SceneOutput.create(self._scene, output)
self._scene_layout.add_output(l_output, scene_output)

def output_frame(self, listener, data) -> None:
output = self.outputs[0]
scene_output = self._scene.get_scene_output(output)
Expand Down
2 changes: 2 additions & 0 deletions wlroots/ffi_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,8 @@ def has_xwayland() -> bool:
struct wlr_scene_output_layout *wlr_scene_attach_output_layout(struct wlr_scene *scene,
struct wlr_output_layout *output_layout);
void wlr_scene_output_layout_add_output(struct wlr_scene_output_layout *sol, struct wlr_output_layout_output *lo, struct wlr_scene_output *so);
struct wlr_scene_tree *wlr_scene_subsurface_tree_create(
struct wlr_scene_tree *parent, struct wlr_surface *surface);
Expand Down
1 change: 1 addition & 0 deletions wlroots/wlr_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
SceneNode,
SceneNodeType,
SceneOutput,
SceneOutputLayout,
SceneSurface,
SceneTree,
)
Expand Down
20 changes: 17 additions & 3 deletions wlroots/wlr_types/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def tree(self) -> SceneTree:

def attach_output_layout(
self, output_layout: OutputLayout
) -> OutputLayoutOutput | None:
"""Get a scene-graph output from a wlr_output."""
) -> SceneOutputLayout | None:
"""Attach an output layout to a scene."""
ptr = lib.wlr_scene_attach_output_layout(self._ptr, output_layout._ptr)
if ptr == ffi.NULL:
return None
return OutputLayoutOutput(ptr)
return SceneOutputLayout(ptr)

def set_presentation(self, presentation: Presentation) -> None:
"""
Expand Down Expand Up @@ -353,6 +353,20 @@ def configure(self, full_area: Box, usable_area: Box) -> None:
)


class SceneOutputLayout(Ptr):
def __init__(self, ptr) -> None:
"""A `struct wlr_scene_output_layout_scene`"""
self._ptr = ptr

def add_output(
self, output_layout_output: OutputLayoutOutput, scene_output: SceneOutput
) -> None:
"""Add an output to the scene output layout."""
lib.wlr_scene_output_layout_add_output(
self._ptr, output_layout_output._ptr, scene_output._ptr
)


class SceneOutputStateOptions(Ptr):
def __init__(self, ptr) -> None:
"""A `struct wlr_scene_output_state_options`."""
Expand Down

0 comments on commit 9f29208

Please sign in to comment.