Use Niri::insert_client() in tests

This commit is contained in:
Ivan Molodetskikh
2025-01-27 08:15:51 +03:00
parent ec43493522
commit 902222675a
2 changed files with 14 additions and 16 deletions
+4 -14
View File
@@ -1,13 +1,11 @@
use std::cmp::min;
use std::collections::HashMap;
use std::ffi::OsStr;
use std::fmt;
use std::fmt::Write as _;
use std::os::unix::net::UnixStream;
use std::path::PathBuf;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use std::{env, fmt};
use calloop::EventLoop;
use calloop_wayland_source::WaylandSource;
@@ -105,21 +103,13 @@ impl fmt::Display for Configure {
}
}
fn connect(socket_name: &OsStr) -> Connection {
let mut socket_path = PathBuf::from(env::var_os("XDG_RUNTIME_DIR").unwrap());
socket_path.push(socket_name);
let stream = UnixStream::connect(socket_path).unwrap();
let backend = Backend::connect(stream).unwrap();
Connection::from_backend(backend)
}
impl Client {
pub fn new(socket_name: &OsStr) -> Self {
pub fn new(stream: UnixStream) -> Self {
let id = ClientId::next();
let event_loop = EventLoop::try_new().unwrap();
let connection = connect(socket_name);
let backend = Backend::connect(stream).unwrap();
let connection = Connection::from_backend(backend);
let queue = connection.new_event_queue();
let qh = queue.handle();
WaylandSource::new(connection.clone(), queue)
+10 -2
View File
@@ -1,4 +1,5 @@
use std::os::fd::AsFd as _;
use std::os::unix::net::UnixStream;
use std::sync::atomic::Ordering;
use std::time::Duration;
@@ -9,7 +10,7 @@ use smithay::output::Output;
use super::client::{Client, ClientId};
use super::server::Server;
use crate::niri::Niri;
use crate::niri::{NewClient, Niri};
pub struct Fixture {
pub event_loop: EventLoop<'static, State>,
@@ -88,7 +89,14 @@ impl Fixture {
}
pub fn add_client(&mut self) -> ClientId {
let client = Client::new(&self.state.server.state.niri.socket_name);
let (sock1, sock2) = UnixStream::pair().unwrap();
self.niri().insert_client(NewClient {
client: sock1,
restricted: false,
credentials_unknown: false,
});
let client = Client::new(sock2);
let id = client.id;
let fd = client.event_loop.as_fd().try_clone_to_owned().unwrap();