Skip to content

Commit

Permalink
Merge pull request #102 from m-col/output
Browse files Browse the repository at this point in the history
Fix up some output code
  • Loading branch information
flacjacket authored Sep 8, 2022
2 parents 7e987ae + 9bdcd71 commit 817f1fb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
11 changes: 3 additions & 8 deletions tiny/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,9 @@ def server_new_xdg_surface(self, listener, xdg_surface: XdgSurface) -> None:
def server_new_output(self, listener, output: Output) -> None:
output.init_render(self._allocator, self._renderer)

if output.modes != []:
mode = output.preferred_mode()
if mode is None:
logger.error("Got no output mode")
return
output.set_mode(mode)
output.enable()
output.commit()
output.set_mode(output.preferred_mode())
output.enable()
output.commit()

self.outputs.append(output)
self._output_layout.add_auto(output)
Expand Down
8 changes: 8 additions & 0 deletions wlroots/ffi_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,14 @@ def has_xwayland() -> bool:

# types/wlr_output.h
CDEF += """
struct wlr_output_mode {
int32_t width, height;
int32_t refresh; // mHz
bool preferred;
struct wl_list link;
...;
};
struct wlr_output_state {
...;
};
Expand Down
25 changes: 19 additions & 6 deletions wlroots/wlr_types/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

from pywayland.server import Signal
from pywayland.protocol.wayland import WlOutput
from pywayland.utils import wl_list_for_each

from wlroots import ffi, PtrHasData, lib, Ptr, str_or_none
from wlroots.util.region import PixmanRegion32
from .matrix import Matrix

if TYPE_CHECKING:
from typing import Iterator

from wlroots.allocator import Allocator
from wlroots.renderer import Renderer

Expand Down Expand Up @@ -77,16 +80,23 @@ def physical_size_mm(self) -> tuple[int, int]:
return self._ptr.phys_width, self._ptr.phys_height

@property
def modes(self):
if lib.wl_list_empty(ffi.addressof(self._ptr.modes)) == 1:
return []
def modes(self) -> Iterator[OutputMode]:
for ptr in wl_list_for_each(
"struct wlr_output_mode *",
self._ptr.modes,
"link",
ffi=ffi,
):
yield OutputMode(ptr)

@property
def enabled(self) -> bool:
return self._ptr.enabled

@property
def current_mode(self) -> OutputMode:
def current_mode(self) -> OutputMode | None:
if self._ptr.current_mode == ffi.NULL:
return None
return OutputMode(self._ptr.current_mode)

@property
Expand Down Expand Up @@ -120,12 +130,15 @@ def preferred_mode(self) -> OutputMode | None:

return OutputMode(output_mode_ptr)

def set_mode(self, mode: OutputMode) -> None:
def set_mode(self, mode: OutputMode | None) -> None:
"""Sets the output mode
The output needs to be enabled.
"""
lib.wlr_output_set_mode(self._ptr, mode._ptr)
if mode is None:
lib.wlr_output_set_mode(self._ptr, ffi.NULL)
else:
lib.wlr_output_set_mode(self._ptr, mode._ptr)

def set_custom_mode(self, width: int, height: int, refresh: int) -> None:
"""
Expand Down
4 changes: 3 additions & 1 deletion wlroots/wlr_types/output_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ def remove(self, output: Output) -> None:
"""Remove an output from the layout."""
lib.wlr_output_layout_remove(self._ptr, output._ptr)

def get_box(self, reference: Output | None = None) -> Box:
def get_box(self, reference: Output | None = None) -> Box | None:
"""
Get the box of the layout for the given reference output in layout
coordinates. If `reference` is None, the box will be for the extents of the
entire layout.
"""
if reference:
box_ptr = lib.wlr_output_layout_get_box(self._ptr, reference._ptr)
if box_ptr == ffi.NULL:
return None
else:
box_ptr = lib.wlr_output_layout_get_box(self._ptr, ffi.NULL)
return Box(ptr=box_ptr)
Expand Down
11 changes: 8 additions & 3 deletions wlroots/wlr_types/output_management_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,17 @@ def output(self) -> Output:
return Output(self._ptr.output)

@property
def mode(self) -> OutputMode:
def mode(self) -> OutputMode | None:
if self._ptr.mode == ffi.NULL:
return None
return OutputMode(self._ptr.mode)

@mode.setter
def mode(self, value: OutputMode) -> None:
self._ptr.mode = value._ptr
def mode(self, mode: OutputMode | None) -> None:
if mode is None:
self._ptr.mode = ffi.NULL
else:
self._ptr.mode = mode._ptr

@property
def custom_mode(self):
Expand Down

0 comments on commit 817f1fb

Please sign in to comment.