1
0
Fork 0
forked from wry/wry

autocommit 2022-04-19 13:08:10 CEST

This commit is contained in:
Julian Orth 2022-04-19 13:08:10 +02:00
parent 54cf01f745
commit c1773c0fee
12 changed files with 136 additions and 45 deletions

View file

@ -32,16 +32,15 @@ use {
leaks::Tracker,
object::{Object, ObjectId},
state::State,
tree::{
generic_node_visitor, ContainerSplit, FloatNode, FoundNode, Node, OutputNode,
},
tree::{generic_node_visitor, ContainerSplit, FloatNode, FoundNode, Node, OutputNode},
utils::{
asyncevent::AsyncEvent,
buffd::{MsgParser, MsgParserError},
clonecell::CloneCell,
copyhashmap::CopyHashMap,
errorfmt::ErrorFmt,
linkedlist::{LinkedNode},
linkedlist::LinkedNode,
numcell::NumCell,
rc_eq::rc_eq,
},
wire::{
@ -137,8 +136,12 @@ pub struct WlSeatGlobal {
tree_changed_handler: Cell<Option<SpawnedFuture<()>>>,
output: CloneCell<Rc<OutputNode>>,
desired_known_cursor: Cell<Option<KnownCursor>>,
changes: NumCell<u32>,
}
const CHANGE_CURSOR_MOVED: u32 = 1 << 0;
const CHANGE_TREE: u32 = 1 << 1;
impl WlSeatGlobal {
pub fn new(name: GlobalName, seat_name: &str, state: &Rc<State>) -> Rc<Self> {
let slf = Rc::new(Self {
@ -174,13 +177,15 @@ impl WlSeatGlobal {
tree_changed_handler: Cell::new(None),
output: CloneCell::new(state.dummy_output.get().unwrap()),
desired_known_cursor: Cell::new(None),
changes: NumCell::new(CHANGE_CURSOR_MOVED | CHANGE_TREE),
});
let seat = slf.clone();
let future = state.eng.spawn(async move {
loop {
seat.tree_changed.triggered().await;
seat.state.tree_changed_sent.set(false);
seat.tree_changed();
seat.changes.or_assign(CHANGE_TREE);
seat.apply_changes();
}
});
slf.tree_changed_handler.set(Some(future));

View file

@ -16,13 +16,13 @@ use {
AXIS_SOURCE_SINCE_VERSION, AXIS_STOP_SINCE_VERSION,
POINTER_FRAME_SINCE_VERSION, WHEEL_TILT, WHEEL_TILT_SINCE_VERSION,
},
Dnd, SeatId, WlSeat, WlSeatGlobal,
Dnd, SeatId, WlSeat, WlSeatGlobal, CHANGE_CURSOR_MOVED,
},
wl_surface::{xdg_surface::xdg_popup::XdgPopup, WlSurface},
},
object::ObjectId,
tree::{FloatNode, Node, SizedNode, ToplevelNode},
utils::{clonecell::CloneCell, smallmap::SmallMap},
utils::{bitflags::BitflagsExt, clonecell::CloneCell, smallmap::SmallMap},
wire::WlDataOfferId,
xkbcommon::{ModifierState, XKB_KEY_DOWN, XKB_KEY_UP},
},
@ -400,7 +400,11 @@ impl WlSeatGlobal {
fn set_new_position(self: &Rc<Self>, x: Fixed, y: Fixed) {
self.pos.set((x, y));
self.handle_new_position(true);
if let Some(cursor) = self.cursor.get() {
cursor.set_position(x.round_down(), y.round_down());
}
self.changes.or_assign(CHANGE_CURSOR_MOVED);
self.apply_changes();
}
pub fn add_shortcut(&self, mods: Modifiers, keysym: KeySym) {
@ -415,18 +419,9 @@ impl WlSeatGlobal {
self.tree_changed.trigger();
}
pub(super) fn tree_changed(self: &Rc<Self>) {
self.handle_new_position(false);
}
fn handle_new_position(self: &Rc<Self>, pos_changed: bool) {
let (x, y) = self.pos.get();
if pos_changed {
if let Some(cursor) = self.cursor.get() {
cursor.set_position(x.round_down(), y.round_down());
}
}
self.pointer_owner.handle_pointer_position(self);
pub(super) fn apply_changes(self: &Rc<Self>) {
self.pointer_owner.apply_changes(self);
self.changes.set(0);
}
}
@ -492,7 +487,7 @@ impl WlSeatGlobal {
// Enter callbacks
impl WlSeatGlobal {
pub fn enter_toplevel(self: &Rc<Self>, n: Rc<dyn ToplevelNode>) {
if n.accepts_keyboard_focus() {
if n.accepts_keyboard_focus() && self.changes.get().contains(CHANGE_CURSOR_MOVED) {
self.focus_toplevel(n);
}
}

View file

@ -58,8 +58,8 @@ impl PointerOwnerHolder {
}
}
pub fn handle_pointer_position(&self, seat: &Rc<WlSeatGlobal>) {
self.owner.get().handle_pointer_position(seat)
pub fn apply_changes(&self, seat: &Rc<WlSeatGlobal>) {
self.owner.get().apply_changes(seat)
}
pub fn start_drag(
@ -99,7 +99,7 @@ impl PointerOwnerHolder {
trait PointerOwner {
fn button(&self, seat: &Rc<WlSeatGlobal>, button: u32, state: KeyState);
fn axis_node(&self, seat: &Rc<WlSeatGlobal>) -> Option<Rc<dyn Node>>;
fn handle_pointer_position(&self, seat: &Rc<WlSeatGlobal>);
fn apply_changes(&self, seat: &Rc<WlSeatGlobal>);
fn start_drag(
&self,
seat: &Rc<WlSeatGlobal>,
@ -155,7 +155,7 @@ impl PointerOwner for DefaultPointerOwner {
seat.pointer_node()
}
fn handle_pointer_position(&self, seat: &Rc<WlSeatGlobal>) {
fn apply_changes(&self, seat: &Rc<WlSeatGlobal>) {
let (x, y) = seat.pos.get();
let mut found_tree = seat.found_tree.borrow_mut();
let mut stack = seat.pointer_stack.borrow_mut();
@ -278,7 +278,7 @@ impl PointerOwner for GrabPointerOwner {
Some(self.node.clone())
}
fn handle_pointer_position(&self, seat: &Rc<WlSeatGlobal>) {
fn apply_changes(&self, seat: &Rc<WlSeatGlobal>) {
let (x, y) = seat.pos.get();
let pos = self.node.node_absolute_position();
let (x_int, y_int) = pos.translate(x.round_down(), y.round_down());
@ -341,7 +341,7 @@ impl PointerOwner for GrabPointerOwner {
// old.unfocus(seat);
// }
seat.pointer_owner.owner.set(pointer_owner.clone());
pointer_owner.handle_pointer_position(seat);
pointer_owner.apply_changes(seat);
Ok(())
}
@ -405,7 +405,7 @@ impl PointerOwner for DndPointerOwner {
None
}
fn handle_pointer_position(&self, seat: &Rc<WlSeatGlobal>) {
fn apply_changes(&self, seat: &Rc<WlSeatGlobal>) {
let (x, y) = seat.pos.get();
let (x_int, y_int) = (x.round_down(), y.round_down());
let (node, x_int, y_int) = {

View file

@ -293,7 +293,9 @@ impl SizedNode for XdgPopup {
}
fn parent(&self) -> Option<Rc<dyn Node>> {
self.parent.get().and_then(|x| x.workspace.get().map(|w| w as 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) {

View file

@ -319,9 +319,9 @@ impl XdgToplevel {
}
fn map_floating(self: &Rc<Self>, workspace: &Rc<WorkspaceNode>) {
let extents = self.xdg.extents.get();
let (width, height) = self.toplevel_data.float_size(workspace);
let state = &self.xdg.surface.client.state;
state.map_floating(self.clone(), extents.width(), extents.height(), workspace);
state.map_floating(self.clone(), width, height, workspace);
}
fn map_child(self: &Rc<Self>, parent: &XdgToplevel) {
@ -459,6 +459,10 @@ impl SizedNode for XdgToplevel {
let nh = rect.height();
let de = self.xdg.absolute_desired_extents.get();
if de.width() != nw || de.height() != nh {
if self.toplevel_data.is_floating.get() {
self.toplevel_data.float_width.set(rect.width());
self.toplevel_data.float_height.set(rect.height());
}
self.send_configure_checked(nw, nh);
self.xdg.do_send_configure();
self.xdg.surface.client.flush();
@ -471,6 +475,7 @@ impl SizedNode for XdgToplevel {
}
fn set_parent(self: &Rc<Self>, parent: Rc<dyn Node>) {
self.toplevel_data.is_floating.set(parent.node_is_float());
self.parent_node.set(Some(parent));
self.notify_parent();
}

View file

@ -435,6 +435,10 @@ impl SizedNode for Xwindow {
// log::info!("xwin {} change_extents {:?}", self.data.window_id, rect);
let old = self.data.info.extents.replace(*rect);
if old != *rect {
if self.toplevel_data.is_floating.get() {
self.toplevel_data.float_width.set(rect.width());
self.toplevel_data.float_height.set(rect.height());
}
if !self.data.info.override_redirect.get() {
self.data
.state
@ -453,6 +457,7 @@ impl SizedNode for Xwindow {
}
fn set_parent(self: &Rc<Self>, parent: Rc<dyn Node>) {
self.toplevel_data.is_floating.set(parent.node_is_float());
self.parent_node.set(Some(parent));
self.notify_parent();
}
@ -508,10 +513,10 @@ impl ToplevelNode for Xwindow {
self.data.state.map_tiled(self.clone());
} else if let Some(ws) = self.workspace.get() {
parent.node_remove_child(&*self);
let extents = self.data.info.extents.get();
let (width, height) = self.toplevel_data.float_size(&ws);
self.data
.state
.map_floating(self.clone(), extents.width(), extents.height(), &ws);
.map_floating(self.clone(), width, height, &ws);
}
}