Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/utils/atomic_scale.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

//! Atomic scale type backed by 64-bit atomic on platform supporting it, falling-back to 32-bit storage on unsupported platforms.

use std::sync::atomic::Ordering;

#[cfg(target_has_atomic = "64")]
type AtomicFScaleValue = f64;
#[cfg(target_has_atomic = "64")]
type AtomicFScaleInner = atomic_float::AtomicF64;

#[cfg(not(target_has_atomic = "64"))]
type AtomicFScaleValue = f32;

#[cfg(not(target_has_atomic = "64"))]
type AtomicFScaleInner = atomic_float::AtomicF32;

/// Wrapper about either [`AtomicF64`](atomic_float::AtomicF64) or [`AtomicF32`](atomic_float::AtomicF32)
///
/// On platforms supporting 64-bit atomics, this acts exactly like
/// [`AtomicF64`](atomic_float::AtomicF64) would.
///
/// On platforms having only 32-bit ones, this still has API with [`f64`],
/// but uses [`AtomicF32`](atomic_float::AtomicF32) internally and
/// storing operations will lead to precision loss.
#[derive(Debug)]
pub struct AtomicFScale(AtomicFScaleInner);
impl AtomicFScale {
/// Loads a value from the atomic float.
///
/// On platforms lacking 64-bit atomic support, this will widen the float.
#[inline]
pub fn load(&self, ordering: Ordering) -> f64 {
self.0.load(ordering).into()
}

/// Initialize atomic from value
///
/// On platforms lacking 64-bit atomic supports, this means precision loss.
#[inline]
pub fn new(val: f64) -> Self {
Self((val as AtomicFScaleValue).into())
}

/// Stores a value into the atomic float, returning the previous value.
///
/// On platforms lacking 64-bit atomic supports, this means precision loss.
#[inline]
pub fn swap(&self, new_value: f64, ordering: Ordering) -> f64 {
self.0.swap(new_value as AtomicFScaleValue, ordering).into()
}

/// Store a value into the atomic float.
///
/// On platforms lacking 64-bit atomic supports, this means precision loss.
#[inline]
pub fn store(&self, new_value: f64, ordering: Ordering) {
self.0.store(new_value as AtomicFScaleValue, ordering);
}
}
2 changes: 1 addition & 1 deletion src/utils/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ where
fn add(self, rhs: T) -> Self::Output {
let rhs = rhs.into();
let tv_nsec = (self.tp.tv_nsec + rhs.tp.tv_nsec) % NANOS_PER_SEC;
let tv_sec = (self.tp.tv_sec + rhs.tp.tv_sec) + ((self.tp.tv_nsec + rhs.tp.tv_nsec) / NANOS_PER_SEC);
let tv_sec = (self.tp.tv_sec + rhs.tp.tv_sec) + i64::from((self.tp.tv_nsec + rhs.tp.tv_nsec) / NANOS_PER_SEC);
Self::from(Timespec { tv_sec, tv_nsec })
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub mod user_data;
pub(crate) mod alive_tracker;
pub use self::alive_tracker::IsAlive;

mod atomic_scale;
pub(crate) use atomic_scale::AtomicFScale;

#[cfg(feature = "wayland_frontend")]
pub(crate) mod iter;

Expand Down
9 changes: 4 additions & 5 deletions src/wayland/compositor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ pub use self::tree::{AlreadyHasRole, TraversalAction};
use self::tree::{PrivateSurfaceData, SuggestedSurfaceState};
pub use crate::utils::hook::HookId;
use crate::utils::Transform;
use crate::utils::{user_data::UserDataMap, Buffer, Logical, Point, Rectangle};
use atomic_float::AtomicF64;
use crate::utils::{user_data::UserDataMap, Buffer, Logical, Point, Rectangle, AtomicFScale};
use wayland_server::backend::GlobalId;
use wayland_server::protocol::wl_compositor::WlCompositor;
use wayland_server::protocol::wl_subcompositor::WlSubcompositor;
Expand Down Expand Up @@ -614,14 +613,14 @@ pub struct CompositorState {
#[derive(Debug)]
pub struct CompositorClientState {
queue: Mutex<Option<TransactionQueue>>,
scale_override: Arc<AtomicF64>,
scale_override: Arc<AtomicFScale>,
}

impl Default for CompositorClientState {
fn default() -> Self {
CompositorClientState {
queue: Mutex::new(None),
scale_override: Arc::new(AtomicF64::new(1.)),
scale_override: Arc::new(AtomicFScale::new(1.)),
}
}
}
Expand Down Expand Up @@ -664,7 +663,7 @@ impl CompositorClientState {
self.scale_override.load(Ordering::Acquire)
}

pub(crate) fn clone_client_scale(&self) -> Arc<AtomicF64> {
pub(crate) fn clone_client_scale(&self) -> Arc<AtomicFScale> {
self.scale_override.clone()
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/wayland/output/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::{atomic::Ordering, Arc};

use atomic_float::AtomicF64;
use tracing::{trace, warn, warn_span};
use wayland_protocols::xdg::xdg_output::zv1::server::{
zxdg_output_manager_v1::{self, ZxdgOutputManagerV1},
Expand All @@ -11,6 +10,7 @@ use wayland_server::{
Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource,
};

use crate::utils::AtomicFScale;
use crate::wayland::compositor::CompositorHandler;

use super::{xdg::XdgOutput, Output, OutputHandler, OutputManagerState, OutputUserData, WlOutputData};
Expand Down Expand Up @@ -40,7 +40,7 @@ where
resource,
OutputUserData {
output: global_data.output.downgrade(),
last_client_scale: AtomicF64::new(client_scale.load(Ordering::Acquire)),
last_client_scale: AtomicFScale::new(client_scale.load(Ordering::Acquire)),
client_scale,
},
);
Expand Down Expand Up @@ -191,7 +191,7 @@ where
id,
XdgOutputUserData {
xdg_output,
last_client_scale: AtomicF64::new(client_scale.load(Ordering::Acquire)),
last_client_scale: AtomicFScale::new(client_scale.load(Ordering::Acquire)),
client_scale,
},
);
Expand All @@ -208,8 +208,8 @@ where
#[derive(Debug)]
pub struct XdgOutputUserData {
xdg_output: XdgOutput,
pub(super) last_client_scale: AtomicF64,
pub(super) client_scale: Arc<AtomicF64>,
pub(super) last_client_scale: AtomicFScale,
pub(super) client_scale: Arc<AtomicFScale>,
}

impl<D> Dispatch<ZxdgOutputV1, XdgOutputUserData, D> for OutputManagerState
Expand Down
9 changes: 4 additions & 5 deletions src/wayland/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ use crate::{
utils::iter::new_locked_obj_iter,
};

use atomic_float::AtomicF64;
use tracing::info;
use wayland_protocols::xdg::xdg_output::zv1::server::zxdg_output_manager_v1::ZxdgOutputManagerV1;
use wayland_server::{
Expand All @@ -94,7 +93,7 @@ use wayland_server::{
Client, DisplayHandle, GlobalDispatch, Resource,
};

use crate::utils::{Logical, Point};
use crate::utils::{Logical, Point, AtomicFScale};

pub use self::handlers::XdgOutputUserData;

Expand Down Expand Up @@ -148,15 +147,15 @@ impl OutputManagerState {
#[derive(Debug)]
pub struct OutputUserData {
pub(crate) output: WeakOutput,
last_client_scale: AtomicF64,
client_scale: Arc<AtomicF64>,
last_client_scale: AtomicFScale,
client_scale: Arc<AtomicFScale>,
}

impl Clone for OutputUserData {
fn clone(&self) -> Self {
OutputUserData {
output: self.output.clone(),
last_client_scale: AtomicF64::new(self.last_client_scale.load(Ordering::Acquire)),
last_client_scale: AtomicFScale::new(self.last_client_scale.load(Ordering::Acquire)),
client_scale: self.client_scale.clone(),
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/wayland/pointer_gestures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@

use std::sync::{atomic::Ordering, Arc, Mutex};

use atomic_float::AtomicF64;
use wayland_protocols::wp::pointer_gestures::zv1::server::{
zwp_pointer_gesture_hold_v1::{self, ZwpPointerGestureHoldV1},
zwp_pointer_gesture_pinch_v1::{self, ZwpPointerGesturePinchV1},
Expand All @@ -120,7 +119,7 @@ use crate::{
},
SeatHandler,
},
utils::{Serial, SERIAL_COUNTER},
utils::{Serial, SERIAL_COUNTER, AtomicFScale},
wayland::seat::PointerUserData,
};

Expand Down Expand Up @@ -366,7 +365,7 @@ pub struct PointerGestureUserData<D: SeatHandler> {
handle: Option<PointerHandle<D>>,
/// This gesture is in the middle between its begin() and end() on this surface.
pub(crate) in_progress_on: Mutex<Option<WlSurface>>,
client_scale: Arc<AtomicF64>,
client_scale: Arc<AtomicFScale>,
}

/// State of the pointer gestures
Expand Down
4 changes: 2 additions & 2 deletions src/wayland/relative_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@

use std::sync::{atomic::Ordering, Arc, Mutex};

use atomic_float::AtomicF64;
use wayland_protocols::wp::relative_pointer::zv1::server::{
zwp_relative_pointer_manager_v1::{self, ZwpRelativePointerManagerV1},
zwp_relative_pointer_v1::{self, ZwpRelativePointerV1},
Expand All @@ -103,6 +102,7 @@ use crate::{
SeatHandler,
},
wayland::seat::PointerUserData,
utils::AtomicFScale,
};

const MANAGER_VERSION: u32 = 1;
Expand Down Expand Up @@ -158,7 +158,7 @@ impl WpRelativePointerHandle {
#[derive(Debug)]
pub struct RelativePointerUserData<D: SeatHandler> {
handle: Option<PointerHandle<D>>,
client_scale: Arc<AtomicF64>,
client_scale: Arc<AtomicFScale>,
}

/// State of the relative pointer manager
Expand Down
5 changes: 2 additions & 3 deletions src/wayland/seat/pointer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::{atomic::Ordering, Arc, Mutex};

use atomic_float::AtomicF64;
use wayland_server::{
backend::{ClientId, ObjectId},
protocol::{
Expand All @@ -24,7 +23,7 @@ use crate::{
},
Seat,
},
utils::{iter::new_locked_obj_iter_from_vec, Client as ClientCoords, Point, Serial},
utils::{iter::new_locked_obj_iter_from_vec, Client as ClientCoords, Point, Serial, AtomicFScale},
wayland::{compositor, pointer_constraints::with_pointer_constraint},
};

Expand Down Expand Up @@ -345,7 +344,7 @@ where
#[derive(Debug)]
pub struct PointerUserData<D: SeatHandler> {
pub(crate) handle: Option<PointerHandle<D>>,
pub(crate) client_scale: Arc<AtomicF64>,
pub(crate) client_scale: Arc<AtomicFScale>,
}

impl<D> Dispatch<WlPointer, PointerUserData<D>, D> for SeatState<D>
Expand Down
8 changes: 5 additions & 3 deletions src/wayland/seat/touch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::{atomic::Ordering, Arc};

use atomic_float::AtomicF64;
use wayland_server::{
backend::ClientId,
protocol::wl_touch::{self, WlTouch},
Expand All @@ -14,7 +13,10 @@ use crate::input::{
Seat,
};
use crate::{input::touch::DownEvent, wayland::seat::wl_surface::WlSurface};
use crate::{input::touch::TouchHandle, utils::Serial};
use crate::{
input::touch::TouchHandle,
utils::{AtomicFScale, Serial},
};

impl<D: SeatHandler> TouchHandle<D> {
pub(crate) fn new_touch(&self, touch: WlTouch) {
Expand Down Expand Up @@ -132,7 +134,7 @@ where
#[derive(Debug)]
pub struct TouchUserData<D: SeatHandler> {
pub(crate) handle: Option<TouchHandle<D>>,
pub(crate) client_scale: Arc<AtomicF64>,
pub(crate) client_scale: Arc<AtomicFScale>,
}

impl<D> Dispatch<WlTouch, TouchUserData<D>, D> for SeatState<D>
Expand Down
5 changes: 2 additions & 3 deletions src/wayland/tablet_manager/tablet_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::input::pointer::{CursorImageAttributes, CursorImageStatus};
use crate::utils::{Client as ClientCoords, Logical, Point};
use crate::wayland::compositor::CompositorHandler;
use crate::wayland::seat::CURSOR_IMAGE_ROLE;
use atomic_float::AtomicF64;
use wayland_protocols::wp::tablet::zv2::server::{
zwp_tablet_seat_v2::ZwpTabletSeatV2,
zwp_tablet_tool_v2::{self, ZwpTabletToolV2},
Expand All @@ -16,7 +15,7 @@ use wayland_server::protocol::wl_surface::WlSurface;
use wayland_server::Weak;
use wayland_server::{backend::ClientId, Client, DataInit, Dispatch, DisplayHandle, Resource};

use crate::{utils::Serial, wayland::compositor};
use crate::{utils::{Serial, AtomicFScale}, wayland::compositor};

use super::tablet::TabletHandle;
use super::tablet_seat::TabletSeatHandler;
Expand Down Expand Up @@ -455,7 +454,7 @@ impl From<ButtonState> for zwp_tablet_tool_v2::ButtonState {
pub struct TabletToolUserData {
pub(crate) handle: TabletToolHandle,
pub(crate) desc: TabletToolDescriptor,
client_scale: Arc<AtomicF64>,
client_scale: Arc<AtomicFScale>,
}

impl fmt::Debug for TabletToolUserData {
Expand Down
5 changes: 2 additions & 3 deletions src/xwayland/xwm/dnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use std::{
},
};

use atomic_float::AtomicF64;
use calloop::LoopHandle;
use rustix::fs::OFlags;
use smallvec::SmallVec;
Expand Down Expand Up @@ -38,7 +37,7 @@ use crate::{
pointer::Focus,
Seat, SeatHandler,
},
utils::{IsAlive, Logical, Point, Serial},
utils::{AtomicFScale, IsAlive, Logical, Point, Serial},
xwayland::{
xwm::{atom_from_mime, mime_from_atom, selection::XWmSelection, Atoms, OwnedX11Window, XwmId},
X11Surface, XwmHandler,
Expand Down Expand Up @@ -297,7 +296,7 @@ impl XWmDnd {
window: &X11Surface,
status_msg: ClientMessageData,
atoms: &Atoms,
client_scale: Arc<AtomicF64>,
client_scale: Arc<AtomicFScale>,
) {
if let Some(offer) = self.active_offer.as_ref() {
let data = status_msg.as_data32();
Expand Down
5 changes: 2 additions & 3 deletions src/xwayland/xwm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,12 @@ use crate::{
SeatHandler,
},
output::Output,
utils::{x11rb::X11Source, Client, Logical, Point, Rectangle, Size},
utils::{x11rb::X11Source, AtomicFScale, Client, Logical, Point, Rectangle, Size},
wayland::{
selection::SelectionTarget,
xwayland_shell::{self, XWaylandShellHandler},
},
};
use atomic_float::AtomicF64;
use calloop::{generic::Generic, Interest, LoopHandle, Mode, PostAction};
use rustix::fs::OFlags;
use std::{
Expand Down Expand Up @@ -469,7 +468,7 @@ pub trait XwmHandler {
pub struct X11Wm {
id: XwmId,
conn: Arc<RustConnection>,
client_scale: Arc<AtomicF64>,
client_scale: Arc<AtomicFScale>,
screen: Screen,
wm_window: OwnedX11Window,
atoms: Atoms,
Expand Down
Loading