Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how do I get notified when display setup is complete? #204

Open
JetA2 opened this issue Oct 18, 2024 · 2 comments
Open

Question: how do I get notified when display setup is complete? #204

JetA2 opened this issue Oct 18, 2024 · 2 comments

Comments

@JetA2
Copy link

JetA2 commented Oct 18, 2024

Hi, and thanks for the work on the wlroots bindings.

I have a 1024x768 display I want to use with Linux which seems to behave in a non-standard way.
The only way I can get the display to work properly is using a wlroots-based compositor.
It seems the DRM atomic commit operation is what's doing the trick.

X does not work with my display. However, once I've run and exited sway for example, the display is setup correctly and X applications work.

To initialise my display I'm writing a wlroots utility that should only do an output commit and then exit.
This is working, but I'm not able to exit the display event loop using `display.terminate()´.

If I call it from the backend's new_output_event callback, I guess it's too early since the event loop is not yet started.

Is there an event from the display I can listen for that I can use to terminate the display?

This is the current source that sets up the display fine, but of course does not exit:

from pywayland.server import Display, Listener
from wlroots.backend import Backend, BackendType
from wlroots.wlr_types import Output, OutputState
from wlroots.renderer import Renderer
from wlroots.allocator import Allocator

def server_new_output(listener, output: Output) -> None:
	print("New output")

	global allocator, renderer
	
	output.init_render(allocator, renderer)

	state = OutputState()
	state.set_enabled(True)
	if mode := output.preferred_mode():
		state.set_mode(mode)

	output.commit(state)
	state.finish()

print("Starting")

display = Display()

backend = Backend(display, backend_type=BackendType.AUTO)
backend.new_output_event.add(Listener(server_new_output))

renderer = Renderer.autocreate(backend)

allocator = Allocator.autocreate(backend, renderer)

backend.start()

display.run()

print("Bye!")
@JetA2
Copy link
Author

JetA2 commented Oct 18, 2024

This seems to do what I want:

def idle(display) -> None:
        display.terminate()

event_loop = display.get_event_loop()
event_loop.add_idle(idle,display)

However, I'm getting a segmentation fault on exit during garbage collection.
Did I miss creating any required objects?

Fatal Python error: Segmentation fault

Current thread 0x00007e8c846aeb80 (most recent call first):
  Garbage-collecting
  <no Python frame>

@heuer
Copy link
Contributor

heuer commented Dec 11, 2024

Maybe this helps?

import signal

from pywayland.server import Display, Listener
from wlroots.backend import Backend
from wlroots.wlr_types import Output, OutputState
from wlroots.renderer import Renderer
from wlroots.allocator import Allocator


def server_new_output(_, output: Output) -> None:
    print("New output")

    global allocator, renderer
	
    output.init_render(allocator, renderer)

    state = OutputState()
    state.set_enabled(True)
    if mode := output.preferred_mode():
        state.set_mode(mode)
    output.commit()
    state.finish()

    signal.raise_signal(signal.SIGTERM)


print("Starting")

display = Display()


backend = Backend(display)
backend.new_output_event.add(Listener(server_new_output))

renderer = Renderer.autocreate(backend)

allocator = Allocator.autocreate(backend, renderer)

backend.new_output_event.add(Listener(server_new_output))

backend.start()
display.run()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants