Windows에서 Zipelo 창 위에 놓으면 기다리지 않고 끌기와 풀기를 바로 취소함
- 작성자
- 호시노 히나타
- 작성 시각
- 커밋
7b2f88bce9b4952770fa6724bc15702ba5fb43f2- 부모
- a659c09
변경된 파일 4개
+107-12| @@ -58,7 +58,7 @@ rfd = { version = "=0.16.0", optional = true, default-features = false } | ||
| 58 | 58 | [target.'cfg(target_os = "windows")'.dependencies] |
| 59 | 59 | wgpu = { version = "=30.0.1", optional = true, default-features = false, features = ["std", "dx12"] } |
| 60 | 60 | # 창 밖으로 끌어 놓기(지연 제공 IDataObject와 SHDoDragDrop). |
| 61 | 삭제: windows-sys = { version = "=0.61.2", optional = true, features = ["Win32_Foundation", "Win32_System_Com", "Win32_System_Memory", "Win32_System_Ole", "Win32_UI_Shell", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_WindowsAndMessaging"] } | |
| 61 | 추가: windows-sys = { version = "=0.61.2", optional = true, features = ["Win32_Foundation", "Win32_System_Com", "Win32_System_Memory", "Win32_System_Ole", "Win32_System_Threading", "Win32_UI_Shell", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_WindowsAndMessaging"] } | |
| 62 | 62 | eframe = { version = "=0.37.0", optional = true, default-features = false, features = ["wgpu_no_default_features"] } |
| 63 | 63 | |
| 64 | 64 | [[test]] |
| @@ -52,6 +52,36 @@ pub trait DragOut { | ||
| 52 | 52 | fn fail(&mut self); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 추가: /// 끌던 버튼을 놓았을 때 끌기를 어떻게 끝낼지. | |
| 56 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 57 | 추가: pub enum ReleaseAction { | |
| 58 | 추가: /// 다 풀렸으므로 놓기를 받아들임. | |
| 59 | 추가: Drop, | |
| 60 | 추가: /// 끌기와 풀기를 함께 취소함. | |
| 61 | 추가: Cancel, | |
| 62 | 추가: /// 아직 푸는 중이므로 다 풀릴 때까지 기다린 뒤 놓음. | |
| 63 | 추가: Wait, | |
| 64 | 추가: } | |
| 65 | 추가: | |
| 66 | 추가: /// 창 위에서 버튼을 놓았을 때의 처리를 정함. `ready`는 풀기 결과(풀리는 중이면 None, 다 | |
| 67 | 추가: /// 풀렸으면 Some(true), 실패했으면 Some(false)). Zipelo 창 위에 놓으면 받을 곳이 없으므로 | |
| 68 | 추가: /// 풀린 정도와 관계없이 기다리지 않고 바로 취소함(X11과 같음). | |
| 69 | 추가: pub fn release_action(ready: Option<bool>, over_own_window: bool) -> ReleaseAction { | |
| 70 | 추가: if over_own_window { | |
| 71 | 추가: return ReleaseAction::Cancel; | |
| 72 | 추가: } | |
| 73 | 추가: match ready { | |
| 74 | 추가: Some(true) => ReleaseAction::Drop, | |
| 75 | 추가: Some(false) => ReleaseAction::Cancel, | |
| 76 | 추가: None => ReleaseAction::Wait, | |
| 77 | 추가: } | |
| 78 | 추가: } | |
| 79 | 추가: | |
| 80 | 추가: /// 커서 아래 최상위 창의 소유 프로세스가 이 프로그램인지. 창이 없으면(None) 아님. | |
| 81 | 추가: pub fn is_own_window(owner_process: Option<u32>, own_process: u32) -> bool { | |
| 82 | 추가: owner_process == Some(own_process) | |
| 83 | 추가: } | |
| 84 | 추가: | |
| 55 | 85 | /// RFC 2483 text/uri-list 본문을 만듦. 경로의 각 바이트를 file URI 규칙으로 바꿈. |
| 56 | 86 | pub fn uri_list(paths: &[PathBuf]) -> String { |
| 57 | 87 | let mut text = String::new(); |
| @@ -88,3 +118,7 @@ pub fn file_uri(path: &Path) -> String { | ||
| 88 | 118 | #[cfg(test)] |
| 89 | 119 | #[path = "../../../tests/rust-app-ui/drag_out_uri.rs"] |
| 90 | 120 | mod tests; |
| 121 | 추가: | |
| 122 | 추가: #[cfg(test)] | |
| 123 | 추가: #[path = "../../../tests/rust-app-ui/drag_out_release.rs"] | |
| 124 | 추가: mod release_tests; |
| @@ -23,25 +23,31 @@ use std::{ | ||
| 23 | 23 | }; |
| 24 | 24 | use windows_sys::{ |
| 25 | 25 | Win32::{ |
| 26 | 삭제: Foundation::{DRAGDROP_S_CANCEL, DRAGDROP_S_DROP, DRAGDROP_S_USEDEFAULTCURSORS, HWND}, | |
| 26 | 추가: Foundation::{ | |
| 27 | 추가: DRAGDROP_S_CANCEL, DRAGDROP_S_DROP, DRAGDROP_S_USEDEFAULTCURSORS, HWND, POINT, | |
| 28 | 추가: }, | |
| 27 | 29 | System::{ |
| 28 | 30 | Com::{CLSCTX_INPROC_SERVER, CoCreateInstance}, |
| 29 | 31 | Memory::{GHND, GlobalAlloc, GlobalLock, GlobalUnlock}, |
| 30 | 32 | Ole::{CF_HDROP, DROPEFFECT, DROPEFFECT_COPY, DoDragDrop, OleInitialize}, |
| 33 | 추가: Threading::GetCurrentProcessId, | |
| 31 | 34 | }, |
| 32 | 35 | UI::{ |
| 33 | 36 | Input::KeyboardAndMouse::{GetAsyncKeyState, VK_ESCAPE, VK_LBUTTON, VK_RBUTTON}, |
| 34 | 37 | Shell::SHCreateStdEnumFmtEtc, |
| 35 | 38 | WindowsAndMessaging::{ |
| 36 | 삭제: DispatchMessageW, GetSystemMetrics, MSG, MsgWaitForMultipleObjects, PM_REMOVE, | |
| 37 | 삭제: PeekMessageW, PostQuitMessage, QS_ALLINPUT, SM_SWAPBUTTON, TranslateMessage, | |
| 38 | 삭제: WM_KEYDOWN, WM_QUIT, | |
| 39 | 추가: DispatchMessageW, GA_ROOT, GetAncestor, GetCursorPos, GetSystemMetrics, | |
| 40 | 추가: GetWindowThreadProcessId, MSG, MsgWaitForMultipleObjects, PM_REMOVE, PeekMessageW, | |
| 41 | 추가: PostQuitMessage, QS_ALLINPUT, SM_SWAPBUTTON, TranslateMessage, WM_KEYDOWN, WM_QUIT, | |
| 42 | 추가: WindowFromPoint, | |
| 39 | 43 | }, |
| 40 | 44 | }, |
| 41 | 45 | }, |
| 42 | 46 | core::{GUID, HRESULT}, |
| 43 | 47 | }; |
| 44 | 삭제: use zipelo_ui_memory_app::drag_out::{DragEvent, DragOut, Pump, PumpState}; | |
| 48 | 추가: use zipelo_ui_memory_app::drag_out::{ | |
| 49 | 추가: DragEvent, DragOut, Pump, PumpState, ReleaseAction, is_own_window, release_action, | |
| 50 | 추가: }; | |
| 45 | 51 | |
| 46 | 52 | thread_local! { |
| 47 | 53 | /// 끌기가 진행되는 동안(start 안에서만) 앱이 넘긴 작업 진행 함수. |
| @@ -194,6 +200,26 @@ fn pump_messages() -> bool { | ||
| 194 | 200 | cancel |
| 195 | 201 | } |
| 196 | 202 | |
| 203 | 추가: /// 커서 아래 최상위 창이 Zipelo 프로세스의 창인지. | |
| 204 | 추가: fn cursor_over_own_window() -> bool { | |
| 205 | 추가: // 안전성: 인자만 받는 Win32 상태 조회이며 POINT는 호출 동안 유효함. | |
| 206 | 추가: unsafe { | |
| 207 | 추가: let mut point = POINT { x: 0, y: 0 }; | |
| 208 | 추가: if GetCursorPos(&mut point) == 0 { | |
| 209 | 추가: return false; | |
| 210 | 추가: } | |
| 211 | 추가: let window = WindowFromPoint(point); | |
| 212 | 추가: if window.is_null() { | |
| 213 | 추가: return false; | |
| 214 | 추가: } | |
| 215 | 추가: let root = GetAncestor(window, GA_ROOT); | |
| 216 | 추가: let top = if root.is_null() { window } else { root }; | |
| 217 | 추가: let mut process = 0u32; | |
| 218 | 추가: GetWindowThreadProcessId(top, &mut process); | |
| 219 | 추가: is_own_window((process != 0).then_some(process), GetCurrentProcessId()) | |
| 220 | 추가: } | |
| 221 | 추가: } | |
| 222 | 추가: | |
| 197 | 223 | /// 메시지가 오거나 시간이 지날 때까지 기다림. |
| 198 | 224 | fn wait_messages(timeout: Duration) { |
| 199 | 225 | // 안전성: 기다릴 핸들 없이 메시지 도착만 기다림. |
| @@ -717,12 +743,21 @@ unsafe extern "system" fn query_continue_drag( | ||
| 717 | 743 | if keys & (MK_LBUTTON | MK_RBUTTON) != 0 { |
| 718 | 744 | return S_OK; |
| 719 | 745 | } |
| 720 | 삭제: // 버튼을 놓음: 다 풀린 뒤에 놓기를 완료함. | |
| 721 | 삭제: match source.ready() { | |
| 722 | 삭제: Some(true) => DRAGDROP_S_DROP, | |
| 723 | 삭제: Some(false) => DRAGDROP_S_CANCEL, | |
| 724 | 삭제: None if source.wait_for_files() => DRAGDROP_S_DROP, | |
| 725 | 삭제: None => DRAGDROP_S_CANCEL, | |
| 746 | 추가: // 버튼을 놓음: Zipelo 창 위면 기다리지 않고 끌기와 풀기를 함께 취소하고, 아니면 다 풀린 | |
| 747 | 추가: // 뒤에 놓기를 완료함. | |
| 748 | 추가: let over_own = cursor_over_own_window(); | |
| 749 | 추가: match release_action(source.ready(), over_own) { | |
| 750 | 추가: ReleaseAction::Drop => DRAGDROP_S_DROP, | |
| 751 | 추가: ReleaseAction::Cancel => { | |
| 752 | 추가: if over_own { | |
| 753 | 추가: zipelo_ui_memory_app::log_debug!("Zipelo 창 위에 놓음: 끌기와 풀기를 취소함"); | |
| 754 | 추가: } | |
| 755 | 추가: pump(true); | |
| 756 | 추가: source.set_ready(PumpState::Failed); | |
| 757 | 추가: DRAGDROP_S_CANCEL | |
| 758 | 추가: } | |
| 759 | 추가: ReleaseAction::Wait if source.wait_for_files() => DRAGDROP_S_DROP, | |
| 760 | 추가: ReleaseAction::Wait => DRAGDROP_S_CANCEL, | |
| 726 | 761 | } |
| 727 | 762 | } |
| 728 | 763 |
| @@ -0,0 +1,26 @@ | ||
| 1 | 추가: // 끌던 버튼을 놓을 때의 처리 판단 시험. drag_out.rs의 `release_tests` 모듈로 포함됨. | |
| 2 | 추가: use super::*; | |
| 3 | 추가: | |
| 4 | 추가: #[test] | |
| 5 | 추가: fn release_over_own_window_cancels_without_waiting() { | |
| 6 | 추가: // 아직 푸는 중이어도 기다리지 않고 바로 취소함. | |
| 7 | 추가: assert_eq!(release_action(None, true), ReleaseAction::Cancel); | |
| 8 | 추가: // 이미 다 풀렸어도 자기 창이면 받을 곳이 없으므로 취소함. | |
| 9 | 추가: assert_eq!(release_action(Some(true), true), ReleaseAction::Cancel); | |
| 10 | 추가: assert_eq!(release_action(Some(false), true), ReleaseAction::Cancel); | |
| 11 | 추가: } | |
| 12 | 추가: | |
| 13 | 추가: #[test] | |
| 14 | 추가: fn release_over_other_window_keeps_drop_and_wait() { | |
| 15 | 추가: assert_eq!(release_action(None, false), ReleaseAction::Wait); | |
| 16 | 추가: assert_eq!(release_action(Some(true), false), ReleaseAction::Drop); | |
| 17 | 추가: assert_eq!(release_action(Some(false), false), ReleaseAction::Cancel); | |
| 18 | 추가: } | |
| 19 | 추가: | |
| 20 | 추가: #[test] | |
| 21 | 추가: fn own_window_is_decided_by_owner_process() { | |
| 22 | 추가: assert!(is_own_window(Some(4242), 4242)); | |
| 23 | 추가: assert!(!is_own_window(Some(100), 4242)); | |
| 24 | 추가: // 커서 아래에 창이 없거나 소유자를 알 수 없으면 자기 창이 아님. | |
| 25 | 추가: assert!(!is_own_window(None, 4242)); | |
| 26 | 추가: } |