rust-windowing / rust-windowing/winit

Left mouse button is not released after `Window::drag_window`.

Open
#2,999 14 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

DS - x11
Dominant language
Rust
Stars
6.2k
Forks
1.3k
Avg merge
2d 19h
Merged PRs (30d)
9

Description

After dragging a window using Window::drag_window, winit doesn't seem to release the left mouse button.

Here's an example. Run it and drag the content area (not the title bar) of the window.

use winit::event::{ElementState, Event, MouseButton, WindowEvent};
use winit::event_loop::EventLoop;
use winit::window::WindowBuilder;

fn main() {
    let event_loop = EventLoop::new();
    let window = WindowBuilder::new().build(&event_loop).unwrap();

    event_loop.run(move |event, _, control_flow| {
        let Event::WindowEvent { event, .. } = event else { return };
        match event {
            WindowEvent::CloseRequested => control_flow.set_exit(),
            WindowEvent::MouseInput {
                state,
                button: MouseButton::Left,
                ..
            } => {
                println!("state = {state:?}");
                if state == ElementState::Pressed {
                    window.drag_window().unwrap();
                }
            }
            _ => (),
        }
    });
}

You will get the following output.
As you can see, It doesn't print "state = Released" after "state = Pressed".

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 2.17s
     Running `target/debug/drag-window`
state = Pressed

My setup is:

winit: 0.28.6 with the default features
rustc: 1.71.0 (8ede3aae2 2023-07-12)
OS: Ubuntu 22.04.2 LTS
Kernel: Linux 5.19.0-50-generic
Architecture: x86-64
Window System: X11 (not Wayland)

#2192 and #2564 are relevant, but seem to be focused on Windows.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided minimal example under X11 and reproduce the missing release event. Start at the Window::drag_window entry point and review the related discussions in #2192 and #2564; done means the example prints both the pressed and released states after dragging.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, rust
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.