1
0
Fork 0
forked from wry/wry

autocommit 2022-02-21 23:21:13 CET

This commit is contained in:
Julian Orth 2022-02-21 23:21:13 +01:00
parent 1cbc7a6445
commit 145d1c15b7
31 changed files with 1455 additions and 252 deletions

View file

@ -75,6 +75,22 @@ impl NodeSeatState {
self.kb_foci.len() > 0
}
pub fn release_kb_grab(&self) {
for (_, seat) in &self.kb_foci {
seat.ungrab_kb();
}
}
pub fn release_kb_focus(&self) {
while let Some((_, seat)) = self.kb_foci.pop() {
seat.ungrab_kb();
seat.keyboard_node.set(seat.state.root.clone());
if let Some(tl) = seat.toplevel_focus_history.last() {
seat.focus_xdg_surface(&tl.xdg);
}
}
}
pub fn destroy_node(&self, node: &dyn Node) {
while let Some((_, seat)) = self.grabs.pop() {
seat.pointer_owner.revert_to_default(&seat);
@ -94,12 +110,7 @@ impl NodeSeatState {
}
seat.state.tree_changed();
}
while let Some((_, seat)) = self.kb_foci.pop() {
seat.keyboard_node.set(seat.state.root.clone());
if let Some(tl) = seat.toplevel_focus_history.last() {
seat.focus_xdg_surface(&tl.xdg);
}
}
self.release_kb_focus();
}
}
@ -124,8 +135,9 @@ impl WlSeatGlobal {
Some(o) => o,
_ => return,
};
x += Fixed::from_int(output.x.get());
y += Fixed::from_int(output.y.get());
let pos = output.position();
x += Fixed::from_int(pos.x1());
y += Fixed::from_int(pos.y1());
self.set_new_position(x, y);
}
@ -216,21 +228,16 @@ impl WlSeatGlobal {
self.focus_node(xdg.focus_surface(self));
}
pub fn focus_node(self: &Rc<Self>, node: Rc<dyn Node>) {
let old = self.keyboard_node.get();
if old.id() == node.id() {
return;
}
old.unfocus(self);
if old.seat_state().unfocus(self) {
old.active_changed(false);
}
fn ungrab_kb(self: &Rc<Self>) {
self.kb_owner.ungrab(self);
}
if node.seat_state().focus(self) {
node.active_changed(true);
}
node.clone().focus(self);
self.keyboard_node.set(node.clone());
pub fn grab(self: &Rc<Self>, node: Rc<dyn Node>) {
self.kb_owner.grab(self, node);
}
pub fn focus_node(self: &Rc<Self>, node: Rc<dyn Node>) {
self.kb_owner.set_kb_node(self, node);
}
fn offer_selection<T: ipc::Vtable>(
@ -380,7 +387,7 @@ impl WlSeatGlobal {
let serial = self.serial.fetch_add(1);
self.surface_pointer_event(0, surface, |p| p.send_button(serial, 0, button, state));
self.surface_pointer_frame(surface);
if pressed && surface.belongs_to_toplevel() {
if pressed && surface.accepts_kb_focus() {
self.focus_node(surface.clone());
}
}

View file

@ -0,0 +1,85 @@
use std::rc::Rc;
use crate::CloneCell;
use crate::ifs::wl_seat::WlSeatGlobal;
use crate::tree::Node;
pub struct KbOwnerHolder {
default: Rc<DefaultKbOwner>,
owner: CloneCell<Rc<dyn KbOwner>>,
}
impl Default for KbOwnerHolder {
fn default() -> Self {
Self {
default: Rc::new(DefaultKbOwner),
owner: CloneCell::new(Rc::new(DefaultKbOwner)),
}
}
}
impl KbOwnerHolder {
pub fn grab(&self, seat: &Rc<WlSeatGlobal>, node: Rc<dyn Node>) -> bool {
self.owner.get().grab(seat, node)
}
pub fn ungrab(&self, seat: &Rc<WlSeatGlobal>) {
self.owner.get().ungrab(seat)
}
pub fn set_kb_node(&self, seat: &Rc<WlSeatGlobal>, node: Rc<dyn Node>) {
self.owner.get().set_kb_node(seat, node);
}
}
struct DefaultKbOwner;
struct GrabKbOwner;
trait KbOwner {
fn grab(&self, seat: &Rc<WlSeatGlobal>, node: Rc<dyn Node>) -> bool;
fn ungrab(&self, seat: &Rc<WlSeatGlobal>);
fn set_kb_node(&self, seat: &Rc<WlSeatGlobal>, node: Rc<dyn Node>);
}
impl KbOwner for DefaultKbOwner {
fn grab(&self, seat: &Rc<WlSeatGlobal>, node: Rc<dyn Node>) -> bool {
self.set_kb_node(seat, node);
seat.kb_owner.owner.set(Rc::new(GrabKbOwner));
true
}
fn ungrab(&self, _seat: &Rc<WlSeatGlobal>) {
// nothing
}
fn set_kb_node(&self, seat: &Rc<WlSeatGlobal>, node: Rc<dyn Node>) {
let old = seat.keyboard_node.get();
if old.id() == node.id() {
return;
}
old.unfocus(seat);
if old.seat_state().unfocus(seat) {
old.active_changed(false);
}
if node.seat_state().focus(seat) {
node.active_changed(true);
}
node.clone().focus(seat);
seat.keyboard_node.set(node.clone());
}
}
impl KbOwner for GrabKbOwner {
fn grab(&self, _seat: &Rc<WlSeatGlobal>, _node: Rc<dyn Node>) -> bool {
false
}
fn ungrab(&self, seat: &Rc<WlSeatGlobal>) {
seat.kb_owner.owner.set(seat.kb_owner.default.clone());
}
fn set_kb_node(&self, _seat: &Rc<WlSeatGlobal>, _node: Rc<dyn Node>) {
// nothing
}
}

View file

@ -147,9 +147,11 @@ impl PointerOwner for DefaultPointerOwner {
}
if (stack.len(), found_tree.len()) == (divergence, divergence) {
if let Some(node) = found_tree.last() {
node.node
.clone()
.pointer_motion(seat, x.apply_fract(node.x), y.apply_fract(node.y));
node.node.clone().pointer_motion(
seat,
x.apply_fract(node.x),
y.apply_fract(node.y),
);
}
} else {
if let Some(last) = stack.last() {
@ -161,16 +163,20 @@ impl PointerOwner for DefaultPointerOwner {
}
if found_tree.len() == divergence {
if let Some(node) = found_tree.last() {
node.node
.clone()
.pointer_motion(seat, x.apply_fract(node.x), y.apply_fract(node.y));
node.node.clone().pointer_motion(
seat,
x.apply_fract(node.x),
y.apply_fract(node.y),
);
}
} else {
for new in found_tree.drain(divergence..) {
new.node.seat_state().enter(seat);
new.node
.clone()
.pointer_enter(seat, x.apply_fract(new.x), y.apply_fract(new.y));
new.node.clone().pointer_enter(
seat,
x.apply_fract(new.x),
y.apply_fract(new.y),
);
stack.push(new.node);
}
}