Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
}
/// This for now is Android specific since the process can continue running but the display
/// is restarted. We support reinitializing the display.
fn set_or_replace_display(display: native::NativeDisplayData) {

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, aarch64-apple-ios)

function `set_or_replace_display` is never used

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-ios)

function `set_or_replace_display` is never used

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (macos-latest, x86_64-apple-darwin)

function `set_or_replace_display` is never used

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

function `set_or_replace_display` is never used

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu)

function `set_or_replace_display` is never used

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, wasm32-unknown-unknown)

function `set_or_replace_display` is never used

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

function `set_or_replace_display` is never used

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

function `set_or_replace_display` is never used

Check warning on line 102 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, armv7-unknown-linux-gnueabihf)

function `set_or_replace_display` is never used
if let Some(m) = NATIVE_DISPLAY.get() {
// Replace existing display
*m.lock().unwrap() = display;
Expand Down Expand Up @@ -298,15 +298,15 @@
}
pub fn dropped_file_count() -> usize {
let d = native_display().lock().unwrap();
d.dropped_files.bytes.len()
d.dropped_files.len()
}
pub fn dropped_file_bytes(index: usize) -> Option<Vec<u8>> {
let d = native_display().lock().unwrap();
d.dropped_files.bytes.get(index).cloned()
d.dropped_files.get(index).map(|file| file.bytes.clone())
}
pub fn dropped_file_path(index: usize) -> Option<std::path::PathBuf> {
let d = native_display().lock().unwrap();
d.dropped_files.paths.get(index).cloned()
d.dropped_files.get(index).map(|file| file.path.clone())
}

/// Show/hide onscreen keyboard.
Expand Down
10 changes: 5 additions & 5 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

use std::sync::mpsc;

#[derive(Default)]
pub(crate) struct DroppedFiles {
pub paths: Vec<std::path::PathBuf>,
pub bytes: Vec<Vec<u8>>,
pub(crate) struct DroppedFile {
pub path: std::path::PathBuf,
pub bytes: Vec<u8>,
}

pub(crate) struct NativeDisplayData {
pub screen_width: i32,
pub screen_height: i32,
Expand All @@ -17,7 +17,7 @@ pub(crate) struct NativeDisplayData {
pub quit_ordered: bool,
pub native_requests: mpsc::Sender<Request>,
pub clipboard: Box<dyn Clipboard>,
pub dropped_files: DroppedFiles,
pub dropped_files: Vec<DroppedFile>,
pub blocking_event_loop: bool,

#[cfg(target_vendor = "apple")]
Expand Down
5 changes: 2 additions & 3 deletions src/native/linux_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use libxkbcommon::*;

use crate::{
event::{EventHandler, KeyCode, KeyMods, MouseButton},
native::{egl, NativeDisplayData, Request},
native::{egl, DroppedFile, NativeDisplayData, Request},
};

use core::time::Duration;
Expand Down Expand Up @@ -1277,8 +1277,7 @@ where
for filename in filenames.lines() {
let path = std::path::PathBuf::from(filename);
if let Ok(bytes) = std::fs::read(&path) {
d.dropped_files.paths.push(path);
d.dropped_files.bytes.push(bytes);
d.dropped_files.push(DroppedFile { path, bytes });
}
}
// drop d since files_dropped_event is likely to need access to it
Expand Down
5 changes: 2 additions & 3 deletions src/native/linux_x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod xi_input;

use crate::{
event::EventHandler,
native::{egl, gl, module, NativeDisplayData, Request},
native::{egl, gl, module, DroppedFile, NativeDisplayData, Request},
CursorIcon,
};

Expand Down Expand Up @@ -203,8 +203,7 @@ impl X11Display {
for filename in filenames.lines() {
let path = std::path::PathBuf::from(filename);
if let Ok(bytes) = std::fs::read(&path) {
d.dropped_files.paths.push(path);
d.dropped_files.bytes.push(bytes);
d.dropped_files.push(DroppedFile { path, bytes });
}
}
// drop d since files_dropped_event is likely to need access to it
Expand Down
5 changes: 2 additions & 3 deletions src/native/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{

use crate::{
event::EventHandler,
native::{NativeDisplayData, Request},
native::{DroppedFile, NativeDisplayData, Request},
};

// fn dropped_file_count(&mut self) -> usize {
Expand Down Expand Up @@ -362,6 +362,5 @@ pub extern "C" fn on_file_dropped(
let path = PathBuf::from(unsafe { String::from_raw_parts(path, path_len, path_len) });
let bytes = unsafe { Vec::from_raw_parts(bytes, bytes_len, bytes_len) };

d.dropped_files.paths.push(path);
d.dropped_files.bytes.push(bytes);
d.dropped_files.push(DroppedFile { path, bytes });
}
9 changes: 6 additions & 3 deletions src/native/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{ffi::OsString, os::windows::ffi::OsStringExt, path::PathBuf};
use crate::{
conf::{Conf, Icon},
event::{KeyMods, MouseButton},
native::{NativeDisplayData, Request},
native::{DroppedFile, NativeDisplayData, Request},
CursorIcon, EventHandler,
};

Expand Down Expand Up @@ -520,6 +520,7 @@ unsafe extern "system" fn win32_wndproc(
let num_drops = DragQueryFileW(hdrop, u32::MAX, std::ptr::null_mut(), 0);

let mut d = crate::native_display().lock().unwrap();
d.dropped_files = Default::default();
for i in 0..num_drops {
let path_ptr = path.as_mut_ptr() as *mut u16;
let path_len = DragQueryFileW(hdrop, i, path_ptr, MAX_PATH as u32) as usize;
Expand All @@ -530,8 +531,10 @@ unsafe extern "system" fn win32_wndproc(
let path = path.assume_init();
PathBuf::from(OsString::from_wide(&path[0..path_len]))
};
d.dropped_files.bytes.push(std::fs::read(&path).unwrap());
d.dropped_files.paths.push(path);
d.dropped_files.push(DroppedFile {
bytes: std::fs::read(&path).unwrap(),
path,
});
}
}
}
Expand Down
Loading