fix(wayland): 1 seat per client

This commit is contained in:
Nova
2022-09-18 19:26:59 -04:00
parent 66aa72e18c
commit 76721a17f8
4 changed files with 32 additions and 29 deletions

View File

@@ -9,14 +9,14 @@ pub mod xdg_decoration;
pub mod xdg_shell;
use self::{panel_item::PanelItem, state::WaylandState, surface::CORE_SURFACES};
use crate::wayland::state::ClientState;
use crate::wayland::{seat::SeatData, state::ClientState};
use anyhow::{ensure, Result};
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use slog::Logger;
use smithay::{
backend::{egl::EGLContext, renderer::gles2::Gles2Renderer},
reexports::wayland_server::{backend::GlobalId, Display, ListeningSocket},
reexports::wayland_server::{backend::GlobalId, Display, ListeningSocket, Resource},
};
use std::os::unix::prelude::AsRawFd;
use std::{
@@ -62,7 +62,7 @@ pub struct Wayland {
display: Arc<Mutex<Display<WaylandState>>>,
join_handle: JoinHandle<Result<()>>,
renderer: Gles2Renderer,
// state: Arc<Mutex<WaylandState>>,
state: Arc<Mutex<WaylandState>>,
}
impl Wayland {
pub fn new(log: Logger) -> Result<Self> {
@@ -92,14 +92,15 @@ impl Wayland {
let (global_destroy_queue_in, global_destroy_queue) = mpsc::channel(8);
GLOBAL_DESTROY_QUEUE.set(global_destroy_queue_in).unwrap();
let join_handle = Wayland::start_loop(display.clone(), state, global_destroy_queue)?;
let join_handle =
Wayland::start_loop(display.clone(), state.clone(), global_destroy_queue)?;
Ok(Wayland {
log,
display,
join_handle,
renderer,
// state,
state,
})
}
@@ -131,7 +132,9 @@ impl Wayland {
}
acc = listen_async.accept() => { // New client connected
let (stream, _) = acc?;
dh2.insert_client(stream.into_std()?, Arc::new(ClientState))?;
let client = dh2.insert_client(stream.into_std()?, Arc::new(ClientState))?;
state.lock().new_client(client.id(), &dh2);
}
e = dispatch_poll_listener.readable() => { // Dispatch
let mut guard = e?;
@@ -149,13 +152,15 @@ impl Wayland {
let time_ms = (sk.time_getf() * 1000.) as u32;
for core_surface in CORE_SURFACES.get_valid_contents() {
let client_id = core_surface.wl_surface().client_id().unwrap();
let seat_data = self.state.lock().seats.get(&client_id).unwrap().clone();
core_surface.process(
sk,
&mut self.renderer,
time_ms,
&self.log,
|data| {
PanelItem::on_mapped(&core_surface, data);
PanelItem::on_mapped(&core_surface, data, seat_data);
},
|data| {
PanelItem::if_mapped(&core_surface, data);

View File

@@ -18,10 +18,7 @@ use glam::Mat4;
use lazy_static::lazy_static;
use nanoid::nanoid;
use smithay::{
reexports::wayland_server::{
protocol::wl_pointer::{Axis, ButtonState},
Resource,
},
reexports::wayland_server::protocol::wl_pointer::{Axis, ButtonState},
wayland::{compositor::SurfaceData, shell::xdg::XdgToplevelSurfaceData},
};
use stardust_xr::{
@@ -62,7 +59,7 @@ pub struct PanelItem {
seat_data: SeatData,
}
impl PanelItem {
pub fn create(core_surface: &Arc<CoreSurface>) -> Arc<Node> {
pub fn create(core_surface: &Arc<CoreSurface>, seat_data: SeatData) -> Arc<Node> {
let node = Arc::new(Node::create(
&INTERNAL_CLIENT,
"/item/panel/item",
@@ -71,11 +68,6 @@ impl PanelItem {
));
Spatial::add_to(&node, None, Mat4::IDENTITY).unwrap();
let seat_data = SeatData::new(
&core_surface.dh,
core_surface.wl_surface().client_id().unwrap(),
);
let specialization = ItemType::Panel(PanelItem {
node: Arc::downgrade(&node),
core_surface: Arc::downgrade(core_surface),
@@ -167,7 +159,11 @@ impl PanelItem {
Ok(())
}
pub fn on_mapped(core_surface: &Arc<CoreSurface>, surface_data: &SurfaceData) {
pub fn on_mapped(
core_surface: &Arc<CoreSurface>,
surface_data: &SurfaceData,
seat_data: SeatData,
) {
if surface_data
.data_map
.get::<XdgToplevelSurfaceData>()
@@ -175,7 +171,7 @@ impl PanelItem {
{
surface_data
.data_map
.insert_if_missing_threadsafe(|| PanelItem::create(core_surface));
.insert_if_missing_threadsafe(|| PanelItem::create(core_surface, seat_data));
}
}

View File

@@ -1,6 +1,6 @@
use std::sync::Arc;
use crate::wayland::seat::SeatData;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
use slog::Logger;
use smithay::{
delegate_output, delegate_shm,
@@ -19,13 +19,12 @@ use smithay::{
shm::{ShmHandler, ShmState},
},
};
use super::seat::SeatDelegate;
use std::sync::Arc;
pub struct ClientState;
impl ClientData for ClientState {
fn initialized(&self, client_id: ClientId) {
println!("Wayland client {:?} connected", client_id);
println!("Wayland client {:?} connected", client_id.clone());
}
fn disconnected(&self, client_id: ClientId, reason: DisconnectReason) {
@@ -46,7 +45,7 @@ pub struct WaylandState {
pub shm_state: ShmState,
pub output_manager_state: OutputManagerState,
pub output: Output,
pub seat_state: SeatDelegate,
pub seats: FxHashMap<ClientId, SeatData>,
}
impl WaylandState {
@@ -86,9 +85,14 @@ impl WaylandState {
shm_state,
output_manager_state,
output,
seat_state: SeatDelegate,
seats: FxHashMap::default(),
}
}
pub fn new_client(&mut self, client: ClientId, dh: &DisplayHandle) {
let seat_data = SeatData::new(dh, client.clone());
self.seats.insert(client, seat_data);
}
}
impl Drop for WaylandState {
fn drop(&mut self) {

View File

@@ -32,8 +32,6 @@ impl XdgShellHandler for WaylandState {
fn new_popup(&mut self, _surface: PopupSurface, _positioner: PositionerState) {}
fn grab(&mut self, _surface: PopupSurface, _seat: WlSeat, _serial: Serial) {
todo!()
}
fn grab(&mut self, _surface: PopupSurface, _seat: WlSeat, _serial: Serial) {}
}
delegate_xdg_shell!(WaylandState);