mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Extract Niri::insert_client()
This commit is contained in:
+10
-1
@@ -45,7 +45,16 @@ impl DBusServers {
|
||||
let mut dbus = Self::default();
|
||||
|
||||
if is_session_instance {
|
||||
let service_channel = ServiceChannel::new(niri.display_handle.clone());
|
||||
let (to_niri, from_service_channel) = calloop::channel::channel();
|
||||
let service_channel = ServiceChannel::new(to_niri);
|
||||
niri.event_loop
|
||||
.insert_source(from_service_channel, move |event, _, state| match event {
|
||||
calloop::channel::Event::Msg(new_client) => {
|
||||
state.niri.insert_client(new_client);
|
||||
}
|
||||
calloop::channel::Event::Closed => (),
|
||||
})
|
||||
.unwrap();
|
||||
dbus.conn_service_channel = try_start(service_channel);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::sync::Arc;
|
||||
|
||||
use smithay::reexports::wayland_server::DisplayHandle;
|
||||
use zbus::{fdo, interface, zvariant};
|
||||
|
||||
use super::Start;
|
||||
use crate::niri::ClientState;
|
||||
use crate::niri::NewClient;
|
||||
|
||||
pub struct ServiceChannel {
|
||||
display: DisplayHandle,
|
||||
to_niri: calloop::channel::Sender<NewClient>,
|
||||
}
|
||||
|
||||
#[interface(name = "org.gnome.Mutter.ServiceChannel")]
|
||||
@@ -24,23 +22,24 @@ impl ServiceChannel {
|
||||
}
|
||||
|
||||
let (sock1, sock2) = UnixStream::pair().unwrap();
|
||||
let data = Arc::new(ClientState {
|
||||
compositor_state: Default::default(),
|
||||
// Would be nice to thread config here but for now it's fine.
|
||||
can_view_decoration_globals: false,
|
||||
primary_selection_disabled: false,
|
||||
let client = NewClient {
|
||||
client: sock2,
|
||||
restricted: false,
|
||||
// FIXME: maybe you can get the PID from D-Bus somehow?
|
||||
credentials_unknown: true,
|
||||
});
|
||||
self.display.insert_client(sock2, data).unwrap();
|
||||
};
|
||||
if let Err(err) = self.to_niri.send(client) {
|
||||
warn!("error sending message to niri: {err:?}");
|
||||
return Err(fdo::Error::Failed("internal error".to_owned()));
|
||||
}
|
||||
|
||||
Ok(zvariant::OwnedFd::from(std::os::fd::OwnedFd::from(sock1)))
|
||||
}
|
||||
}
|
||||
|
||||
impl ServiceChannel {
|
||||
pub fn new(display: DisplayHandle) -> Self {
|
||||
Self { display }
|
||||
pub fn new(to_niri: calloop::channel::Sender<NewClient>) -> Self {
|
||||
Self { to_niri }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-12
@@ -71,7 +71,7 @@ use smithay::{
|
||||
};
|
||||
|
||||
pub use crate::handlers::xdg_shell::KdeDecorationsModeState;
|
||||
use crate::niri::{ClientState, DndIcon, State};
|
||||
use crate::niri::{DndIcon, NewClient, State};
|
||||
use crate::protocols::foreign_toplevel::{
|
||||
self, ForeignToplevelHandler, ForeignToplevelManagerState,
|
||||
};
|
||||
@@ -471,20 +471,12 @@ impl SecurityContextHandler for State {
|
||||
self.niri
|
||||
.event_loop
|
||||
.insert_source(source, move |client, _, state| {
|
||||
let config = state.niri.config.borrow();
|
||||
let data = Arc::new(ClientState {
|
||||
compositor_state: Default::default(),
|
||||
can_view_decoration_globals: config.prefer_no_csd,
|
||||
primary_selection_disabled: config.clipboard.disable_primary,
|
||||
trace!("inserting a new restricted client, context={context:?}");
|
||||
state.niri.insert_client(NewClient {
|
||||
client,
|
||||
restricted: true,
|
||||
credentials_unknown: false,
|
||||
});
|
||||
|
||||
if let Err(err) = state.niri.display_handle.insert_client(client, data) {
|
||||
warn!("error inserting client: {err}");
|
||||
} else {
|
||||
trace!("inserted a new restricted client, context={context:?}");
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
+30
-9
@@ -1,6 +1,7 @@
|
||||
use std::cell::{Cell, OnceCell, RefCell};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::ffi::OsString;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
@@ -1932,18 +1933,11 @@ impl Niri {
|
||||
let socket_name = socket_source.socket_name().to_os_string();
|
||||
event_loop
|
||||
.insert_source(socket_source, move |client, _, state| {
|
||||
let config = state.niri.config.borrow();
|
||||
let data = Arc::new(ClientState {
|
||||
compositor_state: Default::default(),
|
||||
can_view_decoration_globals: config.prefer_no_csd,
|
||||
primary_selection_disabled: config.clipboard.disable_primary,
|
||||
state.niri.insert_client(NewClient {
|
||||
client,
|
||||
restricted: false,
|
||||
credentials_unknown: false,
|
||||
});
|
||||
|
||||
if let Err(err) = state.niri.display_handle.insert_client(client, data) {
|
||||
warn!("error inserting client: {err}");
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
@@ -2125,6 +2119,27 @@ impl Niri {
|
||||
niri
|
||||
}
|
||||
|
||||
pub fn insert_client(&mut self, client: NewClient) {
|
||||
let NewClient {
|
||||
client,
|
||||
restricted,
|
||||
credentials_unknown,
|
||||
} = client;
|
||||
|
||||
let config = self.config.borrow();
|
||||
let data = Arc::new(ClientState {
|
||||
compositor_state: Default::default(),
|
||||
can_view_decoration_globals: config.prefer_no_csd,
|
||||
primary_selection_disabled: config.clipboard.disable_primary,
|
||||
restricted,
|
||||
credentials_unknown,
|
||||
});
|
||||
|
||||
if let Err(err) = self.display_handle.insert_client(client, data) {
|
||||
warn!("error inserting client: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "dbus")]
|
||||
pub fn inhibit_power_key(&mut self) -> anyhow::Result<()> {
|
||||
use std::os::fd::{AsRawFd, BorrowedFd};
|
||||
@@ -5171,6 +5186,12 @@ impl Niri {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NewClient {
|
||||
pub client: UnixStream,
|
||||
pub restricted: bool,
|
||||
pub credentials_unknown: bool,
|
||||
}
|
||||
|
||||
pub struct ClientState {
|
||||
pub compositor_state: CompositorClientState,
|
||||
pub can_view_decoration_globals: bool,
|
||||
|
||||
Reference in New Issue
Block a user