@@ -23,6 +23,17 @@ impl FileChooser { |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
| 25 | | 25 | |
| | 26 | + /// Parse X11 window ID from portal parent_window string. |
| | 27 | + /// Format is "x11:<xid>" where xid is the window ID in hex. |
| | 28 | + fn parse_parent_window(parent_window: &str) -> Option<u32> { |
| | 29 | + if parent_window.starts_with("x11:") { |
| | 30 | + let hex_str = &parent_window[4..]; |
| | 31 | + u32::from_str_radix(hex_str, 16).ok() |
| | 32 | + } else { |
| | 33 | + None |
| | 34 | + } |
| | 35 | + } |
| | 36 | + |
| 26 | /// Spawn garfield in picker mode and collect results. | 37 | /// Spawn garfield in picker mode and collect results. |
| 27 | async fn spawn_picker( | 38 | async fn spawn_picker( |
| 28 | &self, | 39 | &self, |
@@ -32,6 +43,7 @@ impl FileChooser { |
| 32 | multiple: bool, | 43 | multiple: bool, |
| 33 | filters: Vec<String>, | 44 | filters: Vec<String>, |
| 34 | current_folder: Option<String>, | 45 | current_folder: Option<String>, |
| | 46 | + parent_window: Option<u32>, |
| 35 | ) -> (u32, HashMap<String, Value<'static>>) { | 47 | ) -> (u32, HashMap<String, Value<'static>>) { |
| 36 | // Find garfield binary - prefer ~/.cargo/bin (development), then /usr/local/bin, then PATH | 48 | // Find garfield binary - prefer ~/.cargo/bin (development), then /usr/local/bin, then PATH |
| 37 | let home = std::env::var("HOME").unwrap_or_default(); | 49 | let home = std::env::var("HOME").unwrap_or_default(); |
@@ -63,6 +75,10 @@ impl FileChooser { |
| 63 | cmd.arg("--filter").arg(filters.join(";")); | 75 | cmd.arg("--filter").arg(filters.join(";")); |
| 64 | } | 76 | } |
| 65 | | 77 | |
| | 78 | + if let Some(parent) = parent_window { |
| | 79 | + cmd.arg("--parent-window").arg(parent.to_string()); |
| | 80 | + } |
| | 81 | + |
| 66 | if let Some(folder) = current_folder { | 82 | if let Some(folder) = current_folder { |
| 67 | cmd.arg(&folder); | 83 | cmd.arg(&folder); |
| 68 | } | 84 | } |
@@ -210,6 +226,7 @@ impl FileChooser { |
| 210 | title: &str, | 226 | title: &str, |
| 211 | suggested_filename: Option<String>, | 227 | suggested_filename: Option<String>, |
| 212 | current_folder: Option<String>, | 228 | current_folder: Option<String>, |
| | 229 | + parent_window: Option<u32>, |
| 213 | ) -> (u32, HashMap<String, Value<'static>>) { | 230 | ) -> (u32, HashMap<String, Value<'static>>) { |
| 214 | // Find garfield binary - prefer ~/.cargo/bin (development), then /usr/local/bin, then PATH | 231 | // Find garfield binary - prefer ~/.cargo/bin (development), then /usr/local/bin, then PATH |
| 215 | let home = std::env::var("HOME").unwrap_or_default(); | 232 | let home = std::env::var("HOME").unwrap_or_default(); |
@@ -234,6 +251,10 @@ impl FileChooser { |
| 234 | cmd.arg("--title").arg(title); | 251 | cmd.arg("--title").arg(title); |
| 235 | } | 252 | } |
| 236 | | 253 | |
| | 254 | + if let Some(parent) = parent_window { |
| | 255 | + cmd.arg("--parent-window").arg(parent.to_string()); |
| | 256 | + } |
| | 257 | + |
| 237 | if let Some(folder) = current_folder { | 258 | if let Some(folder) = current_folder { |
| 238 | cmd.arg(&folder); | 259 | cmd.arg(&folder); |
| 239 | } | 260 | } |
@@ -311,13 +332,14 @@ impl FileChooser { |
| 311 | #[zbus(object_server)] server: &zbus::ObjectServer, | 332 | #[zbus(object_server)] server: &zbus::ObjectServer, |
| 312 | handle: ObjectPath<'_>, | 333 | handle: ObjectPath<'_>, |
| 313 | _app_id: &str, | 334 | _app_id: &str, |
| 314 | - _parent_window: &str, | 335 | + parent_window: &str, |
| 315 | title: &str, | 336 | title: &str, |
| 316 | options: HashMap<&str, Value<'_>>, | 337 | options: HashMap<&str, Value<'_>>, |
| 317 | ) -> fdo::Result<(u32, HashMap<String, Value<'static>>)> { | 338 | ) -> fdo::Result<(u32, HashMap<String, Value<'static>>)> { |
| 318 | - tracing::info!("OpenFile request: handle={}, title={}", handle, title); | 339 | + tracing::info!("OpenFile request: handle={}, title={}, parent_window={}", handle, title, parent_window); |
| 319 | | 340 | |
| 320 | let handle_owned: OwnedObjectPath = handle.into(); | 341 | let handle_owned: OwnedObjectPath = handle.into(); |
| | 342 | + let parent_window_id = Self::parse_parent_window(parent_window); |
| 321 | | 343 | |
| 322 | // Parse options | 344 | // Parse options |
| 323 | let multiple = options.get("multiple") | 345 | let multiple = options.get("multiple") |
@@ -348,6 +370,7 @@ impl FileChooser { |
| 348 | multiple, | 370 | multiple, |
| 349 | filters, | 371 | filters, |
| 350 | current_folder, | 372 | current_folder, |
| | 373 | + parent_window_id, |
| 351 | ).await; | 374 | ).await; |
| 352 | | 375 | |
| 353 | tracing::debug!("Picker returned: {:?}", result.0); | 376 | tracing::debug!("Picker returned: {:?}", result.0); |
@@ -367,18 +390,19 @@ impl FileChooser { |
| 367 | #[zbus(object_server)] server: &zbus::ObjectServer, | 390 | #[zbus(object_server)] server: &zbus::ObjectServer, |
| 368 | handle: ObjectPath<'_>, | 391 | handle: ObjectPath<'_>, |
| 369 | _app_id: &str, | 392 | _app_id: &str, |
| 370 | - _parent_window: &str, | 393 | + parent_window: &str, |
| 371 | title: &str, | 394 | title: &str, |
| 372 | options: HashMap<&str, Value<'_>>, | 395 | options: HashMap<&str, Value<'_>>, |
| 373 | ) -> fdo::Result<(u32, HashMap<String, Value<'static>>)> { | 396 | ) -> fdo::Result<(u32, HashMap<String, Value<'static>>)> { |
| 374 | - tracing::info!("SaveFile request: handle={}, title={}", handle, title); | 397 | + tracing::info!("SaveFile request: handle={}, title={}, parent_window={}", handle, title, parent_window); |
| 375 | tracing::debug!("SaveFile options: {:?}", options); | 398 | tracing::debug!("SaveFile options: {:?}", options); |
| 376 | | 399 | |
| 377 | let handle_owned: OwnedObjectPath = handle.into(); | 400 | let handle_owned: OwnedObjectPath = handle.into(); |
| | 401 | + let parent_window_id = Self::parse_parent_window(parent_window); |
| 378 | let current_folder = Self::parse_current_folder(&options); | 402 | let current_folder = Self::parse_current_folder(&options); |
| 379 | let suggested_filename = Self::parse_current_name(&options); | 403 | let suggested_filename = Self::parse_current_name(&options); |
| 380 | | 404 | |
| 381 | - tracing::info!("SaveFile: folder={:?}, filename={:?}", current_folder, suggested_filename); | 405 | + tracing::info!("SaveFile: folder={:?}, filename={:?}, parent={:?}", current_folder, suggested_filename, parent_window_id); |
| 382 | | 406 | |
| 383 | let request = Request::new(handle_owned.clone(), self.request_manager.clone()); | 407 | let request = Request::new(handle_owned.clone(), self.request_manager.clone()); |
| 384 | server.at(handle_owned.as_ref(), request).await | 408 | server.at(handle_owned.as_ref(), request).await |
@@ -390,6 +414,7 @@ impl FileChooser { |
| 390 | title, | 414 | title, |
| 391 | suggested_filename, | 415 | suggested_filename, |
| 392 | current_folder, | 416 | current_folder, |
| | 417 | + parent_window_id, |
| 393 | ).await; | 418 | ).await; |
| 394 | | 419 | |
| 395 | let _ = server.remove::<Request, _>(&handle_owned).await; | 420 | let _ = server.remove::<Request, _>(&handle_owned).await; |
@@ -403,14 +428,15 @@ impl FileChooser { |
| 403 | #[zbus(object_server)] server: &zbus::ObjectServer, | 428 | #[zbus(object_server)] server: &zbus::ObjectServer, |
| 404 | handle: ObjectPath<'_>, | 429 | handle: ObjectPath<'_>, |
| 405 | _app_id: &str, | 430 | _app_id: &str, |
| 406 | - _parent_window: &str, | 431 | + parent_window: &str, |
| 407 | title: &str, | 432 | title: &str, |
| 408 | options: HashMap<&str, Value<'_>>, | 433 | options: HashMap<&str, Value<'_>>, |
| 409 | ) -> fdo::Result<(u32, HashMap<String, Value<'static>>)> { | 434 | ) -> fdo::Result<(u32, HashMap<String, Value<'static>>)> { |
| 410 | - tracing::info!("SaveFiles request: handle={}, title={}", handle, title); | 435 | + tracing::info!("SaveFiles request: handle={}, title={}, parent_window={}", handle, title, parent_window); |
| 411 | | 436 | |
| 412 | // SaveFiles picks a directory for saving multiple files | 437 | // SaveFiles picks a directory for saving multiple files |
| 413 | let handle_owned: OwnedObjectPath = handle.into(); | 438 | let handle_owned: OwnedObjectPath = handle.into(); |
| | 439 | + let parent_window_id = Self::parse_parent_window(parent_window); |
| 414 | let current_folder = Self::parse_current_folder(&options); | 440 | let current_folder = Self::parse_current_folder(&options); |
| 415 | | 441 | |
| 416 | let request = Request::new(handle_owned.clone(), self.request_manager.clone()); | 442 | let request = Request::new(handle_owned.clone(), self.request_manager.clone()); |
@@ -424,6 +450,7 @@ impl FileChooser { |
| 424 | false, | 450 | false, |
| 425 | Vec::new(), | 451 | Vec::new(), |
| 426 | current_folder, | 452 | current_folder, |
| | 453 | + parent_window_id, |
| 427 | ).await; | 454 | ).await; |
| 428 | | 455 | |
| 429 | let _ = server.remove::<Request, _>(&handle_owned).await; | 456 | let _ = server.remove::<Request, _>(&handle_owned).await; |