Wayland에서 목록 항목을 창 밖으로 끌어 놓아 풀기
- 선택한 행을 끌면 wl_data_device로 운영체제 끌기를 시작하고 선택 항목을 임시 폴더에 풂 - 받는 쪽에는 text/uri-list와 샌드박스 앱용 문서 포털 전송 키를 넘김 - 놓지 않고 취소하면 풀던 작업을 취소하며 결과 창을 띄우지 않음 - winit이 끌기 시작을 지원하지 않아 같은 Wayland 연결에 별도 큐와 포인터를 둠 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 작성자
- LeeJunyoung
- 작성 시각
- 커밋
485ace452e41881436d51421dd755e31f7d85624- 부모
- 28ce187
변경된 파일 11개
+834-9| @@ -64,6 +64,7 @@ main `3a77cfd`는 Windows 11 Pro build 26300과 Ubuntu 26.04.1 Wayland/X11에서 | ||
| 64 | 64 | |
| 65 | 65 | - **찾기:** 압축파일을 연 뒤 Ctrl+F를 누르면 지금 보고 있는 폴더 아래의 모든 하위 폴더에서 이름으로 찾고, Ctrl+Shift+F를 누르면 압축파일 전체 경로에서 찾습니다. 찾기 창의 결과를 두 번 누르거나 Enter를 누르면 그 위치로 이동합니다. |
| 66 | 66 | - **Esc:** 찾기 창, 작업 결과 창, 압축 파일 만들기 창 등 자식 창이 떠 있으면 그 창을 닫고, 아무 창도 없으면 프로그램을 종료합니다. 진행 중인 작업 창은 [취소] 버튼을 사용합니다. |
| 67 | 추가: - **끌어서 풀기(Ubuntu Wayland):** 목록에서 고른 파일과 폴더를 누른 채 창 밖으로 끌어 파일 관리자나 브라우저의 파일 올리기 영역에 놓으면, 압축파일 옆 Zipelo 임시 폴더에 풀린 뒤 받는 프로그램으로 넘어갑니다. 파일 관리자의 폴더 위에 놓으면 그 폴더 안에, 빈 곳에 놓으면 열린 폴더에 복사되며 이름이 겹칠 때의 처리(바꾸기, 건너뛰기, 이름 바꾸기)는 받는 프로그램이 정합니다. 스냅·Flatpak 앱에는 문서 포털로 넘깁니다. 임시 폴더는 Zipelo를 닫을 때 지웁니다. X11과 Windows에서는 아직 지원하지 않습니다. | |
| 67 | 68 | - **폴더 크기:** 목록의 폴더 크기를 0 B가 아닌, 안에 든 모든 파일 크기의 합으로 표시합니다. |
| 68 | 69 | - **로그:** 배포 빌드는 오류만 표준 오류에 남깁니다. 디버그 빌드는 작업 요청과 작업자 응답까지 자세히 남깁니다. 문제를 조사할 때는 `ZIPELO_LOG=debug zipelo`처럼 `ZIPELO_LOG`(off, error, warn, info, debug, trace)로 단계를 바꿀 수 있습니다. 암호는 어느 단계에서도 남기지 않습니다. |
| 69 | 70 |
| @@ -92,6 +92,10 @@ cargo +1.99.1 build --locked --manifest-path experiments/rust-ui-memory-app/Carg | ||
| 92 | 92 | - uninstall-ubuntu-missing: 이전 앱이 없어 복원하지 못한 경우의 터미널 안내 문구를 확인한다. |
| 93 | 93 | - uninstall-ubuntu-unknown-user: 제거 사용자를 확인하지 못해 설정을 유지하는 안내 문구를 확인한다. |
| 94 | 94 | |
| 95 | 추가: ## 창 밖으로 끌어서 풀기 | |
| 96 | 추가: | |
| 97 | 추가: Wayland에서 목록의 행을 누른 채 끌면 운영체제 끌어 놓기를 시작합니다. 선택하지 않은 행을 끌면 그 행만 선택합니다. 새 창, 버튼이나 문구는 없으며 풀기 진행 중에는 기존 작업 창이 보이고, 끝나면 결과 창 없이 받는 프로그램이 파일을 가져갑니다. 놓지 않고 취소하면 풀던 작업을 취소하며 취소 결과 창도 띄우지 않습니다. 화면 변화가 없으므로 상황은 추가하지 않았고, 흐름은 tests/rust-app-ui/drag_out_flow.rs의 가짜 끌기 구현으로 확인합니다. 실제 파일 관리자와 브라우저에 놓기는 Ubuntu Wayland 실기로 확인합니다. X11과 Windows에서는 행을 끌어도 아무 동작을 하지 않습니다. | |
| 98 | 추가: | |
| 95 | 99 | ## Esc 키 |
| 96 | 100 | |
| 97 | 101 | 자식 창(찾기 창, 작업 결과 창, 압축 파일 만들기 창, 미리보기, 암호 입력, 큰 작업 승인, 파일 충돌 선택, 종료 확인 등)이 떠 있으면 Esc는 그 창을 닫거나 취소합니다. 진행 중인 작업 창은 Esc로 닫지 않으며 [취소] 버튼을 사용합니다. 목록에 선택한 항목이 있으면 Esc는 먼저 선택을 해제하고, 입력란에 초점이 있으면 초점만 해제합니다. 아무 자식 창도 없으면 Esc로 프로그램을 종료하며, 작업 중이면 기존 종료 확인 창을 거칩니다. 미리보기 상황은 입력을 받지 않으므로 Esc 동작은 tests/rust-app-ui/explorer_selection.rs와 실제 실행으로 확인합니다. |
| @@ -4630,8 +4630,11 @@ dependencies = [ | ||
| 4630 | 4630 | "ashpd", |
| 4631 | 4631 | "eframe", |
| 4632 | 4632 | "pollster 0.4.0", |
| 4633 | 추가: "raw-window-handle", | |
| 4633 | 4634 | "rfd", |
| 4634 | 4635 | "sha2 0.10.9", |
| 4636 | 추가: "wayland-backend", | |
| 4637 | 추가: "wayland-client", | |
| 4635 | 4638 | "wgpu", |
| 4636 | 4639 | "zipelo-archive-worker", |
| 4637 | 4640 | ] |
| @@ -14,7 +14,7 @@ doctest = false | ||
| 14 | 14 | |
| 15 | 15 | [features] |
| 16 | 16 | default = [] |
| 17 | 삭제: ui = ["dep:eframe", "dep:wgpu", "dep:rfd", "dep:ashpd", "dep:pollster"] | |
| 17 | 추가: ui = ["dep:eframe", "dep:wgpu", "dep:rfd", "dep:ashpd", "dep:pollster", "dep:wayland-client", "dep:wayland-backend", "dep:raw-window-handle"] | |
| 18 | 18 | ui-fixture = ["ui"] |
| 19 | 19 | |
| 20 | 20 | [dependencies] |
| @@ -42,6 +42,10 @@ path = "../../tests/rust-app-real-worker/formats.rs" | ||
| 42 | 42 | [target.'cfg(target_os = "linux")'.dependencies] |
| 43 | 43 | ashpd = { version = "=0.11.1", optional = true, default-features = false, features = ["async-std"] } |
| 44 | 44 | pollster = { version = "=0.4.0", optional = true } |
| 45 | 추가: # 창 밖으로 끌어 놓기(Wayland wl_data_device). eframe/winit이 이미 쓰는 같은 버전을 씀. | |
| 46 | 추가: wayland-client = { version = "=0.31.15", optional = true } | |
| 47 | 추가: wayland-backend = { version = "=0.3.17", optional = true, features = ["client_system"] } | |
| 48 | 추가: raw-window-handle = { version = "=0.6.2", optional = true } | |
| 45 | 49 | rfd = { version = "=0.16.0", optional = true, default-features = false, features = ["xdg-portal", "async-std"] } |
| 46 | 50 | |
| 47 | 51 | [target.'cfg(not(target_os = "linux"))'.dependencies] |
| @@ -202,6 +202,8 @@ struct OpenRequest { | ||
| 202 | 202 | name: String, |
| 203 | 203 | destination: PathBuf, |
| 204 | 204 | automatic: bool, |
| 205 | 추가: /// 창 밖으로 끌어 놓으려고 푸는 경우, 받는 쪽에 넘길 항목(압축파일 안 경로). | |
| 206 | 추가: drag: Option<Vec<String>>, | |
| 205 | 207 | } |
| 206 | 208 | |
| 207 | 209 | /// 찾기 창(Ctrl+F, Ctrl+Shift+F) 크기. 검색어 입력란 아래로 결과 목록이 길게 이어지는 |
| @@ -315,6 +317,10 @@ pub struct ArchiveApp { | ||
| 315 | 317 | open_roots: Vec<(PathBuf, present::OpenRoot)>, |
| 316 | 318 | open_count: u64, |
| 317 | 319 | opener: Opener, |
| 320 | 추가: /// 운영체제 끌어 놓기 구현. 지원하지 않는 환경에서는 없음. | |
| 321 | 추가: drag_out: Option<Box<dyn crate::drag_out::DragOut>>, | |
| 322 | 추가: /// 끌기를 놓지 않고 취소해 풀던 작업을 취소했는지. 결과 창을 띄우지 않음. | |
| 323 | 추가: drag_cancelled: bool, | |
| 318 | 324 | find: FindState, |
| 319 | 325 | /// 이번 화면에서 목록 선택 해제 등 다른 곳이 Esc를 이미 처리했는지. |
| 320 | 326 | escape_handled: bool, |
| @@ -398,6 +404,8 @@ impl ArchiveApp { | ||
| 398 | 404 | open_roots: Vec::new(), |
| 399 | 405 | open_count: 0, |
| 400 | 406 | opener: Box::new(present::open_with_default), |
| 407 | 추가: drag_out: None, | |
| 408 | 추가: drag_cancelled: false, | |
| 401 | 409 | find: FindState::default(), |
| 402 | 410 | escape_handled: false, |
| 403 | 411 | focus_list: false, |
| @@ -450,9 +458,30 @@ impl ArchiveApp { | ||
| 450 | 458 | self.ui_error = Some(present::open_blocked_text(&name)); |
| 451 | 459 | return false; |
| 452 | 460 | } |
| 453 | 삭제: let Some(archive) = self.model.archive.clone() else { | |
| 461 | 추가: let Some(folder) = self.new_open_folder() else { | |
| 454 | 462 | return false; |
| 455 | 463 | }; |
| 464 | 추가: let request = OpenRequest { | |
| 465 | 추가: folder: folder.clone(), | |
| 466 | 추가: name: name.replace('\\', "/"), | |
| 467 | 추가: destination: std::mem::replace(&mut self.destination, folder), | |
| 468 | 추가: automatic: std::mem::replace(&mut self.automatic_destination, true), | |
| 469 | 추가: drag: None, | |
| 470 | 추가: }; | |
| 471 | 추가: self.opening = Some(request); | |
| 472 | 추가: if self.extract_selection(Selection::EntryIds(vec![entry_id])) { | |
| 473 | 추가: self.last_open = Some(entry_id); | |
| 474 | 추가: true | |
| 475 | 추가: } else { | |
| 476 | 추가: self.finish_open(false); | |
| 477 | 추가: false | |
| 478 | 추가: } | |
| 479 | 추가: } | |
| 480 | 추가: | |
| 481 | 추가: /// 압축파일별 임시 폴더 아래에 이번 열기(또는 끌어 놓기)용 새 하위 폴더 경로를 정함. | |
| 482 | 추가: /// 같은 파일을 여러 번 열어도 충돌하지 않도록 매번 새 하위 폴더에 풂. | |
| 483 | 추가: fn new_open_folder(&mut self) -> Option<PathBuf> { | |
| 484 | 추가: let archive = self.model.archive.clone()?; | |
| 456 | 485 | let root = match self.open_roots.iter().find(|(a, _)| *a == archive) { |
| 457 | 486 | Some((_, root)) if root.is_current() => root.path().to_path_buf(), |
| 458 | 487 | _ => match present::create_open_root(&archive) { |
| @@ -465,22 +494,79 @@ impl ArchiveApp { | ||
| 465 | 494 | Err(_) => { |
| 466 | 495 | self.dismissed = false; |
| 467 | 496 | self.ui_error = Some(present::FOLDER_ERROR.into()); |
| 468 | 삭제: return false; | |
| 497 | 추가: return None; | |
| 469 | 498 | } |
| 470 | 499 | }, |
| 471 | 500 | }; |
| 472 | 삭제: // 같은 파일을 여러 번 열어도 충돌하지 않도록 열 때마다 새 하위 폴더에 풂. | |
| 473 | 501 | self.open_count += 1; |
| 474 | 삭제: let folder = present::unique_folder(&root.join(self.open_count.to_string())); | |
| 502 | 추가: Some(present::unique_folder( | |
| 503 | 추가: &root.join(self.open_count.to_string()), | |
| 504 | 추가: )) | |
| 505 | 추가: } | |
| 506 | 추가: | |
| 507 | 추가: /// 운영체제 끌어 놓기 구현을 정함. Wayland처럼 지원하는 환경에서만 씀. | |
| 508 | 추가: pub fn set_drag_out(&mut self, drag_out: Box<dyn crate::drag_out::DragOut>) { | |
| 509 | 추가: self.drag_out = Some(drag_out); | |
| 510 | 추가: } | |
| 511 | 추가: | |
| 512 | 추가: /// 목록에서 선택한 항목을 창 밖으로 끌기 시작함. 운영체제 끌기를 시작한 뒤 선택 | |
| 513 | 추가: /// 항목을 임시 폴더에 풀고, 다 풀리면 받는 쪽에 파일 경로를 넘김. | |
| 514 | 추가: pub fn begin_drag_out(&mut self) -> bool { | |
| 515 | 추가: self.release_open(); | |
| 516 | 추가: if self.drag_out.is_none() | |
| 517 | 추가: || !self.model.can_extract() | |
| 518 | 추가: || self.opening.is_some() | |
| 519 | 추가: || self.model.selected.is_empty() | |
| 520 | 추가: { | |
| 521 | 추가: return false; | |
| 522 | 추가: } | |
| 523 | 추가: let gzip = self | |
| 524 | 추가: .model | |
| 525 | 추가: .list_id | |
| 526 | 추가: .as_ref() | |
| 527 | 추가: .is_some_and(|id| id.format == Format::Gzip); | |
| 528 | 추가: let names: Vec<String> = if gzip { | |
| 529 | 추가: vec![self.gzip_name.clone()] | |
| 530 | 추가: } else { | |
| 531 | 추가: browser::rows(&self.model.entries, &self.folder, &self.search) | |
| 532 | 추가: .into_iter() | |
| 533 | 추가: .filter(|row| !row.ids.is_empty() && row.ids.is_subset(&self.model.selected)) | |
| 534 | 추가: .map(|row| row.path) | |
| 535 | 추가: .collect() | |
| 536 | 추가: }; | |
| 537 | 추가: if names.is_empty() { | |
| 538 | 추가: return false; | |
| 539 | 추가: } | |
| 540 | 추가: if !self.drag_out.as_mut().is_some_and(|drag| drag.start()) { | |
| 541 | 추가: crate::log_warn!("운영체제 끌기를 시작하지 못함"); | |
| 542 | 추가: return false; | |
| 543 | 추가: } | |
| 544 | 추가: crate::log_debug!("창 밖으로 끌기 시작: {names:?}"); | |
| 545 | 추가: // 운영체제가 끌기를 넘겨받으면 버튼 놓기가 이 창에 오지 않으므로 대신 넣어 줌. | |
| 546 | 추가: self.release_after_move = true; | |
| 547 | 추가: self.marquee = None; | |
| 548 | 추가: self.drag_cancelled = false; | |
| 549 | 추가: self.last_open = None; | |
| 550 | 추가: let Some(folder) = self.new_open_folder() else { | |
| 551 | 추가: if let Some(drag) = self.drag_out.as_mut() { | |
| 552 | 추가: drag.fail(); | |
| 553 | 추가: } | |
| 554 | 추가: return false; | |
| 555 | 추가: }; | |
| 475 | 556 | let request = OpenRequest { |
| 476 | 557 | folder: folder.clone(), |
| 477 | 삭제: name: name.replace('\\', "/"), | |
| 558 | 추가: name: String::new(), | |
| 478 | 559 | destination: std::mem::replace(&mut self.destination, folder), |
| 479 | 560 | automatic: std::mem::replace(&mut self.automatic_destination, true), |
| 561 | 추가: drag: Some(names), | |
| 480 | 562 | }; |
| 481 | 563 | self.opening = Some(request); |
| 482 | 삭제: if self.extract_selection(Selection::EntryIds(vec![entry_id])) { | |
| 483 | 삭제: self.last_open = Some(entry_id); | |
| 564 | 추가: let selection = Selection::EntryIds( | |
| 565 | 추가: browser::expand_selection(&self.model.entries, &self.model.selected) | |
| 566 | 추가: .into_iter() | |
| 567 | 추가: .collect(), | |
| 568 | 추가: ); | |
| 569 | 추가: if self.extract_selection(selection) { | |
| 484 | 570 | true |
| 485 | 571 | } else { |
| 486 | 572 | self.finish_open(false); |
| @@ -488,6 +574,20 @@ impl ArchiveApp { | ||
| 488 | 574 | } |
| 489 | 575 | } |
| 490 | 576 | |
| 577 | 추가: /// 운영체제 끌기에서 온 사건을 처리함. | |
| 578 | 추가: fn poll_drag_out(&mut self) { | |
| 579 | 추가: while let Some(event) = self.drag_out.as_mut().and_then(|drag| drag.poll()) { | |
| 580 | 추가: crate::log_debug!("끌어 놓기 사건: {event:?}"); | |
| 581 | 추가: let dragging = self.opening.as_ref().is_some_and(|r| r.drag.is_some()); | |
| 582 | 추가: if event == crate::drag_out::DragEvent::Cancelled && dragging && self.model.busy() { | |
| 583 | 추가: // 받을 곳이 없으므로 풀던 작업을 취소하고 결과 창은 띄우지 않음. | |
| 584 | 추가: self.drag_cancelled = true; | |
| 585 | 추가: self.clear_password(); | |
| 586 | 추가: self.model.cancel(); | |
| 587 | 추가: } | |
| 588 | 추가: } | |
| 589 | 추가: } | |
| 590 | 추가: | |
| 491 | 591 | /// 한도를 늘려 다시 시도할 수 있는 결과가 화면에 남아 있는 동안은 열기 상태를 유지함. |
| 492 | 592 | fn open_retry_pending(&self) -> bool { |
| 493 | 593 | self.opening.is_some() && !self.dismissed && self.model.can_retry_expanded() |
| @@ -507,6 +607,34 @@ impl ArchiveApp { | ||
| 507 | 607 | }; |
| 508 | 608 | self.destination = request.destination; |
| 509 | 609 | self.automatic_destination = request.automatic; |
| 610 | 추가: if let Some(names) = request.drag { | |
| 611 | 추가: let cancelled = std::mem::take(&mut self.drag_cancelled); | |
| 612 | 추가: let paths: Vec<PathBuf> = names | |
| 613 | 추가: .iter() | |
| 614 | 추가: .map(|name| { | |
| 615 | 추가: name.split('/') | |
| 616 | 추가: .fold(request.folder.clone(), |path, part| path.join(part)) | |
| 617 | 추가: }) | |
| 618 | 추가: .filter(|path| completed && path.exists()) | |
| 619 | 추가: .collect(); | |
| 620 | 추가: let Some(drag) = self.drag_out.as_mut() else { | |
| 621 | 추가: return; | |
| 622 | 추가: }; | |
| 623 | 추가: if paths.is_empty() { | |
| 624 | 추가: drag.fail(); | |
| 625 | 추가: if cancelled { | |
| 626 | 추가: self.dismissed = true; | |
| 627 | 추가: } else if completed { | |
| 628 | 추가: self.ui_error = Some(present::OPEN_MISSING.into()); | |
| 629 | 추가: } | |
| 630 | 추가: } else { | |
| 631 | 추가: crate::log_debug!("끌어 놓을 파일 준비 끝: {}개", paths.len()); | |
| 632 | 추가: drag.provide(&paths); | |
| 633 | 추가: // 결과 창 없이 받는 쪽이 파일을 가져가게 함. | |
| 634 | 추가: self.dismissed = true; | |
| 635 | 추가: } | |
| 636 | 추가: return; | |
| 637 | 추가: } | |
| 510 | 638 | if !completed { |
| 511 | 639 | return; |
| 512 | 640 | } |
| @@ -1329,6 +1457,7 @@ impl ArchiveApp { | ||
| 1329 | 1457 | self.initialized = true; |
| 1330 | 1458 | } |
| 1331 | 1459 | self.poll(); |
| 1460 | 추가: self.poll_drag_out(); | |
| 1332 | 1461 | let preview_was_open = self.preview_open; |
| 1333 | 1462 | self.poll_picker(); |
| 1334 | 1463 | if self.model.challenge.is_some_and(|(_, _, encrypt)| encrypt) |
| @@ -2166,6 +2295,7 @@ impl ArchiveApp { | ||
| 2166 | 2295 | let mut open = None; |
| 2167 | 2296 | let mut open_file = None; |
| 2168 | 2297 | let mut menu_action = None; |
| 2298 | 추가: let mut drag_out = false; | |
| 2169 | 2299 | let mut next_offset = None; |
| 2170 | 2300 | let output = egui::ScrollArea::vertical() |
| 2171 | 2301 | .id_salt("archive-rows") |
| @@ -2260,7 +2390,10 @@ impl ArchiveApp { | ||
| 2260 | 2390 | .interact( |
| 2261 | 2391 | rect, |
| 2262 | 2392 | egui::Id::unique(("archive-row", &row.path)), |
| 2263 | 삭제: if active { | |
| 2393 | 추가: if active && self.drag_out.is_some() { | |
| 2394 | 추가: // 선택한 항목을 창 밖으로 끌어 놓을 수 있게 끌기도 받음. | |
| 2395 | 추가: egui::Sense::click_and_drag() | |
| 2396 | 추가: } else if active { | |
| 2264 | 2397 | egui::Sense::click() |
| 2265 | 2398 | } else { |
| 2266 | 2399 | egui::Sense::hover() |
| @@ -2305,6 +2438,13 @@ impl ArchiveApp { | ||
| 2305 | 2438 | modifiers.shift, |
| 2306 | 2439 | ); |
| 2307 | 2440 | } |
| 2441 | 추가: if active && self.drag_out.is_some() && response.drag_started() { | |
| 2442 | 추가: if !selected { | |
| 2443 | 추가: // 선택하지 않은 행을 끌면 그 행만 선택한 뒤 끎. | |
| 2444 | 추가: self.select_row(&rows, index, false, false); | |
| 2445 | 추가: } | |
| 2446 | 추가: drag_out = true; | |
| 2447 | 추가: } | |
| 2308 | 2448 | if response.double_clicked() { |
| 2309 | 2449 | if row.directory { |
| 2310 | 2450 | open = Some(row.path.clone()); |
| @@ -2503,6 +2643,9 @@ impl ArchiveApp { | ||
| 2503 | 2643 | if let Some(id) = open_file { |
| 2504 | 2644 | self.open_entry(id); |
| 2505 | 2645 | } |
| 2646 | 추가: if drag_out { | |
| 2647 | 추가: self.begin_drag_out(); | |
| 2648 | 추가: } | |
| 2506 | 2649 | match menu_action { |
| 2507 | 2650 | Some(MenuAction::NewFolder) => { |
| 2508 | 2651 | self.extract_to_new_folder(); |
| @@ -13,6 +13,9 @@ mod fake; | ||
| 13 | 13 | mod renderer; |
| 14 | 14 | #[path = "system_font.rs"] |
| 15 | 15 | mod system_font; |
| 16 | 추가: #[cfg(target_os = "linux")] | |
| 17 | 추가: #[path = "drag_out_wayland.rs"] | |
| 18 | 추가: mod drag_out_wayland; | |
| 16 | 19 | use eframe::egui; |
| 17 | 20 | fn main() -> eframe::Result { |
| 18 | 21 | zipelo_ui_memory_app::log_info!( |
| @@ -151,6 +154,11 @@ fn run() -> eframe::Result { | ||
| 151 | 154 | fixture, |
| 152 | 155 | ); |
| 153 | 156 | app.set_custom_frame(custom_frame); |
| 157 | 추가: // Wayland에서는 목록 항목을 창 밖으로 끌어 놓아 풀 수 있게 함. | |
| 158 | 추가: #[cfg(target_os = "linux")] | |
| 159 | 추가: if !fixture && let Some(drag) = drag_out_wayland::create(cc, cc.egui_ctx.clone()) { | |
| 160 | 추가: app.set_drag_out(Box::new(drag)); | |
| 161 | 추가: } | |
| 154 | 162 | app.set_work_window_in_parent(custom_frame); |
| 155 | 163 | Ok(Box::new(app)) |
| 156 | 164 | }) |
| @@ -0,0 +1,83 @@ | ||
| 1 | 추가: //! 압축파일 안 항목을 창 밖(파일 관리자, 브라우저 업로드 영역 등)으로 끌어 놓는 기능의 | |
| 2 | 추가: //! 운영체제 독립 부분. | |
| 3 | 추가: //! | |
| 4 | 추가: //! 끌기를 시작하면 앱은 선택 항목을 임시 폴더에 풀고, 받는 쪽이 데이터를 요청하면 풀린 | |
| 5 | 추가: //! 파일의 경로를 넘김. 실제 복사(폴더 위에 놓으면 그 폴더 안, 빈 곳이면 열린 폴더)와 | |
| 6 | 추가: //! 같은 이름 처리는 받는 프로그램이 함. 운영체제별 끌기 시작은 [`DragOut`] 구현이 맡음. | |
| 7 | 추가: | |
| 8 | 추가: use std::path::{Path, PathBuf}; | |
| 9 | 추가: | |
| 10 | 추가: /// 운영체제 끌기에서 앱이 알아야 하는 사건. | |
| 11 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 12 | 추가: pub enum DragEvent { | |
| 13 | 추가: /// 받는 쪽이 놓기를 받아들임. 이제 데이터를 요청하거나 이미 요청함. | |
| 14 | 추가: Dropped, | |
| 15 | 추가: /// 받는 쪽이 데이터를 다 받음. | |
| 16 | 추가: Finished, | |
| 17 | 추가: /// 놓지 않고 취소했거나 받는 쪽이 거절함. | |
| 18 | 추가: Cancelled, | |
| 19 | 추가: } | |
| 20 | 추가: | |
| 21 | 추가: /// 운영체제별 끌어 놓기 시작 구현. | |
| 22 | 추가: pub trait DragOut { | |
| 23 | 추가: /// 지금 누르고 있는 마우스 버튼으로 운영체제 끌기를 시작함. 시작하지 못하면 false. | |
| 24 | 추가: fn start(&mut self) -> bool; | |
| 25 | 추가: /// 지난 화면 이후 들어온 끌기 사건. | |
| 26 | 추가: fn poll(&mut self) -> Option<DragEvent>; | |
| 27 | 추가: /// 풀기가 끝난 파일과 폴더의 절대 경로를 넘김. 이미 들어온 요청과 이후 요청에 씀. | |
| 28 | 추가: fn provide(&mut self, paths: &[PathBuf]); | |
| 29 | 추가: /// 풀기에 실패함. 기다리는 요청에는 빈 목록을 보내고 끌기를 끝냄. | |
| 30 | 추가: fn fail(&mut self); | |
| 31 | 추가: } | |
| 32 | 추가: | |
| 33 | 추가: /// RFC 2483 text/uri-list 본문을 만듦. 경로의 각 바이트를 file URI 규칙으로 바꿈. | |
| 34 | 추가: pub fn uri_list(paths: &[PathBuf]) -> String { | |
| 35 | 추가: let mut text = String::new(); | |
| 36 | 추가: for path in paths { | |
| 37 | 추가: text.push_str(&file_uri(path)); | |
| 38 | 추가: text.push_str("\r\n"); | |
| 39 | 추가: } | |
| 40 | 추가: text | |
| 41 | 추가: } | |
| 42 | 추가: | |
| 43 | 추가: /// 절대 경로를 file:// URI로 바꿈. 영문, 숫자, '-', '.', '_', '~', '/'만 그대로 두고 | |
| 44 | 추가: /// 나머지 바이트(공백, 한글 UTF-8 등)는 %XX로 씀. | |
| 45 | 추가: pub fn file_uri(path: &Path) -> String { | |
| 46 | 추가: #[cfg(unix)] | |
| 47 | 추가: let bytes = { | |
| 48 | 추가: use std::os::unix::ffi::OsStrExt; | |
| 49 | 추가: path.as_os_str().as_bytes().to_vec() | |
| 50 | 추가: }; | |
| 51 | 추가: #[cfg(not(unix))] | |
| 52 | 추가: let bytes = path.to_string_lossy().replace('\\', "/").into_bytes(); | |
| 53 | 추가: let mut uri = String::from("file://"); | |
| 54 | 추가: #[cfg(not(unix))] | |
| 55 | 추가: uri.push('/'); | |
| 56 | 추가: for byte in bytes { | |
| 57 | 추가: if byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'.' | b'_' | b'~' | b'/') { | |
| 58 | 추가: uri.push(byte as char); | |
| 59 | 추가: } else { | |
| 60 | 추가: uri.push_str(&format!("%{byte:02X}")); | |
| 61 | 추가: } | |
| 62 | 추가: } | |
| 63 | 추가: uri | |
| 64 | 추가: } | |
| 65 | 추가: | |
| 66 | 추가: #[cfg(test)] | |
| 67 | 추가: mod tests { | |
| 68 | 추가: use super::*; | |
| 69 | 추가: | |
| 70 | 추가: #[cfg(unix)] | |
| 71 | 추가: #[test] | |
| 72 | 추가: fn uri_list_escapes_spaces_hangul_and_reserved_bytes() { | |
| 73 | 추가: let paths = [ | |
| 74 | 추가: PathBuf::from("/tmp/여행 자료/a#b.txt"), | |
| 75 | 추가: PathBuf::from("/tmp/x/폴더"), | |
| 76 | 추가: ]; | |
| 77 | 추가: assert_eq!( | |
| 78 | 추가: uri_list(&paths), | |
| 79 | 추가: "file:///tmp/%EC%97%AC%ED%96%89%20%EC%9E%90%EB%A3%8C/a%23b.txt\r\n\ | |
| 80 | 추가: file:///tmp/x/%ED%8F%B4%EB%8D%94\r\n" | |
| 81 | 추가: ); | |
| 82 | 추가: } | |
| 83 | 추가: } |
| @@ -0,0 +1,407 @@ | ||
| 1 | 추가: //! Wayland에서 압축파일 안 항목을 창 밖으로 끌어 놓기. | |
| 2 | 추가: //! | |
| 3 | 추가: //! winit은 끌어 놓기를 받기만 하고 시작하지는 못하므로, winit이 쓰는 같은 Wayland 연결에 | |
| 4 | 추가: //! 별도 이벤트 큐를 만들어 wl_data_device로 직접 끌기를 시작함. 끌기 시작에는 버튼을 누른 | |
| 5 | 추가: //! 순간의 serial이 필요하므로 같은 seat에서 포인터를 하나 더 받아 왼쪽 버튼 누름을 기억함. | |
| 6 | 추가: //! | |
| 7 | 추가: //! 받는 쪽에는 text/uri-list(풀린 파일 경로)와, 샌드박스 앱(스냅·Flatpak 브라우저 등)을 | |
| 8 | 추가: //! 위한 application/vnd.portal.filetransfer(문서 포털 전송 키)를 함께 제공함. | |
| 9 | 추가: | |
| 10 | 추가: use std::{ | |
| 11 | 추가: collections::VecDeque, | |
| 12 | 추가: io::Write, | |
| 13 | 추가: os::fd::OwnedFd, | |
| 14 | 추가: path::PathBuf, | |
| 15 | 추가: sync::{Arc, Mutex}, | |
| 16 | 추가: }; | |
| 17 | 추가: use wayland_client::{ | |
| 18 | 추가: Connection, Dispatch, Proxy, QueueHandle, WEnum, event_created_child, | |
| 19 | 추가: protocol::{ | |
| 20 | 추가: wl_data_device, wl_data_device_manager, wl_data_offer, wl_data_source, wl_pointer, | |
| 21 | 추가: wl_registry, wl_seat, wl_surface, | |
| 22 | 추가: }, | |
| 23 | 추가: }; | |
| 24 | 추가: use zipelo_ui_memory_app::drag_out::{DragEvent, DragOut, uri_list}; | |
| 25 | 추가: | |
| 26 | 추가: const URI_LIST: &str = "text/uri-list"; | |
| 27 | 추가: const PORTAL: &str = "application/vnd.portal.filetransfer"; | |
| 28 | 추가: /// linux/input-event-codes.h의 BTN_LEFT. | |
| 29 | 추가: const BTN_LEFT: u32 = 0x110; | |
| 30 | 추가: | |
| 31 | 추가: enum Ready { | |
| 32 | 추가: Paths(Vec<PathBuf>), | |
| 33 | 추가: Failed, | |
| 34 | 추가: } | |
| 35 | 추가: | |
| 36 | 추가: #[derive(Default)] | |
| 37 | 추가: struct Shared { | |
| 38 | 추가: /// 이 창 위에서 누르고 있는 왼쪽 버튼의 serial. | |
| 39 | 추가: press: Option<u32>, | |
| 40 | 추가: /// 파일이 준비되기 전에 들어온 데이터 요청. | |
| 41 | 추가: pending: Vec<(String, OwnedFd)>, | |
| 42 | 추가: ready: Option<Ready>, | |
| 43 | 추가: events: VecDeque<DragEvent>, | |
| 44 | 추가: source: Option<wl_data_source::WlDataSource>, | |
| 45 | 추가: } | |
| 46 | 추가: | |
| 47 | 추가: struct State { | |
| 48 | 추가: shared: Arc<Mutex<Shared>>, | |
| 49 | 추가: surface: wl_surface::WlSurface, | |
| 50 | 추가: focused: bool, | |
| 51 | 추가: seat: Option<wl_seat::WlSeat>, | |
| 52 | 추가: manager: Option<wl_data_device_manager::WlDataDeviceManager>, | |
| 53 | 추가: pointer: Option<wl_pointer::WlPointer>, | |
| 54 | 추가: repaint: eframe::egui::Context, | |
| 55 | 추가: } | |
| 56 | 추가: | |
| 57 | 추가: pub struct WaylandDrag { | |
| 58 | 추가: conn: Connection, | |
| 59 | 추가: qh: QueueHandle<State>, | |
| 60 | 추가: manager: wl_data_device_manager::WlDataDeviceManager, | |
| 61 | 추가: device: wl_data_device::WlDataDevice, | |
| 62 | 추가: surface: wl_surface::WlSurface, | |
| 63 | 추가: shared: Arc<Mutex<Shared>>, | |
| 64 | 추가: /// 문서 포털 전송을 쓸 수 있는지. 시작을 늦추지 않도록 따로 확인함. | |
| 65 | 추가: portal: Arc<std::sync::atomic::AtomicBool>, | |
| 66 | 추가: } | |
| 67 | 추가: | |
| 68 | 추가: /// 창이 Wayland 창이면 끌어 놓기 구현을 만듦. 아니면(X11, Windows) None. | |
| 69 | 추가: pub fn create( | |
| 70 | 추가: handles: &(impl raw_window_handle::HasDisplayHandle + raw_window_handle::HasWindowHandle), | |
| 71 | 추가: repaint: eframe::egui::Context, | |
| 72 | 추가: ) -> Option<WaylandDrag> { | |
| 73 | 추가: use raw_window_handle::{RawDisplayHandle, RawWindowHandle}; | |
| 74 | 추가: let RawDisplayHandle::Wayland(display) = handles.display_handle().ok()?.as_raw() else { | |
| 75 | 추가: return None; | |
| 76 | 추가: }; | |
| 77 | 추가: let RawWindowHandle::Wayland(window) = handles.window_handle().ok()?.as_raw() else { | |
| 78 | 추가: return None; | |
| 79 | 추가: }; | |
| 80 | 추가: // 안전성: winit이 만든 wl_display와 wl_surface는 창이 살아 있는 동안 유효함. | |
| 81 | 추가: // 앱은 창과 같은 수명으로 이 구현을 들고 있으며, 외부 디스플레이는 닫지 않음. | |
| 82 | 추가: let backend = unsafe { | |
| 83 | 추가: wayland_backend::sys::client::Backend::from_foreign_display(display.display.as_ptr().cast()) | |
| 84 | 추가: }; | |
| 85 | 추가: let conn = Connection::from_backend(backend); | |
| 86 | 추가: let surface_id = unsafe { | |
| 87 | 추가: wayland_backend::sys::client::ObjectId::from_ptr( | |
| 88 | 추가: wl_surface::WlSurface::interface(), | |
| 89 | 추가: window.surface.as_ptr().cast(), | |
| 90 | 추가: ) | |
| 91 | 추가: } | |
| 92 | 추가: .ok()?; | |
| 93 | 추가: let surface = wl_surface::WlSurface::from_id(&conn, surface_id).ok()?; | |
| 94 | 추가: let mut queue = conn.new_event_queue::<State>(); | |
| 95 | 추가: let qh = queue.handle(); | |
| 96 | 추가: let shared = Arc::new(Mutex::new(Shared::default())); | |
| 97 | 추가: let mut state = State { | |
| 98 | 추가: shared: shared.clone(), | |
| 99 | 추가: surface: surface.clone(), | |
| 100 | 추가: focused: false, | |
| 101 | 추가: seat: None, | |
| 102 | 추가: manager: None, | |
| 103 | 추가: pointer: None, | |
| 104 | 추가: repaint, | |
| 105 | 추가: }; | |
| 106 | 추가: conn.display().get_registry(&qh, ()); | |
| 107 | 추가: queue.roundtrip(&mut state).ok()?; | |
| 108 | 추가: // seat의 포인터 지원 여부를 받음. | |
| 109 | 추가: queue.roundtrip(&mut state).ok()?; | |
| 110 | 추가: let manager = state.manager.clone()?; | |
| 111 | 추가: let device = manager.get_data_device(state.seat.as_ref()?, &qh, ()); | |
| 112 | 추가: queue.roundtrip(&mut state).ok()?; | |
| 113 | 추가: let portal = Arc::new(std::sync::atomic::AtomicBool::new(false)); | |
| 114 | 추가: let found = portal.clone(); | |
| 115 | 추가: let _ = std::thread::Builder::new() | |
| 116 | 추가: .name("zipelo-portal-check".into()) | |
| 117 | 추가: .spawn(move || { | |
| 118 | 추가: let available = pollster::block_on(ashpd::documents::FileTransfer::new()).is_ok(); | |
| 119 | 추가: zipelo_ui_memory_app::log_debug!("문서 포털 전송 사용 가능: {available}"); | |
| 120 | 추가: found.store(available, std::sync::atomic::Ordering::Release); | |
| 121 | 추가: }); | |
| 122 | 추가: zipelo_ui_memory_app::log_debug!( | |
| 123 | 추가: "Wayland 끌어 놓기 준비 (데이터 장치 v{})", | |
| 124 | 추가: manager.version() | |
| 125 | 추가: ); | |
| 126 | 추가: std::thread::Builder::new() | |
| 127 | 추가: .name("zipelo-wayland-drag".into()) | |
| 128 | 추가: .spawn(move || { | |
| 129 | 추가: loop { | |
| 130 | 추가: if let Err(error) = queue.blocking_dispatch(&mut state) { | |
| 131 | 추가: zipelo_ui_memory_app::log_warn!("Wayland 끌어 놓기 큐 종료: {error}"); | |
| 132 | 추가: break; | |
| 133 | 추가: } | |
| 134 | 추가: } | |
| 135 | 추가: }) | |
| 136 | 추가: .ok()?; | |
| 137 | 추가: Some(WaylandDrag { | |
| 138 | 추가: conn, | |
| 139 | 추가: qh, | |
| 140 | 추가: manager, | |
| 141 | 추가: device, | |
| 142 | 추가: surface, | |
| 143 | 추가: shared, | |
| 144 | 추가: portal, | |
| 145 | 추가: }) | |
| 146 | 추가: } | |
| 147 | 추가: | |
| 148 | 추가: impl DragOut for WaylandDrag { | |
| 149 | 추가: fn start(&mut self) -> bool { | |
| 150 | 추가: let mut shared = self.shared.lock().unwrap(); | |
| 151 | 추가: let Some(serial) = shared.press else { | |
| 152 | 추가: zipelo_ui_memory_app::log_debug!("끌기 시작 실패: 누르고 있는 버튼 없음"); | |
| 153 | 추가: return false; | |
| 154 | 추가: }; | |
| 155 | 추가: if let Some(old) = shared.source.take() { | |
| 156 | 추가: old.destroy(); | |
| 157 | 추가: } | |
| 158 | 추가: shared.pending.clear(); | |
| 159 | 추가: shared.ready = None; | |
| 160 | 추가: shared.events.clear(); | |
| 161 | 추가: let source = self.manager.create_data_source(&self.qh, ()); | |
| 162 | 추가: source.offer(URI_LIST.into()); | |
| 163 | 추가: if self.portal.load(std::sync::atomic::Ordering::Acquire) { | |
| 164 | 추가: source.offer(PORTAL.into()); | |
| 165 | 추가: } | |
| 166 | 추가: if source.version() >= 3 { | |
| 167 | 추가: source.set_actions(wl_data_device_manager::DndAction::Copy); | |
| 168 | 추가: } | |
| 169 | 추가: self.device | |
| 170 | 추가: .start_drag(Some(&source), &self.surface, None, serial); | |
| 171 | 추가: shared.source = Some(source); | |
| 172 | 추가: drop(shared); | |
| 173 | 추가: self.conn.flush().is_ok() | |
| 174 | 추가: } | |
| 175 | 추가: | |
| 176 | 추가: fn poll(&mut self) -> Option<DragEvent> { | |
| 177 | 추가: self.shared.lock().unwrap().events.pop_front() | |
| 178 | 추가: } | |
| 179 | 추가: | |
| 180 | 추가: fn provide(&mut self, paths: &[PathBuf]) { | |
| 181 | 추가: let pending = { | |
| 182 | 추가: let mut shared = self.shared.lock().unwrap(); | |
| 183 | 추가: shared.ready = Some(Ready::Paths(paths.to_vec())); | |
| 184 | 추가: std::mem::take(&mut shared.pending) | |
| 185 | 추가: }; | |
| 186 | 추가: for (mime, fd) in pending { | |
| 187 | 추가: send(mime, fd, paths.to_vec()); | |
| 188 | 추가: } | |
| 189 | 추가: } | |
| 190 | 추가: | |
| 191 | 추가: fn fail(&mut self) { | |
| 192 | 추가: let mut shared = self.shared.lock().unwrap(); | |
| 193 | 추가: shared.ready = Some(Ready::Failed); | |
| 194 | 추가: // 기다리던 요청은 fd를 닫아 빈 데이터로 끝냄. | |
| 195 | 추가: shared.pending.clear(); | |
| 196 | 추가: } | |
| 197 | 추가: } | |
| 198 | 추가: | |
| 199 | 추가: /// 받는 쪽이 요청한 형식으로 데이터를 써 줌. 받는 쪽이 늦게 읽어도 화면이 멈추지 않게 | |
| 200 | 추가: /// 별도 스레드에서 씀. | |
| 201 | 추가: fn send(mime: String, fd: OwnedFd, paths: Vec<PathBuf>) { | |
| 202 | 추가: let _ = std::thread::Builder::new() | |
| 203 | 추가: .name("zipelo-wayland-send".into()) | |
| 204 | 추가: .spawn(move || { | |
| 205 | 추가: let data = if mime == PORTAL { | |
| 206 | 추가: match portal_key(&paths) { | |
| 207 | 추가: Ok(key) => key, | |
| 208 | 추가: Err(error) => { | |
| 209 | 추가: zipelo_ui_memory_app::log_warn!("문서 포털 전송 실패: {error}"); | |
| 210 | 추가: return; | |
| 211 | 추가: } | |
| 212 | 추가: } | |
| 213 | 추가: } else { | |
| 214 | 추가: uri_list(&paths) | |
| 215 | 추가: }; | |
| 216 | 추가: let mut file = std::fs::File::from(fd); | |
| 217 | 추가: if let Err(error) = file.write_all(data.as_bytes()) { | |
| 218 | 추가: zipelo_ui_memory_app::log_warn!("끌어 놓기 데이터 쓰기 실패: {error}"); | |
| 219 | 추가: } | |
| 220 | 추가: }); | |
| 221 | 추가: } | |
| 222 | 추가: | |
| 223 | 추가: /// 문서 포털에 파일을 올리고 받는 쪽에 넘길 전송 키를 만듦. | |
| 224 | 추가: fn portal_key(paths: &[PathBuf]) -> Result<String, String> { | |
| 225 | 추가: use std::os::unix::fs::OpenOptionsExt; | |
| 226 | 추가: let files = paths | |
| 227 | 추가: .iter() | |
| 228 | 추가: .map(|path| { | |
| 229 | 추가: // 폴더도 넘길 수 있도록 O_PATH로 엶. | |
| 230 | 추가: std::fs::OpenOptions::new() | |
| 231 | 추가: .read(true) | |
| 232 | 추가: .custom_flags(0o10000000 | 0o2000000) | |
| 233 | 추가: .open(path) | |
| 234 | 추가: }) | |
| 235 | 추가: .collect::<Result<Vec<_>, _>>() | |
| 236 | 추가: .map_err(|error| error.to_string())?; | |
| 237 | 추가: pollster::block_on(async { | |
| 238 | 추가: let transfer = ashpd::documents::FileTransfer::new().await?; | |
| 239 | 추가: let key = transfer.start_transfer(false, true).await?; | |
| 240 | 추가: transfer.add_files(&key, &files).await?; | |
| 241 | 추가: Ok::<_, ashpd::Error>(key) | |
| 242 | 추가: }) | |
| 243 | 추가: .map_err(|error| error.to_string()) | |
| 244 | 추가: } | |
| 245 | 추가: | |
| 246 | 추가: impl Dispatch<wl_registry::WlRegistry, ()> for State { | |
| 247 | 추가: fn event( | |
| 248 | 추가: state: &mut Self, | |
| 249 | 추가: registry: &wl_registry::WlRegistry, | |
| 250 | 추가: event: wl_registry::Event, | |
| 251 | 추가: _: &(), | |
| 252 | 추가: _: &Connection, | |
| 253 | 추가: qh: &QueueHandle<Self>, | |
| 254 | 추가: ) { | |
| 255 | 추가: if let wl_registry::Event::Global { | |
| 256 | 추가: name, | |
| 257 | 추가: interface, | |
| 258 | 추가: version, | |
| 259 | 추가: } = event | |
| 260 | 추가: { | |
| 261 | 추가: match interface.as_str() { | |
| 262 | 추가: "wl_seat" if state.seat.is_none() => { | |
| 263 | 추가: state.seat = Some(registry.bind(name, version.min(5), qh, ())); | |
| 264 | 추가: } | |
| 265 | 추가: "wl_data_device_manager" if state.manager.is_none() => { | |
| 266 | 추가: state.manager = Some(registry.bind(name, version.min(3), qh, ())); | |
| 267 | 추가: } | |
| 268 | 추가: _ => {} | |
| 269 | 추가: } | |
| 270 | 추가: } | |
| 271 | 추가: } | |
| 272 | 추가: } | |
| 273 | 추가: | |
| 274 | 추가: impl Dispatch<wl_seat::WlSeat, ()> for State { | |
| 275 | 추가: fn event( | |
| 276 | 추가: state: &mut Self, | |
| 277 | 추가: seat: &wl_seat::WlSeat, | |
| 278 | 추가: event: wl_seat::Event, | |
| 279 | 추가: _: &(), | |
| 280 | 추가: _: &Connection, | |
| 281 | 추가: qh: &QueueHandle<Self>, | |
| 282 | 추가: ) { | |
| 283 | 추가: if let wl_seat::Event::Capabilities { | |
| 284 | 추가: capabilities: WEnum::Value(capabilities), | |
| 285 | 추가: } = event | |
| 286 | 추가: && capabilities.contains(wl_seat::Capability::Pointer) | |
| 287 | 추가: && state.pointer.is_none() | |
| 288 | 추가: { | |
| 289 | 추가: state.pointer = Some(seat.get_pointer(qh, ())); | |
| 290 | 추가: } | |
| 291 | 추가: } | |
| 292 | 추가: } | |
| 293 | 추가: | |
| 294 | 추가: impl Dispatch<wl_pointer::WlPointer, ()> for State { | |
| 295 | 추가: fn event( | |
| 296 | 추가: state: &mut Self, | |
| 297 | 추가: _: &wl_pointer::WlPointer, | |
| 298 | 추가: event: wl_pointer::Event, | |
| 299 | 추가: _: &(), | |
| 300 | 추가: _: &Connection, | |
| 301 | 추가: _: &QueueHandle<Self>, | |
| 302 | 추가: ) { | |
| 303 | 추가: match event { | |
| 304 | 추가: wl_pointer::Event::Enter { surface, .. } => { | |
| 305 | 추가: state.focused = surface == state.surface; | |
| 306 | 추가: } | |
| 307 | 추가: wl_pointer::Event::Leave { .. } => state.focused = false, | |
| 308 | 추가: wl_pointer::Event::Button { | |
| 309 | 추가: serial, | |
| 310 | 추가: button: BTN_LEFT, | |
| 311 | 추가: state: WEnum::Value(pressed), | |
| 312 | 추가: .. | |
| 313 | 추가: } => { | |
| 314 | 추가: state.shared.lock().unwrap().press = | |
| 315 | 추가: (state.focused && pressed == wl_pointer::ButtonState::Pressed) | |
| 316 | 추가: .then_some(serial); | |
| 317 | 추가: } | |
| 318 | 추가: _ => {} | |
| 319 | 추가: } | |
| 320 | 추가: } | |
| 321 | 추가: } | |
| 322 | 추가: | |
| 323 | 추가: impl Dispatch<wl_data_device_manager::WlDataDeviceManager, ()> for State { | |
| 324 | 추가: fn event( | |
| 325 | 추가: _: &mut Self, | |
| 326 | 추가: _: &wl_data_device_manager::WlDataDeviceManager, | |
| 327 | 추가: _: wl_data_device_manager::Event, | |
| 328 | 추가: _: &(), | |
| 329 | 추가: _: &Connection, | |
| 330 | 추가: _: &QueueHandle<Self>, | |
| 331 | 추가: ) { | |
| 332 | 추가: } | |
| 333 | 추가: } | |
| 334 | 추가: | |
| 335 | 추가: impl Dispatch<wl_data_device::WlDataDevice, ()> for State { | |
| 336 | 추가: fn event( | |
| 337 | 추가: _: &mut Self, | |
| 338 | 추가: _: &wl_data_device::WlDataDevice, | |
| 339 | 추가: _: wl_data_device::Event, | |
| 340 | 추가: _: &(), | |
| 341 | 추가: _: &Connection, | |
| 342 | 추가: _: &QueueHandle<Self>, | |
| 343 | 추가: ) { | |
| 344 | 추가: // 이 창으로 들어오는 끌어 놓기는 winit이 따로 처리하므로 무시함. | |
| 345 | 추가: } | |
| 346 | 추가: | |
| 347 | 추가: event_created_child!(State, wl_data_device::WlDataDevice, [ | |
| 348 | 추가: wl_data_device::EVT_DATA_OFFER_OPCODE => (wl_data_offer::WlDataOffer, ()), | |
| 349 | 추가: ]); | |
| 350 | 추가: } | |
| 351 | 추가: | |
| 352 | 추가: impl Dispatch<wl_data_offer::WlDataOffer, ()> for State { | |
| 353 | 추가: fn event( | |
| 354 | 추가: _: &mut Self, | |
| 355 | 추가: _: &wl_data_offer::WlDataOffer, | |
| 356 | 추가: _: wl_data_offer::Event, | |
| 357 | 추가: _: &(), | |
| 358 | 추가: _: &Connection, | |
| 359 | 추가: _: &QueueHandle<Self>, | |
| 360 | 추가: ) { | |
| 361 | 추가: } | |
| 362 | 추가: } | |
| 363 | 추가: | |
| 364 | 추가: impl Dispatch<wl_data_source::WlDataSource, ()> for State { | |
| 365 | 추가: fn event( | |
| 366 | 추가: state: &mut Self, | |
| 367 | 추가: source: &wl_data_source::WlDataSource, | |
| 368 | 추가: event: wl_data_source::Event, | |
| 369 | 추가: _: &(), | |
| 370 | 추가: _: &Connection, | |
| 371 | 추가: _: &QueueHandle<Self>, | |
| 372 | 추가: ) { | |
| 373 | 추가: let mut shared = state.shared.lock().unwrap(); | |
| 374 | 추가: let current = shared.source.as_ref() == Some(source); | |
| 375 | 추가: match event { | |
| 376 | 추가: wl_data_source::Event::Send { mime_type, fd } => { | |
| 377 | 추가: zipelo_ui_memory_app::log_debug!("끌어 놓기 데이터 요청: {mime_type}"); | |
| 378 | 추가: match &shared.ready { | |
| 379 | 추가: Some(Ready::Paths(paths)) => send(mime_type, fd, paths.clone()), | |
| 380 | 추가: // 실패했으면 fd를 닫아 빈 데이터로 끝냄. | |
| 381 | 추가: Some(Ready::Failed) => {} | |
| 382 | 추가: None => shared.pending.push((mime_type, fd)), | |
| 383 | 추가: } | |
| 384 | 추가: } | |
| 385 | 추가: wl_data_source::Event::Cancelled => { | |
| 386 | 추가: source.destroy(); | |
| 387 | 추가: if current { | |
| 388 | 추가: shared.source = None; | |
| 389 | 추가: shared.events.push_back(DragEvent::Cancelled); | |
| 390 | 추가: } | |
| 391 | 추가: } | |
| 392 | 추가: wl_data_source::Event::DndDropPerformed if current => { | |
| 393 | 추가: shared.events.push_back(DragEvent::Dropped); | |
| 394 | 추가: } | |
| 395 | 추가: wl_data_source::Event::DndFinished => { | |
| 396 | 추가: source.destroy(); | |
| 397 | 추가: if current { | |
| 398 | 추가: shared.source = None; | |
| 399 | 추가: shared.events.push_back(DragEvent::Finished); | |
| 400 | 추가: } | |
| 401 | 추가: } | |
| 402 | 추가: _ => {} | |
| 403 | 추가: } | |
| 404 | 추가: drop(shared); | |
| 405 | 추가: state.repaint.request_repaint(); | |
| 406 | 추가: } | |
| 407 | 추가: } |
| @@ -24,5 +24,7 @@ pub mod window_frame; | ||
| 24 | 24 | |
| 25 | 25 | pub mod archive_path; |
| 26 | 26 | |
| 27 | 추가: pub mod drag_out; | |
| 28 | 추가: | |
| 27 | 29 | #[cfg(feature = "ui")] |
| 28 | 30 | pub mod app_icon; |
| @@ -0,0 +1,169 @@ | ||
| 1 | 추가: // 목록 항목을 창 밖으로 끌어 놓는 흐름 시험. 운영체제 끌기는 가짜 구현으로 대신함. | |
| 2 | 추가: // presentation.rs의 widgets 모듈 안에 explorer_selection.rs 다음으로 포함됨. | |
| 3 | 추가: | |
| 4 | 추가: #[derive(Default)] | |
| 5 | 추가: struct DragLog { | |
| 6 | 추가: starts: usize, | |
| 7 | 추가: accept: bool, | |
| 8 | 추가: provided: Vec<Vec<PathBuf>>, | |
| 9 | 추가: failed: usize, | |
| 10 | 추가: events: std::collections::VecDeque<zipelo_ui_memory_app::drag_out::DragEvent>, | |
| 11 | 추가: } | |
| 12 | 추가: | |
| 13 | 추가: struct FakeDrag(std::rc::Rc<std::cell::RefCell<DragLog>>); | |
| 14 | 추가: | |
| 15 | 추가: impl zipelo_ui_memory_app::drag_out::DragOut for FakeDrag { | |
| 16 | 추가: fn start(&mut self) -> bool { | |
| 17 | 추가: let mut log = self.0.borrow_mut(); | |
| 18 | 추가: log.starts += 1; | |
| 19 | 추가: log.accept | |
| 20 | 추가: } | |
| 21 | 추가: fn poll(&mut self) -> Option<zipelo_ui_memory_app::drag_out::DragEvent> { | |
| 22 | 추가: self.0.borrow_mut().events.pop_front() | |
| 23 | 추가: } | |
| 24 | 추가: fn provide(&mut self, paths: &[PathBuf]) { | |
| 25 | 추가: self.0.borrow_mut().provided.push(paths.to_vec()); | |
| 26 | 추가: } | |
| 27 | 추가: fn fail(&mut self) { | |
| 28 | 추가: self.0.borrow_mut().failed += 1; | |
| 29 | 추가: } | |
| 30 | 추가: } | |
| 31 | 추가: | |
| 32 | 추가: fn with_drag(s: &mut Explorer) -> std::rc::Rc<std::cell::RefCell<DragLog>> { | |
| 33 | 추가: let log = std::rc::Rc::new(std::cell::RefCell::new(DragLog { | |
| 34 | 추가: accept: true, | |
| 35 | 추가: ..Default::default() | |
| 36 | 추가: })); | |
| 37 | 추가: s.app.set_drag_out(Box::new(FakeDrag(log.clone()))); | |
| 38 | 추가: s.frame(egui::Modifiers::NONE, vec![]); | |
| 39 | 추가: log | |
| 40 | 추가: } | |
| 41 | 추가: | |
| 42 | 추가: /// 행을 누른 채 아래로 끌어 egui 끌기를 시작함. | |
| 43 | 추가: fn drag_row(s: &mut Explorer, path: &str) { | |
| 44 | 추가: s.time += 1.0; | |
| 45 | 추가: let start = s.row(path).center(); | |
| 46 | 추가: s.pointer(start, true, egui::Modifiers::NONE); | |
| 47 | 추가: for step in 1..=4 { | |
| 48 | 추가: s.frame( | |
| 49 | 추가: egui::Modifiers::NONE, | |
| 50 | 추가: vec![egui::Event::PointerMoved(start + egui::vec2(0.0, 12.0 * step as f32))], | |
| 51 | 추가: ); | |
| 52 | 추가: } | |
| 53 | 추가: } | |
| 54 | 추가: | |
| 55 | 추가: fn finish_worker(s: &mut Explorer) { | |
| 56 | 추가: { | |
| 57 | 추가: let mut worker = s.factory.state.borrow_mut(); | |
| 58 | 추가: worker.frame(Event::Accepted { encryption: false }); | |
| 59 | 추가: worker.finish(Outcome::Completed, Publication::Complete); | |
| 60 | 추가: } | |
| 61 | 추가: for _ in 0..10 { | |
| 62 | 추가: s.frame(egui::Modifiers::NONE, vec![]); | |
| 63 | 추가: } | |
| 64 | 추가: } | |
| 65 | 추가: | |
| 66 | 추가: #[test] | |
| 67 | 추가: fn dragging_selected_rows_out_extracts_them_and_hands_over_their_paths() { | |
| 68 | 추가: let scratch = Folder::new(); | |
| 69 | 추가: let mut s = Explorer::new(&scratch); | |
| 70 | 추가: let log = with_drag(&mut s); | |
| 71 | 추가: s.click("alpha.txt", egui::Modifiers::NONE); | |
| 72 | 추가: s.click("docs", explorer_ctrl()); | |
| 73 | 추가: s.selected(&[0, 1, 5]); | |
| 74 | 추가: s.factory.state.borrow_mut().manual = true; | |
| 75 | 추가: drag_row(&mut s, "alpha.txt"); | |
| 76 | 추가: assert_eq!(log.borrow().starts, 1); | |
| 77 | 추가: // 선택이 유지되고(끌기는 범위 선택이 아님), 하위 항목을 포함해 임시 폴더에 풂. | |
| 78 | 추가: s.selected(&[0, 1, 5]); | |
| 79 | 추가: let folder = scratch.0.join("sample.zip (Zipelo 임시)").join("1"); | |
| 80 | 추가: { | |
| 81 | 추가: let state = s.factory.state.borrow(); | |
| 82 | 추가: let Some(Start::Extract { | |
| 83 | 추가: destination, | |
| 84 | 추가: selection: Selection::EntryIds(ids), | |
| 85 | 추가: .. | |
| 86 | 추가: }) = state.starts.last() | |
| 87 | 추가: else { | |
| 88 | 추가: panic!("{:?}", state.starts.last()); | |
| 89 | 추가: }; | |
| 90 | 추가: assert_eq!(destination, &folder); | |
| 91 | 추가: assert_eq!(ids, &vec![0, 1, 5]); | |
| 92 | 추가: } | |
| 93 | 추가: // 풀기가 끝나기 전에는 경로를 넘기지 않음. | |
| 94 | 추가: assert!(log.borrow().provided.is_empty()); | |
| 95 | 추가: fs::create_dir_all(folder.join("docs")).unwrap(); | |
| 96 | 추가: fs::write(folder.join("docs/child.txt"), "x").unwrap(); | |
| 97 | 추가: fs::write(folder.join("alpha.txt"), "x").unwrap(); | |
| 98 | 추가: finish_worker(&mut s); | |
| 99 | 추가: assert_eq!( | |
| 100 | 추가: log.borrow().provided, | |
| 101 | 추가: // 목록과 같은 순서(폴더 먼저). | |
| 102 | 추가: vec![vec![folder.join("docs"), folder.join("alpha.txt")]] | |
| 103 | 추가: ); | |
| 104 | 추가: // 결과 창 없이 끝나고, 원래 풀 위치로 되돌아옴. | |
| 105 | 추가: assert!(!s.app.model.busy()); | |
| 106 | 추가: s.factory.state.borrow_mut().manual = false; | |
| 107 | 추가: assert!(s.app.begin_extract()); | |
| 108 | 추가: assert!(matches!( | |
| 109 | 추가: s.factory.state.borrow().starts.last(), | |
| 110 | 추가: Some(Start::Extract { destination, .. }) if !destination.starts_with(scratch.0.join("sample.zip (Zipelo 임시)")) | |
| 111 | 추가: )); | |
| 112 | 추가: } | |
| 113 | 추가: | |
| 114 | 추가: #[test] | |
| 115 | 추가: fn dragging_an_unselected_row_selects_only_that_row() { | |
| 116 | 추가: let scratch = Folder::new(); | |
| 117 | 추가: let mut s = Explorer::new(&scratch); | |
| 118 | 추가: let log = with_drag(&mut s); | |
| 119 | 추가: s.click("alpha.txt", egui::Modifiers::NONE); | |
| 120 | 추가: s.factory.state.borrow_mut().manual = true; | |
| 121 | 추가: drag_row(&mut s, "beta.txt"); | |
| 122 | 추가: assert_eq!(log.borrow().starts, 1); | |
| 123 | 추가: s.selected(&[2]); | |
| 124 | 추가: } | |
| 125 | 추가: | |
| 126 | 추가: #[test] | |
| 127 | 추가: fn cancelling_the_drag_cancels_extraction_without_a_result_window() { | |
| 128 | 추가: let scratch = Folder::new(); | |
| 129 | 추가: let mut s = Explorer::new(&scratch); | |
| 130 | 추가: let log = with_drag(&mut s); | |
| 131 | 추가: s.click("alpha.txt", egui::Modifiers::NONE); | |
| 132 | 추가: s.factory.state.borrow_mut().manual = true; | |
| 133 | 추가: drag_row(&mut s, "alpha.txt"); | |
| 134 | 추가: assert!(s.app.model.busy()); | |
| 135 | 추가: log.borrow_mut() | |
| 136 | 추가: .events | |
| 137 | 추가: .push_back(zipelo_ui_memory_app::drag_out::DragEvent::Cancelled); | |
| 138 | 추가: s.frame(egui::Modifiers::NONE, vec![]); | |
| 139 | 추가: assert!(s.app.model.cancellation_requested()); | |
| 140 | 추가: { | |
| 141 | 추가: let mut worker = s.factory.state.borrow_mut(); | |
| 142 | 추가: worker.frame(Event::Accepted { encryption: false }); | |
| 143 | 추가: worker.finish(Outcome::Cancelled, Publication::None); | |
| 144 | 추가: } | |
| 145 | 추가: let mut labels = Vec::new(); | |
| 146 | 추가: for _ in 0..10 { | |
| 147 | 추가: labels = layout_text(&s.frame(egui::Modifiers::NONE, vec![])); | |
| 148 | 추가: } | |
| 149 | 추가: assert_eq!(log.borrow().failed, 1); | |
| 150 | 추가: assert!(log.borrow().provided.is_empty()); | |
| 151 | 추가: assert!( | |
| 152 | 추가: !labels.iter().any(|(text, _, _)| text.contains("취소했습니다")), | |
| 153 | 추가: "{labels:?}" | |
| 154 | 추가: ); | |
| 155 | 추가: } | |
| 156 | 추가: | |
| 157 | 추가: #[test] | |
| 158 | 추가: fn rows_do_not_start_a_drag_when_the_platform_cannot() { | |
| 159 | 추가: let scratch = Folder::new(); | |
| 160 | 추가: let mut s = Explorer::new(&scratch); | |
| 161 | 추가: let log = with_drag(&mut s); | |
| 162 | 추가: log.borrow_mut().accept = false; | |
| 163 | 추가: s.click("alpha.txt", egui::Modifiers::NONE); | |
| 164 | 추가: drag_row(&mut s, "alpha.txt"); | |
| 165 | 추가: assert_eq!(log.borrow().starts, 1); | |
| 166 | 추가: // 끌기를 시작하지 못하면 아무 작업도 시작하지 않음. | |
| 167 | 추가: assert!(!s.app.model.busy()); | |
| 168 | 추가: assert_eq!(s.factory.state.borrow().starts.len(), 1); | |
| 169 | 추가: } |
| @@ -1051,6 +1051,7 @@ mod widgets { | ||
| 1051 | 1051 | include!("long_layout.rs"); |
| 1052 | 1052 | include!("explorer_selection.rs"); |
| 1053 | 1053 | include!("find_escape.rs"); |
| 1054 | 추가: include!("drag_out_flow.rs"); | |
| 1054 | 1055 | include!("window_frame.rs"); |
| 1055 | 1056 | include!("work_window.rs"); |
| 1056 | 1057 | include!("create_window.rs"); |