1
0
Fork 0
forked from wry/wry

autocommit 2022-02-02 20:01:25 CET

This commit is contained in:
Julian Orth 2022-02-02 20:01:25 +01:00
parent 65a7a55b82
commit 89b8396932
12 changed files with 279 additions and 57 deletions

View file

@ -294,13 +294,28 @@ impl WlSeatGlobal {
self.handle_new_position(false);
}
fn handle_new_position(self: &Rc<Self>, changed: bool) {
fn handle_new_position(self: &Rc<Self>, pos_changed: bool) {
let (x, y) = self.pos.get();
if changed {
if pos_changed {
if let Some(cursor) = self.cursor.get() {
cursor.set_position(x.round_down(), y.round_down());
}
}
'handle_grab: {
let grab_node = {
let grabber = self.grabber.borrow_mut();
match grabber.as_ref() {
Some(n) => n.node.clone(),
None => break 'handle_grab,
}
};
if pos_changed {
let pos = grab_node.absolute_position();
let (x_int, y_int) = pos.translate(x.round_down(), y.round_down());
grab_node.motion(self, x.apply_fract(x_int), y.apply_fract(y_int));
}
return;
}
let mut found_tree = self.found_tree.borrow_mut();
let mut stack = self.pointer_stack.borrow_mut();
// if self.move_.get() {
@ -332,7 +347,7 @@ impl WlSeatGlobal {
}
}
if (stack.len(), found_tree.len()) == (divergence, divergence) {
if changed {
if pos_changed {
if let Some(node) = found_tree.last() {
node.node
.motion(self, x.apply_fract(node.x), y.apply_fract(node.y));

View file

@ -50,11 +50,25 @@ const TOUCH: u32 = 4;
#[allow(dead_code)]
const MISSING_CAPABILITY: u32 = 0;
#[allow(dead_code)]
const BTN_LEFT: u32 = 0x110;
pub const BTN_LEFT: u32 = 0x110;
pub const SEAT_NAME_SINCE: u32 = 2;
pub struct PointerGrab {
seat: Rc<WlSeatGlobal>,
}
pub struct PointerGrabber {
node: Rc<dyn Node>,
}
impl Drop for PointerGrab {
fn drop(&mut self) {
*self.seat.grabber.borrow_mut() = None;
self.seat.tree_changed();
}
}
pub struct WlSeatGlobal {
name: GlobalName,
state: Rc<State>,
@ -76,6 +90,7 @@ pub struct WlSeatGlobal {
layout_size: u32,
cursor: CloneCell<Option<Rc<dyn Cursor>>>,
serial: NumCell<u32>,
grabber: RefCell<Option<PointerGrabber>>,
}
impl WlSeatGlobal {
@ -118,9 +133,23 @@ impl WlSeatGlobal {
layout_size,
cursor: Default::default(),
serial: Default::default(),
grabber: RefCell::new(None),
}
}
pub fn grab_pointer(self: &Rc<Self>, node: Rc<dyn Node>) -> Option<PointerGrab> {
let mut grabber = self.grabber.borrow_mut();
if grabber.is_some() {
return None;
}
*grabber = Some(PointerGrabber {
node,
});
Some(PointerGrab {
seat: self.clone(),
})
}
pub fn set_known_cursor(&self, cursor: KnownCursor) {
let cursors = match self.state.cursors.get() {
Some(c) => c,

View file

@ -8,7 +8,7 @@ use crate::ifs::xdg_positioner::{XdgPositioned, XdgPositioner, CA};
use crate::object::{Interface, Object, ObjectId};
use crate::rect::Rect;
use crate::render::Renderer;
use crate::tree::{AbsoluteNode, FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode};
use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode};
use crate::utils::buffd::MsgParser;
use crate::utils::clonecell::CloneCell;
use crate::utils::linkedlist::LinkedNode;
@ -37,8 +37,8 @@ pub struct XdgPopup {
pub xdg: Rc<XdgSurface>,
pub(super) parent: CloneCell<Option<Rc<XdgSurface>>>,
relative_position: Cell<Rect>,
display_link: RefCell<Option<LinkedNode<Rc<dyn AbsoluteNode>>>>,
workspace_link: RefCell<Option<LinkedNode<Rc<dyn AbsoluteNode>>>>,
display_link: RefCell<Option<LinkedNode<Rc<dyn Node>>>>,
workspace_link: RefCell<Option<LinkedNode<Rc<dyn Node>>>>,
pos: RefCell<XdgPositioned>,
}
@ -268,16 +268,6 @@ impl Object for XdgPopup {
}
}
impl AbsoluteNode for XdgPopup {
fn into_node(self: Rc<Self>) -> Rc<dyn Node> {
self
}
fn absolute_position(&self) -> (Rect, bool) {
(self.xdg.absolute_desired_extents.get(), false)
}
}
impl Node for XdgPopup {
fn id(&self) -> NodeId {
self.node_id.into()
@ -294,6 +284,14 @@ impl Node for XdgPopup {
self.xdg.seat_state.destroy_node(self);
}
fn absolute_position(&self) -> Rect {
self.xdg.absolute_desired_extents.get()
}
fn absolute_position_constrains_input(&self) -> bool {
false
}
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
self.xdg.find_tree_at(x, y, tree)
}

View file

@ -1,6 +1,6 @@
mod types;
use crate::backend::SeatId;
use crate::backend::{SeatId};
use crate::client::{ClientId, DynEventFormatter};
use crate::fixed::Fixed;
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
@ -388,6 +388,10 @@ impl Node for XdgToplevel {
self.xdg.seat_state.destroy_node(self)
}
fn absolute_position(&self) -> Rect {
self.xdg.absolute_desired_extents.get()
}
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
self.xdg.find_tree_at(x, y, tree)
}
@ -405,12 +409,14 @@ impl Node for XdgToplevel {
}
fn change_extents(self: Rc<Self>, rect: &Rect) {
let nw = rect.width();
let nh = rect.height();
let de = self.xdg.absolute_desired_extents.replace(*rect);
if de.width() != rect.width() || de.height() != rect.height() {
if de.width() != nw || de.height() != nh {
self.xdg
.surface
.client
.event(self.configure(rect.width(), rect.height()));
.event(self.configure(nw.max(1), nh.max(1)));
self.xdg.send_configure();
self.xdg.surface.client.flush();
}

View file

@ -1,9 +1,7 @@
#![feature(
generic_associated_types,
type_alias_impl_trait,
never_type,
c_variadic,
thread_local
thread_local,
label_break_value,
)]
#![allow(
clippy::len_zero,

View file

@ -97,6 +97,7 @@ impl Rect {
self.x1 <= x && self.y1 <= y && self.x2 > x && self.y2 > y
}
#[allow(dead_code)]
pub fn contains_rect(&self, rect: &Self) -> bool {
self.x1 <= rect.x1 && self.y1 <= rect.x1 && rect.x2 <= self.x2 && rect.y2 <= self.y2
}

View file

@ -50,7 +50,7 @@ impl Renderer<'_> {
self.render_container(&node, x, y)
}
for stacked in workspace.stacked.iter() {
let (pos, _) = stacked.absolute_position();
let pos = stacked.absolute_position();
stacked.render(self, pos.x1(), pos.y1());
}
}

View file

@ -1,4 +1,4 @@
use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
use crate::ifs::wl_seat::{BTN_LEFT, NodeSeatState, PointerGrab, WlSeatGlobal};
use crate::rect::Rect;
use crate::render::Renderer;
use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, WorkspaceNode};
@ -8,8 +8,9 @@ use crate::{NumCell, State};
use ahash::AHashMap;
use std::cell::{Cell, RefCell};
use std::mem;
use std::ops::DerefMut;
use std::rc::Rc;
use crate::backend::SeatId;
use crate::backend::{KeyState, SeatId};
use crate::cursor::KnownCursor;
use crate::fixed::Fixed;
@ -67,6 +68,7 @@ struct SeatState {
target: bool,
x: i32,
y: i32,
op: Option<SeatOp>,
}
impl ContainerChild {
@ -109,7 +111,7 @@ impl ContainerNode {
Self {
id: state.node_ids.next(),
parent: CloneCell::new(parent),
split: Cell::new(ContainerSplit::Vertical),
split: Cell::new(ContainerSplit::Horizontal),
mono_child: CloneCell::new(None),
mono_body: Cell::new(Default::default()),
mono_content: Cell::new(Default::default()),
@ -290,9 +292,40 @@ impl ContainerNode {
target: false,
x,
y,
op: None,
});
seat_state.x = x;
seat_state.y = y;
if let Some(op) = &seat_state.op {
match op.kind {
SeatOpKind::Move => {
// todo
}
SeatOpKind::Resize { dist_left, dist_right } => {
let prev = op.child.prev();
let prev_body = prev.body.get();
let child_body = op.child.body.get();
match self.split.get() {
ContainerSplit::Horizontal => {
let cw = self.content_width.get();
if prev_body.x1() + dist_left > x || x + dist_right > child_body.x2() {
return;
}
let prev_factor = (x - prev_body.x1() - dist_left) as f64 / cw as f64;
let child_factor = (child_body.x2() - x - dist_right) as f64 / cw as f64;
let sum_factors = 1.0 - prev.factor.get() - op.child.factor.get() + prev_factor + child_factor;
prev.factor.set(prev_factor);
op.child.factor.set(child_factor);
self.apply_factors(sum_factors);
}
ContainerSplit::Vertical => {
// todo
}
}
}
}
return;
}
let new_cursor = if self.mono_child.get().is_some() {
KnownCursor::Default
} else if self.split.get() == ContainerSplit::Horizontal {
@ -322,6 +355,21 @@ impl ContainerNode {
}
}
struct SeatOp {
_grab: PointerGrab,
child: NodeRef<ContainerChild>,
kind: SeatOpKind,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
enum SeatOpKind {
Move,
Resize {
dist_left: i32,
dist_right: i32,
}
}
impl Node for ContainerNode {
fn id(&self) -> NodeId {
self.id.into()
@ -335,6 +383,7 @@ impl Node for ContainerNode {
if detach {
self.parent.get().remove_child(self);
}
mem::take(self.seats.borrow_mut().deref_mut());
let mut cn = self.child_nodes.borrow_mut();
for (_, n) in cn.drain() {
n.node.destroy_node(false);
@ -342,6 +391,89 @@ impl Node for ContainerNode {
self.seat_state.destroy_node(self);
}
fn absolute_position(&self) -> Rect {
Rect::new_sized(self.abs_x1.get(), self.abs_y1.get(), self.width.get(), self.height.get()).unwrap()
}
fn button(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState) {
if button != BTN_LEFT {
return;
}
let mut seat_datas = self.seats.borrow_mut();
let seat_data = match seat_datas.get_mut(&seat.id()) {
Some(s) => s,
_ => return,
};
if seat_data.op.is_none() {
if state != KeyState::Pressed {
return;
}
let (kind, child) = 'res: {
if self.mono_child.get().is_some() {
let width_per_child = self.width.get() / self.num_children.get() as i32;
let mut width_per_child_rem = self.width.get() % self.num_children.get() as i32;
let mut pos = 0;
for child in self.children.iter() {
pos += width_per_child;
if width_per_child_rem > 0 {
pos += 1;
width_per_child_rem -= 1;
}
if pos > seat_data.x {
break 'res (SeatOpKind::Move, child);
}
}
} else if self.split.get() == ContainerSplit::Horizontal {
for child in self.children.iter() {
let body = child.body.get();
if seat_data.x < body.x2() {
let op = if seat_data.x < body.x1() {
SeatOpKind::Resize {
dist_left: seat_data.x - child.prev().body.get().x2(),
dist_right: body.x1() - seat_data.x,
}
} else {
SeatOpKind::Move
};
break 'res (op, child);
}
}
} else {
for child in self.children.iter() {
let body = child.body.get();
if seat_data.x < body.y1() {
let op = if seat_data.x < body.y1() - CONTAINER_TITLE_HEIGHT {
SeatOpKind::Resize {
dist_left: seat_data.y - child.prev().body.get().y2(),
dist_right: body.y1() - seat_data.x,
}
} else {
SeatOpKind::Move
};
break 'res (op, child);
}
}
};
return;
};
let grab = match seat.grab_pointer(self.clone()) {
None => return,
Some(g) => g,
};
seat_data.op = Some(SeatOp {
_grab: grab,
child,
kind,
})
} else if state == KeyState::Released {
let op = seat_data.op.take().unwrap();
drop(seat_datas);
if op.kind == SeatOpKind::Move {
// todo
}
}
}
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
let mut recurse = |content: Rect, child: NodeRef<ContainerChild>| {
if content.contains(x, y) {
@ -405,6 +537,10 @@ impl Node for ContainerNode {
}
}
fn enter(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, x: Fixed, y: Fixed) {
self.pointer_move(seat, x.round_down(), y.round_down());
}
fn pointer_untarget(&self, seat: &Rc<WlSeatGlobal>) {
let mut seats = self.seats.borrow_mut();
if let Some(seat_state) = seats.get_mut(&seat.id()) {
@ -424,10 +560,6 @@ impl Node for ContainerNode {
self.pointer_move(seat, x.round_down(), y.round_down());
}
fn enter(self: Rc<Self>, seat: &Rc<WlSeatGlobal>, x: Fixed, y: Fixed) {
self.pointer_move(seat, x.round_down(), y.round_down());
}
fn render(&self, renderer: &mut Renderer, x: i32, y: i32) {
renderer.render_container(self, x, y);
}

View file

@ -60,17 +60,19 @@ pub enum FindTreeResult {
Other,
}
pub trait AbsoluteNode: Node {
fn into_node(self: Rc<Self>) -> Rc<dyn Node>;
fn absolute_position(&self) -> (Rect, bool);
}
pub trait Node {
fn id(&self) -> NodeId;
fn seat_state(&self) -> &NodeSeatState;
fn destroy_node(&self, detach: bool);
fn absolute_position(&self) -> Rect {
Rect::new_empty(0, 0)
}
fn absolute_position_constrains_input(&self) -> bool {
true
}
fn active_changed(&self, active: bool) {
let _ = active;
}
@ -183,7 +185,7 @@ tree_id!(ToplevelNodeId);
pub struct DisplayNode {
pub id: NodeId,
pub outputs: CopyHashMap<OutputId, Rc<OutputNode>>,
pub stacked: LinkedList<Rc<dyn AbsoluteNode>>,
pub stacked: LinkedList<Rc<dyn Node>>,
pub seat_state: NodeSeatState,
}
@ -221,15 +223,15 @@ impl Node for DisplayNode {
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
for stacked in self.stacked.rev_iter() {
let (ext, constrain) = stacked.absolute_position();
if constrain && !ext.contains(x, y) {
let ext = stacked.absolute_position();
if stacked.absolute_position_constrains_input() && !ext.contains(x, y) {
// TODO: make constrain always true
continue;
}
let (x, y) = ext.translate(x, y);
let idx = tree.len();
tree.push(FoundNode {
node: stacked.deref().clone().into_node(),
node: stacked.deref().clone(),
x,
y,
});
@ -295,6 +297,10 @@ impl Node for OutputNode {
self.seat_state.destroy_node(self);
}
fn absolute_position(&self) -> Rect {
self.position.get()
}
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
if let Some(ws) = self.workspace.get() {
tree.push(FoundNode {
@ -333,23 +339,13 @@ pub struct FloatNode {
pub visible: Cell<bool>,
pub position: Cell<Rect>,
pub display: Rc<DisplayNode>,
pub display_link: Cell<Option<LinkedNode<Rc<dyn AbsoluteNode>>>>,
pub workspace_link: Cell<Option<LinkedNode<Rc<dyn AbsoluteNode>>>>,
pub display_link: Cell<Option<LinkedNode<Rc<dyn Node>>>>,
pub workspace_link: Cell<Option<LinkedNode<Rc<dyn Node>>>>,
pub workspace: CloneCell<Rc<WorkspaceNode>>,
pub child: CloneCell<Option<Rc<dyn Node>>>,
pub seat_state: NodeSeatState,
}
impl AbsoluteNode for FloatNode {
fn into_node(self: Rc<Self>) -> Rc<dyn Node> {
self
}
fn absolute_position(&self) -> (Rect, bool) {
(self.position.get(), true)
}
}
impl Node for FloatNode {
fn id(&self) -> NodeId {
self.id.into()
@ -368,6 +364,10 @@ impl Node for FloatNode {
self.seat_state.destroy_node(self);
}
fn absolute_position(&self) -> Rect {
self.position.get()
}
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
let child = match self.child.get() {
Some(c) => c,

View file

@ -2,7 +2,7 @@ use crate::ifs::wl_seat::{NodeSeatState, WlSeatGlobal};
use crate::rect::Rect;
use crate::render::Renderer;
use crate::tree::container::ContainerNode;
use crate::tree::{AbsoluteNode, FindTreeResult, FoundNode, Node, NodeId, OutputNode};
use crate::tree::{FindTreeResult, FoundNode, Node, NodeId, OutputNode};
use crate::utils::clonecell::CloneCell;
use crate::utils::linkedlist::LinkedList;
use std::rc::Rc;
@ -14,7 +14,7 @@ pub struct WorkspaceNode {
pub id: WorkspaceNodeId,
pub output: CloneCell<Rc<OutputNode>>,
pub container: CloneCell<Option<Rc<ContainerNode>>>,
pub stacked: LinkedList<Rc<dyn AbsoluteNode>>,
pub stacked: LinkedList<Rc<dyn Node>>,
pub seat_state: NodeSeatState,
}
@ -46,6 +46,10 @@ impl Node for WorkspaceNode {
self.seat_state.destroy_node(self);
}
fn absolute_position(&self) -> Rect {
self.output.get().position.get()
}
fn find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
if let Some(n) = self.container.get() {
tree.push(FoundNode {

View file

@ -196,6 +196,29 @@ impl<T> NodeRef<T> {
pub fn append(&self, t: T) -> LinkedNode<T> {
unsafe { append(self.data, t) }
}
pub fn prev(&self) -> NodeRef<T> {
unsafe {
let data = self.data.as_ref();
let other = data.prev.get();
other.as_ref().rc.fetch_add(1);
NodeRef {
data: other,
}
}
}
#[allow(dead_code)]
pub fn next(&self) -> NodeRef<T> {
unsafe {
let data = self.data.as_ref();
let other = data.next.get();
other.as_ref().rc.fetch_add(1);
NodeRef {
data: other,
}
}
}
}
struct NodeData<T> {

16
todo.md Normal file
View file

@ -0,0 +1,16 @@
- Container resizing
- Container moving (mouse)
- Container moving (kb)
- Float toggle
- Toplevel splitting
- Shortcuts
- Config
- Workspaces
- Float moving
- Highlighting active
- dnd
- clipboard
- primary selection
- presentation time
- viewporter
- session lock