Skip to content

Commit

Permalink
Add set_without_clear function (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
complexspaces committed Oct 21, 2021
1 parent de5c273 commit 907a1b1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/raw.rs
Expand Up @@ -259,8 +259,18 @@ pub fn get_vec(format: u32, out: &mut alloc::vec::Vec<u8>) -> SysResult<usize> {
Ok(result)
}

///Copies raw bytes onto clipboard with specified `format`, returning whether it was successful.
/// Copies raw bytes onto clipboard with specified `format`, returning whether it was successful.
///
/// This function empties the clipboard before setting the data.
pub fn set(format: u32, data: &[u8]) -> SysResult<()> {
let _ = empty();
set_without_clear(format, data)
}

/// Copies raw bytes onto the clipboard with the specified `format`, returning whether it was successful.
///
/// This function does not empty the clipboard before setting the data.
pub fn set_without_clear(format: u32, data: &[u8]) -> SysResult<()> {
let size = data.len();
debug_assert!(size > 0);

Expand All @@ -271,8 +281,6 @@ pub fn set(format: u32, data: &[u8]) -> SysResult<()> {
unsafe { ptr::copy_nonoverlapping(data.as_ptr(), ptr.as_ptr() as _, size) };
}

let _ = empty();

if unsafe { !SetClipboardData(format, mem.get()).is_null() } {
//SetClipboardData takes ownership
mem.release();
Expand Down

0 comments on commit 907a1b1

Please sign in to comment.