Skip to content

Commit

Permalink
Remove second thread from win32 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Osspial committed Nov 9, 2018
1 parent 64b8a9c commit 2e83bac
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 408 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ core-graphics = "0.17.3"
version = "0.3.6"
features = [
"combaseapi",
"commctrl",
"dwmapi",
"errhandlingapi",
"hidusage",
Expand Down
9 changes: 0 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,6 @@ impl EventLoop {
MonitorId { inner: self.events_loop.get_primary_monitor() }
}

/// Fetches all the events that are pending, calls the callback function for each of them,
/// and returns.
#[inline]
pub fn poll_events<F>(&mut self, callback: F)
where F: FnMut(Event)
{
self.events_loop.poll_events(callback)
}

/// Calls `callback` every time an event is received. If no event is available, sleeps the
/// current thread and waits for an event. If the callback returns `ControlFlow::Break` then
/// `run_forever` will immediately return.
Expand Down
19 changes: 14 additions & 5 deletions src/platform/windows/drop_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::os::windows::ffi::OsStringExt;
use std::path::PathBuf;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{mem, ptr};
use std::rc::Rc;
use std::cell::RefCell;

use winapi::ctypes::c_void;
use winapi::shared::guiddef::REFIID;
Expand All @@ -14,7 +16,6 @@ use winapi::um::oleidl::{IDropTarget, IDropTargetVtbl};
use winapi::um::winnt::HRESULT;
use winapi::um::{shellapi, unknwnbase};

use platform::platform::events_loop::send_event;
use platform::platform::WindowId;

use {Event, WindowId as SuperWindowId};
Expand All @@ -24,6 +25,7 @@ pub struct FileDropHandlerData {
pub interface: IDropTarget,
refcount: AtomicUsize,
window: HWND,
event_queue: Rc<RefCell<Vec<Event>>>,
}

pub struct FileDropHandler {
Expand All @@ -32,13 +34,14 @@ pub struct FileDropHandler {

#[allow(non_snake_case)]
impl FileDropHandler {
pub fn new(window: HWND) -> FileDropHandler {
pub fn new(window: HWND, event_queue: Rc<RefCell<Vec<Event>>>) -> FileDropHandler {
let data = Box::new(FileDropHandlerData {
interface: IDropTarget {
lpVtbl: &DROP_TARGET_VTBL as *const IDropTargetVtbl,
},
refcount: AtomicUsize::new(1),
window,
event_queue,
});
FileDropHandler {
data: Box::into_raw(data),
Expand Down Expand Up @@ -82,7 +85,7 @@ impl FileDropHandler {
use events::WindowEvent::HoveredFile;
let drop_handler = Self::from_interface(this);
Self::iterate_filenames(pDataObj, |filename| {
send_event(Event::WindowEvent {
drop_handler.send_event(Event::WindowEvent {
window_id: SuperWindowId(WindowId(drop_handler.window)),
event: HoveredFile(filename),
});
Expand All @@ -103,7 +106,7 @@ impl FileDropHandler {
pub unsafe extern "system" fn DragLeave(this: *mut IDropTarget) -> HRESULT {
use events::WindowEvent::HoveredFileCancelled;
let drop_handler = Self::from_interface(this);
send_event(Event::WindowEvent {
drop_handler.send_event(Event::WindowEvent {
window_id: SuperWindowId(WindowId(drop_handler.window)),
event: HoveredFileCancelled,
});
Expand All @@ -121,7 +124,7 @@ impl FileDropHandler {
use events::WindowEvent::DroppedFile;
let drop_handler = Self::from_interface(this);
let hdrop = Self::iterate_filenames(pDataObj, |filename| {
send_event(Event::WindowEvent {
drop_handler.send_event(Event::WindowEvent {
window_id: SuperWindowId(WindowId(drop_handler.window)),
event: DroppedFile(filename),
});
Expand Down Expand Up @@ -182,6 +185,12 @@ impl FileDropHandler {
}
}

impl FileDropHandlerData {
fn send_event(&self, event: Event) {
self.event_queue.borrow_mut().push(event);
}
}

impl Drop for FileDropHandler {
fn drop(&mut self) {
unsafe {
Expand Down
Loading

0 comments on commit 2e83bac

Please sign in to comment.