-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add dragging window with cursor feature #1840
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
1002f30
X11 implementation.
daxpedda a6a536d
Introduce example.
daxpedda 838d9ba
Wayland implementation.
daxpedda a24038a
Windows implementation.
daxpedda 8b268a0
Improve Wayland seat passing.
daxpedda b7e96ea
MacOS implementation.
daxpedda 6072a46
Correct windows implementation per specification.
daxpedda 35aa76f
Update dependency smithay-client-toolkit from branch to master.
daxpedda c8f7030
Fixed blocking thread in windows implementation.
daxpedda b58ca0d
Add multi-window example.
daxpedda 213af50
Move Wayland to a different PR.
daxpedda 47b223c
Fix CHANGELOG.
daxpedda a6694f8
Improve example.
daxpedda 487014f
Rename `set_drag_window` to `begin_drag`.
daxpedda bd7d4c8
Improve example.
daxpedda aae5d18
Fix CHANGELOG.
daxpedda 6e20839
Fix CHANGELOG.
daxpedda 5ec7722
Rename to `drag_window`.
daxpedda 8f49e37
Fix typo.
daxpedda cf90ed5
Re-introduce Wayland implementation.
daxpedda 8340572
Fixing Wayland build.
daxpedda 1b79efd
Fixing Wayland build.
daxpedda 65c5e06
Move SCTK to 0.12.3.
daxpedda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| use simple_logger::SimpleLogger; | ||
| use winit::{ | ||
| event::{ | ||
| ElementState, Event, KeyboardInput, MouseButton, StartCause, VirtualKeyCode, WindowEvent, | ||
| }, | ||
| event_loop::{ControlFlow, EventLoop}, | ||
| window::{Window, WindowBuilder, WindowId}, | ||
| }; | ||
|
|
||
| fn main() { | ||
| SimpleLogger::new().init().unwrap(); | ||
| let event_loop = EventLoop::new(); | ||
|
|
||
| let window_1 = WindowBuilder::new().build(&event_loop).unwrap(); | ||
| let window_2 = WindowBuilder::new().build(&event_loop).unwrap(); | ||
|
|
||
| let mut switched = false; | ||
| let mut entered_id = window_2.id(); | ||
|
|
||
| event_loop.run(move |event, _, control_flow| match event { | ||
| Event::NewEvents(StartCause::Init) => { | ||
| eprintln!("Switch which window is to be dragged by pressing \"x\".") | ||
| } | ||
| Event::WindowEvent { event, window_id } => match event { | ||
| WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, | ||
| WindowEvent::MouseInput { | ||
| state: ElementState::Pressed, | ||
| button: MouseButton::Left, | ||
| .. | ||
| } => { | ||
| let window = if (window_id == window_1.id() && switched) | ||
| || (window_id == window_2.id() && !switched) | ||
| { | ||
| &window_2 | ||
| } else { | ||
| &window_1 | ||
| }; | ||
|
|
||
| window.drag_window().unwrap() | ||
| } | ||
| WindowEvent::CursorEntered { .. } => { | ||
| entered_id = window_id; | ||
| name_windows(entered_id, switched, &window_1, &window_2) | ||
| } | ||
| WindowEvent::KeyboardInput { | ||
| input: | ||
| KeyboardInput { | ||
| state: ElementState::Released, | ||
| virtual_keycode: Some(VirtualKeyCode::X), | ||
| .. | ||
| }, | ||
| .. | ||
| } => { | ||
| switched = !switched; | ||
| name_windows(entered_id, switched, &window_1, &window_2); | ||
| println!("Switched!") | ||
| } | ||
| _ => (), | ||
| }, | ||
| _ => (), | ||
| }); | ||
| } | ||
|
|
||
| fn name_windows(window_id: WindowId, switched: bool, window_1: &Window, window_2: &Window) { | ||
| let (drag_target, other) = | ||
| if (window_id == window_1.id() && switched) || (window_id == window_2.id() && !switched) { | ||
| (&window_2, &window_1) | ||
| } else { | ||
| (&window_1, &window_2) | ||
| }; | ||
| drag_target.set_title("drag target"); | ||
| other.set_title("winit window"); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.