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

Wayland support for set_cursor_icon #1204

Merged
merged 1 commit into from
Oct 3, 2019

Conversation

kchibisov
Copy link
Member

  • Tested on all platforms changed
  • Compilation warnings were addressed
  • cargo fmt has been run on this branch
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

Cursors' names were copied from X11 implementation, however some of them were truncated, but I've checked these cursors on X11 and Wayland and they were the same. I've also noticed that animated cursors don't work, but I feel like it's a SCTK problem.

P.s.
I've also added cursor grab to feature matrix, since it was recently implemented, but not added to matrix.

Copy link
Contributor

@elinorbgr elinorbgr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks ! 👍

The animation of the cursors is indeed something that will have to be fixed at SCTK's level.

@goddessfreya goddessfreya merged commit 5ced36e into rust-windowing:master Oct 3, 2019
@andersrein
Copy link
Contributor

andersrein commented Oct 3, 2019

EDIT: The top of the stack trace containing the error message was lost somewhere in the copy + past

Hate to be the bearer of bad news, but this broke my project because I am running set_cursor_visible and set_cursor_grab from another thread than the event loop. I am getting this error:

thread 'main' panicked at 'Trying to implement a proxy with a non-Send implementation from an other thread than the one of its event queue.', /home/are/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wayland-client-0.23.6/src/proxy.rs:392:13
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:200
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:214
   6: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:477
   7: std::panicking::begin_panic
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libstd/panicking.rs:411
   8: wayland_client::proxy::NewProxy<I>::implement_closure
             at /home/are/source/winit/<::std::macros::panic macros>:4
   9: winit::platform_impl::platform::wayland::pointer::implement_locked_pointer::{{closure}}
             at /home/are/source/winit/src/platform_impl/linux/wayland/pointer.rs:266
  10: core::result::Result<T,E>::map
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libcore/result.rs:460
  11: wayland_client::proxy::Proxy<I>::send_constructor
             at /home/are/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/wayland-client-0.23.6/src/proxy.rs:126
  12: wayland_protocols::unstable::pointer_constraints::v1::generated::client::zwp_pointer_constraints_v1::ZwpPointerConstraintsV1::lock_pointer
             at /home/are/source/yarve/target/debug/build/wayland-protocols-784ae8ed89f4c591/out/pointer-constraints-v1_client_api.rs:362
  13: winit::platform_impl::platform::wayland::pointer::implement_locked_pointer
             at /home/are/source/winit/src/platform_impl/linux/wayland/pointer.rs:265
  14: winit::platform_impl::platform::wayland::event_loop::CursorManager::grab_pointer::{{closure}}
             at /home/are/source/winit/src/platform_impl/linux/wayland/event_loop.rs:207
  15: core::option::Option<T>::and_then
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libcore/option.rs:624
  16: winit::platform_impl::platform::wayland::event_loop::CursorManager::grab_pointer
             at /home/are/source/winit/src/platform_impl/linux/wayland/event_loop.rs:201
  17: winit::platform_impl::platform::wayland::window::Window::set_cursor_grab
             at /home/are/source/winit/src/platform_impl/linux/wayland/window.rs:314
  18: winit::platform_impl::platform::Window::set_cursor_grab
             at /home/are/source/winit/src/platform_impl/linux/mod.rs:334
  19: winit::window::Window::set_cursor_grab
             at /home/are/source/winit/src/window.rs:664
  20: desktop_host::DesktopWindow::set_cursor_grab
             at desktop_host/src/lib.rs:220
  21: <desktop_host::DesktopHost as vrab::driver::RenderHost>::get_events
             at desktop_host/src/lib.rs:312
  22: vrab::driver::RenderDriver::run
             at /home/are/source/yarve/vrab/src/driver.rs:198
  23: cube::main
             at renderer/examples/cube.rs:230
  24: std::rt::lang_start::{{closure}}
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libstd/rt.rs:64
  25: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:49
  26: std::panicking::try::do_call
             at src/libstd/panicking.rs:296
  27: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:82
  28: std::panicking::try
             at src/libstd/panicking.rs:275
  29: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  30: std::rt::lang_start_internal
             at src/libstd/rt.rs:48
  31: std::rt::lang_start
             at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libstd/rt.rs:64
  32: main
  33: __libc_start_main
  34: _start

As far as I can see from the documentation you should be able to move the window to another thread:

If you need cross-thread access, the Window created from this EventsLoop can be sent to an other thread

Interestingly enough I tried the exact same thing of passing the cursor_manager to the window class in a mutex when I implemented the set_cursor_visible and the set_cursor_grab, but because of this error I had to to add some arguments to the giant closure in WindowStore::for_each.

@kchibisov
Copy link
Member Author

kchibisov commented Oct 3, 2019

@andersrein Would you mind sharing a code for me to repro this issue? I can't repro in alacritty btw. The initial approach with cusror_change and for_each thing wasn't working, because things were delayed with updates in some cases.

P.s. I've tested all the functions I've changed.

P.P.s. Ah, ok we're not moving windows between threads in alacritty. the code will be appreciated.

@andersrein
Copy link
Contributor

@kchibisov It is a fairly giant project. Let me see if I can hack together a minimal reproducible example

@kchibisov
Copy link
Member Author

@andersrein Ok, let me try something. Would you mind testing set_cursor_icon and set_cursor_visible?

@andersrein
Copy link
Contributor

I'm kind of new to github and open source contributing in general... What is the best way to just share a source file or a patch over github?

Anyway, I was able to reproduce it by modifying the cursor_grab example. Pasting the entire code into this comment:

use winit::{
    event::{DeviceEvent, ElementState, Event, KeyboardInput, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};

fn main() {
    let event_loop = EventLoop::new();

    let window = WindowBuilder::new()
        .with_title("Super Cursor Grab'n'Hide Simulator 9000")
        .build(&event_loop)
        .unwrap();

    let thread = std::thread::spawn(
        move || {
            println!("Waiting a bit before grabing and hiding cursor");
            std::thread::sleep(std::time::Duration::from_secs(5));
            println!("Grabing cursor now");
            window.set_cursor_grab(true).unwrap();
            window.set_cursor_visible(false);
        }
    );

    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Wait;
        match event {
            Event::WindowEvent { event, .. } => match event {
                WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
                WindowEvent::KeyboardInput {
                    input:
                        KeyboardInput {
                            state: ElementState::Released,
                            virtual_keycode: Some(key),
                            modifiers,
                            ..
                        },
                    ..
                } => {
                    use winit::event::VirtualKeyCode::*;
                    match key {
                        Escape => *control_flow = ControlFlow::Exit,
                        _ => (),
                    }
                }
                _ => (),
            },
            Event::DeviceEvent { event, .. } => match event {
                DeviceEvent::MouseMotion { delta } => println!("mouse moved: {:?}", delta),
                DeviceEvent::Button { button, state } => match state {
                    ElementState::Pressed => println!("mouse button {} pressed", button),
                    ElementState::Released => println!("mouse button {} released", button),
                },
                _ => (),
            },
            _ => (),
        }
    });
}

@kchibisov
Copy link
Member Author

@andersrein Ok, thx for the example. I've understood the issue and will send a fix soon.

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

Successfully merging this pull request may close these issues.

4 participants