1
0
Fork 0
forked from wry/wry

autocommit 2022-04-18 14:14:25 CEST

This commit is contained in:
Julian Orth 2022-04-18 14:14:25 +02:00
parent 085ca95835
commit 54cf01f745
20 changed files with 155 additions and 109 deletions

View file

@ -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
);
}
}
}

View file

@ -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 }
}

View file

@ -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();

View file

@ -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,

View file

@ -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<Vec<Rc<dyn Node>>>,
found_tree: RefCell<Vec<FoundNode>>,
toplevel_focus_history: LinkedList<Rc<dyn ToplevelNode>>,
keyboard_node: CloneCell<Rc<dyn Node>>,
pressed_keys: RefCell<AHashSet<u32>>,
bindings: RefCell<AHashMap<ClientId, AHashMap<WlSeatId, Rc<WlSeat>>>>,
@ -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(),

View file

@ -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<Rc<dyn ToplevelNode>> {
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<FloatNode>) {
self.move_.set(true);
self.move_start_pos.set(self.pos.get());
@ -301,8 +278,6 @@ impl WlSeatGlobal {
}
pub fn focus_toplevel(self: &Rc<Self>, n: Rc<dyn ToplevelNode>) {
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));
}

View file

@ -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<Rc<dyn Node>> {
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() {

View file

@ -292,6 +292,10 @@ impl SizedNode for XdgPopup {
self.xdg.surface.visible.get()
}
fn parent(&self) -> Option<Rc<dyn Node>> {
self.parent.get().and_then(|x| x.workspace.get().map(|w| w as Rc<dyn Node>))
}
fn set_visible(&self, visible: bool) {
log::info!("set visible = {}", visible);
self.xdg.set_visible(visible);

View file

@ -403,6 +403,10 @@ impl SizedNode for XdgToplevel {
self.xdg.surface.visible.get()
}
fn parent(&self) -> Option<Rc<dyn Node>> {
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<Rc<dyn Node>> {
self.parent_node.get()
}
fn as_node(&self) -> &dyn Node {
self
}

View file

@ -366,6 +366,10 @@ impl SizedNode for Xwindow {
self.surface.visible.get()
}
fn parent(&self) -> Option<Rc<dyn Node>> {
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<Rc<dyn Node>> {
self.parent_node.get()
}
fn as_node(&self) -> &dyn Node {
self
}

View file

@ -381,6 +381,10 @@ impl SizedNode for ZwlrLayerSurfaceV1 {
true
}
fn parent(&self) -> Option<Rc<dyn Node>> {
Some(self.output.clone())
}
fn absolute_position(&self) -> Rect {
self.pos.get()
}

View file

@ -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<Self>, node: Rc<dyn Node>) {
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(

View file

@ -75,6 +75,7 @@ pub trait SizedNode: Sized + 'static {
fn visit(self: &Rc<Self>, visitor: &mut dyn NodeVisitor);
fn visit_children(&self, visitor: &mut dyn NodeVisitor);
fn visible(&self) -> bool;
fn parent(&self) -> Option<Rc<dyn Node>>;
fn last_active_child(self: &Rc<Self>) -> Rc<dyn Node> {
self.clone()
@ -285,6 +286,10 @@ pub trait SizedNode: Sized + 'static {
None
}
fn into_workspace(self: &Rc<Self>) -> Option<Rc<WorkspaceNode>> {
None
}
fn is_container(&self) -> bool {
false
}
@ -372,6 +377,7 @@ pub trait Node {
fn node_visit(self: Rc<Self>, visitor: &mut dyn NodeVisitor);
fn node_visit_children(&self, visitor: &mut dyn NodeVisitor);
fn node_visible(&self) -> bool;
fn node_parent(&self) -> Option<Rc<dyn Node>>;
fn node_last_active_child(self: Rc<Self>) -> Rc<dyn Node>;
fn node_set_visible(&self, visible: bool);
fn node_get_workspace(&self) -> Option<Rc<WorkspaceNode>>;
@ -428,6 +434,7 @@ pub trait Node {
fn node_render(&self, renderer: &mut Renderer, x: i32, y: i32);
fn node_into_float(self: Rc<Self>) -> Option<Rc<FloatNode>>;
fn node_into_container(self: Rc<Self>) -> Option<Rc<ContainerNode>>;
fn node_into_workspace(self: Rc<Self>) -> Option<Rc<WorkspaceNode>>;
fn node_is_container(&self) -> bool;
fn node_is_output(&self) -> bool;
fn node_into_output(self: Rc<Self>) -> Option<Rc<OutputNode>>;
@ -467,6 +474,9 @@ impl<T: SizedNode> Node for T {
fn node_visible(&self) -> bool {
<Self as SizedNode>::visible(self)
}
fn node_parent(&self) -> Option<Rc<dyn Node>> {
<Self as SizedNode>::parent(self)
}
fn node_last_active_child(self: Rc<Self>) -> Rc<dyn Node> {
<Self as SizedNode>::last_active_child(&self)
}
@ -613,6 +623,9 @@ impl<T: SizedNode> Node for T {
fn node_into_container(self: Rc<Self>) -> Option<Rc<ContainerNode>> {
<Self as SizedNode>::into_container(&self)
}
fn node_into_workspace(self: Rc<Self>) -> Option<Rc<WorkspaceNode>> {
<Self as SizedNode>::into_workspace(&self)
}
fn node_is_container(&self) -> bool {
<Self as SizedNode>::is_container(self)
}

View file

@ -766,6 +766,10 @@ impl SizedNode for ContainerNode {
self.visible.get()
}
fn parent(&self) -> Option<Rc<dyn Node>> {
Some(self.parent.get())
}
fn last_active_child(self: &Rc<Self>) -> Rc<dyn Node> {
if let Some(last) = self.focus_history.last() {
return last.node.clone().node_last_active_child();

View file

@ -99,6 +99,10 @@ impl SizedNode for DisplayNode {
true
}
fn parent(&self) -> Option<Rc<dyn Node>> {
None
}
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
let outputs = self.outputs.lock();
for output in outputs.values() {

View file

@ -352,6 +352,10 @@ impl SizedNode for FloatNode {
self.visible.get()
}
fn parent(&self) -> Option<Rc<dyn Node>> {
Some(self.workspace.get())
}
fn set_visible(&self, visible: bool) {
self.visible.set(visible);
if let Some(child) = self.child.get() {

View file

@ -303,6 +303,10 @@ impl SizedNode for OutputNode {
true
}
fn parent(&self) -> Option<Rc<dyn Node>> {
Some(self.state.root.clone())
}
fn last_active_child(self: &Rc<Self>) -> Rc<dyn Node> {
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<Self>, seat: &Rc<WlSeatGlobal>, direction: Direction) {
if let Some(ws) = self.workspace.get() {
ws.do_focus(seat, direction);
}
}
fn absolute_position(&self) -> Rect {
self.global.pos.get()
}

View file

@ -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<Rc<dyn Node>>;
fn as_node(&self) -> &dyn Node;
fn into_node(self: Rc<Self>) -> Rc<dyn Node>;
fn accepts_keyboard_focus(&self) -> bool;
@ -25,13 +24,11 @@ pub trait ToplevelNode {
pub struct ToplevelData {
pub active_surfaces: NumCell<u32>,
pub focus_surface: SmallMap<SeatId, Rc<WlSurface>, 1>,
pub toplevel_history: SmallMap<SeatId, LinkedNode<Rc<dyn ToplevelNode>>, 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<Rc<dyn Node>> {
self.as_node().node_parent()
}
}

View file

@ -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<Rc<dyn Node>> {
Some(self.output.get())
}
fn last_active_child(self: &Rc<Self>) -> Rc<dyn Node> {
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<Self>, seat: &Rc<WlSeatGlobal>, 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<Self>) -> Option<Rc<WorkspaceNode>> {
Some(self.clone())
}
fn accepts_child(&self, node: &dyn Node) -> bool {
node.node_is_container()
}

View file

@ -1,7 +1,6 @@
use std::mem;
use {
crate::utils::ptr_ext::{MutPtrExt, PtrExt},
std::cell::UnsafeCell,
std::{cell::UnsafeCell, mem},
};
pub struct Stack<T> {
@ -38,8 +37,6 @@ impl<T> Stack<T> {
}
pub fn take(&self) -> Vec<T> {
unsafe {
mem::take(self.vec.get().deref_mut())
}
unsafe { mem::take(self.vec.get().deref_mut()) }
}
}