Focus target window/output on DnD
Browse files at this commitc239937fac836f308311eff5f5d5fc5262c6eb55Parent: bafa5742 changed files +35 -3
- Cargo.lock +2 -2
- src/handlers/mod.rs +33 -1
Cargo.lockmodified+2 -2
| @@ -3658,7 +3658,7 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" | ||
| 3658 | 3658 | [[package]] |
| 3659 | 3659 | name = "smithay" |
| 3660 | 3660 | version = "0.3.0" |
| 3661 | -source = "git+https://github.com/Smithay/smithay.git#eef07680c43e20cf4e528dd1222b3cadf6a32182" | |
| 3661 | +source = "git+https://github.com/Smithay/smithay.git#b8292400ea7d137946099e941bf3985ade3ecf91" | |
| 3662 | 3662 | dependencies = [ |
| 3663 | 3663 | "appendlist", |
| 3664 | 3664 | "bitflags 2.6.0", |
| @@ -3730,7 +3730,7 @@ dependencies = [ | ||
| 3730 | 3730 | [[package]] |
| 3731 | 3731 | name = "smithay-drm-extras" |
| 3732 | 3732 | version = "0.1.0" |
| 3733 | -source = "git+https://github.com/Smithay/smithay.git#eef07680c43e20cf4e528dd1222b3cadf6a32182" | |
| 3733 | +source = "git+https://github.com/Smithay/smithay.git#b8292400ea7d137946099e941bf3985ade3ecf91" | |
| 3734 | 3734 | dependencies = [ |
| 3735 | 3735 | "drm", |
| 3736 | 3736 | "libdisplay-info", |
src/handlers/mod.rsmodified+33 -1
| @@ -306,7 +306,39 @@ impl ClientDndGrabHandler for State { | ||
| 306 | 306 | self.niri.queue_redraw_all(); |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - fn dropped(&mut self, _seat: Seat<Self>) { | |
| 309 | + fn dropped(&mut self, target: Option<WlSurface>, validated: bool, _seat: Seat<Self>) { | |
| 310 | + trace!("client dropped, target: {target:?}, validated: {validated}"); | |
| 311 | + | |
| 312 | + // Activate the target output, since that's how Firefox drag-tab-into-new-window works for | |
| 313 | + // example. On successful drop, additionally activate the target window. | |
| 314 | + let mut activate_output = true; | |
| 315 | + if let Some(target) = validated.then_some(target).flatten() { | |
| 316 | + if let Some(root) = self.niri.root_surface.get(&target) { | |
| 317 | + if let Some((mapped, _)) = self.niri.layout.find_window_and_output(root) { | |
| 318 | + let window = mapped.window.clone(); | |
| 319 | + self.niri.layout.activate_window(&window); | |
| 320 | + activate_output = false; | |
| 321 | + } | |
| 322 | + } | |
| 323 | + } | |
| 324 | + | |
| 325 | + if activate_output { | |
| 326 | + // Find the output from cursor coordinates. | |
| 327 | + // | |
| 328 | + // FIXME: uhhh, we can't actually properly tell if the DnD comes from pointer or touch, | |
| 329 | + // and if it comes from touch, then what the coordinates are. Need to pass more | |
| 330 | + // parameters from Smithay I guess. | |
| 331 | + // | |
| 332 | + // Assume that hidden pointer means touch DnD. | |
| 333 | + if !self.niri.pointer_hidden { | |
| 334 | + // We can't even get the current pointer location because it's locked (we're deep | |
| 335 | + // in the grab call stack here). So use the last known one. | |
| 336 | + if let Some(output) = &self.niri.pointer_contents.output { | |
| 337 | + self.niri.layout.activate_output(output); | |
| 338 | + } | |
| 339 | + } | |
| 340 | + } | |
| 341 | + | |
| 310 | 342 | self.niri.dnd_icon = None; |
| 311 | 343 | // FIXME: more granular |
| 312 | 344 | self.niri.queue_redraw_all(); |