From c987fdb58db68397563a592a932b16eb95e4e3f3 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Thu, 17 Oct 2024 15:20:46 +0200 Subject: [PATCH] all: track serials as u64 internally --- src/client.rs | 30 ++++++++++++------- src/ifs/ipc.rs | 4 +-- src/ifs/ipc/wl_data_device.rs | 21 +++++++------ src/ifs/ipc/wl_data_offer.rs | 2 +- src/ifs/ipc/x_data_device.rs | 2 +- src/ifs/ipc/zwlr_data_control_device_v1.rs | 2 +- .../ipc/zwp_primary_selection_device_v1.rs | 10 +++---- src/ifs/wl_seat.rs | 20 ++++++------- src/ifs/wl_seat/event_handling.rs | 6 ++-- src/ifs/wl_seat/pointer_owner.rs | 12 ++++---- .../wl_seat/tablet/zwp_tablet_pad_group_v2.rs | 4 +-- src/ifs/wl_seat/tablet/zwp_tablet_pad_v2.rs | 8 ++--- src/ifs/wl_seat/tablet/zwp_tablet_tool_v2.rs | 14 ++++----- .../zwp_input_method_keyboard_grab_v2.rs | 10 +++---- src/ifs/wl_seat/wl_keyboard.rs | 24 +++++++-------- src/ifs/wl_seat/wl_pointer.rs | 14 ++++----- src/ifs/wl_seat/wl_touch.rs | 8 ++--- .../wl_seat/zwp_pointer_gesture_hold_v1.rs | 8 ++--- .../wl_seat/zwp_pointer_gesture_pinch_v1.rs | 8 ++--- .../wl_seat/zwp_pointer_gesture_swipe_v1.rs | 8 ++--- src/ifs/wl_seat/zwp_virtual_keyboard_v1.rs | 2 +- src/ifs/wl_surface.rs | 4 +-- src/state.rs | 7 ++--- src/tree.rs | 4 +-- src/tree/container.rs | 2 +- src/tree/float.rs | 2 +- src/tree/output.rs | 2 +- src/utils/pending_serial.rs | 4 +-- 28 files changed, 123 insertions(+), 119 deletions(-) diff --git a/src/client.rs b/src/client.rs index 4f2c41f5..70a7f586 100644 --- a/src/client.rs +++ b/src/client.rs @@ -161,7 +161,7 @@ impl Clients { is_xwayland, effective_caps, bounding_caps, - last_enter_serial: Cell::new(0), + last_enter_serial: Default::default(), pid_info: get_pid_info(uid, pid), serials: Default::default(), symmetric_delete: Cell::new(false), @@ -277,7 +277,7 @@ pub struct Client { pub is_xwayland: bool, pub effective_caps: ClientCaps, pub bounding_caps: ClientCaps, - pub last_enter_serial: Cell, + pub last_enter_serial: Cell>, pub pid_info: PidInfo, pub serials: RefCell>, pub symmetric_delete: Cell, @@ -291,8 +291,8 @@ pub struct Client { pub const NUM_CACHED_SERIAL_RANGES: usize = 64; pub struct SerialRange { - pub lo: u32, - pub hi: u32, + pub lo: u64, + pub hi: u64, } impl Client { @@ -320,20 +320,28 @@ impl Client { } } - pub fn valid_serial(&self, serial: u32) -> bool { + pub fn map_serial(&self, serial: u32) -> Option { let serials = self.serials.borrow_mut(); + let latest = serials.back()?; + let mut serial = ((latest.hi >> 32) << 32) | (serial as u64); + if serial > latest.hi { + serial = serial.checked_sub(1 << 32)?; + } for range in serials.iter().rev() { - if serial.wrapping_sub(range.hi) as i32 > 0 { - return false; + if serial > range.hi { + return None; } - if serial.wrapping_sub(range.lo) as i32 >= 0 { - return true; + if serial >= range.lo { + return Some(serial); } } - serials.len() == NUM_CACHED_SERIAL_RANGES + if serials.len() == NUM_CACHED_SERIAL_RANGES { + return Some(serial); + } + None } - pub fn next_serial(&self) -> u32 { + pub fn next_serial(&self) -> u64 { self.state.next_serial(Some(self)) } diff --git a/src/ifs/ipc.rs b/src/ifs/ipc.rs index d83a6a7e..0def2a61 100644 --- a/src/ifs/ipc.rs +++ b/src/ifs/ipc.rs @@ -115,7 +115,7 @@ pub trait DynDataOffer: 'static { any::type_name_of_val(self) ) } - fn send_enter(&self, surface: WlSurfaceId, x: Fixed, y: Fixed, serial: u32) { + fn send_enter(&self, surface: WlSurfaceId, x: Fixed, y: Fixed, serial: u64) { let _ = surface; let _ = x; let _ = y; @@ -155,7 +155,7 @@ pub trait IpcVtable: Sized { fn set_seat_selection( seat: &Rc, source: &Rc, - serial: Option, + serial: Option, ) -> Result<(), WlSeatError>; fn create_offer( dd: &Rc, diff --git a/src/ifs/ipc/wl_data_device.rs b/src/ifs/ipc/wl_data_device.rs index cf4b55ec..35b935ea 100644 --- a/src/ifs/ipc/wl_data_device.rs +++ b/src/ifs/ipc/wl_data_device.rs @@ -73,11 +73,11 @@ impl WlDataDevice { x: Fixed, y: Fixed, offer: WlDataOfferId, - serial: u32, + serial: u64, ) { self.client.event(Enter { self_id: self.id, - serial, + serial: serial as _, surface, x, y, @@ -103,10 +103,10 @@ impl WlDataDeviceRequestHandler for WlDataDevice { type Error = WlDataDeviceError; fn start_drag(&self, req: StartDrag, _slf: &Rc) -> Result<(), Self::Error> { - if !self.client.valid_serial(req.serial) { + let Some(serial) = self.client.map_serial(req.serial) else { log::warn!("Client tried to start_drag with an invalid serial"); return Ok(()); - } + }; let origin = self.client.lookup(req.origin)?; let source = if req.source.is_some() { Some(self.client.lookup(req.source)?) @@ -119,16 +119,16 @@ impl WlDataDeviceRequestHandler for WlDataDevice { } else { None }; - self.seat.start_drag(&origin, source, icon, req.serial)?; + self.seat.start_drag(&origin, source, icon, serial)?; Ok(()) } fn set_selection(&self, req: SetSelection, _slf: &Rc) -> Result<(), Self::Error> { - if !self.client.valid_serial(req.serial) { + let Some(serial) = self.client.map_serial(req.serial) else { log::warn!("Client tried to set_selection with an invalid serial"); return Ok(()); - } - if !self.seat.may_modify_selection(&self.client, req.serial) { + }; + if !self.seat.may_modify_selection(&self.client, serial) { log::warn!("Ignoring disallowed set_selection request"); return Ok(()); } @@ -137,8 +137,7 @@ impl WlDataDeviceRequestHandler for WlDataDevice { } else { Some(self.client.lookup(req.source)?) }; - self.seat - .set_wl_data_source_selection(src, Some(req.serial))?; + self.seat.set_wl_data_source_selection(src, Some(serial))?; Ok(()) } @@ -177,7 +176,7 @@ impl IpcVtable for ClipboardIpc { fn set_seat_selection( seat: &Rc, source: &Rc, - serial: Option, + serial: Option, ) -> Result<(), WlSeatError> { seat.set_wl_data_source_selection(Some(source.clone()), serial) } diff --git a/src/ifs/ipc/wl_data_offer.rs b/src/ifs/ipc/wl_data_offer.rs index c2db7aba..e422bafc 100644 --- a/src/ifs/ipc/wl_data_offer.rs +++ b/src/ifs/ipc/wl_data_offer.rs @@ -68,7 +68,7 @@ impl DynDataOffer for WlDataOffer { cancel_offer::(self); } - fn send_enter(&self, surface: WlSurfaceId, x: Fixed, y: Fixed, serial: u32) { + fn send_enter(&self, surface: WlSurfaceId, x: Fixed, y: Fixed, serial: u64) { self.device.send_enter(surface, x, y, self.id, serial); } diff --git a/src/ifs/ipc/x_data_device.rs b/src/ifs/ipc/x_data_device.rs index 1c374fc4..aa03bb69 100644 --- a/src/ifs/ipc/x_data_device.rs +++ b/src/ifs/ipc/x_data_device.rs @@ -80,7 +80,7 @@ impl IpcVtable for T { fn set_seat_selection( seat: &Rc, source: &Rc, - _serial: Option, + _serial: Option, ) -> Result<(), WlSeatError> { match source.location { IpcLocation::Clipboard => seat.set_selection(Some(source.clone())), diff --git a/src/ifs/ipc/zwlr_data_control_device_v1.rs b/src/ifs/ipc/zwlr_data_control_device_v1.rs index 127d5049..cf62a678 100644 --- a/src/ifs/ipc/zwlr_data_control_device_v1.rs +++ b/src/ifs/ipc/zwlr_data_control_device_v1.rs @@ -232,7 +232,7 @@ impl IpcVtable for WlrIpcImpl { fn set_seat_selection( seat: &Rc, source: &Rc, - serial: Option, + serial: Option, ) -> Result<(), WlSeatError> { debug_assert!(serial.is_none()); let _ = serial; diff --git a/src/ifs/ipc/zwp_primary_selection_device_v1.rs b/src/ifs/ipc/zwp_primary_selection_device_v1.rs index e2f3a932..346bd091 100644 --- a/src/ifs/ipc/zwp_primary_selection_device_v1.rs +++ b/src/ifs/ipc/zwp_primary_selection_device_v1.rs @@ -69,13 +69,13 @@ impl ZwpPrimarySelectionDeviceV1RequestHandler for ZwpPrimarySelectionDeviceV1 { type Error = ZwpPrimarySelectionDeviceV1Error; fn set_selection(&self, req: SetSelection, _slf: &Rc) -> Result<(), Self::Error> { - if !self.client.valid_serial(req.serial) { + let Some(serial) = self.client.map_serial(req.serial) else { log::warn!("Client tried to set_selection with an invalid serial"); return Ok(()); - } + }; if !self .seat - .may_modify_primary_selection(&self.client, Some(req.serial)) + .may_modify_primary_selection(&self.client, Some(serial)) { log::warn!("Ignoring disallowed set_selection request"); return Ok(()); @@ -85,7 +85,7 @@ impl ZwpPrimarySelectionDeviceV1RequestHandler for ZwpPrimarySelectionDeviceV1 { } else { Some(self.client.lookup(req.source)?) }; - self.seat.set_zwp_primary_selection(src, Some(req.serial))?; + self.seat.set_zwp_primary_selection(src, Some(serial))?; Ok(()) } @@ -124,7 +124,7 @@ impl IpcVtable for PrimarySelectionIpc { fn set_seat_selection( seat: &Rc, source: &Rc, - serial: Option, + serial: Option, ) -> Result<(), WlSeatError> { seat.set_zwp_primary_selection(Some(source.clone()), serial) } diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index b68c911b..df190682 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -173,9 +173,9 @@ pub struct WlSeatGlobal { tree_changed: Rc, tree_changed_needs_layout: Cell, selection: CloneCell>>, - selection_serial: Cell, + selection_serial: Cell, primary_selection: CloneCell>>, - primary_selection_serial: Cell, + primary_selection_serial: Cell, pointer_owner: PointerOwnerHolder, kb_owner: KbOwnerHolder, gesture_owner: GestureOwnerHolder, @@ -766,7 +766,7 @@ impl WlSeatGlobal { origin: &Rc, source: Option>, icon: Option>, - serial: u32, + serial: u64, ) -> Result<(), WlSeatError> { if let Some(icon) = &icon { icon.surface().set_output(&self.pointer_cursor.output()); @@ -798,7 +798,7 @@ impl WlSeatGlobal { pub fn set_wl_data_source_selection( self: &Rc, selection: Option>, - serial: Option, + serial: Option, ) -> Result<(), WlSeatError> { if let Some(serial) = serial { self.selection_serial.set(serial); @@ -825,18 +825,16 @@ impl WlSeatGlobal { self.selection.get() } - pub fn may_modify_selection(&self, client: &Rc, serial: u32) -> bool { - let dist = serial.wrapping_sub(self.selection_serial.get()) as i32; - if dist < 0 { + pub fn may_modify_selection(&self, client: &Rc, serial: u64) -> bool { + if serial < self.selection_serial.get() { return false; } self.keyboard_node.get().node_client_id() == Some(client.id) } - pub fn may_modify_primary_selection(&self, client: &Rc, serial: Option) -> bool { + pub fn may_modify_primary_selection(&self, client: &Rc, serial: Option) -> bool { if let Some(serial) = serial { - let dist = serial.wrapping_sub(self.primary_selection_serial.get()) as i32; - if dist < 0 { + if serial < self.primary_selection_serial.get() { return false; } } @@ -851,7 +849,7 @@ impl WlSeatGlobal { pub fn set_zwp_primary_selection( self: &Rc, selection: Option>, - serial: Option, + serial: Option, ) -> Result<(), WlSeatError> { if let Some(serial) = serial { self.primary_selection_serial.set(serial); diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index 87db20fd..cdc1ceb7 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -1137,7 +1137,7 @@ impl WlSeatGlobal { time_usec: u64, button: u32, state: KeyState, - serial: u32, + serial: u64, ) { let (state, pressed) = match state { KeyState::Released => (wl_pointer::RELEASED, false), @@ -1250,7 +1250,7 @@ impl WlSeatGlobal { pub fn enter_surface(&self, n: &WlSurface, x: Fixed, y: Fixed) { let serial = n.client.next_serial(); - n.client.last_enter_serial.set(serial); + n.client.last_enter_serial.set(Some(serial)); self.surface_pointer_event(Version::ALL, n, |p| p.send_enter(serial, n.id, x, y)); self.surface_pointer_frame(n); for (_, constraint) in &n.constraints { @@ -1428,7 +1428,7 @@ impl WlSeatGlobal { dnd: &Dnd, x: Fixed, y: Fixed, - serial: u32, + serial: u64, ) { if let Some(src) = &dnd.src { if !surface.client.is_xwayland { diff --git a/src/ifs/wl_seat/pointer_owner.rs b/src/ifs/wl_seat/pointer_owner.rs index 7701c3b4..8c9b4ad1 100644 --- a/src/ifs/wl_seat/pointer_owner.rs +++ b/src/ifs/wl_seat/pointer_owner.rs @@ -128,7 +128,7 @@ impl PointerOwnerHolder { origin: &Rc, source: Option>, icon: Option>, - serial: u32, + serial: u64, ) -> Result<(), WlSeatError> { self.owner .get() @@ -230,7 +230,7 @@ trait PointerOwner { origin: &Rc, source: Option>, icon: Option>, - serial: u32, + serial: u64, ) -> Result<(), WlSeatError> { let _ = origin; let _ = icon; @@ -284,7 +284,7 @@ struct SimpleGrabPointerOwner { usecase: T, buttons: SmallMap, node: Rc, - serial: u32, + serial: u64, } struct DndPointerOwner { @@ -473,7 +473,7 @@ impl PointerOwner for SimpleGrabPointerOwner { origin: &Rc, src: Option>, icon: Option>, - serial: u32, + serial: u64, ) -> Result<(), WlSeatError> { self.usecase .start_drag(self, seat, origin, src, icon, serial) @@ -627,7 +627,7 @@ trait SimplePointerOwnerUsecase: Sized + Clone + 'static { origin: &Rc, src: Option>, icon: Option>, - serial: u32, + serial: u64, ) -> Result<(), WlSeatError> { let _ = grab; let _ = origin; @@ -720,7 +720,7 @@ impl SimplePointerOwnerUsecase for DefaultPointerUsecase { origin: &Rc, src: Option>, icon: Option>, - serial: u32, + serial: u64, ) -> Result<(), WlSeatError> { let button = match grab.buttons.iter().next() { Some((b, _)) => b, diff --git a/src/ifs/wl_seat/tablet/zwp_tablet_pad_group_v2.rs b/src/ifs/wl_seat/tablet/zwp_tablet_pad_group_v2.rs index 4fd989a3..1ab8a91a 100644 --- a/src/ifs/wl_seat/tablet/zwp_tablet_pad_group_v2.rs +++ b/src/ifs/wl_seat/tablet/zwp_tablet_pad_group_v2.rs @@ -60,11 +60,11 @@ impl ZwpTabletPadGroupV2 { self.client.event(Done { self_id: self.id }); } - pub fn send_mode_switch(&self, time: u32, serial: u32, mode: u32) { + pub fn send_mode_switch(&self, time: u32, serial: u64, mode: u32) { self.client.event(ModeSwitch { self_id: self.id, time, - serial, + serial: serial as _, mode, }); } diff --git a/src/ifs/wl_seat/tablet/zwp_tablet_pad_v2.rs b/src/ifs/wl_seat/tablet/zwp_tablet_pad_v2.rs index 6dd37b23..d7801e43 100644 --- a/src/ifs/wl_seat/tablet/zwp_tablet_pad_v2.rs +++ b/src/ifs/wl_seat/tablet/zwp_tablet_pad_v2.rs @@ -68,21 +68,21 @@ impl ZwpTabletPadV2 { }); } - pub fn send_enter(&self, serial: u32, tablet: &ZwpTabletV2, surface: &WlSurface) { + pub fn send_enter(&self, serial: u64, tablet: &ZwpTabletV2, surface: &WlSurface) { self.entered.set(true); self.client.event(Enter { self_id: self.id, - serial, + serial: serial as _, tablet: tablet.id, surface: surface.id, }); } - pub fn send_leave(&self, serial: u32, surface: &WlSurface) { + pub fn send_leave(&self, serial: u64, surface: &WlSurface) { self.entered.set(false); self.client.event(Leave { self_id: self.id, - serial, + serial: serial as _, surface: surface.id, }); } diff --git a/src/ifs/wl_seat/tablet/zwp_tablet_tool_v2.rs b/src/ifs/wl_seat/tablet/zwp_tablet_tool_v2.rs index 4bd2b5c9..a78ad514 100644 --- a/src/ifs/wl_seat/tablet/zwp_tablet_tool_v2.rs +++ b/src/ifs/wl_seat/tablet/zwp_tablet_tool_v2.rs @@ -98,11 +98,11 @@ impl ZwpTabletToolV2 { self.client.event(Removed { self_id: self.id }); } - pub fn send_proximity_in(&self, serial: u32, tablet: &ZwpTabletV2, surface: &WlSurface) { + pub fn send_proximity_in(&self, serial: u64, tablet: &ZwpTabletV2, surface: &WlSurface) { self.entered.set(true); self.client.event(ProximityIn { self_id: self.id, - serial, + serial: serial as _, tablet: tablet.id, surface: surface.id, }); @@ -113,10 +113,10 @@ impl ZwpTabletToolV2 { self.client.event(ProximityOut { self_id: self.id }); } - pub fn send_down(&self, serial: u32) { + pub fn send_down(&self, serial: u64) { self.client.event(Down { self_id: self.id, - serial, + serial: serial as _, }); } @@ -177,10 +177,10 @@ impl ZwpTabletToolV2 { }); } - pub fn send_button(&self, serial: u32, button: u32, state: ToolButtonState) { + pub fn send_button(&self, serial: u64, button: u32, state: ToolButtonState) { self.client.event(Button { self_id: self.id, - serial, + serial: serial as _, button, state: match state { ToolButtonState::Released => 0, @@ -204,7 +204,7 @@ impl ZwpTabletToolV2RequestHandler for ZwpTabletToolV2 { let Some(tool) = self.tool.get() else { return Ok(()); }; - if !self.seat.client.valid_serial(req.serial) { + if self.seat.client.map_serial(req.serial).is_none() { log::warn!("Client tried to set_cursor with an invalid serial"); return Ok(()); } diff --git a/src/ifs/wl_seat/text_input/zwp_input_method_keyboard_grab_v2.rs b/src/ifs/wl_seat/text_input/zwp_input_method_keyboard_grab_v2.rs index 062f0d0f..3e359bb8 100644 --- a/src/ifs/wl_seat/text_input/zwp_input_method_keyboard_grab_v2.rs +++ b/src/ifs/wl_seat/text_input/zwp_input_method_keyboard_grab_v2.rs @@ -42,7 +42,7 @@ impl ZwpInputMethodKeyboardGrabV2 { }); } - fn update_state(&self, serial: u32, kb_state: &KeyboardState) { + fn update_state(&self, serial: u64, kb_state: &KeyboardState) { self.send_keymap(kb_state); self.send_modifiers(serial, kb_state); self.kb_state_id.set(kb_state.id); @@ -56,10 +56,10 @@ impl ZwpInputMethodKeyboardGrabV2 { self.send_key(serial, time_usec, key, state); } - fn send_key(&self, serial: u32, time_usec: u64, key: u32, state: u32) { + fn send_key(&self, serial: u64, time_usec: u64, key: u32, state: u32) { self.client.event(Key { self_id: self.id, - serial, + serial: serial as _, time: (time_usec / 1000) as _, key, state, @@ -74,10 +74,10 @@ impl ZwpInputMethodKeyboardGrabV2 { self.send_modifiers(serial, kb_state); } - fn send_modifiers(&self, serial: u32, kb_state: &KeyboardState) { + fn send_modifiers(&self, serial: u64, kb_state: &KeyboardState) { self.client.event(Modifiers { self_id: self.id, - serial, + serial: serial as _, mods_depressed: kb_state.mods.mods_depressed, mods_latched: kb_state.mods.mods_latched, mods_locked: kb_state.mods.mods_locked, diff --git a/src/ifs/wl_seat/wl_keyboard.rs b/src/ifs/wl_seat/wl_keyboard.rs index 45120a92..c93f50dd 100644 --- a/src/ifs/wl_seat/wl_keyboard.rs +++ b/src/ifs/wl_seat/wl_keyboard.rs @@ -44,7 +44,7 @@ impl WlKeyboard { fn send_kb_state( &self, - serial: u32, + serial: u64, kb_state: &KeyboardState, surface_id: WlSurfaceId, send_leave: bool, @@ -78,7 +78,7 @@ impl WlKeyboard { }); } - pub fn enter(&self, serial: u32, surface: WlSurfaceId, kb_state: &KeyboardState) { + pub fn enter(&self, serial: u64, surface: WlSurfaceId, kb_state: &KeyboardState) { if kb_state.id != self.kb_state_id.get() { self.send_kb_state(serial, kb_state, surface, false); } else { @@ -87,26 +87,26 @@ impl WlKeyboard { } } - fn send_enter(&self, serial: u32, surface: WlSurfaceId, keys: &[u32]) { + fn send_enter(&self, serial: u64, surface: WlSurfaceId, keys: &[u32]) { self.seat.client.event(Enter { self_id: self.id, - serial, + serial: serial as _, surface, keys, }) } - pub fn send_leave(&self, serial: u32, surface: WlSurfaceId) { + pub fn send_leave(&self, serial: u64, surface: WlSurfaceId) { self.seat.client.event(Leave { self_id: self.id, - serial, + serial: serial as _, surface, }) } pub fn on_key( &self, - serial: u32, + serial: u64, time: u32, key: u32, state: u32, @@ -119,17 +119,17 @@ impl WlKeyboard { self.send_key(serial, time, key, state); } - fn send_key(&self, serial: u32, time: u32, key: u32, state: u32) { + fn send_key(&self, serial: u64, time: u32, key: u32, state: u32) { self.seat.client.event(Key { self_id: self.id, - serial, + serial: serial as _, time, key, state, }) } - pub fn on_mods_changed(&self, serial: u32, surface: WlSurfaceId, kb_state: &KeyboardState) { + pub fn on_mods_changed(&self, serial: u64, surface: WlSurfaceId, kb_state: &KeyboardState) { if self.kb_state_id.get() != kb_state.id { self.send_kb_state(serial, kb_state, surface, true); } else { @@ -137,10 +137,10 @@ impl WlKeyboard { } } - fn send_modifiers(&self, serial: u32, mods: &ModifierState) { + fn send_modifiers(&self, serial: u64, mods: &ModifierState) { self.seat.client.event(Modifiers { self_id: self.id, - serial, + serial: serial as _, mods_depressed: mods.mods_depressed, mods_latched: mods.mods_latched, mods_locked: mods.mods_locked, diff --git a/src/ifs/wl_seat/wl_pointer.rs b/src/ifs/wl_seat/wl_pointer.rs index 03ced6a9..f1bce71e 100644 --- a/src/ifs/wl_seat/wl_pointer.rs +++ b/src/ifs/wl_seat/wl_pointer.rs @@ -86,22 +86,22 @@ impl WlPointer { } } - pub fn send_enter(&self, serial: u32, surface: WlSurfaceId, mut x: Fixed, mut y: Fixed) { + pub fn send_enter(&self, serial: u64, surface: WlSurfaceId, mut x: Fixed, mut y: Fixed) { self.last_motion.set((x, y)); logical_to_client_wire_scale!(self.seat.client, x, y); self.seat.client.event(Enter { self_id: self.id, - serial, + serial: serial as u32, surface, surface_x: x, surface_y: y, }) } - pub fn send_leave(&self, serial: u32, surface: WlSurfaceId) { + pub fn send_leave(&self, serial: u64, surface: WlSurfaceId) { self.seat.client.event(Leave { self_id: self.id, - serial, + serial: serial as u32, surface, }) } @@ -119,10 +119,10 @@ impl WlPointer { }) } - pub fn send_button(&self, serial: u32, time: u32, button: u32, state: u32) { + pub fn send_button(&self, serial: u64, time: u32, button: u32, state: u32) { self.seat.client.event(Button { self_id: self.id, - serial, + serial: serial as u32, time, button, state, @@ -187,7 +187,7 @@ impl WlPointerRequestHandler for WlPointer { type Error = WlPointerError; fn set_cursor(&self, mut req: SetCursor, _slf: &Rc) -> Result<(), Self::Error> { - if !self.seat.client.valid_serial(req.serial) { + if self.seat.client.map_serial(req.serial).is_none() { log::warn!("Client tried to set_cursor with an invalid serial"); return Ok(()); } diff --git a/src/ifs/wl_seat/wl_touch.rs b/src/ifs/wl_seat/wl_touch.rs index 5ecdf12e..fba96452 100644 --- a/src/ifs/wl_seat/wl_touch.rs +++ b/src/ifs/wl_seat/wl_touch.rs @@ -33,7 +33,7 @@ impl WlTouch { pub fn send_down( &self, - serial: u32, + serial: u64, time: u32, surface: WlSurfaceId, id: i32, @@ -43,7 +43,7 @@ impl WlTouch { logical_to_client_wire_scale!(self.seat.client, x, y); self.seat.client.event(Down { self_id: self.id, - serial, + serial: serial as _, time, surface, id, @@ -52,10 +52,10 @@ impl WlTouch { }) } - pub fn send_up(&self, serial: u32, time: u32, id: i32) { + pub fn send_up(&self, serial: u64, time: u32, id: i32) { self.seat.client.event(Up { self_id: self.id, - serial, + serial: serial as _, time, id, }) diff --git a/src/ifs/wl_seat/zwp_pointer_gesture_hold_v1.rs b/src/ifs/wl_seat/zwp_pointer_gesture_hold_v1.rs index 2f29f124..f636b8e1 100644 --- a/src/ifs/wl_seat/zwp_pointer_gesture_hold_v1.rs +++ b/src/ifs/wl_seat/zwp_pointer_gesture_hold_v1.rs @@ -23,20 +23,20 @@ impl ZwpPointerGestureHoldV1 { self.seat.hold_bindings.remove(&self.client, self); } - pub fn send_hold_begin(&self, n: &WlSurface, serial: u32, time_usec: u64, finger_count: u32) { + pub fn send_hold_begin(&self, n: &WlSurface, serial: u64, time_usec: u64, finger_count: u32) { self.client.event(Begin { self_id: self.id, - serial, + serial: serial as _, time: (time_usec / 1000) as u32, surface: n.id, fingers: finger_count, }); } - pub fn send_hold_end(&self, serial: u32, time_usec: u64, cancelled: bool) { + pub fn send_hold_end(&self, serial: u64, time_usec: u64, cancelled: bool) { self.client.event(End { self_id: self.id, - serial, + serial: serial as _, time: (time_usec / 1000) as u32, cancelled: cancelled as _, }); diff --git a/src/ifs/wl_seat/zwp_pointer_gesture_pinch_v1.rs b/src/ifs/wl_seat/zwp_pointer_gesture_pinch_v1.rs index 7c592d6b..b6f05684 100644 --- a/src/ifs/wl_seat/zwp_pointer_gesture_pinch_v1.rs +++ b/src/ifs/wl_seat/zwp_pointer_gesture_pinch_v1.rs @@ -24,10 +24,10 @@ impl ZwpPointerGesturePinchV1 { self.seat.pinch_bindings.remove(&self.client, self); } - pub fn send_pinch_begin(&self, n: &WlSurface, serial: u32, time_usec: u64, finger_count: u32) { + pub fn send_pinch_begin(&self, n: &WlSurface, serial: u64, time_usec: u64, finger_count: u32) { self.client.event(Begin { self_id: self.id, - serial, + serial: serial as _, time: (time_usec / 1000) as u32, surface: n.id, fingers: finger_count, @@ -52,10 +52,10 @@ impl ZwpPointerGesturePinchV1 { }); } - pub fn send_pinch_end(&self, serial: u32, time_usec: u64, cancelled: bool) { + pub fn send_pinch_end(&self, serial: u64, time_usec: u64, cancelled: bool) { self.client.event(End { self_id: self.id, - serial, + serial: serial as _, time: (time_usec / 1000) as u32, cancelled: cancelled as _, }); diff --git a/src/ifs/wl_seat/zwp_pointer_gesture_swipe_v1.rs b/src/ifs/wl_seat/zwp_pointer_gesture_swipe_v1.rs index b8b8a198..5ad4dc5e 100644 --- a/src/ifs/wl_seat/zwp_pointer_gesture_swipe_v1.rs +++ b/src/ifs/wl_seat/zwp_pointer_gesture_swipe_v1.rs @@ -24,10 +24,10 @@ impl ZwpPointerGestureSwipeV1 { self.seat.swipe_bindings.remove(&self.client, self); } - pub fn send_swipe_begin(&self, n: &WlSurface, serial: u32, time_usec: u64, finger_count: u32) { + pub fn send_swipe_begin(&self, n: &WlSurface, serial: u64, time_usec: u64, finger_count: u32) { self.client.event(Begin { self_id: self.id, - serial, + serial: serial as _, time: (time_usec / 1000) as u32, surface: n.id, fingers: finger_count, @@ -43,10 +43,10 @@ impl ZwpPointerGestureSwipeV1 { }); } - pub fn send_swipe_end(&self, serial: u32, time_usec: u64, cancelled: bool) { + pub fn send_swipe_end(&self, serial: u64, time_usec: u64, cancelled: bool) { self.client.event(End { self_id: self.id, - serial, + serial: serial as _, time: (time_usec / 1000) as u32, cancelled: cancelled as _, }); diff --git a/src/ifs/wl_seat/zwp_virtual_keyboard_v1.rs b/src/ifs/wl_seat/zwp_virtual_keyboard_v1.rs index e100ce3e..c9b4d8b8 100644 --- a/src/ifs/wl_seat/zwp_virtual_keyboard_v1.rs +++ b/src/ifs/wl_seat/zwp_virtual_keyboard_v1.rs @@ -30,7 +30,7 @@ pub struct ZwpVirtualKeyboardV1 { impl ZwpVirtualKeyboardV1 { fn for_each_kb(&self, mut f: F) where - F: FnMut(u32, &WlSurface, &WlKeyboard), + F: FnMut(u64, &WlSurface, &WlKeyboard), { let Some(surface) = self.seat.keyboard_node.get().node_into_surface() else { return; diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index d501247a..e19d5735 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -1776,7 +1776,7 @@ impl Node for WlSurface { time_usec: u64, button: u32, state: KeyState, - serial: u32, + serial: u64, ) { seat.button_surface(&self, time_usec, button, state, serial); } @@ -1829,7 +1829,7 @@ impl Node for WlSurface { dnd.seat.dnd_surface_leave(self, dnd); } - fn node_on_dnd_enter(&self, dnd: &Dnd, x: Fixed, y: Fixed, serial: u32) { + fn node_on_dnd_enter(&self, dnd: &Dnd, x: Fixed, y: Fixed, serial: u64) { dnd.seat.dnd_surface_enter(self, dnd, x, y, serial); } diff --git a/src/state.rs b/src/state.rs index ae619f6a..e84b65dc 100644 --- a/src/state.rs +++ b/src/state.rs @@ -106,7 +106,6 @@ use { cell::{Cell, RefCell}, fmt::{Debug, Formatter}, mem, - num::Wrapping, ops::DerefMut, rc::{Rc, Weak}, sync::Arc, @@ -169,7 +168,7 @@ pub struct State { pub run_args: RunArgs, pub xwayland: XWaylandState, pub acceptor: CloneCell>>, - pub serial: NumCell>, + pub serial: NumCell, pub run_toplevel: Rc, pub config_dir: Option, pub config_file_id: NumCell, @@ -755,8 +754,8 @@ impl State { } } - pub fn next_serial(&self, client: Option<&Client>) -> u32 { - let serial = self.serial.fetch_add(Wrapping(1)).0; + pub fn next_serial(&self, client: Option<&Client>) -> u64 { + let serial = self.serial.fetch_add(1); if let Some(client) = client { 'update_range: { let mut serials = client.serials.borrow_mut(); diff --git a/src/tree.rs b/src/tree.rs index fc4d9dea..1901af79 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -250,7 +250,7 @@ pub trait Node: 'static { time_usec: u64, button: u32, state: KeyState, - serial: u32, + serial: u64, ) { let _ = seat; let _ = time_usec; @@ -322,7 +322,7 @@ pub trait Node: 'static { let _ = dnd; } - fn node_on_dnd_enter(&self, dnd: &Dnd, x: Fixed, y: Fixed, serial: u32) { + fn node_on_dnd_enter(&self, dnd: &Dnd, x: Fixed, y: Fixed, serial: u64) { let _ = dnd; let _ = x; let _ = y; diff --git a/src/tree/container.rs b/src/tree/container.rs index 1bc9e99c..2fef939a 100644 --- a/src/tree/container.rs +++ b/src/tree/container.rs @@ -1623,7 +1623,7 @@ impl Node for ContainerNode { time_usec: u64, button: u32, state: KeyState, - _serial: u32, + _serial: u64, ) { let id = CursorType::Seat(seat.id()); self.button(id, seat, time_usec, state == KeyState::Pressed, button); diff --git a/src/tree/float.rs b/src/tree/float.rs index 822324f8..bf6fc2c9 100644 --- a/src/tree/float.rs +++ b/src/tree/float.rs @@ -632,7 +632,7 @@ impl Node for FloatNode { time_usec: u64, button: u32, state: KeyState, - _serial: u32, + _serial: u64, ) { if button != BTN_LEFT { return; diff --git a/src/tree/output.rs b/src/tree/output.rs index 3f8e37da..52cbd96a 100644 --- a/src/tree/output.rs +++ b/src/tree/output.rs @@ -1356,7 +1356,7 @@ impl Node for OutputNode { _time_usec: u64, button: u32, state: KeyState, - _serial: u32, + _serial: u64, ) { if button != BTN_LEFT { return; diff --git a/src/utils/pending_serial.rs b/src/utils/pending_serial.rs index d7890014..f1c8087e 100644 --- a/src/utils/pending_serial.rs +++ b/src/utils/pending_serial.rs @@ -1,7 +1,7 @@ use crate::client::Client; pub struct PendingSerial<'a> { - serial: Option, + serial: Option, client: &'a Client, } @@ -13,7 +13,7 @@ impl<'a> PendingSerial<'a> { } } - pub fn get(&mut self) -> u32 { + pub fn get(&mut self) -> u64 { *self.serial.get_or_insert_with(|| self.client.next_serial()) } }