forge
Explore
Log in

Don't you dare go Hollow

Focus target window/output on DnD

Browse files at this commit

c239937fac836f308311eff5f5d5fc5262c6eb55Ivan MolodetskikhParent: bafa574
In sway, focus-follows-mouse keeps working during DnD, but not in niri.
So it can be surprising when you DnD something into another app, but it
doesn't get automatically focused. This commit fixes that.

Even if the DnD is not validated, or if there's no target surface (e.g.
dropped on the niri background), focus the target output, since that's
how Firefox's drag-tab-into-new-window works for example.
Cargo.lockmodified+2 -2
@@ -3658,7 +3658,7 @@ checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"
36583658 [[package]]
36593659 name = "smithay"
36603660 version = "0.3.0"
3661-source = "git+https://github.com/Smithay/smithay.git#eef07680c43e20cf4e528dd1222b3cadf6a32182"
3661+source = "git+https://github.com/Smithay/smithay.git#b8292400ea7d137946099e941bf3985ade3ecf91"
36623662 dependencies = [
36633663 "appendlist",
36643664 "bitflags 2.6.0",
@@ -3730,7 +3730,7 @@ dependencies = [
37303730 [[package]]
37313731 name = "smithay-drm-extras"
37323732 version = "0.1.0"
3733-source = "git+https://github.com/Smithay/smithay.git#eef07680c43e20cf4e528dd1222b3cadf6a32182"
3733+source = "git+https://github.com/Smithay/smithay.git#b8292400ea7d137946099e941bf3985ade3ecf91"
37343734 dependencies = [
37353735 "drm",
37363736 "libdisplay-info",
src/handlers/mod.rsmodified+33 -1
@@ -306,7 +306,39 @@ impl ClientDndGrabHandler for State {
306306 self.niri.queue_redraw_all();
307307 }
308308
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+
310342 self.niri.dnd_icon = None;
311343 // FIXME: more granular
312344 self.niri.queue_redraw_all();