1
0
Fork 0
forked from wry/wry

seat: add cursor groups

This commit is contained in:
Julian Orth 2024-04-30 22:45:07 +02:00
parent dc97827f7a
commit efdca4de49
28 changed files with 629 additions and 401 deletions

View file

@ -57,7 +57,7 @@ impl JayInput {
name: data.seat_name(),
repeat_rate: data.get_rate().0,
repeat_delay: data.get_rate().1,
hardware_cursor: data.hardware_cursor() as _,
hardware_cursor: data.cursor_group().hardware_cursor() as _,
});
}
@ -202,7 +202,8 @@ impl JayInputRequestHandler for JayInput {
) -> Result<(), Self::Error> {
self.or_error(|| {
let seat = self.seat(req.seat)?;
seat.set_hardware_cursor(req.use_hardware_cursor != 0);
seat.cursor_group()
.set_hardware_cursor(req.use_hardware_cursor != 0);
Ok(())
})
}
@ -316,7 +317,7 @@ impl JayInputRequestHandler for JayInput {
fn set_cursor_size(&self, req: SetCursorSize, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.or_error(|| {
let seat = self.seat(req.seat)?;
seat.set_cursor_size(req.size);
seat.cursor_group().set_cursor_size(req.size);
Ok(())
})
}

View file

@ -42,7 +42,7 @@ impl JayPointerRequestHandler for JayPointer {
if pointer_node.node_client_id() != Some(self.client.id) {
return Ok(());
}
self.seat.set_known_cursor(cursor);
self.seat.pointer_cursor().set_known(cursor);
Ok(())
}
}

View file

