-
Notifications
You must be signed in to change notification settings - Fork 937
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add cursor position drag and drop events. * Reword drag events to match pointer ones. * appkit: Use `convertPoint_fromView` for coordinate conversion. * appkit: use ProtocolObject<dyn NSDraggingInfo>. * x11: store dnd.position as pair of i16 It's what translate_coords takes anyway, so the extra precision is misleading if we're going to cast it to i16 everywhere it's used. We can also simplify the "unpacking" from the XdndPosition message--we can and should use the value of 16 as the shift instead of size_of::<c_short> * 2 or something like that, because the specification gives us the constant 16. * x11: store translated DnD coords. * x11: don't emit DragLeave without DragEnter. * windows: only emit DragEnter if valid. * windows: in DnD, always set pdwEffect. It appears other apps (like Chromium) set pdwEffect on Drop too: https://github.com/chromium/chromium/blob/61a391b86bd946d6e1105412539e77ba9fb2a6b3/ui/base/dragdrop/drop_target_win.cc * docs: make it clearer that drag events are for dragged *files*. * examples/dnd: handle RedrawRequested event. Co-authored-by: amrbashir <[email protected]>
- Loading branch information
1 parent
77f1c73
commit f5dcd2a
Showing
11 changed files
with
327 additions
and
121 deletions.
There are no files selected for viewing
This file contains 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,64 @@ | ||
use std::error::Error; | ||
|
||
use winit::application::ApplicationHandler; | ||
use winit::event::WindowEvent; | ||
use winit::event_loop::{ActiveEventLoop, EventLoop}; | ||
use winit::window::{Window, WindowAttributes, WindowId}; | ||
|
||
#[path = "util/fill.rs"] | ||
mod fill; | ||
#[path = "util/tracing.rs"] | ||
mod tracing; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
tracing::init(); | ||
|
||
let event_loop = EventLoop::new()?; | ||
|
||
let app = Application::new(); | ||
Ok(event_loop.run_app(app)?) | ||
} | ||
|
||
/// Application state and event handling. | ||
struct Application { | ||
window: Option<Box<dyn Window>>, | ||
} | ||
|
||
impl Application { | ||
fn new() -> Self { | ||
Self { window: None } | ||
} | ||
} | ||
|
||
impl ApplicationHandler for Application { | ||
fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) { | ||
let window_attributes = | ||
WindowAttributes::default().with_title("Drag and drop files on me!"); | ||
self.window = Some(event_loop.create_window(window_attributes).unwrap()); | ||
} | ||
|
||
fn window_event( | ||
&mut self, | ||
event_loop: &dyn ActiveEventLoop, | ||
_window_id: WindowId, | ||
event: WindowEvent, | ||
) { | ||
match event { | ||
WindowEvent::DragLeft { .. } | ||
| WindowEvent::DragEntered { .. } | ||
| WindowEvent::DragMoved { .. } | ||
| WindowEvent::DragDropped { .. } => { | ||
println!("{:?}", event); | ||
}, | ||
WindowEvent::RedrawRequested => { | ||
let window = self.window.as_ref().unwrap(); | ||
window.pre_present_notify(); | ||
fill::fill_window(window.as_ref()); | ||
}, | ||
WindowEvent::CloseRequested => { | ||
event_loop.exit(); | ||
}, | ||
_ => {}, | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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.