egui icon indicating copy to clipboard operation
egui copied to clipboard

File drag and drop not working under wayland

Open tfachmann opened this issue 2 years ago • 6 comments

Describe the bug Under wayland, File drag and drop is unrecognized. In particular, the following two interfaces are always empty:

&ctx.input().raw.hovered_files
&ctx.input().raw.dropped_files

To Reproduce Use the egui::DroppedFile interface under wayland.

Expected behavior Under wayland, raw.hovered_files and raw.dropped_files should be recognized and processed. Under the web, the events are recognized. Under Xwayland (via env -u WAYLAND_DISPLAY cargo run) the events are also recognized

Desktop (please complete the following information):

  • OS: 5.17.5-arch1-1
  • WM: sway version 1.7
  • Version: egui = "0.18.0" && eframe = "0.18.0"

Additional context

I tried forcing

let mut native_options = eframe::NativeOptions::default();
native_options.drag_and_drop_support = true;

with no luck.

tfachmann avatar May 03 '22 17:05 tfachmann

Do you get a WindowEvent::DroppedFile in egui-winit/src/lib.rs?

emilk avatar May 03 '22 18:05 emilk

How do I best test for this? I basically use the code provided here (under ui_file_drag_and_drop)

tfachmann avatar May 03 '22 19:05 tfachmann

Ok, I built it manually. This are prints of the Event under wayland:

Received Event: CursorMoved { device_id: DeviceId(Wayland(DeviceId)), position: PhysicalPosition { x: 75.5234375, y: 225.234375 }, modifiers: (empty) }
Received Event: CursorMoved { device_id: DeviceId(Wayland(DeviceId)), position: PhysicalPosition { x: 34.3203125, y: 235.41796875 }, modifiers: (empty) }
Received Event: CursorLeft { device_id: DeviceId(Wayland(DeviceId)) }
Received Event: Focused(false)
Received Event: Focused(true)
Received Event: ModifiersChanged((empty))
Received Event: CursorEntered { device_id: DeviceId(Wayland(DeviceId)) }
Received Event: CursorMoved { device_id: DeviceId(Wayland(DeviceId)), position: PhysicalPosition { x: 408.11328125, y: 212.62890625 }, modifiers: (empty) }

and this under Xwayland:

Received Event: AxisMotion { device_id: DeviceId(X(DeviceId(2))), axis: 0, value: 968.0 }
Received Event: AxisMotion { device_id: DeviceId(X(DeviceId(2))), axis: 1, value: 781.0 }
Received Event: ModifiersChanged((empty))
Received Event: Focused(false)
Received Event: Focused(true)
Received Event: CursorMoved { device_id: DeviceId(X(DeviceId(2))), position: PhysicalPosition { x: 3.0, y: 221.0 }, modifiers: (empty) }
Received Event: HoveredFile("/home/timo/bitmap.png")
Received Event: DroppedFile("/home/timo/bitmap.png")
Received Event: HoveredFileCancelled
Received Event: ModifiersChanged((empty))
Received Event: Focused(false)
Received Event: Focused(true)
Received Event: CursorMoved { device_id: DeviceId(X(DeviceId(2))), position: PhysicalPosition { x: 3.0, y: 221.0 }, modifiers: (empty) }
Received Event: CursorMoved { device_id: DeviceId(X(DeviceId(2))), position: PhysicalPosition { x: 427.0, y: 173.0 }, modifiers: (empty) }
Received Event: AxisMotion { device_id: DeviceId(X(DeviceId(2))), axis: 0, value: 1392.0 }

So indeed, no WindowEvent::DroppedFile is emitted

tfachmann avatar May 03 '22 19:05 tfachmann

Then that sounds like a bug in winit. I suggest making a simple drag-and-drop demo for winit (you can find some templates at https://github.com/rust-windowing/winit/tree/master/examples) and open an winit issue.

emilk avatar May 04 '22 07:05 emilk

Thanks for the clarification that it's the responsibility of winit. There is an open issue in for exactly that: https://github.com/rust-windowing/winit/issues/1881 Currently, it's just not implemented yet. If it is resolved, we can mark this issue as resolved as well.

tfachmann avatar May 04 '22 10:05 tfachmann

I think this is relevant docs drag and drop wayland

line 68 winit>src>lib.rs

    pub fn new_with_wayland_display(wayland_display: Option<*mut c_void>) -> Self {
        Self {
            start_time: instant::Instant::now(),
            egui_input: Default::default(),
            pointer_pos_in_points: None,
            any_pointer_button_down: false,
            current_cursor_icon: egui::CursorIcon::Default,
            current_pixels_per_point: 1.0,

            clipboard: clipboard::Clipboard::new(wayland_display),
            screen_reader: screen_reader::ScreenReader::default(),

            simulate_touch_screen: false,
            pointer_touch_id: None,
        }

thomas992 avatar May 31 '22 21:05 thomas992