Sync with server to get seat name
This commit is contained in:
parent
f84c9be419
commit
4eecc726c0
1 changed files with 19 additions and 33 deletions
52
src/lib.rs
52
src/lib.rs
|
|
@ -33,8 +33,8 @@ use sctk::wayland_client::sys::client::wl_display;
|
||||||
type SeatMap = HashMap<String, (Arc<Mutex<DataDevice>>, u32)>;
|
type SeatMap = HashMap<String, (Arc<Mutex<DataDevice>>, u32)>;
|
||||||
|
|
||||||
enum WaylandRequest {
|
enum WaylandRequest {
|
||||||
Store(String, String),
|
Store(Option<String>, String),
|
||||||
Load(String),
|
Load(Option<String>),
|
||||||
Kill,
|
Kill,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +42,6 @@ enum WaylandRequest {
|
||||||
pub struct WaylandClipboard {
|
pub struct WaylandClipboard {
|
||||||
request_send: mpsc::Sender<WaylandRequest>,
|
request_send: mpsc::Sender<WaylandRequest>,
|
||||||
load_recv: mpsc::Receiver<String>,
|
load_recv: mpsc::Receiver<String>,
|
||||||
last_seat_name: Arc<Mutex<String>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for WaylandClipboard {
|
impl Drop for WaylandClipboard {
|
||||||
|
|
@ -60,28 +59,19 @@ impl WaylandClipboard {
|
||||||
let (request_send, request_recv) = mpsc::channel::<WaylandRequest>();
|
let (request_send, request_recv) = mpsc::channel::<WaylandRequest>();
|
||||||
let (load_send, load_recv) = mpsc::channel();
|
let (load_send, load_recv) = mpsc::channel();
|
||||||
let display = display.clone();
|
let display = display.clone();
|
||||||
let last_seat_name = Arc::new(Mutex::new(String::new()));
|
|
||||||
|
|
||||||
let last_seat_name_clone = last_seat_name.clone();
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let mut event_queue = display.create_event_queue();
|
let mut event_queue = display.create_event_queue();
|
||||||
let display = (*display)
|
let display = (*display)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.make_wrapper(&event_queue.get_token())
|
.make_wrapper(&event_queue.get_token())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Self::clipboard_thread(
|
Self::clipboard_thread(&display, &mut event_queue, request_recv, load_send);
|
||||||
&display,
|
|
||||||
&mut event_queue,
|
|
||||||
request_recv,
|
|
||||||
load_send,
|
|
||||||
last_seat_name_clone,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
WaylandClipboard {
|
WaylandClipboard {
|
||||||
request_send,
|
request_send,
|
||||||
load_recv,
|
load_recv,
|
||||||
last_seat_name,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,24 +83,15 @@ impl WaylandClipboard {
|
||||||
let (request_send, request_recv) = mpsc::channel::<WaylandRequest>();
|
let (request_send, request_recv) = mpsc::channel::<WaylandRequest>();
|
||||||
let (load_send, load_recv) = mpsc::channel();
|
let (load_send, load_recv) = mpsc::channel();
|
||||||
let display = display_ptr.as_mut().unwrap();
|
let display = display_ptr.as_mut().unwrap();
|
||||||
let last_seat_name = Arc::new(Mutex::new(String::new()));
|
|
||||||
|
|
||||||
let last_seat_name_clone = last_seat_name.clone();
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let (display, mut event_queue) = Display::from_external_display(display);
|
let (display, mut event_queue) = Display::from_external_display(display);
|
||||||
Self::clipboard_thread(
|
Self::clipboard_thread(&display, &mut event_queue, request_recv, load_send);
|
||||||
&display,
|
|
||||||
&mut event_queue,
|
|
||||||
request_recv,
|
|
||||||
load_send,
|
|
||||||
last_seat_name_clone,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
WaylandClipboard {
|
WaylandClipboard {
|
||||||
request_send,
|
request_send,
|
||||||
load_recv,
|
load_recv,
|
||||||
last_seat_name,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,7 +185,6 @@ impl WaylandClipboard {
|
||||||
event_queue: &mut EventQueue,
|
event_queue: &mut EventQueue,
|
||||||
request_recv: mpsc::Receiver<WaylandRequest>,
|
request_recv: mpsc::Receiver<WaylandRequest>,
|
||||||
load_send: mpsc::Sender<String>,
|
load_send: mpsc::Sender<String>,
|
||||||
last_seat_name: Arc<Mutex<String>>,
|
|
||||||
) {
|
) {
|
||||||
let seat_map = Arc::new(Mutex::new(SeatMap::new()));
|
let seat_map = Arc::new(Mutex::new(SeatMap::new()));
|
||||||
|
|
||||||
|
|
@ -213,6 +193,7 @@ impl WaylandClipboard {
|
||||||
|
|
||||||
let data_device_manager_clone = data_device_manager.clone();
|
let data_device_manager_clone = data_device_manager.clone();
|
||||||
let seat_map_clone = seat_map.clone();
|
let seat_map_clone = seat_map.clone();
|
||||||
|
let last_seat_name = Arc::new(Mutex::new(String::new()));
|
||||||
let last_seat_name_clone = last_seat_name.clone();
|
let last_seat_name_clone = last_seat_name.clone();
|
||||||
GlobalManager::new_with_cb(&display, move |event, reg| {
|
GlobalManager::new_with_cb(&display, move |event, reg| {
|
||||||
if let GlobalEvent::New {
|
if let GlobalEvent::New {
|
||||||
|
|
@ -264,8 +245,13 @@ impl WaylandClipboard {
|
||||||
if let Ok(request) = request_recv.try_recv() {
|
if let Ok(request) = request_recv.try_recv() {
|
||||||
match request {
|
match request {
|
||||||
WaylandRequest::Load(seat_name) => {
|
WaylandRequest::Load(seat_name) => {
|
||||||
|
event_queue.sync_roundtrip().unwrap();
|
||||||
let seat_map = seat_map.lock().unwrap().clone();
|
let seat_map = seat_map.lock().unwrap().clone();
|
||||||
if let Some((device, _)) = seat_map.get(&seat_name) {
|
if let Some((device, _)) =
|
||||||
|
seat_map
|
||||||
|
.get(&dbg!(seat_name
|
||||||
|
.unwrap_or_else(|| last_seat_name.lock().unwrap().clone())))
|
||||||
|
{
|
||||||
// Load
|
// Load
|
||||||
let mut reader = None;
|
let mut reader = None;
|
||||||
device.lock().unwrap().with_selection(|offer| {
|
device.lock().unwrap().with_selection(|offer| {
|
||||||
|
|
@ -294,8 +280,13 @@ impl WaylandClipboard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WaylandRequest::Store(seat_name, contents) => {
|
WaylandRequest::Store(seat_name, contents) => {
|
||||||
|
event_queue.sync_roundtrip().unwrap();
|
||||||
let seat_map = seat_map.lock().unwrap().clone();
|
let seat_map = seat_map.lock().unwrap().clone();
|
||||||
if let Some((device, enter_serial)) = seat_map.get(&seat_name) {
|
if let Some((device, enter_serial)) =
|
||||||
|
seat_map
|
||||||
|
.get(&dbg!(seat_name
|
||||||
|
.unwrap_or_else(|| last_seat_name.lock().unwrap().clone())))
|
||||||
|
{
|
||||||
let data_source = DataSource::new(
|
let data_source = DataSource::new(
|
||||||
data_device_manager.lock().unwrap().as_ref().unwrap(),
|
data_device_manager.lock().unwrap().as_ref().unwrap(),
|
||||||
&["text/plain;charset=utf-8"],
|
&["text/plain;charset=utf-8"],
|
||||||
|
|
@ -328,9 +319,7 @@ impl WaylandClipboard {
|
||||||
/// is used
|
/// is used
|
||||||
pub fn load(&mut self, seat_name: Option<String>) -> String {
|
pub fn load(&mut self, seat_name: Option<String>) -> String {
|
||||||
self.request_send
|
self.request_send
|
||||||
.send(WaylandRequest::Load(seat_name.unwrap_or_else(|| {
|
.send(WaylandRequest::Load(seat_name))
|
||||||
self.last_seat_name.lock().unwrap().clone()
|
|
||||||
})))
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.load_recv.recv().unwrap()
|
self.load_recv.recv().unwrap()
|
||||||
}
|
}
|
||||||
|
|
@ -343,10 +332,7 @@ impl WaylandClipboard {
|
||||||
/// is used
|
/// is used
|
||||||
pub fn store(&mut self, seat_name: Option<String>, text: String) {
|
pub fn store(&mut self, seat_name: Option<String>, text: String) {
|
||||||
self.request_send
|
self.request_send
|
||||||
.send(WaylandRequest::Store(
|
.send(WaylandRequest::Store(seat_name, text))
|
||||||
seat_name.unwrap_or_else(|| self.last_seat_name.lock().unwrap().clone()),
|
|
||||||
text,
|
|
||||||
))
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue