fix(wayland): 1 seat per client
This commit is contained in:
@@ -9,14 +9,14 @@ pub mod xdg_decoration;
|
|||||||
pub mod xdg_shell;
|
pub mod xdg_shell;
|
||||||
|
|
||||||
use self::{panel_item::PanelItem, state::WaylandState, surface::CORE_SURFACES};
|
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 anyhow::{ensure, Result};
|
||||||
use once_cell::sync::OnceCell;
|
use once_cell::sync::OnceCell;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::{egl::EGLContext, renderer::gles2::Gles2Renderer},
|
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::os::unix::prelude::AsRawFd;
|
||||||
use std::{
|
use std::{
|
||||||
@@ -62,7 +62,7 @@ pub struct Wayland {
|
|||||||
display: Arc<Mutex<Display<WaylandState>>>,
|
display: Arc<Mutex<Display<WaylandState>>>,
|
||||||
join_handle: JoinHandle<Result<()>>,
|
join_handle: JoinHandle<Result<()>>,
|
||||||
renderer: Gles2Renderer,
|
renderer: Gles2Renderer,
|
||||||
// state: Arc<Mutex<WaylandState>>,
|
state: Arc<Mutex<WaylandState>>,
|
||||||
}
|
}
|
||||||
impl Wayland {
|
impl Wayland {
|
||||||
pub fn new(log: Logger) -> Result<Self> {
|
pub fn new(log: Logger) -> Result<Self> {
|
||||||
@@ -92,14 +92,15 @@ impl Wayland {
|
|||||||
let (global_destroy_queue_in, global_destroy_queue) = mpsc::channel(8);
|
let (global_destroy_queue_in, global_destroy_queue) = mpsc::channel(8);
|
||||||
GLOBAL_DESTROY_QUEUE.set(global_destroy_queue_in).unwrap();
|
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 {
|
Ok(Wayland {
|
||||||
log,
|
log,
|
||||||
display,
|
display,
|
||||||
join_handle,
|
join_handle,
|
||||||
renderer,
|
renderer,
|
||||||
// state,
|
state,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +132,9 @@ impl Wayland {
|
|||||||
}
|
}
|
||||||
acc = listen_async.accept() => { // New client connected
|
acc = listen_async.accept() => { // New client connected
|
||||||
let (stream, _) = acc?;
|
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
|
e = dispatch_poll_listener.readable() => { // Dispatch
|
||||||
let mut guard = e?;
|
let mut guard = e?;
|
||||||
@@ -149,13 +152,15 @@ impl Wayland {
|
|||||||
let time_ms = (sk.time_getf() * 1000.) as u32;
|
let time_ms = (sk.time_getf() * 1000.) as u32;
|
||||||
|
|
||||||
for core_surface in CORE_SURFACES.get_valid_contents() {
|
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(
|
core_surface.process(
|
||||||
sk,
|
sk,
|
||||||
&mut self.renderer,
|
&mut self.renderer,
|
||||||
time_ms,
|
time_ms,
|
||||||
&self.log,
|
&self.log,
|
||||||
|data| {
|
|data| {
|
||||||
PanelItem::on_mapped(&core_surface, data);
|
PanelItem::on_mapped(&core_surface, data, seat_data);
|
||||||
},
|
},
|
||||||
|data| {
|
|data| {
|
||||||
PanelItem::if_mapped(&core_surface, data);
|
PanelItem::if_mapped(&core_surface, data);
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ use glam::Mat4;
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use smithay::{
|
use smithay::{
|
||||||
reexports::wayland_server::{
|
reexports::wayland_server::protocol::wl_pointer::{Axis, ButtonState},
|
||||||
protocol::wl_pointer::{Axis, ButtonState},
|
|
||||||
Resource,
|
|
||||||
},
|
|
||||||
wayland::{compositor::SurfaceData, shell::xdg::XdgToplevelSurfaceData},
|
wayland::{compositor::SurfaceData, shell::xdg::XdgToplevelSurfaceData},
|
||||||
};
|
};
|
||||||
use stardust_xr::{
|
use stardust_xr::{
|
||||||
@@ -62,7 +59,7 @@ pub struct PanelItem {
|
|||||||
seat_data: SeatData,
|
seat_data: SeatData,
|
||||||
}
|
}
|
||||||
impl PanelItem {
|
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(
|
let node = Arc::new(Node::create(
|
||||||
&INTERNAL_CLIENT,
|
&INTERNAL_CLIENT,
|
||||||
"/item/panel/item",
|
"/item/panel/item",
|
||||||
@@ -71,11 +68,6 @@ impl PanelItem {
|
|||||||
));
|
));
|
||||||
Spatial::add_to(&node, None, Mat4::IDENTITY).unwrap();
|
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 {
|
let specialization = ItemType::Panel(PanelItem {
|
||||||
node: Arc::downgrade(&node),
|
node: Arc::downgrade(&node),
|
||||||
core_surface: Arc::downgrade(core_surface),
|
core_surface: Arc::downgrade(core_surface),
|
||||||
@@ -167,7 +159,11 @@ impl PanelItem {
|
|||||||
Ok(())
|
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
|
if surface_data
|
||||||
.data_map
|
.data_map
|
||||||
.get::<XdgToplevelSurfaceData>()
|
.get::<XdgToplevelSurfaceData>()
|
||||||
@@ -175,7 +171,7 @@ impl PanelItem {
|
|||||||
{
|
{
|
||||||
surface_data
|
surface_data
|
||||||
.data_map
|
.data_map
|
||||||
.insert_if_missing_threadsafe(|| PanelItem::create(core_surface));
|
.insert_if_missing_threadsafe(|| PanelItem::create(core_surface, seat_data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use crate::wayland::seat::SeatData;
|
||||||
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
use smithay::{
|
use smithay::{
|
||||||
delegate_output, delegate_shm,
|
delegate_output, delegate_shm,
|
||||||
@@ -19,13 +19,12 @@ use smithay::{
|
|||||||
shm::{ShmHandler, ShmState},
|
shm::{ShmHandler, ShmState},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
use super::seat::SeatDelegate;
|
|
||||||
|
|
||||||
pub struct ClientState;
|
pub struct ClientState;
|
||||||
impl ClientData for ClientState {
|
impl ClientData for ClientState {
|
||||||
fn initialized(&self, client_id: ClientId) {
|
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) {
|
fn disconnected(&self, client_id: ClientId, reason: DisconnectReason) {
|
||||||
@@ -46,7 +45,7 @@ pub struct WaylandState {
|
|||||||
pub shm_state: ShmState,
|
pub shm_state: ShmState,
|
||||||
pub output_manager_state: OutputManagerState,
|
pub output_manager_state: OutputManagerState,
|
||||||
pub output: Output,
|
pub output: Output,
|
||||||
pub seat_state: SeatDelegate,
|
pub seats: FxHashMap<ClientId, SeatData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WaylandState {
|
impl WaylandState {
|
||||||
@@ -86,9 +85,14 @@ impl WaylandState {
|
|||||||
shm_state,
|
shm_state,
|
||||||
output_manager_state,
|
output_manager_state,
|
||||||
output,
|
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 {
|
impl Drop for WaylandState {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ impl XdgShellHandler for WaylandState {
|
|||||||
|
|
||||||
fn new_popup(&mut self, _surface: PopupSurface, _positioner: PositionerState) {}
|
fn new_popup(&mut self, _surface: PopupSurface, _positioner: PositionerState) {}
|
||||||
|
|
||||||
fn grab(&mut self, _surface: PopupSurface, _seat: WlSeat, _serial: Serial) {
|
fn grab(&mut self, _surface: PopupSurface, _seat: WlSeat, _serial: Serial) {}
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
delegate_xdg_shell!(WaylandState);
|
delegate_xdg_shell!(WaylandState);
|
||||||
|
|||||||
Reference in New Issue
Block a user