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

client: Add a GTK example #572

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

client: Add a GTK example #572

wants to merge 1 commit into from

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