Skip to content
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

Implement winapi dropping files #518

Merged
merged 1 commit into from
Jan 27, 2025
Merged
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ winapi = { version = "0.3", features = [
"windowsx",
"winbase",
"hidusage",
"shellapi",
] }

[target.'cfg(target_os = "android")'.dependencies]
Expand Down
23 changes: 22 additions & 1 deletion src/native/windows.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{ffi::OsString, os::windows::ffi::OsStringExt, path::PathBuf};

use crate::{
conf::{Conf, Icon},
event::{KeyMods, MouseButton},
Expand All @@ -8,13 +10,14 @@
use winapi::{
shared::{
hidusage::{HID_USAGE_GENERIC_MOUSE, HID_USAGE_PAGE_GENERIC},
minwindef::{DWORD, HIWORD, LOWORD, LPARAM, LRESULT, UINT, WPARAM},
minwindef::{DWORD, HIWORD, LOWORD, LPARAM, LRESULT, MAX_PATH, TRUE, UINT, WPARAM},
ntdef::NULL,
windef::{HBRUSH, HCURSOR, HDC, HICON, HWND, POINT, RECT},
windowsx::{GET_X_LPARAM, GET_Y_LPARAM},
},
um::{
libloaderapi::{GetModuleHandleW, GetProcAddress},
shellapi::{DragAcceptFiles, DragQueryFileW, HDROP},
shellscalingapi::*,
wingdi::*,
winuser::*,
Expand Down Expand Up @@ -160,7 +163,7 @@
unsafe {
#[cfg(target_arch = "x86_64")]
SetWindowLongPtrA(self.wnd, GWL_STYLE, win_style as _);
#[cfg(target_arch = "i686")]

Check warning on line 166 in src/native/windows.rs

View workflow job for this annotation

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

unexpected `cfg` condition value: `i686`

Check warning on line 166 in src/native/windows.rs

View workflow job for this annotation

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

unexpected `cfg` condition value: `i686`
SetWindowLong(self.wnd, GWL_STYLE, win_style as _);

if self.fullscreen {
Expand Down Expand Up @@ -511,6 +514,22 @@
WM_EXITSIZEMOVE | WM_EXITMENULOOP => {
KillTimer(hwnd, &mut payload.modal_resizing_timer as *mut _ as usize);
}
WM_DROPFILES => {
let hdrop = wparam as HDROP;
let mut path: [u16; MAX_PATH] = std::mem::uninitialized();

Check warning on line 519 in src/native/windows.rs

View workflow job for this annotation

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

use of deprecated function `std::mem::uninitialized`: use `mem::MaybeUninit` instead

Check warning on line 519 in src/native/windows.rs

View workflow job for this annotation

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

the type `[u16; 260]` does not permit being left uninitialized

Check warning on line 519 in src/native/windows.rs

View workflow job for this annotation

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

use of deprecated function `std::mem::uninitialized`: use `mem::MaybeUninit` instead

Check warning on line 519 in src/native/windows.rs

View workflow job for this annotation

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

the type `[u16; 260]` does not permit being left uninitialized
let num_drops = DragQueryFileW(hdrop, u32::MAX, std::ptr::null_mut(), 0);

let mut d = crate::native_display().lock().unwrap();
for i in 0..num_drops {
let path_len =
DragQueryFileW(hdrop, i, path.as_mut_ptr(), MAX_PATH as u32) as usize;
if path_len > 0 {
let path: PathBuf = OsString::from_wide(&path[0..path_len]).into();
d.dropped_files.bytes.push(std::fs::read(&path).unwrap());
d.dropped_files.paths.push(path);
}
}
}
_ => {}
}

Expand Down Expand Up @@ -693,6 +712,8 @@
let dc = GetDC(hwnd);
assert!(dc.is_null() == false);

DragAcceptFiles(hwnd, TRUE);

(hwnd, dc)
}

Expand Down Expand Up @@ -824,7 +845,7 @@

fn process_request(&mut self, request: Request) {
use Request::*;
unsafe {

Check warning on line 848 in src/native/windows.rs

View workflow job for this annotation

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

unnecessary `unsafe` block

Check warning on line 848 in src/native/windows.rs

View workflow job for this annotation

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

unnecessary `unsafe` block
match request {
ScheduleUpdate => {
self.update_requested = true;
Expand All @@ -838,7 +859,7 @@
} => self.set_window_size(new_width as _, new_height as _),
SetWindowPosition { new_x, new_y } => self.set_window_position(new_x, new_y),
SetFullscreen(fullscreen) => self.set_fullscreen(fullscreen),
ShowKeyboard(show) => {

Check warning on line 862 in src/native/windows.rs

View workflow job for this annotation

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

unused variable: `show`

Check warning on line 862 in src/native/windows.rs

View workflow job for this annotation

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

unused variable: `show`
eprintln!("Not implemented for windows")
}
}
Expand Down Expand Up @@ -917,7 +938,7 @@

#[cfg(target_arch = "x86_64")]
SetWindowLongPtrA(wnd, GWLP_USERDATA, &mut display as *mut _ as isize);
#[cfg(target_arch = "i686")]

Check warning on line 941 in src/native/windows.rs

View workflow job for this annotation

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

unexpected `cfg` condition value: `i686`

Check warning on line 941 in src/native/windows.rs

View workflow job for this annotation

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

unexpected `cfg` condition value: `i686`
SetWindowLong(wnd, GWLP_USERDATA, &mut display as *mut _ as isize);

let mut done = false;
Expand Down
Loading