diff --git a/src/ifs/ipc/mod.rs b/src/ifs/ipc/mod.rs index 84934a73..78c22f4c 100644 --- a/src/ifs/ipc/mod.rs +++ b/src/ifs/ipc/mod.rs @@ -1,16 +1,16 @@ use crate::client::{Client, ClientId, WaylandObject}; use crate::ifs::wl_seat::WlSeatGlobal; use crate::object::ObjectId; +use crate::utils::bitflags::BitflagsExt; use crate::utils::clonecell::CloneCell; use crate::utils::smallmap::SmallMap; +use crate::NumCell; use ahash::AHashSet; use std::cell::{Cell, RefCell}; -use std::ops::{Deref}; +use std::ops::Deref; use std::rc::Rc; use thiserror::Error; use uapi::OwnedFd; -use crate::NumCell; -use crate::utils::bitflags::BitflagsExt; pub mod wl_data_device; pub mod wl_data_device_manager; @@ -122,7 +122,7 @@ impl Default for SharedState { role: Cell::new(Role::Selection), receiver_actions: Cell::new(0), receiver_preferred_action: Cell::new(0), - selected_action: Cell::new(0) + selected_action: Cell::new(0), } } } @@ -272,7 +272,10 @@ fn destroy_offer(offer: &T::Offer) { if let Some(src) = data.source.take() { let src_data = T::get_source_data(&src); src_data.offers.remove(&T::get_offer_id(offer)); - if src_data.offers.is_empty() && src_data.role.get() == Role::Dnd && data.shared.state.get().contains(OFFER_STATE_DROPPED) { + if src_data.offers.is_empty() + && src_data.role.get() == Role::Dnd + && data.shared.state.get().contains(OFFER_STATE_DROPPED) + { if let Some(seat) = src_data.seat.take() { T::unset(&seat, data.shared.role.get()); } diff --git a/src/ifs/ipc/wl_data_offer.rs b/src/ifs/ipc/wl_data_offer.rs index ad1dc4fe..8dacc9a3 100644 --- a/src/ifs/ipc/wl_data_offer.rs +++ b/src/ifs/ipc/wl_data_offer.rs @@ -1,15 +1,18 @@ use crate::client::{Client, ClientError}; use crate::ifs::ipc::wl_data_device::WlDataDevice; -use crate::ifs::ipc::{break_offer_loops, destroy_offer, receive, OfferData, Role, OFFER_STATE_FINISHED, OFFER_STATE_DROPPED, OFFER_STATE_ACCEPTED, SOURCE_STATE_FINISHED}; +use crate::ifs::ipc::wl_data_device_manager::DND_ALL; +use crate::ifs::ipc::{ + break_offer_loops, destroy_offer, receive, OfferData, Role, OFFER_STATE_ACCEPTED, + OFFER_STATE_DROPPED, OFFER_STATE_FINISHED, SOURCE_STATE_FINISHED, +}; use crate::object::Object; +use crate::utils::bitflags::BitflagsExt; use crate::utils::buffd::MsgParser; use crate::utils::buffd::MsgParserError; use crate::wire::wl_data_offer::*; use crate::wire::WlDataOfferId; use std::rc::Rc; use thiserror::Error; -use crate::ifs::ipc::wl_data_device_manager::{DND_ALL}; -use crate::utils::bitflags::BitflagsExt; #[allow(dead_code)] const INVALID_FINISH: u32 = 0; @@ -126,7 +129,10 @@ impl WlDataOffer { return Err(SetActionsError::MultiplePreferred); } self.data.shared.receiver_actions.set(req.dnd_actions); - self.data.shared.receiver_preferred_action.set(req.preferred_action); + self.data + .shared + .receiver_preferred_action + .set(req.preferred_action); if let Some(src) = self.data.source.get() { src.update_selected_action(); } diff --git a/src/ifs/ipc/wl_data_source.rs b/src/ifs/ipc/wl_data_source.rs index d6fd3e37..696e17f4 100644 --- a/src/ifs/ipc/wl_data_source.rs +++ b/src/ifs/ipc/wl_data_source.rs @@ -1,8 +1,13 @@ use crate::client::{Client, ClientError}; use crate::ifs::ipc::wl_data_device::WlDataDevice; +use crate::ifs::ipc::wl_data_device_manager::{DND_ALL, DND_NONE}; use crate::ifs::ipc::wl_data_offer::WlDataOffer; -use crate::ifs::ipc::{add_mime_type, break_source_loops, cancel_offers, destroy_source, OFFER_STATE_ACCEPTED, OFFER_STATE_DROPPED, SharedState, SourceData}; +use crate::ifs::ipc::{ + add_mime_type, break_source_loops, cancel_offers, destroy_source, SharedState, SourceData, + OFFER_STATE_ACCEPTED, OFFER_STATE_DROPPED, +}; use crate::object::Object; +use crate::utils::bitflags::BitflagsExt; use crate::utils::buffd::MsgParser; use crate::utils::buffd::MsgParserError; use crate::wire::wl_data_source::*; @@ -10,8 +15,6 @@ use crate::wire::WlDataSourceId; use std::rc::Rc; use thiserror::Error; use uapi::OwnedFd; -use crate::ifs::ipc::wl_data_device_manager::{DND_ALL, DND_NONE}; -use crate::utils::bitflags::BitflagsExt; #[allow(dead_code)] const INVALID_ACTION_MASK: u32 = 0; @@ -32,7 +35,14 @@ impl WlDataSource { } pub fn on_leave(&self) { - if self.data.shared.get().state.get().contains(OFFER_STATE_DROPPED) { + if self + .data + .shared + .get() + .state + .get() + .contains(OFFER_STATE_DROPPED) + { return; } self.data.shared.set(Rc::new(SharedState::default())); @@ -58,7 +68,12 @@ impl WlDataSource { } else { 0 }; - log::info!("sa = {}, ra = {}, action = {}", server_actions, shared.receiver_actions.get(), action); + log::info!( + "sa = {}, ra = {}, action = {}", + server_actions, + shared.receiver_actions.get(), + action + ); if shared.selected_action.replace(action) != action { for (_, offer) in &self.data.offers { offer.send_action(action); @@ -110,11 +125,16 @@ impl WlDataSource { } pub fn send_action(&self, dnd_action: u32) { - self.data.client.event(Action { self_id: self.id, dnd_action, }) + self.data.client.event(Action { + self_id: self.id, + dnd_action, + }) } pub fn send_dnd_drop_performed(&self) { - self.data.client.event(DndDropPerformed { self_id: self.id }) + self.data + .client + .event(DndDropPerformed { self_id: self.id }) } fn offer(&self, parser: MsgParser<'_, '_>) -> Result<(), OfferError> { diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index 946ccd19..f5820318 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -1,8 +1,8 @@ mod event_handling; +mod pointer_owner; pub mod wl_keyboard; pub mod wl_pointer; pub mod wl_touch; -mod pointer_owner; use crate::backend::{Seat, SeatId}; use crate::client::{Client, ClientError, ClientId}; @@ -15,6 +15,7 @@ use crate::ifs::ipc::wl_data_source::WlDataSource; use crate::ifs::ipc::zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1; use crate::ifs::ipc::zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1; use crate::ifs::ipc::IpcError; +use crate::ifs::wl_seat::pointer_owner::PointerOwnerHolder; use crate::ifs::wl_seat::wl_keyboard::{WlKeyboard, WlKeyboardError, REPEAT_INFO_SINCE}; use crate::ifs::wl_seat::wl_pointer::WlPointer; use crate::ifs::wl_seat::wl_touch::WlTouch; @@ -43,7 +44,6 @@ use std::io::Write; use std::rc::Rc; use thiserror::Error; use uapi::{c, OwnedFd}; -use crate::ifs::wl_seat::pointer_owner::{PointerOwnerHolder}; const POINTER: u32 = 1; const KEYBOARD: u32 = 2; @@ -160,7 +160,7 @@ impl WlSeatGlobal { selection: Default::default(), primary_selection: Default::default(), pointer_owner: Default::default(), - dropped_dnd: RefCell::new(None) + dropped_dnd: RefCell::new(None), } } @@ -177,9 +177,7 @@ impl WlSeatGlobal { } if let Some(client) = self.keyboard_node.get().client() { match src { - Some(src) => { - ipc::offer_source_to::(&src, &client) - }, + Some(src) => ipc::offer_source_to::(&src, &client), _ => T::for_each_device(self, client.id, |device| { T::send_selection(device, ObjectId::NONE.into()); }), diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index 3cfe8d41..f09dd3f8 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -6,7 +6,7 @@ use crate::ifs::ipc::wl_data_device::WlDataDevice; use crate::ifs::ipc::zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1; use crate::ifs::wl_seat::wl_keyboard::WlKeyboard; use crate::ifs::wl_seat::wl_pointer::{WlPointer, POINTER_FRAME_SINCE_VERSION}; -use crate::ifs::wl_seat::{wl_keyboard, wl_pointer, WlSeat, WlSeatGlobal, Dnd}; +use crate::ifs::wl_seat::{wl_keyboard, wl_pointer, Dnd, WlSeat, WlSeatGlobal}; use crate::ifs::wl_surface::xdg_surface::xdg_popup::XdgPopup; use crate::ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel; use crate::ifs::wl_surface::xdg_surface::XdgSurface; @@ -17,7 +17,7 @@ use crate::utils::clonecell::CloneCell; use crate::utils::smallmap::SmallMap; use crate::wire::WlDataOfferId; use crate::xkbcommon::{ModifierState, XKB_KEY_DOWN, XKB_KEY_UP}; -use std::ops::{Deref}; +use std::ops::Deref; use std::rc::Rc; #[derive(Default)] @@ -225,9 +225,7 @@ impl WlSeatGlobal { client: &Rc, ) { match field.get() { - Some(sel) => { - ipc::offer_source_to::(&sel, &client) - }, + Some(sel) => ipc::offer_source_to::(&sel, &client), None => T::for_each_device(self, client.id, |dd| { T::send_selection(dd, ObjectId::NONE.into()); }), diff --git a/src/ifs/wl_seat/pointer_owner.rs b/src/ifs/wl_seat/pointer_owner.rs index 31539995..b20b3e6e 100644 --- a/src/ifs/wl_seat/pointer_owner.rs +++ b/src/ifs/wl_seat/pointer_owner.rs @@ -1,5 +1,3 @@ -use std::cell::Cell; -use std::rc::Rc; use crate::backend::{KeyState, ScrollAxis}; use crate::fixed::Fixed; use crate::ifs::ipc; @@ -10,6 +8,8 @@ use crate::ifs::wl_surface::WlSurface; use crate::tree::{FoundNode, Node}; use crate::utils::clonecell::CloneCell; use crate::utils::smallmap::SmallMap; +use std::cell::Cell; +use std::rc::Rc; pub struct PointerOwnerHolder { default: Rc, @@ -38,12 +38,17 @@ impl PointerOwnerHolder { self.owner.get().handle_pointer_position(seat) } - pub fn start_drag(&self, seat: &Rc, origin: &Rc, source: Option>) -> Result<(), WlSeatError> { + pub fn start_drag( + &self, + seat: &Rc, + origin: &Rc, + source: Option>, + ) -> Result<(), WlSeatError> { self.owner.get().start_drag(seat, origin, source) } pub fn cancel_dnd(&self, seat: &Rc) { - self.owner.get().cancel_dnd(seat) + self.owner.get().cancel_dnd(seat) } pub fn revert_to_default(&self, seat: &Rc) { @@ -59,7 +64,12 @@ trait PointerOwner { fn button(&self, seat: &Rc, button: u32, state: KeyState); fn scroll(&self, seat: &Rc, delta: i32, axis: ScrollAxis); fn handle_pointer_position(&self, seat: &Rc); - fn start_drag(&self, seat: &Rc, origin: &Rc, source: Option>) -> Result<(), WlSeatError>; + fn start_drag( + &self, + seat: &Rc, + origin: &Rc, + source: Option>, + ) -> Result<(), WlSeatError>; fn cancel_dnd(&self, seat: &Rc); fn revert_to_default(&self, seat: &Rc); fn dnd_target_removed(&self, seat: &Rc); @@ -124,7 +134,8 @@ impl PointerOwner for DefaultPointerOwner { } if (stack.len(), found_tree.len()) == (divergence, divergence) { if let Some(node) = found_tree.last() { - node.node.motion(seat, x.apply_fract(node.x), y.apply_fract(node.y)); + node.node + .motion(seat, x.apply_fract(node.x), y.apply_fract(node.y)); } } else { if let Some(last) = stack.last() { @@ -156,7 +167,12 @@ impl PointerOwner for DefaultPointerOwner { found_tree.clear(); } - fn start_drag(&self, _seat: &Rc, _origin: &Rc, _source: Option>) -> Result<(), WlSeatError> { + fn start_drag( + &self, + _seat: &Rc, + _origin: &Rc, + _source: Option>, + ) -> Result<(), WlSeatError> { Ok(()) } @@ -181,12 +197,14 @@ impl PointerOwner for GrabPointerOwner { if self.buttons.is_empty() { self.node.seat_state().remove_pointer_grab(seat); seat.tree_changed.trigger(); - seat.pointer_owner.owner.set(seat.pointer_owner.default.clone()); + seat.pointer_owner + .owner + .set(seat.pointer_owner.default.clone()); } - }, + } KeyState::Pressed => { self.buttons.insert(button, ()); - }, + } } self.node.clone().button(seat, button, state); } @@ -199,10 +217,16 @@ impl PointerOwner for GrabPointerOwner { let (x, y) = seat.pos.get(); let pos = self.node.absolute_position(); let (x_int, y_int) = pos.translate(x.round_down(), y.round_down()); - self.node.motion(seat, x.apply_fract(x_int), y.apply_fract(y_int)); + self.node + .motion(seat, x.apply_fract(x_int), y.apply_fract(y_int)); } - fn start_drag(&self, seat: &Rc, origin: &Rc, src: Option>) -> Result<(), WlSeatError> { + fn start_drag( + &self, + seat: &Rc, + origin: &Rc, + src: Option>, + ) -> Result<(), WlSeatError> { let button = match self.buttons.iter().next() { Some((b, _)) => b, None => return Ok(()), @@ -252,7 +276,9 @@ impl PointerOwner for GrabPointerOwner { fn revert_to_default(&self, seat: &Rc) { self.node.seat_state().remove_pointer_grab(seat); - seat.pointer_owner.owner.set(seat.pointer_owner.default.clone()); + seat.pointer_owner + .owner + .set(seat.pointer_owner.default.clone()); } fn dnd_target_removed(&self, seat: &Rc) { @@ -283,7 +309,9 @@ impl PointerOwner for DndPointerOwner { ipc::detach_seat::(src); } } - seat.pointer_owner.owner.set(seat.pointer_owner.default.clone()); + seat.pointer_owner + .owner + .set(seat.pointer_owner.default.clone()); seat.tree_changed.trigger(); } @@ -302,11 +330,7 @@ impl PointerOwner for DndPointerOwner { y: y_int, }); seat.state.root.find_tree_at(x_int, y_int, &mut found_tree); - let FoundNode { - node, - x, - y, - } = found_tree.pop().unwrap(); + let FoundNode { node, x, y } = found_tree.pop().unwrap(); found_tree.clear(); (node, x, y) }; @@ -326,7 +350,12 @@ impl PointerOwner for DndPointerOwner { self.pos_y.set(y); } - fn start_drag(&self, _seat: &Rc, _origin: &Rc, _source: Option>) -> Result<(), WlSeatError> { + fn start_drag( + &self, + _seat: &Rc, + _origin: &Rc, + _source: Option>, + ) -> Result<(), WlSeatError> { Ok(()) } @@ -337,7 +366,9 @@ impl PointerOwner for DndPointerOwner { if let Some(src) = &self.dnd.src { ipc::detach_seat::(src); } - seat.pointer_owner.owner.set(seat.pointer_owner.default.clone()); + seat.pointer_owner + .owner + .set(seat.pointer_owner.default.clone()); seat.tree_changed.trigger(); }