@ -22,7 +22,7 @@ use {
crate::{
async_engine::SpawnedFuture,
client::{Client, ClientError, ClientId},
cursor::{Cursor, KnownCursor, DEFAULT_CURSOR_SIZE},
cursor_user::{CursorUser, CursorUserGroup, CursorUserOwner},
fixed::Fixed,
globals::{Global, GlobalName},
ifs::{
@ -63,7 +63,6 @@ use {
},
leaks::Tracker,
object::{Object, Version},
rect::Rect,
state::{DeviceHandlerData, State},
time::now_usec,
tree::{
@ -73,7 +72,7 @@ use {
utils::{
asyncevent::AsyncEvent, bindings::PerClientBindings, clonecell::CloneCell,
copyhashmap::CopyHashMap, errorfmt::ErrorFmt, linkedlist::LinkedNode, numcell::NumCell,
rc_eq::rc_eq, smallmap::SmallMap, transform_ext::TransformExt,
rc_eq::rc_eq, smallmap::SmallMap,
},
wire::{
wl_seat::*, ExtIdleNotificationV1Id, WlDataDeviceId, WlKeyboardId, WlPointerId,
@ -141,7 +140,6 @@ pub struct WlSeatGlobal {
state: Rc<State>,
seat_name: String,
pos_time_usec: Cell<u64>,
pos: Cell<(Fixed, Fixed)>,
pointer_stack: RefCell<Vec<Rc<dyn Node>>>,
pointer_stack_modified: Cell<bool>,
found_tree: RefCell<Vec<FoundNode>>,
@ -162,7 +160,8 @@ pub struct WlSeatGlobal {
seat_xkb_state: CloneCell<Rc<RefCell<XkbState>>>,
latest_kb_state: CloneCell<Rc<dyn DynKeyboardState>>,
xkb_states: CopyHashMap<KeymapId, Weak<RefCell<XkbState>>>,
cursor: CloneCell<Option<Rc<dyn Cursor>>>,
cursor_user_group: Rc<CursorUserGroup>,
pointer_cursor: Rc<CursorUser>,
tree_changed: Rc<AsyncEvent>,
selection: CloneCell<Option<Rc<dyn DynDataSource>>>,
selection_serial: Cell<u32>,
@ -175,11 +174,7 @@ pub struct WlSeatGlobal {
shortcuts: RefCell<AHashMap<u32, SmallMap<u32, u32, 2>>>,
queue_link: RefCell<Option<LinkedNode<Rc<Self>>>>,
tree_changed_handler: Cell<Option<SpawnedFuture<()>>>,
output: CloneCell<Rc<OutputNode>>,
desired_known_cursor: Cell<Option<KnownCursor>>,
changes: NumCell<u32>,
cursor_size: Cell<u32>,
hardware_cursor: Cell<bool>,
constraint: CloneCell<Option<Rc<SeatConstraint>>>,
idle_notifications: CopyHashMap<(ClientId, ExtIdleNotificationV1Id), Rc<ExtIdleNotificationV1>>,
last_input_usec: Cell<u64>,
@ -197,12 +192,6 @@ pub struct WlSeatGlobal {
const CHANGE_CURSOR_MOVED: u32 = 1 << 0;
const CHANGE_TREE: u32 = 1 << 1;
impl Drop for WlSeatGlobal {
fn drop(&mut self) {
self.state.remove_cursor_size(self.cursor_size.get());
}
}
impl WlSeatGlobal {
pub fn new(name: GlobalName, seat_name: &str, state: &Rc<State>) -> Rc<Self> {
let seat_xkb_state = state
@ -212,13 +201,15 @@ impl WlSeatGlobal {
.unwrap();
let xkb_states = CopyHashMap::new();
xkb_states.set(state.default_keymap.id, Rc::downgrade(&seat_xkb_state));
let cursor_user_group = CursorUserGroup::create(state);
let cursor_user = cursor_user_group.create_user();
cursor_user.activate();
let slf = Rc::new(Self {
id: state.seat_ids.next(),
name,
state: state.clone(),
seat_name: seat_name.to_string(),
pos_time_usec: Cell::new(0),
pos: Cell::new((Fixed(0), Fixed(0))),
pointer_stack: RefCell::new(vec![]),
pointer_stack_modified: Cell::new(false),
found_tree: RefCell::new(vec![]),
@ -232,7 +223,8 @@ impl WlSeatGlobal {
seat_xkb_state: CloneCell::new(seat_xkb_state.clone()),
latest_kb_state: CloneCell::new(seat_xkb_state.clone()),
xkb_states,
cursor: Default::default(),
cursor_user_group,
pointer_cursor: cursor_user,
tree_changed: Default::default(),
selection: Default::default(),
selection_serial: Cell::new(0),
@ -245,11 +237,7 @@ impl WlSeatGlobal {
shortcuts: Default::default(),
queue_link: Default::default(),
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),
cursor_size: Cell::new(*DEFAULT_CURSOR_SIZE),
hardware_cursor: Cell::new(state.globals.seats.len() == 0),
constraint: Default::default(),
idle_notifications: Default::default(),
last_input_usec: Cell::new(now_usec()),
@ -264,7 +252,7 @@ impl WlSeatGlobal {
pinch_bindings: Default::default(),
hold_bindings: Default::default(),
});
state.add_cursor_size(*DEFAULT_CURSOR_SIZE);
slf.pointer_cursor.set_owner(slf.clone());
let seat = slf.clone();
let future = state.eng.spawn(async move {
loop {
@ -291,109 +279,6 @@ impl WlSeatGlobal {
self.pointer_owner.toplevel_drag()
}
pub fn set_hardware_cursor(&self, hardware_cursor: bool) {
self.hardware_cursor.set(hardware_cursor);
}
pub fn hardware_cursor(&self) -> bool {
self.hardware_cursor.get()
}
fn update_hardware_cursor_position(&self) {
self.update_hardware_cursor_(false);
}
pub fn update_hardware_cursor(&self) {
self.update_hardware_cursor_(true);
}
fn update_hardware_cursor_(&self, render: bool) {
if !self.hardware_cursor.get() {
return;
}
let cursor = match self.get_cursor() {
Some(c) => c,
_ => {
self.state.disable_hardware_cursors();
return;
}
};
if render {
cursor.tick();
}
let (x, y) = self.get_position();
for output in self.state.root.outputs.lock().values() {
if let Some(hc) = output.hardware_cursor.get() {
let transform = output.global.persistent.transform.get();
let render = render | output.hardware_cursor_needs_render.take();
let scale = output.global.persistent.scale.get();
let extents = cursor.extents_at_scale(scale);
let (hc_width, hc_height) = hc.size();
if render {
let (max_width, max_height) = transform.maybe_swap((hc_width, hc_height));
if extents.width() > max_width || extents.height() > max_height {
hc.set_enabled(false);
hc.commit();
continue;
}
}
let opos = output.global.pos.get();
let (x_rel, y_rel);
if scale == 1 {
x_rel = x.round_down() - opos.x1();
y_rel = y.round_down() - opos.y1();
} else {
let scalef = scale.to_f64();
x_rel = ((x - Fixed::from_int(opos.x1())).to_f64() * scalef).round() as i32;
y_rel = ((y - Fixed::from_int(opos.y1())).to_f64() * scalef).round() as i32;
}
let (width, height) = output.global.pixel_size();
if extents.intersects(&Rect::new_sized(-x_rel, -y_rel, width, height).unwrap()) {
if render {
let buffer = hc.get_buffer();
let res = buffer.render_hardware_cursor(
cursor.deref(),
&self.state,
scale,
transform,
);
match res {
Ok(sync_file) => {
hc.set_sync_file(sync_file);
hc.swap_buffer();
}
Err(e) => {
log::error!("Could not render hardware cursor: {}", ErrorFmt(e));
}
}
}
hc.set_enabled(true);
let mode = output.global.mode.get();
let (x_rel, y_rel) =
transform.apply_point(mode.width, mode.height, (x_rel, y_rel));
let (hot_x, hot_y) =
transform.apply_point(hc_width, hc_height, (-extents.x1(), -extents.y1()));
hc.set_position(x_rel - hot_x, y_rel - hot_y);
} else {
if render {
output.hardware_cursor_needs_render.set(true);
}
hc.set_enabled(false);
}
hc.commit();
}
}
}
pub fn set_cursor_size(&self, size: u32) {
let old = self.cursor_size.replace(size);
if size != old {
self.state.remove_cursor_size(old);
self.state.add_cursor_size(size);
self.reload_known_cursor();
}
}
pub fn add_data_device(&self, device: &Rc<WlDataDevice>) {
let mut dd = self.data_devices.borrow_mut();
dd.entry(device.client.id)
@ -452,7 +337,7 @@ impl WlSeatGlobal {
}
pub fn get_output(&self) -> Rc<OutputNode> {
self.output.get()
self.cursor_user_group.latest_output()
}
pub fn set_workspace(&self, ws: &Rc<WorkspaceNode>) {
@ -517,7 +402,7 @@ impl WlSeatGlobal {
fn maybe_constrain_pointer_node(&self) {
if let Some(pn) = self.pointer_node() {
if let Some(surface) = pn.node_into_surface() {
let (mut x, mut y) = self.pos.get();
let (mut x, mut y) = self.pointer_cursor.position();
let (sx, sy) = surface.buffer_abs_pos.get().position();
x -= Fixed::from_int(sx);
y -= Fixed::from_int(sy);
@ -608,47 +493,6 @@ impl WlSeatGlobal {
self.kb_owner.ungrab(self);
}
pub fn set_position(&self, x: i32, y: i32) {
self.pos.set((Fixed::from_int(x), Fixed::from_int(y)));
self.update_hardware_cursor_position();
self.trigger_tree_changed();
let output = 'set_output: {
let outputs = self.state.root.outputs.lock();
for output in outputs.values() {
if output.global.pos.get().contains(x, y) {
break 'set_output output.clone();
}
}
self.state.dummy_output.get().unwrap()
};
self.set_output(&output);
}
fn set_output(&self, output: &Rc<OutputNode>) {
self.output.set(output.clone());
if let Some(cursor) = self.cursor.get() {
cursor.set_output(output);
}
if let Some(dnd) = self.pointer_owner.dnd_icon() {
dnd.set_output(output);
}
if let Some(drag) = self.pointer_owner.toplevel_drag() {
if let Some(tl) = drag.toplevel.get() {
tl.xdg.set_output(output);
}
}
}
pub fn position(&self) -> (Fixed, Fixed) {
self.pos.get()
}
pub fn render_ctx_changed(&self) {
if let Some(cursor) = self.desired_known_cursor.get() {
self.set_known_cursor(cursor);
}
}
pub fn kb_parent_container(&self) -> Option<Rc<ContainerNode>> {
if let Some(tl) = self.keyboard_node.get().node_toplevel() {
if let Some(parent) = tl.tl_data().parent.get() {
@ -877,7 +721,7 @@ impl WlSeatGlobal {
serial: u32,
) -> Result<(), WlSeatError> {
if let Some(icon) = &icon {
icon.set_output(&self.output.get());
icon.set_output(&self.pointer_cursor.output());
}
self.pointer_owner
.start_drag(self, origin, source, icon, serial)
@ -969,89 +813,6 @@ impl WlSeatGlobal {
self.primary_selection.get()
}
pub fn reload_known_cursor(&self) {
if let Some(kc) = self.desired_known_cursor.get() {
self.set_known_cursor(kc);
}
}
#[cfg_attr(not(feature = "it"), allow(dead_code))]
pub fn get_desired_known_cursor(&self) -> Option<KnownCursor> {
self.desired_known_cursor.get()
}
pub fn set_known_cursor(&self, cursor: KnownCursor) {
self.desired_known_cursor.set(Some(cursor));
let cursors = match self.state.cursors.get() {
Some(c) => c,
None => {
self.set_cursor2(None);
return;
}
};
let tpl = match cursor {
KnownCursor::Default => &cursors.default,
KnownCursor::ContextMenu => &cursors.context_menu,
KnownCursor::Help => &cursors.help,
KnownCursor::Pointer => &cursors.pointer,
KnownCursor::Progress => &cursors.progress,
KnownCursor::Wait => &cursors.wait,
KnownCursor::Cell => &cursors.cell,
KnownCursor::Crosshair => &cursors.crosshair,
KnownCursor::Text => &cursors.text,
KnownCursor::VerticalText => &cursors.vertical_text,
KnownCursor::Alias => &cursors.alias,
KnownCursor::Copy => &cursors.copy,
KnownCursor::Move => &cursors.r#move,
KnownCursor::NoDrop => &cursors.no_drop,
KnownCursor::NotAllowed => &cursors.not_allowed,
KnownCursor::Grab => &cursors.grab,
KnownCursor::Grabbing => &cursors.grabbing,
KnownCursor::EResize => &cursors.e_resize,
KnownCursor::NResize => &cursors.n_resize,
KnownCursor::NeResize => &cursors.ne_resize,
KnownCursor::NwResize => &cursors.nw_resize,
KnownCursor::SResize => &cursors.s_resize,
KnownCursor::SeResize => &cursors.se_resize,
KnownCursor::SwResize => &cursors.sw_resize,
KnownCursor::WResize => &cursors.w_resize,
KnownCursor::EwResize => &cursors.ew_resize,
KnownCursor::NsResize => &cursors.ns_resize,
KnownCursor::NeswResize => &cursors.nesw_resize,
KnownCursor::NwseResize => &cursors.nwse_resize,
KnownCursor::ColResize => &cursors.col_resize,
KnownCursor::RowResize => &cursors.row_resize,
KnownCursor::AllScroll => &cursors.all_scroll,
KnownCursor::ZoomIn => &cursors.zoom_in,
KnownCursor::ZoomOut => &cursors.zoom_out,
};
self.set_cursor2(Some(tpl.instantiate(self.cursor_size.get())));
}
pub fn set_app_cursor(&self, cursor: Option<Rc<dyn Cursor>>) {
self.set_cursor2(cursor);
self.desired_known_cursor.set(None);
}
fn set_cursor2(&self, cursor: Option<Rc<dyn Cursor>>) {
if let Some(old) = self.cursor.get() {
if let Some(new) = cursor.as_ref() {
if rc_eq(&old, new) {
self.update_hardware_cursor();
return;
}
}
old.handle_unset();
}
if let Some(cursor) = cursor.as_ref() {
cursor.clone().handle_set();
cursor.set_output(&self.output.get());
}
self.cursor.set(cursor.clone());
self.state.hardware_tick_cursor.push(cursor);
self.update_hardware_cursor();
}
pub fn dnd_icon(&self) -> Option<Rc<WlSurface>> {
self.pointer_owner.dnd_icon()
}
@ -1060,12 +821,12 @@ impl WlSeatGlobal {
self.pointer_owner.remove_dnd_icon();
}
pub fn get_position(&self) -> (Fixed, Fixed) {
self.pos.get()
pub fn pointer_cursor(&self) -> &Rc<CursorUser> {
&self.pointer_cursor
}
pub fn get_cursor(&self) -> Option<Rc<dyn Cursor>> {
self.cursor.get()
pub fn cursor_group(&self) -> &Rc<CursorUserGroup> {
&self.cursor_user_group
}
pub fn clear(self: &Rc<Self>) {
@ -1082,7 +843,7 @@ impl WlSeatGlobal {
self.data_devices.borrow_mut().clear();
self.primary_selection_devices.borrow_mut().clear();
self.wlr_data_devices.clear();
self.cursor.set(None);
self.cursor_user_group.detach();
self.selection.set(None);
self.primary_selection.set(None);
self.pointer_owner.clear();
@ -1090,7 +851,6 @@ impl WlSeatGlobal {
*self.dropped_dnd.borrow_mut() = None;
self.queue_link.take();
self.tree_changed_handler.set(None);
self.output.set(self.state.dummy_output.get().unwrap());
self.constraint.take();
self.text_inputs.borrow_mut().clear();
self.text_input.take();
@ -1099,6 +859,7 @@ impl WlSeatGlobal {
self.swipe_bindings.clear();
self.pinch_bindings.clear();
self.hold_bindings.clear();
self.cursor_user_group.detach();
}
pub fn id(&self) -> SeatId {
@ -1156,9 +917,7 @@ impl WlSeatGlobal {
}
pub fn set_visible(&self, visible: bool) {
if let Some(cursor) = self.cursor.get() {
cursor.set_visible(visible);
}
self.cursor_user_group.set_visible(visible);
if let Some(icon) = self.dnd_icon() {
icon.set_visible(visible);
}
@ -1191,6 +950,19 @@ impl WlSeatGlobal {
}
}
impl CursorUserOwner for WlSeatGlobal {
fn output_changed(&self, output: &Rc<OutputNode>) {
if let Some(dnd) = self.pointer_owner.dnd_icon() {
dnd.set_output(output);
}
if let Some(drag) = self.pointer_owner.toplevel_drag() {
if let Some(tl) = drag.toplevel.get() {
tl.xdg.set_output(output);
}
}
}
}
global_base!(WlSeatGlobal, WlSeat, WlSeatError);
impl Global for WlSeatGlobal {

View file

@ -120,8 +120,7 @@ impl NodeSeatState {
seat.kb_owner.set_kb_node(&seat, seat.state.root.clone());
// log::info!("keyboard_node = root");
if focus_last {
seat.output
.get()
seat.get_output()
.node_do_focus(&seat, Direction::Unspecified);
}
}
@ -320,10 +319,10 @@ impl WlSeatGlobal {
Some(o) => o,
_ => return,
};
self.set_output(&output);
let pos = output.global.pos.get();
x += Fixed::from_int(pos.x1());
y += Fixed::from_int(pos.y1());
(x, y) = self.pointer_cursor.set_position(x, y);
if let Some(c) = self.constraint.get() {
if c.ty == ConstraintType::Lock || !c.contains(x.round_down(), y.round_down()) {
c.deactivate();
@ -332,7 +331,7 @@ impl WlSeatGlobal {
self.state.for_each_seat_tester(|t| {
t.send_pointer_abs(self.id, time_usec, x, y);
});
self.set_new_position(time_usec, x, y);
self.cursor_moved(time_usec);
}
fn motion_event(
@ -356,7 +355,7 @@ impl WlSeatGlobal {
Some(c) if c.ty == ConstraintType::Lock => true,
_ => false,
};
let (mut x, mut y) = self.pos.get();
let (mut x, mut y) = self.pointer_cursor.position();
if !locked {
x += dx;
y += dy;
@ -383,34 +382,8 @@ impl WlSeatGlobal {
dy_unaccelerated,
);
});
let output = self.output.get();
let pos = output.global.pos.get();
let mut x_int = x.round_down();
let mut y_int = y.round_down();
if !pos.contains(x_int, y_int) {
'warp: {
let outputs = self.state.root.outputs.lock();
for output in outputs.values() {
if output.global.pos.get().contains(x_int, y_int) {
self.set_output(output);
break 'warp;
}
}
if x_int < pos.x1() {
x_int = pos.x1();
} else if x_int >= pos.x2() {
x_int = pos.x2() - 1;
}
if y_int < pos.y1() {
y_int = pos.y1();
} else if y_int >= pos.y2() {
y_int = pos.y2() - 1;
}
x = Fixed::from_int(x_int);
y = Fixed::from_int(y_int);
}
}
self.set_new_position(time_usec, x, y);
self.pointer_cursor.set_position(x, y);
self.cursor_moved(time_usec);
}
fn button_event(self: &Rc<Self>, time_usec: u64, button: u32, state: KeyState) {
@ -776,10 +749,8 @@ impl WlSeatGlobal {
// client.flush();
}
fn set_new_position(self: &Rc<Self>, time_usec: u64, x: Fixed, y: Fixed) {
fn cursor_moved(self: &Rc<Self>, time_usec: u64) {
self.pos_time_usec.set(time_usec);
self.pos.set((x, y));
self.update_hardware_cursor_position();
self.changes.or_assign(CHANGE_CURSOR_MOVED);
self.apply_changes();
}

View file

@ -274,7 +274,7 @@ impl<T: SimplePointerOwnerUsecase> PointerOwner for SimplePointerOwner<T> {
}
fn apply_changes(&self, seat: &Rc<WlSeatGlobal>) {
let (x, y) = seat.pos.get();
let (x, y) = seat.pointer_cursor.position();
let mut found_tree = seat.found_tree.borrow_mut();
let mut stack = seat.pointer_stack.borrow_mut();
let x_int = x.round_down();
@ -408,7 +408,7 @@ impl<T: SimplePointerOwnerUsecase> PointerOwner for SimpleGrabPointerOwner<T> {
}
fn apply_changes(&self, seat: &Rc<WlSeatGlobal>) {
let (x, y) = seat.pos.get();
let (x, y) = seat.pointer_cursor.position();
let pos = self.node.node_absolute_position();
let (x_int, y_int) = pos.translate(x.round_down(), y.round_down());
// log::info!("apply_changes");
@ -493,7 +493,7 @@ impl PointerOwner for DndPointerOwner {
}
fn apply_changes(&self, seat: &Rc<WlSeatGlobal>) {
let (x, y) = seat.pos.get();
let (x, y) = seat.pointer_cursor.position();
let (x_int, y_int) = (x.round_down(), y.round_down());
let (node, x_int, y_int) = {
let mut found_tree = seat.found_tree.borrow_mut();
@ -781,7 +781,7 @@ impl<S: ToplevelSelector> NodeSelectorUsecase for SelectToplevelUsecase<S> {
if let Some(tl) = &tl {
tl.tl_data().render_highlight.fetch_add(1);
if !tl.tl_admits_children() {
seat.set_known_cursor(KnownCursor::Pointer);
seat.pointer_cursor().set_known(KnownCursor::Pointer);
}
damage = true;
}
@ -829,7 +829,7 @@ impl<S: WorkspaceSelector> NodeSelectorUsecase for SelectWorkspaceUsecase<S> {
let ws = node.clone().node_into_workspace();
if let Some(ws) = &ws {
ws.render_highlight.fetch_add(1);
seat.set_known_cursor(KnownCursor::Pointer);
seat.pointer_cursor().set_known(KnownCursor::Pointer);
damage = true;
}
if let Some(prev) = self.latest.set(ws) {

View file

@ -186,7 +186,7 @@ impl WlPointerRequestHandler for WlPointer {
let mut cursor_opt = None;
if req.surface.is_some() {
let surface = self.seat.client.lookup(req.surface)?;
let cursor = surface.get_cursor(&self.seat.global)?;
let cursor = surface.get_cursor(&self.seat.global.pointer_cursor)?;
cursor.set_hotspot(req.hotspot_x, req.hotspot_y);
cursor_opt = Some(cursor as Rc<dyn Cursor>);
}
@ -211,7 +211,7 @@ impl WlPointerRequestHandler for WlPointer {
// );
// return Ok(());
// }
self.seat.global.set_app_cursor(cursor_opt);
self.seat.global.pointer_cursor().set(cursor_opt);
Ok(())
}

View file

@ -18,6 +18,7 @@ use {
crate::{
backend::KeyState,
client::{Client, ClientError},
cursor_user::{CursorUser, CursorUserId},
drm_feedback::DrmFeedback,
fixed::Fixed,
gfx_api::{AcquireSync, BufferResv, BufferResvUser, ReleaseSync, SampleRect, SyncFile},
@ -262,7 +263,7 @@ pub struct WlSurface {
pub presentation_feedback: RefCell<Vec<Rc<WpPresentationFeedback>>>,
seat_state: NodeSeatState,
toplevel: CloneCell<Option<Rc<dyn ToplevelNode>>>,
cursors: SmallMap<SeatId, Rc<CursorSurface>, 1>,
cursors: SmallMap<CursorUserId, Rc<CursorSurface>, 1>,
dnd_icons: SmallMap<SeatId, Rc<WlSeatGlobal>, 1>,
pub tracker: Tracker<Self>,
idle_inhibitors: SmallMap<ZwpIdleInhibitorV1Id, Rc<ZwpIdleInhibitorV1>, 1>,
@ -655,13 +656,13 @@ impl WlSurface {
pub fn get_cursor(
self: &Rc<Self>,
seat: &Rc<WlSeatGlobal>,
user: &Rc<CursorUser>,
) -> Result<Rc<CursorSurface>, WlSurfaceError> {
if let Some(cursor) = self.cursors.get(&seat.id()) {
if let Some(cursor) = self.cursors.get(&user.id) {
return Ok(cursor);
}
self.set_role(SurfaceRole::Cursor)?;
let cursor = Rc::new(CursorSurface::new(seat, self));
let cursor = Rc::new(CursorSurface::new(user, self));
track!(self.client, cursor);
cursor.handle_buffer_change();
Ok(cursor)

View file

@ -1,8 +1,9 @@
use {
crate::{
cursor::Cursor,
cursor_user::CursorUser,
fixed::Fixed,
ifs::{wl_seat::WlSeatGlobal, wl_surface::WlSurface},
ifs::wl_surface::WlSurface,
leaks::Tracker,
rect::Rect,
renderer::Renderer,
@ -13,7 +14,7 @@ use {
};
pub struct CursorSurface {
seat: Rc<WlSeatGlobal>,
user: Rc<CursorUser>,
surface: Rc<WlSurface>,
hotspot: Cell<(i32, i32)>,
extents: Cell<Rect>,
@ -21,9 +22,9 @@ pub struct CursorSurface {
}
impl CursorSurface {
pub fn new(seat: &Rc<WlSeatGlobal>, surface: &Rc<WlSurface>) -> Self {
pub fn new(user: &Rc<CursorUser>, surface: &Rc<WlSurface>) -> Self {
Self {
seat: seat.clone(),
user: user.clone(),
surface: surface.clone(),
hotspot: Cell::new((0, 0)),
extents: Cell::new(Default::default()),
@ -38,7 +39,7 @@ impl CursorSurface {
}
pub fn handle_surface_destroy(&self) {
self.seat.set_app_cursor(None);
self.user.set(None);
}
pub fn handle_buffer_change(&self) {
@ -57,9 +58,7 @@ impl CursorSurface {
}
pub fn update_hardware_cursor(&self) {
if self.seat.hardware_cursor() {
self.seat.update_hardware_cursor();
}
self.user.update_hardware_cursor();
}
}
@ -124,7 +123,7 @@ impl Cursor for CursorSurface {
}
fn handle_set(self: Rc<Self>) {
self.surface.cursors.insert(self.seat.id(), self.clone());
self.surface.cursors.insert(self.user.id, self.clone());
if self.surface.cursors.is_not_empty() {
self.surface
.set_visible(self.surface.client.state.root_visible());
@ -132,7 +131,7 @@ impl Cursor for CursorSurface {
}
fn handle_unset(&self) {
self.surface.cursors.remove(&self.seat.id());
self.surface.cursors.remove(&self.user.id);
if self.surface.cursors.is_empty() {
self.surface.set_visible(false);
}

View file

@ -366,7 +366,7 @@ impl Node for Xwindow {
fn node_on_pointer_focus(&self, seat: &Rc<WlSeatGlobal>) {
// log::info!("wl-surface focus");
seat.set_known_cursor(KnownCursor::Default);
seat.pointer_cursor().set_known(KnownCursor::Default);
}
fn node_into_toplevel(self: Rc<Self>) -> Option<Rc<dyn ToplevelNode>> {

View file

@ -344,7 +344,7 @@ impl Node for XdgPopup {
fn node_on_pointer_focus(&self, seat: &Rc<WlSeatGlobal>) {
// log::info!("xdg-popup focus");
seat.set_known_cursor(KnownCursor::Default);
seat.pointer_cursor().set_known(KnownCursor::Default);
}
}

View file

@ -526,7 +526,7 @@ impl Node for XdgToplevel {
fn node_on_pointer_focus(&self, seat: &Rc<WlSeatGlobal>) {
// log::info!("xdg-toplevel focus");
seat.set_known_cursor(KnownCursor::Default);
seat.pointer_cursor().set_known(KnownCursor::Default);
}
fn node_into_toplevel(self: Rc<Self>) -> Option<Rc<dyn ToplevelNode>> {

View file

@ -107,7 +107,7 @@ impl WpCursorShapeDeviceV1RequestHandler for WpCursorShapeDeviceV1 {
if pointer_node.node_client_id() != Some(self.client.id) {
return Ok(());
}
self.seat.set_known_cursor(cursor);
self.seat.pointer_cursor().set_known(cursor);
Ok(())
}
}

View file

@ -102,7 +102,7 @@ impl XdgToplevelDragV1 {
if self.source.data.was_used() {
if let Some(tl) = self.toplevel.get() {
let output = seat.get_output();
let (x, y) = seat.position();
let (x, y) = seat.pointer_cursor().position();
tl.drag.take();
tl.after_toplevel_drag(
&output,