From 54cf01f7456d72b15f27498068409f92756835a0 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Mon, 18 Apr 2022 14:14:25 +0200 Subject: [PATCH] autocommit 2022-04-18 14:14:25 CEST --- src/cli/idle.rs | 13 ++-- src/client.rs | 12 ++-- src/forker.rs | 25 +++++-- src/ifs/jay_idle.rs | 2 +- src/ifs/wl_seat.rs | 5 +- src/ifs/wl_seat/event_handling.rs | 39 ++--------- src/ifs/wl_surface.rs | 9 ++- src/ifs/wl_surface/xdg_surface/xdg_popup.rs | 4 ++ .../wl_surface/xdg_surface/xdg_toplevel.rs | 8 +-- src/ifs/wl_surface/xwindow.rs | 8 +-- src/ifs/wl_surface/zwlr_layer_surface_v1.rs | 4 ++ src/state.rs | 69 ++++++++++--------- src/tree.rs | 13 ++++ src/tree/container.rs | 4 ++ src/tree/display.rs | 4 ++ src/tree/float.rs | 4 ++ src/tree/output.rs | 10 +++ src/tree/toplevel.rs | 9 +-- src/tree/workspace.rs | 15 ++++ src/utils/stack.rs | 7 +- 20 files changed, 155 insertions(+), 109 deletions(-) diff --git a/src/cli/idle.rs b/src/cli/idle.rs index 57a1f38f..279e3283 100644 --- a/src/cli/idle.rs +++ b/src/cli/idle.rs @@ -2,13 +2,11 @@ use { crate::{ cli::{GlobalArgs, IdleArgs, IdleCmd, IdleSetArgs}, tools::tool_client::{Handle, ToolClient}, - utils::errorfmt::ErrorFmt, - wire::{jay_compositor, jay_idle, JayIdleId}, + utils::{errorfmt::ErrorFmt, stack::Stack}, + wire::{jay_compositor, jay_idle, JayIdleId, WlSurfaceId}, }, std::{cell::Cell, collections::VecDeque, rc::Rc, str::FromStr}, }; -use crate::utils::stack::Stack; -use crate::wire::WlSurfaceId; pub fn main(global: GlobalArgs, args: IdleArgs) { let tc = ToolClient::new(global.log_level.into()); @@ -81,10 +79,13 @@ impl Idle { let mut inhibitors = inhibitors.take(); inhibitors.sort_by_key(|i| i.pid); inhibitors.sort_by_key(|i| i.surface); - if inhibitors.len() > 0{ + if inhibitors.len() > 0 { println!("Inhibitors:"); for inhibitor in inhibitors { - println!(" {}, surface {}, pid {}", inhibitor.comm, inhibitor.surface, inhibitor.pid); + println!( + " {}, surface {}, pid {}", + inhibitor.comm, inhibitor.surface, inhibitor.pid + ); } } } diff --git a/src/client.rs b/src/client.rs index 385a3021..7d589469 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,5 +1,3 @@ -use std::collections::VecDeque; -use bstr::ByteSlice; pub use error::{ClientError, MethodError, ObjectError}; use { crate::{ @@ -16,12 +14,15 @@ use { errorfmt::ErrorFmt, numcell::NumCell, queue::AsyncQueue, + trim::AsciiTrim, }, wire::WlRegistryId, }, ahash::AHashMap, + bstr::ByteSlice, std::{ cell::{Cell, RefCell}, + collections::VecDeque, error::Error, fmt::{Debug, Display, Formatter}, mem, @@ -30,7 +31,6 @@ use { }, uapi::{c, OwnedFd}, }; -use crate::utils::trim::AsciiTrim; mod error; mod objects; @@ -459,9 +459,5 @@ fn get_pid_info(uid: c::uid_t, pid: c::pid_t) -> PidInfo { "Unknown".to_string() } }; - PidInfo { - uid, - pid, - comm, - } + PidInfo { uid, pid, comm } } diff --git a/src/forker.rs b/src/forker.rs index b718b221..1867011f 100644 --- a/src/forker.rs +++ b/src/forker.rs @@ -283,8 +283,15 @@ enum ServerMessage { #[derive(Encode, Decode)] enum ForkerMessage { - Log { level: usize, msg: String }, - PidFd { id: u32, success: bool, pid: c::pid_t }, + Log { + level: usize, + msg: String, + }, + PidFd { + id: u32, + success: bool, + pid: c::pid_t, + }, } struct Forker { @@ -413,8 +420,11 @@ impl Forker { Ok(o) => o, Err(e) => { if let Some(id) = pidfd_id { - self.outgoing - .push(ForkerMessage::PidFd { id, success: false, pid: 0 }); + self.outgoing.push(ForkerMessage::PidFd { + id, + success: false, + pid: 0, + }); } self.outgoing.push(ForkerMessage::Log { level: log::Level::Error as usize, @@ -427,8 +437,11 @@ impl Forker { Forked::Parent { pid, pidfd } => { if let Some(id) = pidfd_id { self.fds.borrow_mut().push(Rc::new(pidfd)); - self.outgoing - .push(ForkerMessage::PidFd { id, success: true, pid }); + self.outgoing.push(ForkerMessage::PidFd { + id, + success: true, + pid, + }); } drop(write); let slf = self.clone(); diff --git a/src/ifs/jay_idle.rs b/src/ifs/jay_idle.rs index 695b189a..cf6f5c0c 100644 --- a/src/ifs/jay_idle.rs +++ b/src/ifs/jay_idle.rs @@ -1,6 +1,7 @@ use { crate::{ client::{Client, ClientError}, + ifs::wl_surface::zwp_idle_inhibitor_v1::ZwpIdleInhibitorV1, leaks::Tracker, object::Object, utils::buffd::{MsgParser, MsgParserError}, @@ -9,7 +10,6 @@ use { std::{rc::Rc, time::Duration}, thiserror::Error, }; -use crate::ifs::wl_surface::zwp_idle_inhibitor_v1::ZwpIdleInhibitorV1; pub struct JayIdle { pub id: JayIdleId, diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index 51ba71e6..754e0550 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -34,7 +34,6 @@ use { state::State, tree::{ generic_node_visitor, ContainerSplit, FloatNode, FoundNode, Node, OutputNode, - ToplevelNode, }, utils::{ asyncevent::AsyncEvent, @@ -42,7 +41,7 @@ use { clonecell::CloneCell, copyhashmap::CopyHashMap, errorfmt::ErrorFmt, - linkedlist::{LinkedList, LinkedNode}, + linkedlist::{LinkedNode}, rc_eq::rc_eq, }, wire::{ @@ -111,7 +110,6 @@ pub struct WlSeatGlobal { pos: Cell<(Fixed, Fixed)>, pointer_stack: RefCell>>, found_tree: RefCell>, - toplevel_focus_history: LinkedList>, keyboard_node: CloneCell>, pressed_keys: RefCell>, bindings: RefCell>>>, @@ -154,7 +152,6 @@ impl WlSeatGlobal { pos: Cell::new((Fixed(0), Fixed(0))), pointer_stack: RefCell::new(vec![]), found_tree: RefCell::new(vec![]), - toplevel_focus_history: Default::default(), keyboard_node: CloneCell::new(state.root.clone()), pressed_keys: RefCell::new(Default::default()), bindings: Default::default(), diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index 7e39025e..cc8b2c58 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -21,14 +21,17 @@ use { wl_surface::{xdg_surface::xdg_popup::XdgPopup, WlSurface}, }, object::ObjectId, - tree::{FloatNode, Node, ToplevelNode}, + tree::{FloatNode, Node, SizedNode, ToplevelNode}, utils::{clonecell::CloneCell, smallmap::SmallMap}, wire::WlDataOfferId, xkbcommon::{ModifierState, XKB_KEY_DOWN, XKB_KEY_UP}, }, - jay_config::keyboard::{mods::Modifiers, syms::KeySym, ModifiedKeySym}, + jay_config::{ + keyboard::{mods::Modifiers, syms::KeySym, ModifiedKeySym}, + Direction, + }, smallvec::SmallVec, - std::{ops::Deref, rc::Rc}, + std::rc::Rc, }; #[derive(Default)] @@ -94,9 +97,7 @@ impl NodeSeatState { seat.keyboard_node.set(seat.state.root.clone()); // log::info!("keyboard_node = root"); if focus_last { - if let Some(tl) = seat.toplevel_focus_history.last() { - seat.focus_node(tl.focus_surface(seat.id)); - } + seat.output.get().do_focus(&seat, Direction::Unspecified); } } } @@ -269,30 +270,6 @@ impl WlSeatGlobal { self.pointer_stack.borrow().last().cloned() } - pub fn last_tiled_keyboard_toplevel(&self, new: &dyn Node) -> Option> { - let workspace = match self.output.get().workspace.get() { - Some(ws) => ws, - _ => return None, - }; - let is_container = new.node_is_container(); - for tl in self.toplevel_focus_history.rev_iter() { - match tl.as_node().node_get_workspace() { - Some(ws) if ws.id == workspace.id => {} - _ => continue, - }; - let parent_is_float = match tl.parent() { - Some(pn) => pn.node_is_float(), - _ => false, - }; - if !parent_is_float - && (!is_container || !tl.as_node().node_is_contained_in(new.node_id())) - { - return Some(tl.deref().clone()); - } - } - None - } - pub fn move_(&self, node: &Rc) { self.move_.set(true); self.move_start_pos.set(self.pos.get()); @@ -301,8 +278,6 @@ impl WlSeatGlobal { } pub fn focus_toplevel(self: &Rc, n: Rc) { - let node = self.toplevel_focus_history.add_last(n.clone()); - n.data().toplevel_history.insert(self.id, node); self.focus_node(n.focus_surface(self.id)); } diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index fb33481e..197aa3cb 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -30,11 +30,12 @@ use { utils::{ buffd::{MsgParser, MsgParserError}, clonecell::CloneCell, + copyhashmap::CopyHashMap, linkedlist::LinkedList, numcell::NumCell, smallmap::SmallMap, }, - wire::{wl_surface::*, WlOutputId, WlSurfaceId}, + wire::{wl_surface::*, WlOutputId, WlSurfaceId, ZwpIdleInhibitorV1Id}, xkbcommon::ModifierState, }, ahash::AHashMap, @@ -49,8 +50,6 @@ use { thiserror::Error, zwp_idle_inhibitor_v1::ZwpIdleInhibitorV1, }; -use crate::utils::copyhashmap::CopyHashMap; -use crate::wire::ZwpIdleInhibitorV1Id; #[allow(dead_code)] const INVALID_SCALE: u32 = 0; @@ -691,6 +690,10 @@ impl SizedNode for WlSurface { self.visible.get() } + fn parent(&self) -> Option> { + self.toplevel.get().map(|tl| tl.into_node()) + } + fn set_visible(&self, visible: bool) { self.visible.set(visible); for inhibitor in self.idle_inhibitors.lock().values() { diff --git a/src/ifs/wl_surface/xdg_surface/xdg_popup.rs b/src/ifs/wl_surface/xdg_surface/xdg_popup.rs index 59da3800..506fed84 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_popup.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_popup.rs @@ -292,6 +292,10 @@ impl SizedNode for XdgPopup { self.xdg.surface.visible.get() } + fn parent(&self) -> Option> { + self.parent.get().and_then(|x| x.workspace.get().map(|w| w as Rc)) + } + fn set_visible(&self, visible: bool) { log::info!("set visible = {}", visible); self.xdg.set_visible(visible); diff --git a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs index cf062ffa..f2785093 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs @@ -403,6 +403,10 @@ impl SizedNode for XdgToplevel { self.xdg.surface.visible.get() } + fn parent(&self) -> Option> { + self.parent_node.get() + } + fn set_visible(&self, visible: bool) { self.xdg.set_visible(visible); self.xdg.seat_state.set_visible(self, visible); @@ -481,10 +485,6 @@ impl ToplevelNode for XdgToplevel { &self.toplevel_data } - fn parent(&self) -> Option> { - self.parent_node.get() - } - fn as_node(&self) -> &dyn Node { self } diff --git a/src/ifs/wl_surface/xwindow.rs b/src/ifs/wl_surface/xwindow.rs index aeed9127..b589567a 100644 --- a/src/ifs/wl_surface/xwindow.rs +++ b/src/ifs/wl_surface/xwindow.rs @@ -366,6 +366,10 @@ impl SizedNode for Xwindow { self.surface.visible.get() } + fn parent(&self) -> Option> { + self.parent_node.get() + } + fn set_visible(&self, visible: bool) { self.surface.node_set_visible(visible); self.seat_state.set_visible(self, visible); @@ -463,10 +467,6 @@ impl ToplevelNode for Xwindow { &self.toplevel_data } - fn parent(&self) -> Option> { - self.parent_node.get() - } - fn as_node(&self) -> &dyn Node { self } diff --git a/src/ifs/wl_surface/zwlr_layer_surface_v1.rs b/src/ifs/wl_surface/zwlr_layer_surface_v1.rs index f9478344..6fd907ad 100644 --- a/src/ifs/wl_surface/zwlr_layer_surface_v1.rs +++ b/src/ifs/wl_surface/zwlr_layer_surface_v1.rs @@ -381,6 +381,10 @@ impl SizedNode for ZwlrLayerSurfaceV1 { true } + fn parent(&self) -> Option> { + Some(self.output.clone()) + } + fn absolute_position(&self) -> Rect { self.pos.get() } diff --git a/src/state.rs b/src/state.rs index 9ef0af70..21032bb6 100644 --- a/src/state.rs +++ b/src/state.rs @@ -6,7 +6,7 @@ use { InputDeviceId, InputDeviceIds, MonitorInfo, }, cli::RunArgs, - client::{Client, Clients}, + client::{Client, Clients, SerialRange, NUM_CACHED_SERIAL_RANGES}, config::ConfigProxy, cursor::ServerCursors, dbus::Dbus, @@ -42,12 +42,12 @@ use { std::{ cell::{Cell, RefCell}, num::Wrapping, + ops::Deref, rc::Rc, sync::Arc, time::Duration, }, }; -use crate::client::{NUM_CACHED_SERIAL_RANGES, SerialRange}; pub struct State { pub xkb_ctx: XkbContext, @@ -209,39 +209,44 @@ impl State { } pub fn map_tiled(self: &Rc, node: Rc) { - let seat = self.seat_queue.last(); - if let Some(seat) = &seat { - if let Some(prev) = seat.last_tiled_keyboard_toplevel(&*node) { - if let Some(container) = prev.parent() { - if let Some(container) = container.node_into_container() { - container.add_child_after(prev.as_node(), node); - return; - } - } + let output = self + .seat_queue + .last() + .map(|s| s.get_output()) + .or_else(|| self.root.outputs.lock().values().next().cloned()) + .or_else(|| self.dummy_output.get()) + .unwrap(); + let last_active = output.last_active_child(); + let last_active_parent = last_active.node_parent(); + if let Some(lap) = last_active_parent { + if lap.node_is_container() { + let container = lap.node_into_container().unwrap(); + container.add_child_after(last_active.deref(), node); + return; + } + if lap.node_is_workspace() { + let workspace = lap.node_into_workspace().unwrap(); + let container = ContainerNode::new( + self, + &workspace, + workspace.clone(), + last_active.clone(), + ContainerSplit::Horizontal, + ); + workspace.set_container(&container); + container.add_child_after(last_active.deref(), node); + return; } } - let mut output = seat.map(|s| s.get_output()); - if output.is_none() { - let outputs = self.root.outputs.lock(); - output = outputs.values().next().cloned(); - } - let output = match output { - Some(output) => output, - _ => self.dummy_output.get().unwrap(), - }; let workspace = output.ensure_workspace(); - if let Some(container) = workspace.container.get() { - container.append_child(node); - } else { - let container = ContainerNode::new( - self, - &workspace, - workspace.clone(), - node, - ContainerSplit::Horizontal, - ); - workspace.set_container(&container); - }; + let container = ContainerNode::new( + self, + &workspace, + workspace.clone(), + node, + ContainerSplit::Horizontal, + ); + workspace.set_container(&container); } pub fn map_floating( diff --git a/src/tree.rs b/src/tree.rs index bd424ca2..08c4f103 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -75,6 +75,7 @@ pub trait SizedNode: Sized + 'static { fn visit(self: &Rc, visitor: &mut dyn NodeVisitor); fn visit_children(&self, visitor: &mut dyn NodeVisitor); fn visible(&self) -> bool; + fn parent(&self) -> Option>; fn last_active_child(self: &Rc) -> Rc { self.clone() @@ -285,6 +286,10 @@ pub trait SizedNode: Sized + 'static { None } + fn into_workspace(self: &Rc) -> Option> { + None + } + fn is_container(&self) -> bool { false } @@ -372,6 +377,7 @@ pub trait Node { fn node_visit(self: Rc, visitor: &mut dyn NodeVisitor); fn node_visit_children(&self, visitor: &mut dyn NodeVisitor); fn node_visible(&self) -> bool; + fn node_parent(&self) -> Option>; fn node_last_active_child(self: Rc) -> Rc; fn node_set_visible(&self, visible: bool); fn node_get_workspace(&self) -> Option>; @@ -428,6 +434,7 @@ pub trait Node { fn node_render(&self, renderer: &mut Renderer, x: i32, y: i32); fn node_into_float(self: Rc) -> Option>; fn node_into_container(self: Rc) -> Option>; + fn node_into_workspace(self: Rc) -> Option>; fn node_is_container(&self) -> bool; fn node_is_output(&self) -> bool; fn node_into_output(self: Rc) -> Option>; @@ -467,6 +474,9 @@ impl Node for T { fn node_visible(&self) -> bool { ::visible(self) } + fn node_parent(&self) -> Option> { + ::parent(self) + } fn node_last_active_child(self: Rc) -> Rc { ::last_active_child(&self) } @@ -613,6 +623,9 @@ impl Node for T { fn node_into_container(self: Rc) -> Option> { ::into_container(&self) } + fn node_into_workspace(self: Rc) -> Option> { + ::into_workspace(&self) + } fn node_is_container(&self) -> bool { ::is_container(self) } diff --git a/src/tree/container.rs b/src/tree/container.rs index b9fde514..2ca7828d 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -766,6 +766,10 @@ impl SizedNode for ContainerNode { self.visible.get() } + fn parent(&self) -> Option> { + Some(self.parent.get()) + } + fn last_active_child(self: &Rc) -> Rc { if let Some(last) = self.focus_history.last() { return last.node.clone().node_last_active_child(); diff --git a/src/tree/display.rs b/src/tree/display.rs index 6e26fb0e..c152f7a4 100644 --- a/src/tree/display.rs +++ b/src/tree/display.rs @@ -99,6 +99,10 @@ impl SizedNode for DisplayNode { true } + fn parent(&self) -> Option> { + None + } + fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec) -> FindTreeResult { let outputs = self.outputs.lock(); for output in outputs.values() { diff --git a/src/tree/float.rs b/src/tree/float.rs index 19b6be07..5467525f 100644 --- a/src/tree/float.rs +++ b/src/tree/float.rs @@ -352,6 +352,10 @@ impl SizedNode for FloatNode { self.visible.get() } + fn parent(&self) -> Option> { + Some(self.workspace.get()) + } + fn set_visible(&self, visible: bool) { self.visible.set(visible); if let Some(child) = self.child.get() { diff --git a/src/tree/output.rs b/src/tree/output.rs index f7e9a4a0..d8cf449b 100644 --- a/src/tree/output.rs +++ b/src/tree/output.rs @@ -303,6 +303,10 @@ impl SizedNode for OutputNode { true } + fn parent(&self) -> Option> { + Some(self.state.root.clone()) + } + fn last_active_child(self: &Rc) -> Rc { if let Some(ws) = self.workspace.get() { return ws.last_active_child(); @@ -310,6 +314,12 @@ impl SizedNode for OutputNode { self.clone() } + fn do_focus(self: &Rc, seat: &Rc, direction: Direction) { + if let Some(ws) = self.workspace.get() { + ws.do_focus(seat, direction); + } + } + fn absolute_position(&self) -> Rect { self.global.pos.get() } diff --git a/src/tree/toplevel.rs b/src/tree/toplevel.rs index 019d6a84..81488929 100644 --- a/src/tree/toplevel.rs +++ b/src/tree/toplevel.rs @@ -2,7 +2,7 @@ use { crate::{ ifs::{wl_seat::SeatId, wl_surface::WlSurface}, tree::Node, - utils::{linkedlist::LinkedNode, numcell::NumCell, smallmap::SmallMap}, + utils::{numcell::NumCell, smallmap::SmallMap}, }, std::rc::Rc, }; @@ -10,7 +10,6 @@ use { tree_id!(ToplevelNodeId); pub trait ToplevelNode { fn data(&self) -> &ToplevelData; - fn parent(&self) -> Option>; fn as_node(&self) -> &dyn Node; fn into_node(self: Rc) -> Rc; fn accepts_keyboard_focus(&self) -> bool; @@ -25,13 +24,11 @@ pub trait ToplevelNode { pub struct ToplevelData { pub active_surfaces: NumCell, pub focus_surface: SmallMap, 1>, - pub toplevel_history: SmallMap>, 1>, } impl ToplevelData { pub fn clear(&self) { self.focus_surface.clear(); - self.toplevel_history.clear(); } } @@ -54,4 +51,8 @@ impl<'a> dyn ToplevelNode + 'a { .get(&seat) .unwrap_or_else(|| self.default_surface()) } + + pub fn parent(&self) -> Option> { + self.as_node().node_parent() + } } diff --git a/src/tree/workspace.rs b/src/tree/workspace.rs index 70522010..d79236d3 100644 --- a/src/tree/workspace.rs +++ b/src/tree/workspace.rs @@ -13,6 +13,7 @@ use { linkedlist::{LinkedList, LinkedNode}, }, }, + jay_config::Direction, std::{cell::Cell, fmt::Debug, rc::Rc}, }; @@ -74,6 +75,10 @@ impl SizedNode for WorkspaceNode { self.visible.get() } + fn parent(&self) -> Option> { + Some(self.output.get()) + } + fn last_active_child(self: &Rc) -> Rc { if let Some(c) = self.container.get() { return c.last_active_child(); @@ -89,6 +94,12 @@ impl SizedNode for WorkspaceNode { self.seat_state.set_visible(self, visible); } + fn do_focus(self: &Rc, seat: &Rc, direction: Direction) { + if let Some(container) = self.container.get() { + container.do_focus(seat, direction); + } + } + fn absolute_position(&self) -> Rect { self.position.get() } @@ -117,6 +128,10 @@ impl SizedNode for WorkspaceNode { renderer.render_workspace(self, x, y); } + fn into_workspace(self: &Rc) -> Option> { + Some(self.clone()) + } + fn accepts_child(&self, node: &dyn Node) -> bool { node.node_is_container() } diff --git a/src/utils/stack.rs b/src/utils/stack.rs index c74b24cb..15a36d95 100644 --- a/src/utils/stack.rs +++ b/src/utils/stack.rs @@ -1,7 +1,6 @@ -use std::mem; use { crate::utils::ptr_ext::{MutPtrExt, PtrExt}, - std::cell::UnsafeCell, + std::{cell::UnsafeCell, mem}, }; pub struct Stack { @@ -38,8 +37,6 @@ impl Stack { } pub fn take(&self) -> Vec { - unsafe { - mem::take(self.vec.get().deref_mut()) - } + unsafe { mem::take(self.vec.get().deref_mut()) } } }