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

Listen Wayland events #82

Open
MalpenZibo opened this issue Nov 1, 2024 · 20 comments · May be fixed by #86
Open

Listen Wayland events #82

MalpenZibo opened this issue Nov 1, 2024 · 20 comments · May be fixed by #86

Comments

@MalpenZibo
Copy link

It would be possibile to receive Wayland events? Like for example when a new wl_output appears?
Currently the pop_os iced fork has these kind of event but maybe without forking iced it's impossible to obtain the same results.

My use case would be to create a new surface when a new monitor is attached

@Decodetalkers
Copy link
Collaborator

Decodetalkers commented Nov 2, 2024

Emm. in layershellev, I will mark the manually created window..

If you want to follow the new screen, I think you can use StartMode::AllScreens, then a new layershell surface will becreated..

But iced_layershell does not support to pass wl_output to create surface.. so maybe it will be useless?

But if you want to listen to the event, maybe we need to make a pr to origin iced to let it allow use to add custom events to the iced::event

by the way, I have seen your pr in ashell, you set the startMode to active, that means the main layershells will only created on the activated screen, but if you set to AllScreens, the new layershell will be created follow the outputs

https://github.com/waycrate/lala-bar/blob/master/lala_bar/src/main.rs#L75

@MalpenZibo
Copy link
Author

Sadly I think the same, we have to request a change to iced.

I will try to avoid the necessity to get this information but for example in some situation I need to destroy the surface on the main monitor when an external one is connected and recreate the surface there

@Decodetalkers
Copy link
Collaborator

Decodetalkers commented Nov 2, 2024

Sadly I think the same, we have to request a change to iced.

I will try to avoid the necessity to get this information but for example in some situation I need to destroy the surface on the main monitor when an external one is connected and recreate the surface there

but the main layershell is not designed to be breaked.. Emm, and in iced, the renderer is binding to the first connected wl_surface, if it is brokened, it will panic

@Decodetalkers
Copy link
Collaborator

I have an idea, I will create a new crate to listen to these events and pass to iced

@Decodetalkers Decodetalkers linked a pull request Nov 9, 2024 that will close this issue
@Decodetalkers
Copy link
Collaborator

I add a new crate, and add a new feature, can you take a try? I think this will solve your problem

@MalpenZibo
Copy link
Author

I tried, but if I understand correctly, I should subscribe to the wayland event using the subscribe method in my application's subscription method. But the subscribe method is async, and the subscription method cannot be declared async because the MultiApplication trait doesn't declare that method async.

@Decodetalkers
Copy link
Collaborator

I tried, but if I understand correctly, I should subscribe to the wayland event using the subscribe method in my application's subscription method. But the subscribe method is async, and the subscription method cannot be declared async because the MultiApplication trait doesn't declare that method async.

A, sorry, that is a mistake, I will fix it

@Decodetalkers
Copy link
Collaborator

Decodetalkers commented Nov 10, 2024

Ok. I have fix it, you can try it again.

Now you can use the repo of that branch, and may you please take a try with the iced_layershell and that new crate of that branch?

@MalpenZibo
Copy link
Author

Ok, I tried.
I added a subscription and I tried to log the event but nothing happens if I attach/detach an external monitor

image
image

@Decodetalkers
Copy link
Collaborator

I don't know what is happened... I try to send the message in subscription(now I have changed it to listen), but after it successfully send the message, I cannot receive it . Can you help me resolve this problem?

@MalpenZibo
Copy link
Author

The problem is related to the subscription::channel loop being constantly busy. You can spot the problem by the fact that the CPU constantly runs. Everything works if you add a sleep(3000).await after the for event in current_events {.
I think that the problem is that the poll_connection.await; in my case is resolved instantly every time.

@Decodetalkers
Copy link
Collaborator

Decodetalkers commented Nov 11, 2024

ok, seems solved, thank you

@MalpenZibo
Copy link
Author

I see the changes, in this way every 10 ms we make a check, it would be nice to have the poll_connection work as intended. Anyway if it's impossible this change should resolve the issue!

@Decodetalkers
Copy link
Collaborator

I have met some problems... I write an example to use the wloutput from the subscriber, but then it panic at the process of getting layer surface, can you help take a look?

@Decodetalkers
Copy link
Collaborator

seems usable.. can you take a look?

@MalpenZibo
Copy link
Author

In the next few days I will be quite busy, I will try as soon as I can

@MalpenZibo
Copy link
Author

I tried to open a layer (using LayerOutputSetting::ChosenOutput(event) where event is what I receive in the iced_wayland_subscriber::WaylandEvents::OutputInsert) when a monitor is attached but the app crashed with this error

wl_display#1: error 1: invalid arguments for zwlr_layer_shell_v1#427.get_layer_surface
Io error: Invalid argument (os error 22)
Error trying to flush the wayland display: Invalid argument (os error 22)
Io error: Invalid argument (os error 22)
ERROR [ashell] Panic: panicked at /home/zibo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/blocking/shutdown.rs:51:21:
Cannot drop a runtime in a context where blocking is not allowed. This happens when a runtime is dropped from within an asynchronous context.
 disabled backtrace

@Decodetalkers
Copy link
Collaborator

Decodetalkers commented Nov 18, 2024

I tried to open a layer (using LayerOutputSetting::ChosenOutput(event) where event is what I receive in the iced_wayland_subscriber::WaylandEvents::OutputInsert) when a monitor is attached but the app crashed with this error

wl_display#1: error 1: invalid arguments for zwlr_layer_shell_v1#427.get_layer_surface
Io error: Invalid argument (os error 22)
Error trying to flush the wayland display: Invalid argument (os error 22)
Io error: Invalid argument (os error 22)
ERROR [ashell] Panic: panicked at /home/zibo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.41.1/src/runtime/blocking/shutdown.rs:51:21:
Cannot drop a runtime in a context where blocking is not allowed. This happens when a runtime is dropped from within an asynchronous context.
 disabled backtrace

Update to the latest, I have made some changes. I have already noticed this issue, so now I have fixed it. Seems the wl_output by another eventloop cannot be used, so instead I pass the name of xdg_output

@MalpenZibo
Copy link
Author

I tried the example. Now doesn't crash but on my laptop when I connect an external monitor I get the event but the topbar is rendered on the main screen two time and not on the external one.

@Decodetalkers
Copy link
Collaborator

I tried the example. Now doesn't crash but on my laptop when I connect an external monitor I get the event but the topbar is rendered on the main screen two time and not on the external one.

Now I do not have external monitor, sorry, if you can help me fix it , I will be glad

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

Successfully merging a pull request may close this issue.

2 participants