Skip to content

Commit 2e83bac

Browse files
committedNov 9, 2018
Remove second thread from win32 backend
1 parent 64b8a9c commit 2e83bac

File tree

5 files changed

+299
-408
lines changed

5 files changed

+299
-408
lines changed
 

‎Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ core-graphics = "0.17.3"
3939
version = "0.3.6"
4040
features = [
4141
"combaseapi",
42+
"commctrl",
4243
"dwmapi",
4344
"errhandlingapi",
4445
"hidusage",

‎src/lib.rs

-9
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,6 @@ impl EventLoop {
240240
MonitorId { inner: self.events_loop.get_primary_monitor() }
241241
}
242242

243-
/// Fetches all the events that are pending, calls the callback function for each of them,
244-
/// and returns.
245-
#[inline]
246-
pub fn poll_events<F>(&mut self, callback: F)
247-
where F: FnMut(Event)
248-
{
249-
self.events_loop.poll_events(callback)
250-
}
251-
252243
/// Calls `callback` every time an event is received. If no event is available, sleeps the
253244
/// current thread and waits for an event. If the callback returns `ControlFlow::Break` then
254245
/// `run_forever` will immediately return.

‎src/platform/windows/drop_handler.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::os::windows::ffi::OsStringExt;
33
use std::path::PathBuf;
44
use std::sync::atomic::{AtomicUsize, Ordering};
55
use std::{mem, ptr};
6+
use std::rc::Rc;
7+
use std::cell::RefCell;
68

79
use winapi::ctypes::c_void;
810
use winapi::shared::guiddef::REFIID;
@@ -14,7 +16,6 @@ use winapi::um::oleidl::{IDropTarget, IDropTargetVtbl};
1416
use winapi::um::winnt::HRESULT;
1517
use winapi::um::{shellapi, unknwnbase};
1618

17-
use platform::platform::events_loop::send_event;
1819
use platform::platform::WindowId;
1920

2021
use {Event, WindowId as SuperWindowId};
@@ -24,6 +25,7 @@ pub struct FileDropHandlerData {
2425
pub interface: IDropTarget,
2526
refcount: AtomicUsize,
2627
window: HWND,
28+
event_queue: Rc<RefCell<Vec<Event>>>,
2729
}
2830

2931
pub struct FileDropHandler {
@@ -32,13 +34,14 @@ pub struct FileDropHandler {
3234

3335
#[allow(non_snake_case)]
3436
impl FileDropHandler {
35-
pub fn new(window: HWND) -> FileDropHandler {
37+
pub fn new(window: HWND, event_queue: Rc<RefCell<Vec<Event>>>) -> FileDropHandler {
3638
let data = Box::new(FileDropHandlerData {
3739
interface: IDropTarget {
3840
lpVtbl: &DROP_TARGET_VTBL as *const IDropTargetVtbl,
3941
},
4042
refcount: AtomicUsize::new(1),
4143
window,
44+
event_queue,
4245
});
4346
FileDropHandler {
4447
data: Box::into_raw(data),
@@ -82,7 +85,7 @@ impl FileDropHandler {
8285
use events::WindowEvent::HoveredFile;
8386
let drop_handler = Self::from_interface(this);
8487
Self::iterate_filenames(pDataObj, |filename| {
85-
send_event(Event::WindowEvent {
88+
drop_handler.send_event(Event::WindowEvent {
8689
window_id: SuperWindowId(WindowId(drop_handler.window)),
8790
event: HoveredFile(filename),
8891
});
@@ -103,7 +106,7 @@ impl FileDropHandler {
103106
pub unsafe extern "system" fn DragLeave(this: *mut IDropTarget) -> HRESULT {
104107
use events::WindowEvent::HoveredFileCancelled;
105108
let drop_handler = Self::from_interface(this);
106-
send_event(Event::WindowEvent {
109+
drop_handler.send_event(Event::WindowEvent {
107110
window_id: SuperWindowId(WindowId(drop_handler.window)),
108111
event: HoveredFileCancelled,
109112
});
@@ -121,7 +124,7 @@ impl FileDropHandler {
121124
use events::WindowEvent::DroppedFile;
122125
let drop_handler = Self::from_interface(this);
123126
let hdrop = Self::iterate_filenames(pDataObj, |filename| {
124-
send_event(Event::WindowEvent {
127+
drop_handler.send_event(Event::WindowEvent {
125128
window_id: SuperWindowId(WindowId(drop_handler.window)),
126129
event: DroppedFile(filename),
127130
});
@@ -182,6 +185,12 @@ impl FileDropHandler {
182185
}
183186
}
184187

188+
impl FileDropHandlerData {
189+
fn send_event(&self, event: Event) {
190+
self.event_queue.borrow_mut().push(event);
191+
}
192+
}
193+
185194
impl Drop for FileDropHandler {
186195
fn drop(&mut self) {
187196
unsafe {

0 commit comments

Comments
 (0)