From e3a1a0b30fa08f2ff3254f839a78c6fb0d067d05 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Mon, 8 Apr 2024 14:47:50 +0200 Subject: [PATCH] wayland: make object versions type safe --- src/globals.rs | 4 +- src/ifs/ext_foreign_toplevel_list_v1.rs | 4 +- src/ifs/ext_idle_notifier_v1.rs | 4 +- src/ifs/ext_session_lock_manager_v1.rs | 4 +- src/ifs/ipc/wl_data_device.rs | 8 +-- src/ifs/ipc/wl_data_device_manager.rs | 6 +-- src/ifs/ipc/wl_data_source.rs | 6 +-- src/ifs/ipc/zwlr_data_control_device_v1.rs | 14 ++--- src/ifs/ipc/zwlr_data_control_manager_v1.rs | 6 +-- src/ifs/ipc/zwlr_data_control_source_v1.rs | 6 +-- ...zwp_primary_selection_device_manager_v1.rs | 6 +-- .../ipc/zwp_primary_selection_device_v1.rs | 8 +-- src/ifs/jay_compositor.rs | 4 +- .../org_kde_kwin_server_decoration_manager.rs | 6 +-- src/ifs/wl_compositor.rs | 6 +-- src/ifs/wl_drm.rs | 6 +-- src/ifs/wl_output.rs | 12 ++--- src/ifs/wl_registry.rs | 4 +- src/ifs/wl_seat.rs | 10 ++-- src/ifs/wl_seat/event_handling.rs | 51 ++++++++++--------- src/ifs/wl_seat/wl_keyboard.rs | 4 +- src/ifs/wl_seat/wl_pointer.rs | 16 +++--- src/ifs/wl_seat/zwp_pointer_constraints_v1.rs | 4 +- .../zwp_relative_pointer_manager_v1.rs | 4 +- src/ifs/wl_shm.rs | 6 +-- src/ifs/wl_subcompositor.rs | 4 +- src/ifs/wl_surface.rs | 12 ++--- .../wl_surface/xdg_surface/xdg_toplevel.rs | 6 +-- src/ifs/wl_surface/xwayland_shell_v1.rs | 6 +-- src/ifs/wp_content_type_manager_v1.rs | 6 +-- src/ifs/wp_cursor_shape_manager_v1.rs | 6 +-- src/ifs/wp_fractional_scale_manager_v1.rs | 4 +- src/ifs/wp_linux_drm_syncobj_manager_v1.rs | 4 +- src/ifs/wp_presentation.rs | 4 +- src/ifs/wp_single_pixel_buffer_manager_v1.rs | 4 +- src/ifs/wp_tearing_control_manager_v1.rs | 4 +- src/ifs/wp_viewporter.rs | 4 +- src/ifs/xdg_activation_v1.rs | 6 +-- src/ifs/xdg_toplevel_drag_manager_v1.rs | 6 +-- src/ifs/xdg_wm_base.rs | 6 +-- src/ifs/zwlr_layer_shell_v1.rs | 6 +-- src/ifs/zwlr_screencopy_frame_v1.rs | 4 +- src/ifs/zwlr_screencopy_manager_v1.rs | 6 +-- src/ifs/zwp_idle_inhibit_manager_v1.rs | 6 +-- src/ifs/zwp_linux_dmabuf_v1.rs | 14 ++--- src/ifs/zxdg_decoration_manager_v1.rs | 6 +-- src/ifs/zxdg_output_manager_v1.rs | 6 +-- src/ifs/zxdg_output_v1.rs | 10 ++-- src/macros.rs | 2 +- src/object.rs | 20 ++++++++ 50 files changed, 198 insertions(+), 173 deletions(-) diff --git a/src/globals.rs b/src/globals.rs index aea66c17..afbf9bd7 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -39,7 +39,7 @@ use { zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Global, zxdg_output_manager_v1::ZxdgOutputManagerV1Global, }, - object::{Interface, ObjectId}, + object::{Interface, ObjectId, Version}, state::State, utils::{ copyhashmap::{CopyHashMap, Locked}, @@ -97,7 +97,7 @@ pub trait GlobalBase { self: Rc, client: &'a Rc, id: ObjectId, - version: u32, + version: Version, ) -> Result<(), GlobalsError>; fn interface(&self) -> Interface; } diff --git a/src/ifs/ext_foreign_toplevel_list_v1.rs b/src/ifs/ext_foreign_toplevel_list_v1.rs index 09c9d26e..93f383ad 100644 --- a/src/ifs/ext_foreign_toplevel_list_v1.rs +++ b/src/ifs/ext_foreign_toplevel_list_v1.rs @@ -7,7 +7,7 @@ use { wl_surface::{x_surface::xwindow::Xwindow, xdg_surface::xdg_toplevel::XdgToplevel}, }, leaks::Tracker, - object::Object, + object::{Object, Version}, tree::{NodeVisitorBase, ToplevelNode}, utils::buffd::{MsgParser, MsgParserError}, wire::{ @@ -32,7 +32,7 @@ impl ExtForeignToplevelListV1Global { self: Rc, id: ExtForeignToplevelListV1Id, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), ExtForeignToplevelListV1Error> { let obj = Rc::new(ExtForeignToplevelListV1 { id, diff --git a/src/ifs/ext_idle_notifier_v1.rs b/src/ifs/ext_idle_notifier_v1.rs index cfe8061b..7e08b9c2 100644 --- a/src/ifs/ext_idle_notifier_v1.rs +++ b/src/ifs/ext_idle_notifier_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::ext_idle_notification_v1::ExtIdleNotificationV1, leaks::Tracker, - object::Object, + object::{Object, Version}, time::now_usec, utils::{ buffd::{MsgParser, MsgParserError}, @@ -29,7 +29,7 @@ impl ExtIdleNotifierV1Global { self: Rc, id: ExtIdleNotifierV1Id, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), ExtIdleNotifierV1Error> { let obj = Rc::new(ExtIdleNotifierV1 { id, diff --git a/src/ifs/ext_session_lock_manager_v1.rs b/src/ifs/ext_session_lock_manager_v1.rs index a81a8aac..19e6b9c1 100644 --- a/src/ifs/ext_session_lock_manager_v1.rs +++ b/src/ifs/ext_session_lock_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::ext_session_lock_v1::ExtSessionLockV1, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{ext_session_lock_manager_v1::*, ExtSessionLockManagerV1Id}, }, @@ -25,7 +25,7 @@ impl ExtSessionLockManagerV1Global { self: Rc, id: ExtSessionLockManagerV1Id, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), ExtSessionLockManagerV1Error> { let obj = Rc::new(ExtSessionLockManagerV1 { id, diff --git a/src/ifs/ipc/wl_data_device.rs b/src/ifs/ipc/wl_data_device.rs index 6b7ef840..0ac8b78f 100644 --- a/src/ifs/ipc/wl_data_device.rs +++ b/src/ifs/ipc/wl_data_device.rs @@ -12,7 +12,7 @@ use { wl_surface::{SurfaceRole, WlSurfaceError}, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wl_data_device::*, WlDataDeviceId, WlDataOfferId, WlSurfaceId}, }, @@ -26,7 +26,7 @@ const ROLE: u32 = 0; pub struct WlDataDevice { pub id: WlDataDeviceId, pub client: Rc, - pub version: u32, + pub version: Version, pub seat: Rc, pub data: DeviceData, pub tracker: Tracker, @@ -36,7 +36,7 @@ impl WlDataDevice { pub fn new( id: WlDataDeviceId, client: &Rc, - version: u32, + version: Version, seat: &Rc, ) -> Self { Self { @@ -158,7 +158,7 @@ impl IterableIpcVtable for ClipboardIpc { where C: FnMut(&Rc), { - seat.for_each_data_device(0, client, f); + seat.for_each_data_device(Version::ALL, client, f); } } diff --git a/src/ifs/ipc/wl_data_device_manager.rs b/src/ifs/ipc/wl_data_device_manager.rs index 226dd8e9..7e961fb4 100644 --- a/src/ifs/ipc/wl_data_device_manager.rs +++ b/src/ifs/ipc/wl_data_device_manager.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::ipc::{wl_data_device::WlDataDevice, wl_data_source::WlDataSource}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wl_data_device_manager::*, WlDataDeviceManagerId}, }, @@ -28,7 +28,7 @@ pub struct WlDataDeviceManagerGlobal { pub struct WlDataDeviceManager { pub id: WlDataDeviceManagerId, pub client: Rc, - pub version: u32, + pub version: Version, tracker: Tracker, } @@ -41,7 +41,7 @@ impl WlDataDeviceManagerGlobal { self: Rc, id: WlDataDeviceManagerId, client: &Rc, - version: u32, + version: Version, ) -> Result<(), WlDataDeviceManagerError> { let obj = Rc::new(WlDataDeviceManager { id, diff --git a/src/ifs/ipc/wl_data_source.rs b/src/ifs/ipc/wl_data_source.rs index aecd0956..18281feb 100644 --- a/src/ifs/ipc/wl_data_source.rs +++ b/src/ifs/ipc/wl_data_source.rs @@ -18,7 +18,7 @@ use { xdg_toplevel_drag_v1::XdgToplevelDragV1, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::{ bitflags::BitflagsExt, buffd::{MsgParser, MsgParserError}, @@ -40,7 +40,7 @@ const INVALID_SOURCE: u32 = 1; pub struct WlDataSource { pub id: WlDataSourceId, pub data: SourceData, - pub version: u32, + pub version: Version, pub tracker: Tracker, pub toplevel_drag: CloneCell>>, } @@ -94,7 +94,7 @@ impl DynDataSource for WlDataSource { } impl WlDataSource { - pub fn new(id: WlDataSourceId, client: &Rc, version: u32) -> Self { + pub fn new(id: WlDataSourceId, client: &Rc, version: Version) -> Self { Self { id, tracker: Default::default(), diff --git a/src/ifs/ipc/zwlr_data_control_device_v1.rs b/src/ifs/ipc/zwlr_data_control_device_v1.rs index 9bb6b29e..a8efe85d 100644 --- a/src/ifs/ipc/zwlr_data_control_device_v1.rs +++ b/src/ifs/ipc/zwlr_data_control_device_v1.rs @@ -14,7 +14,7 @@ use { wl_seat::{WlSeatError, WlSeatGlobal}, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{ zwlr_data_control_device_v1::*, ZwlrDataControlDeviceV1Id, ZwlrDataControlOfferV1Id, @@ -25,12 +25,12 @@ use { thiserror::Error, }; -pub const PRIMARY_SELECTION_SINCE: u32 = 2; +pub const PRIMARY_SELECTION_SINCE: Version = Version(2); pub struct ZwlrDataControlDeviceV1 { pub id: ZwlrDataControlDeviceV1Id, pub client: Rc, - pub version: u32, + pub version: Version, pub seat: Rc, pub clipboard_data: DeviceData, pub primary_selection_data: DeviceData, @@ -41,7 +41,7 @@ impl ZwlrDataControlDeviceV1 { pub fn new( id: ZwlrDataControlDeviceV1Id, client: &Rc, - version: u32, + version: Version, seat: &Rc, ) -> Self { Self { @@ -137,7 +137,7 @@ pub type WlrClipboardIpc = WlrIpcImpl; pub type WlrPrimarySelectionIpc = WlrIpcImpl; trait WlrIpc { - const MIN_VERSION: u32; + const MIN_VERSION: Version; const LOCATION: IpcLocation; fn wlr_get_device_data(dd: &ZwlrDataControlDeviceV1) -> &DeviceData; @@ -153,7 +153,7 @@ trait WlrIpc { } impl WlrIpc for WlrClipboardIpcCore { - const MIN_VERSION: u32 = 1; + const MIN_VERSION: Version = Version::ALL; const LOCATION: IpcLocation = IpcLocation::Clipboard; fn wlr_get_device_data(dd: &ZwlrDataControlDeviceV1) -> &DeviceData { @@ -180,7 +180,7 @@ impl WlrIpc for WlrClipboardIpcCore { } impl WlrIpc for WlrPrimarySelectionIpcCore { - const MIN_VERSION: u32 = PRIMARY_SELECTION_SINCE; + const MIN_VERSION: Version = PRIMARY_SELECTION_SINCE; const LOCATION: IpcLocation = IpcLocation::PrimarySelection; fn wlr_get_device_data(dd: &ZwlrDataControlDeviceV1) -> &DeviceData { diff --git a/src/ifs/ipc/zwlr_data_control_manager_v1.rs b/src/ifs/ipc/zwlr_data_control_manager_v1.rs index df2ecdd4..0f77cfa4 100644 --- a/src/ifs/ipc/zwlr_data_control_manager_v1.rs +++ b/src/ifs/ipc/zwlr_data_control_manager_v1.rs @@ -7,7 +7,7 @@ use { zwlr_data_control_source_v1::ZwlrDataControlSourceV1, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{zwlr_data_control_manager_v1::*, ZwlrDataControlManagerV1Id}, }, @@ -22,7 +22,7 @@ pub struct ZwlrDataControlManagerV1Global { pub struct ZwlrDataControlManagerV1 { pub id: ZwlrDataControlManagerV1Id, pub client: Rc, - pub version: u32, + pub version: Version, tracker: Tracker, } @@ -35,7 +35,7 @@ impl ZwlrDataControlManagerV1Global { self: Rc, id: ZwlrDataControlManagerV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), ZwlrDataControlManagerV1Error> { let obj = Rc::new(ZwlrDataControlManagerV1 { id, diff --git a/src/ifs/ipc/zwlr_data_control_source_v1.rs b/src/ifs/ipc/zwlr_data_control_source_v1.rs index bf5fa10a..5e6760fa 100644 --- a/src/ifs/ipc/zwlr_data_control_source_v1.rs +++ b/src/ifs/ipc/zwlr_data_control_source_v1.rs @@ -17,7 +17,7 @@ use { wl_seat::WlSeatGlobal, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{zwlr_data_control_source_v1::*, ZwlrDataControlSourceV1Id}, }, @@ -29,7 +29,7 @@ use { pub struct ZwlrDataControlSourceV1 { pub id: ZwlrDataControlSourceV1Id, pub data: SourceData, - pub version: u32, + pub version: Version, pub location: Cell, pub used: Cell, pub tracker: Tracker, @@ -91,7 +91,7 @@ impl DynDataSource for ZwlrDataControlSourceV1 { } impl ZwlrDataControlSourceV1 { - pub fn new(id: ZwlrDataControlSourceV1Id, client: &Rc, version: u32) -> Self { + pub fn new(id: ZwlrDataControlSourceV1Id, client: &Rc, version: Version) -> Self { Self { id, tracker: Default::default(), diff --git a/src/ifs/ipc/zwp_primary_selection_device_manager_v1.rs b/src/ifs/ipc/zwp_primary_selection_device_manager_v1.rs index fd1768ae..95051b77 100644 --- a/src/ifs/ipc/zwp_primary_selection_device_manager_v1.rs +++ b/src/ifs/ipc/zwp_primary_selection_device_manager_v1.rs @@ -7,7 +7,7 @@ use { zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{zwp_primary_selection_device_manager_v1::*, ZwpPrimarySelectionDeviceManagerV1Id}, }, @@ -22,7 +22,7 @@ pub struct ZwpPrimarySelectionDeviceManagerV1Global { pub struct ZwpPrimarySelectionDeviceManagerV1 { pub id: ZwpPrimarySelectionDeviceManagerV1Id, pub client: Rc, - pub version: u32, + pub version: Version, pub tracker: Tracker, } @@ -35,7 +35,7 @@ impl ZwpPrimarySelectionDeviceManagerV1Global { self: Rc, id: ZwpPrimarySelectionDeviceManagerV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), ZwpPrimarySelectionDeviceManagerV1Error> { let obj = Rc::new(ZwpPrimarySelectionDeviceManagerV1 { id, diff --git a/src/ifs/ipc/zwp_primary_selection_device_v1.rs b/src/ifs/ipc/zwp_primary_selection_device_v1.rs index c73814a5..5cdb32c2 100644 --- a/src/ifs/ipc/zwp_primary_selection_device_v1.rs +++ b/src/ifs/ipc/zwp_primary_selection_device_v1.rs @@ -11,7 +11,7 @@ use { wl_seat::{WlSeatError, WlSeatGlobal}, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{ zwp_primary_selection_device_v1::*, ZwpPrimarySelectionDeviceV1Id, @@ -25,7 +25,7 @@ use { pub struct ZwpPrimarySelectionDeviceV1 { pub id: ZwpPrimarySelectionDeviceV1Id, pub client: Rc, - pub version: u32, + pub version: Version, pub seat: Rc, data: DeviceData, pub tracker: Tracker, @@ -35,7 +35,7 @@ impl ZwpPrimarySelectionDeviceV1 { pub fn new( id: ZwpPrimarySelectionDeviceV1Id, client: &Rc, - version: u32, + version: Version, seat: &Rc, ) -> Self { Self { @@ -106,7 +106,7 @@ impl IterableIpcVtable for PrimarySelectionIpc { where C: FnMut(&Rc), { - seat.for_each_primary_selection_device(0, client, f) + seat.for_each_primary_selection_device(Version::ALL, client, f) } } diff --git a/src/ifs/jay_compositor.rs b/src/ifs/jay_compositor.rs index 66c7b778..134dc700 100644 --- a/src/ifs/jay_compositor.rs +++ b/src/ifs/jay_compositor.rs @@ -11,7 +11,7 @@ use { jay_workspace_watcher::JayWorkspaceWatcher, }, leaks::Tracker, - object::Object, + object::{Object, Version}, screenshoter::take_screenshot, utils::{ buffd::{MsgParser, MsgParserError}, @@ -39,7 +39,7 @@ impl JayCompositorGlobal { self: Rc, id: JayCompositorId, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), JayCompositorError> { let obj = Rc::new(JayCompositor { id, diff --git a/src/ifs/org_kde_kwin_server_decoration_manager.rs b/src/ifs/org_kde_kwin_server_decoration_manager.rs index d01ae3ce..55eeb026 100644 --- a/src/ifs/org_kde_kwin_server_decoration_manager.rs +++ b/src/ifs/org_kde_kwin_server_decoration_manager.rs @@ -6,7 +6,7 @@ use { OrgKdeKwinServerDecoration, OrgKdeKwinServerDecorationError, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{org_kde_kwin_server_decoration_manager::*, OrgKdeKwinServerDecorationManagerId}, }, @@ -32,7 +32,7 @@ impl OrgKdeKwinServerDecorationManagerGlobal { self: Rc, id: OrgKdeKwinServerDecorationManagerId, client: &Rc, - version: u32, + version: Version, ) -> Result<(), OrgKdeKwinServerDecorationManagerError> { let obj = Rc::new(OrgKdeKwinServerDecorationManager { id, @@ -68,7 +68,7 @@ simple_add_global!(OrgKdeKwinServerDecorationManagerGlobal); pub struct OrgKdeKwinServerDecorationManager { id: OrgKdeKwinServerDecorationManagerId, client: Rc, - _version: u32, + _version: Version, pub tracker: Tracker, } diff --git a/src/ifs/wl_compositor.rs b/src/ifs/wl_compositor.rs index 97086f5a..e545fc7b 100644 --- a/src/ifs/wl_compositor.rs +++ b/src/ifs/wl_compositor.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::{wl_region::WlRegion, wl_surface::WlSurface}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wl_compositor::*, WlCompositorId}, xwayland::XWaylandEvent, @@ -20,7 +20,7 @@ pub struct WlCompositorGlobal { pub struct WlCompositor { id: WlCompositorId, client: Rc, - version: u32, + version: Version, pub tracker: Tracker, } @@ -33,7 +33,7 @@ impl WlCompositorGlobal { self: Rc, id: WlCompositorId, client: &Rc, - version: u32, + version: Version, ) -> Result<(), WlCompositorError> { let obj = Rc::new(WlCompositor { id, diff --git a/src/ifs/wl_drm.rs b/src/ifs/wl_drm.rs index b7f22a7c..9b364491 100644 --- a/src/ifs/wl_drm.rs +++ b/src/ifs/wl_drm.rs @@ -5,7 +5,7 @@ use { globals::{Global, GlobalName}, ifs::wl_buffer::WlBuffer, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, video::{ dmabuf::{DmaBuf, DmaBufPlane, PlaneVec}, @@ -33,7 +33,7 @@ impl WlDrmGlobal { self: Rc, id: WlDrmId, client: &Rc, - version: u32, + version: Version, ) -> Result<(), WlDrmError> { let obj = Rc::new(WlDrm { id, @@ -68,7 +68,7 @@ simple_add_global!(WlDrmGlobal); pub struct WlDrm { id: WlDrmId, pub client: Rc, - version: u32, + version: Version, tracker: Tracker, } diff --git a/src/ifs/wl_output.rs b/src/ifs/wl_output.rs index 37d626ea..8de498f1 100644 --- a/src/ifs/wl_output.rs +++ b/src/ifs/wl_output.rs @@ -9,7 +9,7 @@ use { zwlr_screencopy_frame_v1::ZwlrScreencopyFrameV1, zxdg_output_v1::ZxdgOutputV1, }, leaks::Tracker, - object::Object, + object::{Object, Version}, rect::Rect, state::{ConnectorData, State}, time::Time, @@ -183,7 +183,7 @@ impl WlOutputGlobal { self: Rc, id: WlOutputId, client: &Rc, - version: u32, + version: Version, ) -> Result<(), WlOutputError> { let obj = Rc::new(WlOutput { global: self.clone(), @@ -328,13 +328,13 @@ pub struct WlOutput { pub id: WlOutputId, pub xdg_outputs: CopyHashMap>, client: Rc, - pub version: u32, + pub version: Version, tracker: Tracker, } -pub const SEND_DONE_SINCE: u32 = 2; -pub const SEND_SCALE_SINCE: u32 = 2; -pub const SEND_NAME_SINCE: u32 = 4; +pub const SEND_DONE_SINCE: Version = Version(2); +pub const SEND_SCALE_SINCE: Version = Version(2); +pub const SEND_NAME_SINCE: Version = Version(4); impl WlOutput { fn send_geometry(&self) { diff --git a/src/ifs/wl_registry.rs b/src/ifs/wl_registry.rs index 698fd95a..de420cd3 100644 --- a/src/ifs/wl_registry.rs +++ b/src/ifs/wl_registry.rs @@ -3,7 +3,7 @@ use { client::Client, globals::{Global, GlobalName, GlobalsError}, leaks::Tracker, - object::{Interface, Object}, + object::{Interface, Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wl_registry::*, WlRegistryId}, }, @@ -62,7 +62,7 @@ impl WlRegistry { actual: bind.version, })); } - global.bind(&self.client, bind.id, bind.version)?; + global.bind(&self.client, bind.id, Version(bind.version))?; Ok(()) } } diff --git a/src/ifs/wl_seat.rs b/src/ifs/wl_seat.rs index 567efb58..6a57be2f 100644 --- a/src/ifs/wl_seat.rs +++ b/src/ifs/wl_seat.rs @@ -45,7 +45,7 @@ use { xdg_toplevel_drag_v1::XdgToplevelDragV1, }, leaks::Tracker, - object::Object, + object::{Object, Version}, rect::Rect, state::State, time::now_usec, @@ -96,7 +96,7 @@ const MISSING_CAPABILITY: u32 = 0; pub const BTN_LEFT: u32 = 0x110; -pub const SEAT_NAME_SINCE: u32 = 2; +pub const SEAT_NAME_SINCE: Version = Version(2); pub const PX_PER_SCROLL: f64 = 15.0; @@ -1040,7 +1040,7 @@ impl WlSeatGlobal { self: Rc, id: WlSeatId, client: &Rc, - version: u32, + version: Version, ) -> Result<(), WlSeatError> { let obj = Rc::new(WlSeat { global: self.clone(), @@ -1124,11 +1124,11 @@ pub struct WlSeat { pointers: CopyHashMap>, relative_pointers: CopyHashMap>, keyboards: CopyHashMap>, - version: u32, + version: Version, tracker: Tracker, } -const READ_ONLY_KEYMAP_SINCE: u32 = 7; +const READ_ONLY_KEYMAP_SINCE: Version = Version(7); impl WlSeat { fn send_capabilities(self: &Rc) { diff --git a/src/ifs/wl_seat/event_handling.rs b/src/ifs/wl_seat/event_handling.rs index 14b27d9e..aab12a45 100644 --- a/src/ifs/wl_seat/event_handling.rs +++ b/src/ifs/wl_seat/event_handling.rs @@ -27,6 +27,7 @@ use { }, wl_surface::{xdg_surface::xdg_popup::XdgPopup, WlSurface}, }, + object::Version, state::DeviceHandlerData, tree::{Direction, FloatNode, Node, ToplevelNode}, utils::{bitflags::BitflagsExt, smallmap::SmallMap}, @@ -431,7 +432,7 @@ impl WlSeatGlobal { self.kb_owner.set_kb_node(self, node); } - fn for_each_seat(&self, ver: u32, client: ClientId, mut f: C) + fn for_each_seat(&self, ver: Version, client: ClientId, mut f: C) where C: FnMut(&Rc), { @@ -445,7 +446,7 @@ impl WlSeatGlobal { } } - fn for_each_pointer(&self, ver: u32, client: ClientId, mut f: C) + fn for_each_pointer(&self, ver: Version, client: ClientId, mut f: C) where C: FnMut(&Rc), { @@ -461,7 +462,7 @@ impl WlSeatGlobal { where C: FnMut(&Rc), { - self.for_each_seat(0, client, |seat| { + self.for_each_seat(Version::ALL, client, |seat| { let pointers = seat.relative_pointers.lock(); for pointer in pointers.values() { f(pointer); @@ -469,7 +470,7 @@ impl WlSeatGlobal { }) } - fn for_each_kb(&self, ver: u32, client: ClientId, mut f: C) + fn for_each_kb(&self, ver: Version, client: ClientId, mut f: C) where C: FnMut(&Rc), { @@ -481,7 +482,7 @@ impl WlSeatGlobal { }) } - pub fn for_each_data_device(&self, ver: u32, client: ClientId, mut f: C) + pub fn for_each_data_device(&self, ver: Version, client: ClientId, mut f: C) where C: FnMut(&Rc), { @@ -495,7 +496,7 @@ impl WlSeatGlobal { } } - pub fn for_each_primary_selection_device(&self, ver: u32, client: ClientId, mut f: C) + pub fn for_each_primary_selection_device(&self, ver: Version, client: ClientId, mut f: C) where C: FnMut(&Rc), { @@ -509,7 +510,7 @@ impl WlSeatGlobal { } } - pub fn for_each_wlr_data_device(&self, ver: u32, mut f: C) + pub fn for_each_wlr_data_device(&self, ver: Version, mut f: C) where C: FnMut(&Rc), { @@ -524,7 +525,7 @@ impl WlSeatGlobal { self.surface_pointer_event(POINTER_FRAME_SINCE_VERSION, surface, |p| p.send_frame()); } - fn surface_pointer_event(&self, ver: u32, surface: &WlSurface, mut f: F) + fn surface_pointer_event(&self, ver: Version, surface: &WlSurface, mut f: F) where F: FnMut(&Rc), { @@ -545,7 +546,7 @@ impl WlSeatGlobal { }); } - fn surface_kb_event(&self, ver: u32, surface: &WlSurface, mut f: F) + fn surface_kb_event(&self, ver: Version, surface: &WlSurface, mut f: F) where F: FnMut(&Rc), { @@ -603,7 +604,9 @@ impl WlSeatGlobal { KeyState::Pressed => (wl_pointer::PRESSED, true), }; let time = (time_usec / 1000) as u32; - self.surface_pointer_event(0, surface, |p| p.send_button(serial, time, button, state)); + self.surface_pointer_event(Version::ALL, surface, |p| { + p.send_button(serial, time, button, state) + }); self.surface_pointer_frame(surface); if pressed { if let Some(node) = surface.get_focus_node(self.id) { @@ -625,7 +628,7 @@ impl WlSeatGlobal { self.surface_pointer_event(since, surface, |p| p.send_axis_source(source)); } let time = (event.time_usec.get() / 1000) as _; - self.for_each_pointer(0, surface.client.id, |p| { + self.for_each_pointer(Version::ALL, surface.client.id, |p| { for i in 0..1 { let axis = i as _; if let Some(delta) = event.v120[i].get() { @@ -666,7 +669,7 @@ impl WlSeatGlobal { } } let time = (self.pos_time_usec.get() / 1000) as u32; - self.surface_pointer_event(0, n, |p| p.send_motion(time, x, y)); + self.surface_pointer_event(Version::ALL, n, |p| p.send_motion(time, x, y)); } self.surface_pointer_frame(n); self.maybe_constrain(n, x, y); @@ -705,7 +708,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); - self.surface_pointer_event(0, n, |p| p.send_enter(serial, n.id, x, y)); + 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 { if constraint.status.get() == SeatConstraintStatus::ActivatableOnFocus { @@ -723,7 +726,7 @@ impl WlSeatGlobal { for (_, constraint) in &n.constraints { constraint.deactivate(); } - self.surface_pointer_event(0, n, |p| p.send_leave(serial, n.id)); + self.surface_pointer_event(Version::ALL, n, |p| p.send_leave(serial, n.id)); self.surface_pointer_frame(n); } } @@ -732,7 +735,7 @@ impl WlSeatGlobal { impl WlSeatGlobal { pub fn unfocus_surface(&self, surface: &WlSurface) { let serial = surface.client.next_serial(); - self.surface_kb_event(0, surface, |k| k.send_leave(serial, surface.id)) + self.surface_kb_event(Version::ALL, surface, |k| k.send_leave(serial, surface.id)) } } @@ -741,7 +744,7 @@ impl WlSeatGlobal { pub fn focus_surface(&self, surface: &WlSurface) { let pressed_keys: Vec<_> = self.pressed_keys.borrow().iter().copied().collect(); let serial = surface.client.next_serial(); - self.surface_kb_event(0, surface, |k| { + self.surface_kb_event(Version::ALL, surface, |k| { k.send_enter(serial, surface.id, &pressed_keys) }); let ModifierState { @@ -752,7 +755,7 @@ impl WlSeatGlobal { .. } = self.kb_state.borrow().mods(); let serial = surface.client.next_serial(); - self.surface_kb_event(0, surface, |k| { + self.surface_kb_event(Version::ALL, surface, |k| { k.send_modifiers(serial, mods_depressed, mods_latched, mods_locked, group) }); @@ -774,7 +777,9 @@ impl WlSeatGlobal { pub fn key_surface(&self, surface: &WlSurface, time_usec: u64, key: u32, state: u32) { let serial = surface.client.next_serial(); let time = (time_usec / 1000) as _; - self.surface_kb_event(0, surface, |k| k.send_key(serial, time, key, state)); + self.surface_kb_event(Version::ALL, surface, |k| { + k.send_key(serial, time, key, state) + }); } } @@ -782,7 +787,7 @@ impl WlSeatGlobal { impl WlSeatGlobal { pub fn mods_surface(&self, surface: &WlSurface, mods: ModifierState) { let serial = surface.client.next_serial(); - self.surface_kb_event(0, surface, |k| { + self.surface_kb_event(Version::ALL, surface, |k| { k.send_modifiers( serial, mods.mods_depressed, @@ -798,7 +803,7 @@ impl WlSeatGlobal { impl WlSeatGlobal { pub fn dnd_surface_leave(&self, surface: &WlSurface, dnd: &Dnd) { if dnd.src.is_some() || surface.client.id == dnd.client.id { - self.for_each_data_device(0, surface.client.id, |dd| { + self.for_each_data_device(Version::ALL, surface.client.id, |dd| { dd.send_leave(); }) } @@ -810,7 +815,7 @@ impl WlSeatGlobal { pub fn dnd_surface_drop(&self, surface: &WlSurface, dnd: &Dnd) { if dnd.src.is_some() || surface.client.id == dnd.client.id { - self.for_each_data_device(0, surface.client.id, |dd| { + self.for_each_data_device(Version::ALL, surface.client.id, |dd| { dd.send_drop(); }) } @@ -834,7 +839,7 @@ impl WlSeatGlobal { offer.send_source_actions(); }) } else if surface.client.id == dnd.client.id { - self.for_each_data_device(0, dnd.client.id, |dd| { + self.for_each_data_device(Version::ALL, dnd.client.id, |dd| { dd.send_enter(surface.id, x, y, WlDataOfferId::NONE, serial); }) } @@ -850,7 +855,7 @@ impl WlSeatGlobal { y: Fixed, ) { if dnd.src.is_some() || surface.client.id == dnd.client.id { - self.for_each_data_device(0, surface.client.id, |dd| { + self.for_each_data_device(Version::ALL, surface.client.id, |dd| { dd.send_motion(time_usec, x, y); }) } diff --git a/src/ifs/wl_seat/wl_keyboard.rs b/src/ifs/wl_seat/wl_keyboard.rs index 8987bead..2ad5da7c 100644 --- a/src/ifs/wl_seat/wl_keyboard.rs +++ b/src/ifs/wl_seat/wl_keyboard.rs @@ -3,7 +3,7 @@ use { client::ClientError, ifs::wl_seat::WlSeat, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::{ buffd::{MsgParser, MsgParserError}, oserror::OsError, @@ -15,7 +15,7 @@ use { uapi::OwnedFd, }; -pub const REPEAT_INFO_SINCE: u32 = 4; +pub const REPEAT_INFO_SINCE: Version = Version(4); #[allow(dead_code)] const NO_KEYMAP: u32 = 0; diff --git a/src/ifs/wl_seat/wl_pointer.rs b/src/ifs/wl_seat/wl_pointer.rs index e596777f..ba070244 100644 --- a/src/ifs/wl_seat/wl_pointer.rs +++ b/src/ifs/wl_seat/wl_pointer.rs @@ -5,7 +5,7 @@ use { fixed::Fixed, ifs::{wl_seat::WlSeat, wl_surface::WlSurfaceError}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wl_pointer::*, WlPointerId, WlSurfaceId}, }, @@ -31,13 +31,13 @@ pub const WHEEL_TILT: u32 = 3; pub const IDENTICAL: u32 = 0; pub const INVERTED: u32 = 1; -pub const POINTER_FRAME_SINCE_VERSION: u32 = 5; -pub const AXIS_SOURCE_SINCE_VERSION: u32 = 5; -pub const AXIS_DISCRETE_SINCE_VERSION: u32 = 5; -pub const AXIS_STOP_SINCE_VERSION: u32 = 5; -pub const WHEEL_TILT_SINCE_VERSION: u32 = 6; -pub const AXIS_VALUE120_SINCE_VERSION: u32 = 8; -pub const AXIS_RELATIVE_DIRECTION_SINCE_VERSION: u32 = 9; +pub const POINTER_FRAME_SINCE_VERSION: Version = Version(5); +pub const AXIS_SOURCE_SINCE_VERSION: Version = Version(5); +pub const AXIS_DISCRETE_SINCE_VERSION: Version = Version(5); +pub const AXIS_STOP_SINCE_VERSION: Version = Version(5); +pub const WHEEL_TILT_SINCE_VERSION: Version = Version(6); +pub const AXIS_VALUE120_SINCE_VERSION: Version = Version(8); +pub const AXIS_RELATIVE_DIRECTION_SINCE_VERSION: Version = Version(9); #[derive(Default, Debug)] pub struct PendingScroll { diff --git a/src/ifs/wl_seat/zwp_pointer_constraints_v1.rs b/src/ifs/wl_seat/zwp_pointer_constraints_v1.rs index 1062d55a..e0fd8401 100644 --- a/src/ifs/wl_seat/zwp_pointer_constraints_v1.rs +++ b/src/ifs/wl_seat/zwp_pointer_constraints_v1.rs @@ -11,7 +11,7 @@ use { wl_surface::WlSurface, }, leaks::Tracker, - object::Object, + object::{Object, Version}, rect::Region, utils::{ buffd::{MsgParser, MsgParserError}, @@ -154,7 +154,7 @@ impl ZwpPointerConstraintsV1Global { self: Rc, id: ZwpPointerConstraintsV1Id, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), ZwpPointerConstraintsV1Error> { let cs = Rc::new(ZwpPointerConstraintsV1 { id, diff --git a/src/ifs/wl_seat/zwp_relative_pointer_manager_v1.rs b/src/ifs/wl_seat/zwp_relative_pointer_manager_v1.rs index 035f3ae1..bb262bc0 100644 --- a/src/ifs/wl_seat/zwp_relative_pointer_manager_v1.rs +++ b/src/ifs/wl_seat/zwp_relative_pointer_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::wl_seat::zwp_relative_pointer_v1::ZwpRelativePointerV1, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{zwp_relative_pointer_manager_v1::*, ZwpRelativePointerManagerV1Id}, }, @@ -31,7 +31,7 @@ impl ZwpRelativePointerManagerV1Global { self: Rc, id: ZwpRelativePointerManagerV1Id, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), ZwpRelativePointerManagerV1Error> { let obj = Rc::new(ZwpRelativePointerManagerV1 { id, diff --git a/src/ifs/wl_shm.rs b/src/ifs/wl_shm.rs index 6ce90572..cdcf5206 100644 --- a/src/ifs/wl_shm.rs +++ b/src/ifs/wl_shm.rs @@ -5,7 +5,7 @@ use { globals::{Global, GlobalName}, ifs::wl_shm_pool::{WlShmPool, WlShmPoolError}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wl_shm::*, WlShmId}, }, @@ -21,7 +21,7 @@ pub struct WlShm { _global: Rc, id: WlShmId, client: Rc, - version: u32, + version: Version, pub tracker: Tracker, } @@ -34,7 +34,7 @@ impl WlShmGlobal { self: Rc, id: WlShmId, client: &Rc, - version: u32, + version: Version, ) -> Result<(), WlShmError> { let obj = Rc::new(WlShm { _global: self, diff --git a/src/ifs/wl_subcompositor.rs b/src/ifs/wl_subcompositor.rs index 034e9257..01e477d6 100644 --- a/src/ifs/wl_subcompositor.rs +++ b/src/ifs/wl_subcompositor.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::wl_surface::wl_subsurface::{WlSubsurface, WlSubsurfaceError}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wl_subcompositor::*, WlSubcompositorId}, }, @@ -34,7 +34,7 @@ impl WlSubcompositorGlobal { self: Rc, id: WlSubcompositorId, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), WlSubcompositorError> { let obj = Rc::new(WlSubcompositor { id, diff --git a/src/ifs/wl_surface.rs b/src/ifs/wl_surface.rs index c96e8cab..32191bbf 100644 --- a/src/ifs/wl_surface.rs +++ b/src/ifs/wl_surface.rs @@ -43,7 +43,7 @@ use { zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1, }, leaks::Tracker, - object::Object, + object::{Object, Version}, rect::{Rect, Region}, renderer::Renderer, tree::{ @@ -94,9 +94,9 @@ const INVALID_TRANSFORM: u32 = 1; #[allow(dead_code)] const INVALID_SIZE: u32 = 2; -const OFFSET_SINCE: u32 = 5; -const BUFFER_SCALE_SINCE: u32 = 6; -const TRANSFORM_SINCE: u32 = 6; +const OFFSET_SINCE: Version = Version(5); +const BUFFER_SCALE_SINCE: Version = Version(6); +const TRANSFORM_SINCE: Version = Version(6); #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum SurfaceRole { @@ -244,7 +244,7 @@ pub struct WlSurface { xwayland_serial: Cell>, tearing_control: CloneCell>>, tearing: Cell, - version: u32, + version: Version, pub has_content_type_manager: Cell, pub content_type: Cell>, pub drm_feedback: CopyHashMap>, @@ -485,7 +485,7 @@ pub struct StackElement { } impl WlSurface { - pub fn new(id: WlSurfaceId, client: &Rc, version: u32) -> Self { + pub fn new(id: WlSurfaceId, client: &Rc, version: Version) -> Self { Self { id, node_id: client.state.node_ids.next(), diff --git a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs index f8909b09..7feafa51 100644 --- a/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs +++ b/src/ifs/wl_surface/xdg_surface/xdg_toplevel.rs @@ -15,7 +15,7 @@ use { xdg_toplevel_drag_v1::XdgToplevelDragV1, }, leaks::Tracker, - object::Object, + object::{Object, Version}, rect::Rect, renderer::Renderer, state::State, @@ -74,8 +74,8 @@ const CAP_FULLSCREEN: u32 = 3; #[allow(dead_code)] const CAP_MINIMIZE: u32 = 4; -pub const WM_CAPABILITIES_SINCE: u32 = 5; -pub const SUSPENDED_SINCE: u32 = 6; +pub const WM_CAPABILITIES_SINCE: Version = Version(5); +pub const SUSPENDED_SINCE: Version = Version(6); #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum Decoration { diff --git a/src/ifs/wl_surface/xwayland_shell_v1.rs b/src/ifs/wl_surface/xwayland_shell_v1.rs index b54fa421..a749d816 100644 --- a/src/ifs/wl_surface/xwayland_shell_v1.rs +++ b/src/ifs/wl_surface/xwayland_shell_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::wl_surface::{x_surface::xwayland_surface_v1::XwaylandSurfaceV1, WlSurfaceError}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{xwayland_shell_v1::*, WlSurfaceId, XwaylandShellV1Id}, }, @@ -19,7 +19,7 @@ pub struct XwaylandShellV1Global { pub struct XwaylandShellV1 { id: XwaylandShellV1Id, client: Rc, - pub version: u32, + pub version: Version, pub tracker: Tracker, } @@ -32,7 +32,7 @@ impl XwaylandShellV1Global { self: Rc, id: XwaylandShellV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), XwaylandShellV1Error> { let obj = Rc::new(XwaylandShellV1 { id, diff --git a/src/ifs/wp_content_type_manager_v1.rs b/src/ifs/wp_content_type_manager_v1.rs index bca1ddf8..54516b23 100644 --- a/src/ifs/wp_content_type_manager_v1.rs +++ b/src/ifs/wp_content_type_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::wp_content_type_v1::WpContentTypeV1, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wp_content_type_manager_v1::*, WpContentTypeManagerV1Id}, }, @@ -25,7 +25,7 @@ impl WpContentTypeManagerV1Global { self: Rc, id: WpContentTypeManagerV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), WpContentTypeManagerV1Error> { let mgr = Rc::new(WpContentTypeManagerV1 { id, @@ -61,7 +61,7 @@ pub struct WpContentTypeManagerV1 { pub id: WpContentTypeManagerV1Id, pub client: Rc, pub tracker: Tracker, - pub version: u32, + pub version: Version, } impl WpContentTypeManagerV1 { diff --git a/src/ifs/wp_cursor_shape_manager_v1.rs b/src/ifs/wp_cursor_shape_manager_v1.rs index edc034d0..4a0d9be1 100644 --- a/src/ifs/wp_cursor_shape_manager_v1.rs +++ b/src/ifs/wp_cursor_shape_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::wp_cursor_shape_device_v1::WpCursorShapeDeviceV1, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wp_cursor_shape_manager_v1::*, WpCursorShapeManagerV1Id}, }, @@ -25,7 +25,7 @@ impl WpCursorShapeManagerV1Global { self: Rc, id: WpCursorShapeManagerV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), WpCursorShapeManagerV1Error> { let mgr = Rc::new(WpCursorShapeManagerV1 { id, @@ -61,7 +61,7 @@ pub struct WpCursorShapeManagerV1 { pub id: WpCursorShapeManagerV1Id, pub client: Rc, pub tracker: Tracker, - pub version: u32, + pub version: Version, } impl WpCursorShapeManagerV1 { diff --git a/src/ifs/wp_fractional_scale_manager_v1.rs b/src/ifs/wp_fractional_scale_manager_v1.rs index 4f3c4a19..f8a533d9 100644 --- a/src/ifs/wp_fractional_scale_manager_v1.rs +++ b/src/ifs/wp_fractional_scale_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::wl_surface::wp_fractional_scale_v1::{WpFractionalScaleError, WpFractionalScaleV1}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wp_fractional_scale_manager_v1::*, WpFractionalScaleManagerV1Id}, }, @@ -31,7 +31,7 @@ impl WpFractionalScaleManagerV1Global { self: Rc, id: WpFractionalScaleManagerV1Id, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), WpFractionalScaleManagerError> { let obj = Rc::new(WpFractionalScaleManagerV1 { id, diff --git a/src/ifs/wp_linux_drm_syncobj_manager_v1.rs b/src/ifs/wp_linux_drm_syncobj_manager_v1.rs index f31cdb7b..9a40dce2 100644 --- a/src/ifs/wp_linux_drm_syncobj_manager_v1.rs +++ b/src/ifs/wp_linux_drm_syncobj_manager_v1.rs @@ -9,7 +9,7 @@ use { wp_linux_drm_syncobj_timeline_v1::WpLinuxDrmSyncobjTimelineV1, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, video::drm::sync_obj::SyncObj, wire::{wp_linux_drm_syncobj_manager_v1::*, WpLinuxDrmSyncobjManagerV1Id}, @@ -37,7 +37,7 @@ impl WpLinuxDrmSyncobjManagerV1Global { self: Rc, id: WpLinuxDrmSyncobjManagerV1Id, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), WpLinuxDrmSyncobjManagerV1Error> { let obj = Rc::new(WpLinuxDrmSyncobjManagerV1 { id, diff --git a/src/ifs/wp_presentation.rs b/src/ifs/wp_presentation.rs index f9cc4768..684bc018 100644 --- a/src/ifs/wp_presentation.rs +++ b/src/ifs/wp_presentation.rs @@ -5,7 +5,7 @@ use { globals::{Global, GlobalName}, ifs::wp_presentation_feedback::WpPresentationFeedback, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, }, std::rc::Rc, @@ -26,7 +26,7 @@ impl WpPresentationGlobal { self: Rc, id: WpPresentationId, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), WpPresentationError> { let obj = Rc::new(WpPresentation { id, diff --git a/src/ifs/wp_single_pixel_buffer_manager_v1.rs b/src/ifs/wp_single_pixel_buffer_manager_v1.rs index 5b71518e..38827bc1 100644 --- a/src/ifs/wp_single_pixel_buffer_manager_v1.rs +++ b/src/ifs/wp_single_pixel_buffer_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::wl_buffer::WlBuffer, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wp_single_pixel_buffer_manager_v1::*, WpSinglePixelBufferManagerV1Id}, }, @@ -25,7 +25,7 @@ impl WpSinglePixelBufferManagerV1Global { self: Rc, id: WpSinglePixelBufferManagerV1Id, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), WpSinglePixelBufferManagerV1Error> { let obj = Rc::new(WpSinglePixelBufferManagerV1 { id, diff --git a/src/ifs/wp_tearing_control_manager_v1.rs b/src/ifs/wp_tearing_control_manager_v1.rs index b150d815..4ea50aac 100644 --- a/src/ifs/wp_tearing_control_manager_v1.rs +++ b/src/ifs/wp_tearing_control_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::wl_surface::wp_tearing_control_v1::{WpTearingControlV1, WpTearingControlV1Error}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{ wp_tearing_control_manager_v1::{GET_TEARING_CONTROL, *}, @@ -28,7 +28,7 @@ impl WpTearingControlManagerV1Global { self: Rc, id: WpTearingControlManagerV1Id, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), WpTearingControlManagerV1Error> { let obj = Rc::new(WpTearingControlManagerV1 { id, diff --git a/src/ifs/wp_viewporter.rs b/src/ifs/wp_viewporter.rs index 69c76c4f..f919999b 100644 --- a/src/ifs/wp_viewporter.rs +++ b/src/ifs/wp_viewporter.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::wl_surface::wp_viewport::{WpViewport, WpViewportError}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{wp_viewporter::*, WpViewporterId}, }, @@ -25,7 +25,7 @@ impl WpViewporterGlobal { self: Rc, id: WpViewporterId, client: &Rc, - _version: u32, + _version: Version, ) -> Result<(), WpViewporterError> { let obj = Rc::new(WpViewporter { id, diff --git a/src/ifs/xdg_activation_v1.rs b/src/ifs/xdg_activation_v1.rs index 068b291c..78b44f1c 100644 --- a/src/ifs/xdg_activation_v1.rs +++ b/src/ifs/xdg_activation_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::xdg_activation_token_v1::XdgActivationTokenV1, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::{ activation_token::ActivationToken, buffd::{MsgParser, MsgParserError}, @@ -29,7 +29,7 @@ impl XdgActivationV1Global { self: Rc, id: XdgActivationV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), XdgActivationV1Error> { let mgr = Rc::new(XdgActivationV1 { id, @@ -61,7 +61,7 @@ pub struct XdgActivationV1 { pub id: XdgActivationV1Id, pub client: Rc, pub tracker: Tracker, - pub version: u32, + pub version: Version, } impl XdgActivationV1 { diff --git a/src/ifs/xdg_toplevel_drag_manager_v1.rs b/src/ifs/xdg_toplevel_drag_manager_v1.rs index 7ffb5b0d..4a1378ce 100644 --- a/src/ifs/xdg_toplevel_drag_manager_v1.rs +++ b/src/ifs/xdg_toplevel_drag_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::xdg_toplevel_drag_v1::XdgToplevelDragV1, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{xdg_toplevel_drag_manager_v1::*, XdgToplevelDragManagerV1Id}, }, @@ -25,7 +25,7 @@ impl XdgToplevelDragManagerV1Global { self: Rc, id: XdgToplevelDragManagerV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), XdgToplevelDragManagerV1Error> { let mgr = Rc::new(XdgToplevelDragManagerV1 { id, @@ -61,7 +61,7 @@ pub struct XdgToplevelDragManagerV1 { pub id: XdgToplevelDragManagerV1Id, pub client: Rc, pub tracker: Tracker, - pub version: u32, + pub version: Version, } impl XdgToplevelDragManagerV1 { diff --git a/src/ifs/xdg_wm_base.rs b/src/ifs/xdg_wm_base.rs index e9e40486..4f438b6b 100644 --- a/src/ifs/xdg_wm_base.rs +++ b/src/ifs/xdg_wm_base.rs @@ -7,7 +7,7 @@ use { xdg_positioner::XdgPositioner, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::{ buffd::{MsgParser, MsgParserError}, copyhashmap::CopyHashMap, @@ -37,7 +37,7 @@ pub struct XdgWmBaseGlobal { pub struct XdgWmBase { id: XdgWmBaseId, client: Rc, - pub version: u32, + pub version: Version, pub(super) surfaces: CopyHashMap>, pub tracker: Tracker, } @@ -51,7 +51,7 @@ impl XdgWmBaseGlobal { self: Rc, id: XdgWmBaseId, client: &Rc, - version: u32, + version: Version, ) -> Result<(), XdgWmBaseError> { let obj = Rc::new(XdgWmBase { id, diff --git a/src/ifs/zwlr_layer_shell_v1.rs b/src/ifs/zwlr_layer_shell_v1.rs index 2aae59f8..c8da33e5 100644 --- a/src/ifs/zwlr_layer_shell_v1.rs +++ b/src/ifs/zwlr_layer_shell_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::wl_surface::zwlr_layer_surface_v1::{ZwlrLayerSurfaceV1, ZwlrLayerSurfaceV1Error}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{zwlr_layer_shell_v1::*, ZwlrLayerShellV1Id}, }, @@ -24,7 +24,7 @@ pub struct ZwlrLayerShellV1Global { pub struct ZwlrLayerShellV1 { pub id: ZwlrLayerShellV1Id, pub client: Rc, - pub version: u32, + pub version: Version, pub tracker: Tracker, } @@ -37,7 +37,7 @@ impl ZwlrLayerShellV1Global { self: Rc, id: ZwlrLayerShellV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), ZwlrLayerShellV1Error> { let obj = Rc::new(ZwlrLayerShellV1 { id, diff --git a/src/ifs/zwlr_screencopy_frame_v1.rs b/src/ifs/zwlr_screencopy_frame_v1.rs index 92a639fd..022cdd08 100644 --- a/src/ifs/zwlr_screencopy_frame_v1.rs +++ b/src/ifs/zwlr_screencopy_frame_v1.rs @@ -7,7 +7,7 @@ use { wl_output::WlOutputGlobal, }, leaks::Tracker, - object::Object, + object::{Object, Version}, rect::Rect, utils::{ buffd::{MsgParser, MsgParserError}, @@ -33,7 +33,7 @@ pub struct ZwlrScreencopyFrameV1 { pub with_damage: Cell, pub output_link: Cell>>>, pub buffer: Cell>>, - pub version: u32, + pub version: Version, } impl ZwlrScreencopyFrameV1 { diff --git a/src/ifs/zwlr_screencopy_manager_v1.rs b/src/ifs/zwlr_screencopy_manager_v1.rs index 1003e629..036bcc18 100644 --- a/src/ifs/zwlr_screencopy_manager_v1.rs +++ b/src/ifs/zwlr_screencopy_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::zwlr_screencopy_frame_v1::ZwlrScreencopyFrameV1, leaks::Tracker, - object::Object, + object::{Object, Version}, rect::Rect, utils::buffd::{MsgParser, MsgParserError}, wire::{ @@ -29,7 +29,7 @@ impl ZwlrScreencopyManagerV1Global { self: Rc, id: ZwlrScreencopyManagerV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), ZwlrScreencopyManagerV1Error> { let mgr = Rc::new(ZwlrScreencopyManagerV1 { id, @@ -69,7 +69,7 @@ pub struct ZwlrScreencopyManagerV1 { pub id: ZwlrScreencopyManagerV1Id, pub client: Rc, pub tracker: Tracker, - pub version: u32, + pub version: Version, } impl ZwlrScreencopyManagerV1 { diff --git a/src/ifs/zwp_idle_inhibit_manager_v1.rs b/src/ifs/zwp_idle_inhibit_manager_v1.rs index 85ec928e..62801b06 100644 --- a/src/ifs/zwp_idle_inhibit_manager_v1.rs +++ b/src/ifs/zwp_idle_inhibit_manager_v1.rs @@ -7,7 +7,7 @@ use { zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Error, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{zwp_idle_inhibit_manager_v1::*, ZwpIdleInhibitManagerV1Id}, }, @@ -28,7 +28,7 @@ impl ZwpIdleInhibitManagerV1Global { self: Rc, id: ZwpIdleInhibitManagerV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), ZxdgDecorationManagerV1Error> { let obj = Rc::new(ZwpIdleInhibitManagerV1 { id, @@ -63,7 +63,7 @@ simple_add_global!(ZwpIdleInhibitManagerV1Global); pub struct ZwpIdleInhibitManagerV1 { pub id: ZwpIdleInhibitManagerV1Id, pub client: Rc, - pub _version: u32, + pub _version: Version, pub tracker: Tracker, } diff --git a/src/ifs/zwp_linux_dmabuf_v1.rs b/src/ifs/zwp_linux_dmabuf_v1.rs index bd53f35c..a0febff3 100644 --- a/src/ifs/zwp_linux_dmabuf_v1.rs +++ b/src/ifs/zwp_linux_dmabuf_v1.rs @@ -7,7 +7,7 @@ use { zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1, }, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{zwp_linux_dmabuf_v1::*, ZwpLinuxDmabufFeedbackV1Id, ZwpLinuxDmabufV1Id}, }, @@ -28,7 +28,7 @@ impl ZwpLinuxDmabufV1Global { self: Rc, id: ZwpLinuxDmabufV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), ZwpLinuxDmabufV1Error> { let obj = Rc::new(ZwpLinuxDmabufV1 { id, @@ -55,8 +55,8 @@ impl ZwpLinuxDmabufV1Global { } } -const MODIFIERS_SINCE_VERSION: u32 = 3; -const FEEDBACK_SINCE_VERSION: u32 = 4; +const MODIFIERS_SINCE_VERSION: Version = Version(3); +const FEEDBACK_SINCE_VERSION: Version = Version(4); global_base!( ZwpLinuxDmabufV1Global, @@ -79,7 +79,7 @@ simple_add_global!(ZwpLinuxDmabufV1Global); pub struct ZwpLinuxDmabufV1 { id: ZwpLinuxDmabufV1Id, pub client: Rc, - pub version: u32, + pub version: Version, pub tracker: Tracker, } @@ -161,8 +161,8 @@ object_base! { DESTROY => destroy, CREATE_PARAMS => create_params, - GET_DEFAULT_FEEDBACK => get_default_feedback if self.version >= 4, - GET_SURFACE_FEEDBACK => get_surface_feedback if self.version >= 4, + GET_DEFAULT_FEEDBACK => get_default_feedback if self.version.0 >= 4, + GET_SURFACE_FEEDBACK => get_surface_feedback if self.version.0 >= 4, } impl Object for ZwpLinuxDmabufV1 {} diff --git a/src/ifs/zxdg_decoration_manager_v1.rs b/src/ifs/zxdg_decoration_manager_v1.rs index 6cd227f8..fdd4d894 100644 --- a/src/ifs/zxdg_decoration_manager_v1.rs +++ b/src/ifs/zxdg_decoration_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{zxdg_decoration_manager_v1::*, ZxdgDecorationManagerV1Id}, }, @@ -25,7 +25,7 @@ impl ZxdgDecorationManagerV1Global { self: Rc, id: ZxdgDecorationManagerV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), ZxdgDecorationManagerV1Error> { let obj = Rc::new(ZxdgDecorationManagerV1 { id, @@ -60,7 +60,7 @@ simple_add_global!(ZxdgDecorationManagerV1Global); pub struct ZxdgDecorationManagerV1 { id: ZxdgDecorationManagerV1Id, client: Rc, - _version: u32, + _version: Version, tracker: Tracker, } diff --git a/src/ifs/zxdg_output_manager_v1.rs b/src/ifs/zxdg_output_manager_v1.rs index 06654ed7..a218d62e 100644 --- a/src/ifs/zxdg_output_manager_v1.rs +++ b/src/ifs/zxdg_output_manager_v1.rs @@ -4,7 +4,7 @@ use { globals::{Global, GlobalName}, ifs::zxdg_output_v1::ZxdgOutputV1, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{zxdg_output_manager_v1::*, ZxdgOutputManagerV1Id}, }, @@ -19,7 +19,7 @@ pub struct ZxdgOutputManagerV1Global { pub struct ZxdgOutputManagerV1 { pub id: ZxdgOutputManagerV1Id, pub client: Rc, - pub version: u32, + pub version: Version, pub tracker: Tracker, } @@ -32,7 +32,7 @@ impl ZxdgOutputManagerV1Global { self: Rc, id: ZxdgOutputManagerV1Id, client: &Rc, - version: u32, + version: Version, ) -> Result<(), ZxdgOutputManagerV1Error> { let obj = Rc::new(ZxdgOutputManagerV1 { id, diff --git a/src/ifs/zxdg_output_v1.rs b/src/ifs/zxdg_output_v1.rs index 58b4c8b7..97606c55 100644 --- a/src/ifs/zxdg_output_v1.rs +++ b/src/ifs/zxdg_output_v1.rs @@ -3,7 +3,7 @@ use { client::{Client, ClientError}, ifs::wl_output::{WlOutput, SEND_DONE_SINCE}, leaks::Tracker, - object::Object, + object::{Object, Version}, utils::buffd::{MsgParser, MsgParserError}, wire::{zxdg_output_v1::*, ZxdgOutputV1Id}, }, @@ -11,14 +11,14 @@ use { thiserror::Error, }; -pub const NAME_SINCE: u32 = 2; +pub const NAME_SINCE: Version = Version(2); #[allow(dead_code)] -pub const DESCRIPTION_SINCE: u32 = 2; -pub const NO_DONE_SINCE: u32 = 3; +pub const DESCRIPTION_SINCE: Version = Version(2); +pub const NO_DONE_SINCE: Version = Version(3); pub struct ZxdgOutputV1 { pub id: ZxdgOutputV1Id, - pub version: u32, + pub version: Version, pub client: Rc, pub output: Rc, pub tracker: Tracker, diff --git a/src/macros.rs b/src/macros.rs index f570d831..ebd28cd3 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -104,7 +104,7 @@ macro_rules! global_base { self: std::rc::Rc, client: &'a std::rc::Rc, id: crate::object::ObjectId, - version: u32, + version: crate::object::Version, ) -> Result<(), crate::globals::GlobalsError> { if let Err(e) = self.bind_(id.into(), client, version) { return Err(crate::globals::GlobalsError::GlobalError(e.into())); diff --git a/src/object.rs b/src/object.rs index 0aa0938c..21a827e3 100644 --- a/src/object.rs +++ b/src/object.rs @@ -2,6 +2,7 @@ use { crate::{client::ClientError, utils::buffd::MsgParser, wire::WlDisplayId}, std::{ any::Any, + cmp::Ordering, fmt::{Display, Formatter}, rc::Rc, }, @@ -54,3 +55,22 @@ impl Interface { self.0 } } + +#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] +pub struct Version(pub u32); + +impl Version { + pub const ALL: Version = Version(0); +} + +impl PartialEq for Version { + fn eq(&self, other: &u32) -> bool { + self.0 == *other + } +} + +impl PartialOrd for Version { + fn partial_cmp(&self, other: &u32) -> Option { + self.0.partial_cmp(other) + } +}