<NME> mod.rs
<BEF> //! Protocol-related utilities
//!
//! This module contains several handlers to manage the Wayland protocol
//! and the clients.
//!
//! ## General structure
//!
//! Most utilities provided in this module work in the same way:
//!
//! - A module specific `*State` struct will take the wayland display as argument and
//!   insert one or more globals into it through its constructor.
//!   destroy the global at all, you don't need to bother keeping the
//!   `Global` around.

pub mod compositor;
pub mod output;
pub mod seat;
pub mod shell;
pub mod shm;
pub mod keyboard_shortcuts_inhibit;
pub mod output;
pub mod primary_selection;
pub mod seat;
pub mod shell;
pub mod shm;
pub mod socket;
pub mod tablet_manager;
pub mod text_input;
pub mod viewporter;
pub mod virtual_keyboard;
pub mod xdg_activation;

<MSG> wayland: global counter for client serials

<DFF> @@ -12,8 +12,41 @@
 //!   destroy the global at all, you don't need to bother keeping the
 //!   `Global` around.
 
+use std::sync::Mutex;
+
 pub mod compositor;
 pub mod output;
 pub mod seat;
 pub mod shell;
 pub mod shm;
+
+lazy_static! {
+    /// A global SerialCounter for use in your compositor.
+    ///
+    /// Is is also used internally by some parts of Smithay.
+    pub static ref SERIAL_COUNTER: SerialCounter = SerialCounter {
+        serial: Mutex::new(0)
+    };
+}
+
+/// A counter for generating serials, for use in the client protocol
+///
+/// A global instance of this counter is available as the `SERIAL_COUNTER`
+/// static. It is recommended to only use this global counter to ensure the
+/// uniqueness of serials.
+///
+/// The counter will wrap around on overflow, ensuring it can run for as long
+/// as needed.
+pub struct SerialCounter {
+    // TODO: replace with an AtomicU32 when stabilized
+    serial: Mutex<u32>,
+}
+
+impl SerialCounter {
+    /// Retrieve the next serial from the counter
+    pub fn next_serial(&self) -> u32 {
+        let guard = self.serial.lock().unwrap();
+        guard.wrapping_add(1);
+        *guard
+    }
+}

wayland: global counter for client serials