Skip to content

Conversation

ids1024
Copy link
Member

@ids1024 ids1024 commented Oct 5, 2022

This provides an example of how to use wayland_client with a foreign display, in particular GTK. If there is a better way to use wayland_client with GTK, the example can be improved.

I'm not sure if this use of prepare_read is correct. I guess it can't really run into issues given no other thread is actually reading from the connection? Should it instead create a guard before calling unix_fd_add_local, and replace it with a new guard every time the function is called?

This provides an example of how to use `wayland_client` with a foreign
display, in particular GTK. If there is a better way to use
`wayland_client` with GTK, the example can be improved.

I'm not sure if this use of `prepare_read` is correct. I guess it can't
really run into issues given no other thread is actually reading from
the connection? Should it instead create a guard before calling
`unix_fd_add_local`, and replace it with a new guard every time the
function is called?
@secext2022
Copy link

This example no longer work.

After modify a little to compile, it run with crash:

thread 'main' panicked at tmp/src/main.rs:81:35:
called `Option::unwrap()` on a `None` value

panic at this line:

    glib::source::unix_fd_add_local(fd, glib::IOCondition::IN, move |_, _| {
        connection.prepare_read().unwrap().read().unwrap();  // !! PANIC !!
        ControlFlow::Continue
    });

@secext2022
Copy link

This is the new working version:

    glib::source::unix_fd_add_local(fd, glib::IOCondition::IN, move |_, _| {
        if let Some(g) = connection.prepare_read() {
            g.read().unwrap();
        } else {
            connection.backend().dispatch_inner_queue().unwrap();
        }
        ControlFlow::Continue
    });

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

Successfully merging this pull request may close these issues.

2 participants