From f4e8d132f3669b69907390c382fc79d04ac2ae4d Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 19 Feb 2025 16:30:07 +0100 Subject: [PATCH] toplevel: remove focus_node --- src/ifs/wl_seat/event_handling.rs | 6 +++--- src/ifs/wl_seat/tablet/tool.rs | 4 ++-- src/ifs/wl_surface.rs | 17 ++--------------- src/ifs/wl_surface/wl_subsurface.rs | 5 +++++ src/ifs/wl_surface/x_surface/xwindow.rs | 4 ++-- src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs | 4 ++-- src/tree/container.rs | 8 -------- src/tree/toplevel.rs | 17 +++-------------- 8 files changed, 19 insertions(+), 46 deletions(-) diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index d5f24ab5..29226d85 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -923,7 +923,7 @@ impl WlSeatGlobal { } pub fn focus_toplevel(self: &Rc, n: Rc) { - let node = match n.tl_focus_child(self.id) { + let node = match n.tl_focus_child() { Some(n) => n, _ => n.tl_into_node(), }; @@ -1153,7 +1153,7 @@ impl WlSeatGlobal { }); self.surface_pointer_frame(surface); if pressed { - if let Some(node) = surface.get_focus_node(self.id) { + if let Some(node) = surface.get_focus_node() { self.focus_node_with_serial(node, serial); } } @@ -1372,7 +1372,7 @@ impl WlSeatGlobal { self.surface_touch_event(Version::ALL, surface, |t| { t.send_down(serial, time, surface.id, id, x, y) }); - if let Some(node) = surface.get_focus_node(self.id) { + if let Some(node) = surface.get_focus_node() { self.focus_node_with_serial(node, serial); } } diff --git a/src/ifs/wl_seat/tablet/tool.rs b/src/ifs/wl_seat/tablet/tool.rs index fcda9cbf..6f6a8326 100644 --- a/src/ifs/wl_seat/tablet/tool.rs +++ b/src/ifs/wl_seat/tablet/tool.rs @@ -212,7 +212,7 @@ impl TabletTool { }); if state == ToolButtonState::Pressed { n.client.focus_stealing_serial.set(Some(serial.get())); - if let Some(node) = n.get_focus_node(self.tablet.seat.id) { + if let Some(node) = n.get_focus_node() { self.tablet.seat.focus_node_with_serial(node, serial.get()); } } @@ -261,7 +261,7 @@ impl TabletTool { if let Some(changes) = changes { if changes.down == Some(true) { n.client.focus_stealing_serial.set(Some(serial.get())); - if let Some(node) = n.get_focus_node(self.tablet.seat.id) { + if let Some(node) = n.get_focus_node() { self.tablet.seat.focus_node_with_serial(node, serial.get()); } } diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index 8559a0bb..8038ec82 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -777,9 +777,9 @@ impl WlSurface { Ok(cursor) } - pub fn get_focus_node(&self, seat: SeatId) -> Option> { + pub fn get_focus_node(&self) -> Option> { match self.toplevel.get() { - Some(tl) if tl.tl_accepts_keyboard_focus() => tl.tl_focus_child(seat), + Some(tl) if tl.tl_accepts_keyboard_focus() => tl.tl_focus_child(), Some(_) => None, _ => self.ext.get().focus_node(), } @@ -1591,18 +1591,6 @@ impl WlSurface { ss.surface.detach_node(set_invisible); } } - if let Some(tl) = self.toplevel.get() { - let data = tl.tl_data(); - let mut remove = vec![]; - for (seat, s) in data.focus_node.iter() { - if s.node_id() == self.node_id() { - remove.push(seat); - } - } - for seat in remove { - data.focus_node.remove(&seat); - } - } self.seat_state.destroy_node(self); if self.visible.get() && self.toplevel.is_none() { self.client.state.damage(self.buffer_abs_pos.get()); @@ -1802,7 +1790,6 @@ impl Node for WlSurface { fn node_on_focus(self: Rc, seat: &WlSeatGlobal) { if let Some(tl) = self.toplevel.get() { - tl.tl_data().focus_node.insert(seat.id(), self.clone()); tl.tl_on_activate(); } seat.focus_surface(&self); diff --git a/src/ifs/wl_surface/wl_subsurface.rs b/src/ifs/wl_surface/wl_subsurface.rs index d0baf383..d8dc29da 100644 --- a/src/ifs/wl_surface/wl_subsurface.rs +++ b/src/ifs/wl_surface/wl_subsurface.rs @@ -7,6 +7,7 @@ use { }, leaks::Tracker, object::{Object, Version}, + tree::Node, utils::{ clonecell::CloneCell, linkedlist::{LinkedNode, NodeRef}, @@ -375,6 +376,10 @@ impl SurfaceExt for WlSubsurface { Some(self) } + fn focus_node(&self) -> Option> { + self.parent.ext.get().focus_node() + } + fn consume_pending_child( &self, surface: &WlSurface, diff --git a/src/ifs/wl_surface/x_surface/xwindow.rs b/src/ifs/wl_surface/x_surface/xwindow.rs index b558ebe3..182ce5be 100644 --- a/src/ifs/wl_surface/x_surface/xwindow.rs +++ b/src/ifs/wl_surface/x_surface/xwindow.rs @@ -4,7 +4,7 @@ use { cursor::KnownCursor, fixed::Fixed, ifs::{ - wl_seat::{tablet::TabletTool, NodeSeatState, SeatId, WlSeatGlobal}, + wl_seat::{tablet::TabletTool, NodeSeatState, WlSeatGlobal}, wl_surface::{x_surface::XSurface, WlSurface, WlSurfaceError}, }, rect::Rect, @@ -406,7 +406,7 @@ impl ToplevelNodeBase for Xwindow { .push(XWaylandEvent::Activate(self.data.clone())); } - fn tl_focus_child(&self, _seat: SeatId) -> Option> { + fn tl_focus_child(&self) -> Option> { Some(self.x.surface.clone()) } diff --git a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs index 3516d1ba..0a8e5ce9 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs @@ -9,7 +9,7 @@ use { fixed::Fixed, ifs::{ ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1, - wl_seat::{tablet::TabletTool, NodeSeatState, SeatId, WlSeatGlobal}, + wl_seat::{tablet::TabletTool, NodeSeatState, WlSeatGlobal}, wl_surface::{ xdg_surface::{ xdg_toplevel::xdg_dialog_v1::XdgDialogV1, XdgSurface, XdgSurfaceError, @@ -582,7 +582,7 @@ impl ToplevelNodeBase for XdgToplevel { } } - fn tl_focus_child(&self, _seat: SeatId) -> Option> { + fn tl_focus_child(&self) -> Option> { Some(self.xdg.surface.clone()) } diff --git a/src/tree/container.rs b/src/tree/container.rs index 2fef939a..6a9492f8 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -2059,14 +2059,6 @@ impl ToplevelNodeBase for ContainerNode { &self.toplevel_data } - fn tl_default_focus_child(&self) -> Option> { - self.focus_history - .last() - .map(|v| v.node.clone()) - .or_else(|| self.children.first().map(|c| c.node.clone())) - .map(|tl| tl.tl_into_node()) - } - fn tl_set_workspace_ext(&self, ws: &Rc) { for child in self.children.iter() { child.node.clone().tl_set_workspace(ws); diff --git a/src/tree/toplevel.rs b/src/tree/toplevel.rs index 78c65a1f..1d327a3e 100644 --- a/src/tree/toplevel.rs +++ b/src/tree/toplevel.rs @@ -7,7 +7,7 @@ use { ext_image_copy::ext_image_copy_capture_session_v1::ExtImageCopyCaptureSessionV1, jay_screencast::JayScreencast, jay_toplevel::JayToplevel, - wl_seat::{collect_kb_foci, collect_kb_foci2, NodeSeatState, SeatId}, + wl_seat::{collect_kb_foci, collect_kb_foci2, NodeSeatState}, wl_surface::WlSurface, }, rect::Rect, @@ -22,7 +22,6 @@ use { copyhashmap::CopyHashMap, hash_map_ext::HashMapExt, numcell::NumCell, - smallmap::SmallMap, threshold_counter::ThresholdCounter, toplevel_identifier::{toplevel_identifier, ToplevelIdentifier}, }, @@ -172,10 +171,6 @@ impl ToplevelNode for T { pub trait ToplevelNodeBase: Node { fn tl_data(&self) -> &ToplevelData; - fn tl_default_focus_child(&self) -> Option> { - None - } - fn tl_accepts_keyboard_focus(&self) -> bool { true } @@ -188,11 +183,8 @@ pub trait ToplevelNodeBase: Node { // nothing } - fn tl_focus_child(&self, seat: SeatId) -> Option> { - self.tl_data() - .focus_node - .get(&seat) - .or_else(|| self.tl_default_focus_child()) + fn tl_focus_child(&self) -> Option> { + None } fn tl_set_workspace_ext(&self, ws: &Rc) { @@ -259,7 +251,6 @@ pub struct ToplevelData { pub client: Option>, pub state: Rc, pub active_surfaces: ThresholdCounter, - pub focus_node: SmallMap, 1>, pub visible: Cell, pub is_floating: Cell, pub float_width: Cell, @@ -300,7 +291,6 @@ impl ToplevelData { client, state: state.clone(), active_surfaces: Default::default(), - focus_node: Default::default(), visible: Cell::new(false), is_floating: Default::default(), float_width: Default::default(), @@ -393,7 +383,6 @@ impl ToplevelData { } self.workspace.take(); self.seat_state.destroy_node(node); - self.focus_node.clear(); } pub fn broadcast(&self, toplevel: Rc) {