Take an option of a seat name or use name of latest seat event
This commit is contained in:
parent
bd004e8628
commit
61ac558555
2 changed files with 82 additions and 57 deletions
|
|
@ -6,7 +6,7 @@ use sctk::utils::{DoubleMemPool, MemPool};
|
||||||
use sctk::window::{ConceptFrame, Event as WEvent, Window};
|
use sctk::window::{ConceptFrame, Event as WEvent, Window};
|
||||||
use sctk::Environment;
|
use sctk::Environment;
|
||||||
|
|
||||||
use sctk::reexports::client::protocol::{wl_seat, wl_shm, wl_surface};
|
use sctk::reexports::client::protocol::{wl_shm, wl_surface};
|
||||||
use sctk::reexports::client::{Display, NewProxy};
|
use sctk::reexports::client::{Display, NewProxy};
|
||||||
|
|
||||||
use andrew::shapes::rectangle;
|
use andrew::shapes::rectangle;
|
||||||
|
|
@ -21,20 +21,9 @@ fn main() {
|
||||||
let mut clipboard = smithay_clipboard::WaylandClipboard::new_threaded(&display);
|
let mut clipboard = smithay_clipboard::WaylandClipboard::new_threaded(&display);
|
||||||
let cb_contents = Arc::new(Mutex::new(String::new()));
|
let cb_contents = Arc::new(Mutex::new(String::new()));
|
||||||
|
|
||||||
let seat_name = Arc::new(Mutex::new(String::new()));
|
|
||||||
let seat_name_clone = seat_name.clone();
|
|
||||||
let seat = env
|
let seat = env
|
||||||
.manager
|
.manager
|
||||||
.instantiate_range(2, 6, move |proxy| {
|
.instantiate_range(2, 6, NewProxy::implement_dummy)
|
||||||
proxy.implement_closure(
|
|
||||||
move |event, _| {
|
|
||||||
if let wl_seat::Event::Name { name } = event {
|
|
||||||
*seat_name_clone.lock().unwrap() = name
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let need_redraw = Arc::new(atomic::AtomicBool::new(false));
|
let need_redraw = Arc::new(atomic::AtomicBool::new(false));
|
||||||
|
|
@ -48,12 +37,11 @@ fn main() {
|
||||||
} = event
|
} = event
|
||||||
{
|
{
|
||||||
if text == " " {
|
if text == " " {
|
||||||
*cb_contents_clone.lock().unwrap() =
|
*cb_contents_clone.lock().unwrap() = dbg!(clipboard.load(None));
|
||||||
dbg!(clipboard.load(seat_name.lock().unwrap().clone()));
|
|
||||||
need_redraw_clone.store(true, atomic::Ordering::Relaxed)
|
need_redraw_clone.store(true, atomic::Ordering::Relaxed)
|
||||||
} else if text == "s" {
|
} else if text == "s" {
|
||||||
clipboard.store(
|
clipboard.store(
|
||||||
seat_name.lock().unwrap().clone(),
|
None,
|
||||||
"This is an example text thats been copied to the wayland clipboard :)"
|
"This is an example text thats been copied to the wayland clipboard :)"
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
119
src/lib.rs
119
src/lib.rs
|
|
@ -42,6 +42,7 @@ 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 {
|
||||||
|
|
@ -59,19 +60,28 @@ 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(&display, &mut event_queue, request_recv, load_send);
|
Self::clipboard_thread(
|
||||||
|
&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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,14 +93,24 @@ 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(&display, &mut event_queue, request_recv, load_send);
|
Self::clipboard_thread(
|
||||||
|
&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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,6 +118,7 @@ impl WaylandClipboard {
|
||||||
id: u32,
|
id: u32,
|
||||||
version: u32,
|
version: u32,
|
||||||
seat_map: Arc<Mutex<SeatMap>>,
|
seat_map: Arc<Mutex<SeatMap>>,
|
||||||
|
last_seat_name: Arc<Mutex<String>>,
|
||||||
data_device_manager: &wl_data_device_manager::WlDataDeviceManager,
|
data_device_manager: &wl_data_device_manager::WlDataDeviceManager,
|
||||||
reg: &wl_registry::WlRegistry,
|
reg: &wl_registry::WlRegistry,
|
||||||
) {
|
) {
|
||||||
|
|
@ -123,47 +144,54 @@ impl WaylandClipboard {
|
||||||
let seat_map_clone = seat_map.clone();
|
let seat_map_clone = seat_map.clone();
|
||||||
let device_clone = device.clone();
|
let device_clone = device.clone();
|
||||||
let seat_name_clone = seat_name.clone();
|
let seat_name_clone = seat_name.clone();
|
||||||
map_keyboard_auto(&seat, move |event, _| match event {
|
let last_seat_name_clone = last_seat_name.clone();
|
||||||
KbEvent::Enter { serial, .. } => {
|
map_keyboard_auto(&seat, move |event, _| {
|
||||||
seat_map_clone.lock().unwrap().insert(
|
*last_seat_name_clone.lock().unwrap() = seat_name_clone.lock().unwrap().clone();
|
||||||
seat_name_clone.lock().unwrap().clone(),
|
match event {
|
||||||
(device_clone.clone(), serial),
|
KbEvent::Enter { serial, .. } => {
|
||||||
);
|
seat_map_clone.lock().unwrap().insert(
|
||||||
|
seat_name_clone.lock().unwrap().clone(),
|
||||||
|
(device_clone.clone(), serial),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
KbEvent::Key { serial, .. } => {
|
||||||
|
seat_map_clone.lock().unwrap().insert(
|
||||||
|
seat_name_clone.lock().unwrap().clone(),
|
||||||
|
(device_clone.clone(), serial),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
KbEvent::Leave { .. } => {
|
||||||
|
seat_map_clone
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.remove(&*seat_name_clone.lock().unwrap());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
KbEvent::Key { serial, .. } => {
|
|
||||||
seat_map_clone.lock().unwrap().insert(
|
|
||||||
seat_name_clone.lock().unwrap().clone(),
|
|
||||||
(device_clone.clone(), serial),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
KbEvent::Leave { .. } => {
|
|
||||||
seat_map_clone
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.remove(&*seat_name_clone.lock().unwrap());
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
seat.get_pointer(|pointer| {
|
seat.get_pointer(|pointer| {
|
||||||
pointer.implement_closure(
|
pointer.implement_closure(
|
||||||
move |evt, _| match evt {
|
move |evt, _| {
|
||||||
PtrEvent::Enter { serial, .. } => {
|
*last_seat_name.lock().unwrap() = seat_name.lock().unwrap().clone();
|
||||||
seat_map
|
match evt {
|
||||||
.lock()
|
PtrEvent::Enter { serial, .. } => {
|
||||||
.unwrap()
|
seat_map.lock().unwrap().insert(
|
||||||
.insert(seat_name.lock().unwrap().clone(), (device.clone(), serial));
|
seat_name.lock().unwrap().clone(),
|
||||||
|
(device.clone(), serial),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
PtrEvent::Button { serial, .. } => {
|
||||||
|
seat_map.lock().unwrap().insert(
|
||||||
|
seat_name.lock().unwrap().clone(),
|
||||||
|
(device.clone(), serial),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
PtrEvent::Leave { .. } => {
|
||||||
|
seat_map.lock().unwrap().remove(&*seat_name.lock().unwrap());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
PtrEvent::Button { serial, .. } => {
|
|
||||||
seat_map
|
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.insert(seat_name.lock().unwrap().clone(), (device.clone(), serial));
|
|
||||||
}
|
|
||||||
PtrEvent::Leave { .. } => {
|
|
||||||
seat_map.lock().unwrap().remove(&*seat_name.lock().unwrap());
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
},
|
},
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
|
|
@ -176,6 +204,7 @@ 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()));
|
||||||
|
|
||||||
|
|
@ -184,6 +213,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_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 {
|
||||||
id,
|
id,
|
||||||
|
|
@ -199,6 +229,7 @@ impl WaylandClipboard {
|
||||||
id,
|
id,
|
||||||
version,
|
version,
|
||||||
seat_map_clone.clone(),
|
seat_map_clone.clone(),
|
||||||
|
last_seat_name_clone.clone(),
|
||||||
data_device_manager,
|
data_device_manager,
|
||||||
®,
|
®,
|
||||||
);
|
);
|
||||||
|
|
@ -219,6 +250,7 @@ impl WaylandClipboard {
|
||||||
*id,
|
*id,
|
||||||
*version,
|
*version,
|
||||||
seat_map_clone.clone(),
|
seat_map_clone.clone(),
|
||||||
|
last_seat_name_clone.clone(),
|
||||||
data_device_manager_clone.lock().unwrap().as_ref().unwrap(),
|
data_device_manager_clone.lock().unwrap().as_ref().unwrap(),
|
||||||
®,
|
®,
|
||||||
);
|
);
|
||||||
|
|
@ -292,9 +324,11 @@ impl WaylandClipboard {
|
||||||
///
|
///
|
||||||
/// Must be provided with a seat name and that seat must be in
|
/// Must be provided with a seat name and that seat must be in
|
||||||
/// focus to work
|
/// focus to work
|
||||||
pub fn load<S: Into<String>>(&mut self, seat_name: S) -> String {
|
pub fn load(&mut self, seat_name: Option<String>) -> String {
|
||||||
self.request_send
|
self.request_send
|
||||||
.send(WaylandRequest::Load(seat_name.into()))
|
.send(WaylandRequest::Load(seat_name.unwrap_or_else(|| {
|
||||||
|
self.last_seat_name.lock().unwrap().clone()
|
||||||
|
})))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.load_recv.recv().unwrap()
|
self.load_recv.recv().unwrap()
|
||||||
}
|
}
|
||||||
|
|
@ -303,9 +337,12 @@ impl WaylandClipboard {
|
||||||
///
|
///
|
||||||
/// Must be provided with a seat name and that seat must be in
|
/// Must be provided with a seat name and that seat must be in
|
||||||
/// focus to work
|
/// focus to work
|
||||||
pub fn store<S: Into<String>>(&mut self, seat_name: S, text: S) {
|
pub fn store(&mut self, seat_name: Option<String>, text: String) {
|
||||||
self.request_send
|
self.request_send
|
||||||
.send(WaylandRequest::Store(seat_name.into(), text.into()))
|
.send(WaylandRequest::Store(
|
||||||
|
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