mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Make ipc_outputs Arc Mutex
This commit is contained in:
+1
-3
@@ -1,6 +1,4 @@
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -112,7 +110,7 @@ impl Backend {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ipc_outputs(&self) -> Rc<RefCell<HashMap<String, niri_ipc::Output>>> {
|
||||
pub fn ipc_outputs(&self) -> Arc<Mutex<HashMap<String, niri_ipc::Output>>> {
|
||||
match self {
|
||||
Backend::Tty(tty) => tty.ipc_outputs(),
|
||||
Backend::Winit(winit) => winit.ipc_outputs(),
|
||||
|
||||
+5
-4
@@ -84,7 +84,7 @@ pub struct Tty {
|
||||
update_output_config_on_resume: bool,
|
||||
// Whether the debug tinting is enabled.
|
||||
debug_tint: bool,
|
||||
ipc_outputs: Rc<RefCell<HashMap<String, niri_ipc::Output>>>,
|
||||
ipc_outputs: Arc<Mutex<HashMap<String, niri_ipc::Output>>>,
|
||||
enabled_outputs: Arc<Mutex<HashMap<String, Output>>>,
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ impl Tty {
|
||||
dmabuf_global: None,
|
||||
update_output_config_on_resume: false,
|
||||
debug_tint: false,
|
||||
ipc_outputs: Rc::new(RefCell::new(HashMap::new())),
|
||||
ipc_outputs: Arc::new(Mutex::new(HashMap::new())),
|
||||
enabled_outputs: Arc::new(Mutex::new(HashMap::new())),
|
||||
})
|
||||
}
|
||||
@@ -1410,10 +1410,11 @@ impl Tty {
|
||||
}
|
||||
}
|
||||
|
||||
self.ipc_outputs.replace(ipc_outputs);
|
||||
let mut guard = self.ipc_outputs.lock().unwrap();
|
||||
*guard = ipc_outputs;
|
||||
}
|
||||
|
||||
pub fn ipc_outputs(&self) -> Rc<RefCell<HashMap<String, niri_ipc::Output>>> {
|
||||
pub fn ipc_outputs(&self) -> Arc<Mutex<HashMap<String, niri_ipc::Output>>> {
|
||||
self.ipc_outputs.clone()
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ pub struct Winit {
|
||||
output: Output,
|
||||
backend: WinitGraphicsBackend<GlesRenderer>,
|
||||
damage_tracker: OutputDamageTracker,
|
||||
ipc_outputs: Rc<RefCell<HashMap<String, niri_ipc::Output>>>,
|
||||
ipc_outputs: Arc<Mutex<HashMap<String, niri_ipc::Output>>>,
|
||||
enabled_outputs: Arc<Mutex<HashMap<String, Output>>>,
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ impl Winit {
|
||||
output.set_preferred(mode);
|
||||
|
||||
let physical_properties = output.physical_properties();
|
||||
let ipc_outputs = Rc::new(RefCell::new(HashMap::from([(
|
||||
let ipc_outputs = Arc::new(Mutex::new(HashMap::from([(
|
||||
"winit".to_owned(),
|
||||
niri_ipc::Output {
|
||||
name: output.name(),
|
||||
@@ -97,10 +97,12 @@ impl Winit {
|
||||
None,
|
||||
);
|
||||
|
||||
let mut ipc_outputs = winit.ipc_outputs.borrow_mut();
|
||||
let mode = &mut ipc_outputs.get_mut("winit").unwrap().modes[0];
|
||||
mode.width = size.w.clamp(0, u16::MAX as i32) as u16;
|
||||
mode.height = size.h.clamp(0, u16::MAX as i32) as u16;
|
||||
{
|
||||
let mut ipc_outputs = winit.ipc_outputs.lock().unwrap();
|
||||
let mode = &mut ipc_outputs.get_mut("winit").unwrap().modes[0];
|
||||
mode.width = size.w.clamp(0, u16::MAX as i32) as u16;
|
||||
mode.height = size.h.clamp(0, u16::MAX as i32) as u16;
|
||||
}
|
||||
|
||||
state.niri.output_resized(&winit.output);
|
||||
}
|
||||
@@ -228,7 +230,7 @@ impl Winit {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ipc_outputs(&self) -> Rc<RefCell<HashMap<String, niri_ipc::Output>>> {
|
||||
pub fn ipc_outputs(&self) -> Arc<Mutex<HashMap<String, niri_ipc::Output>>> {
|
||||
self.ipc_outputs.clone()
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -1,8 +1,7 @@
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::os::unix::net::{UnixListener, UnixStream};
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::{env, io, process};
|
||||
|
||||
use anyhow::Context;
|
||||
@@ -23,7 +22,7 @@ pub struct IpcServer {
|
||||
|
||||
struct ClientCtx {
|
||||
event_loop: LoopHandle<'static, State>,
|
||||
ipc_outputs: Rc<RefCell<HashMap<String, niri_ipc::Output>>>,
|
||||
ipc_outputs: Arc<Mutex<HashMap<String, niri_ipc::Output>>>,
|
||||
}
|
||||
|
||||
impl IpcServer {
|
||||
@@ -126,7 +125,7 @@ fn process(ctx: &ClientCtx, buf: &str) -> anyhow::Result<Response> {
|
||||
|
||||
let response = match request {
|
||||
Request::Outputs => {
|
||||
let ipc_outputs = ctx.ipc_outputs.borrow().clone();
|
||||
let ipc_outputs = ctx.ipc_outputs.lock().unwrap().clone();
|
||||
Response::Outputs(ipc_outputs)
|
||||
}
|
||||
Request::Action(action) => {
|
||||
|
||||
Reference in New Issue
Block a user