Add basic server operation
This commit is contained in:
@@ -81,6 +81,7 @@ pub struct Config {
|
|||||||
pub widget: Widget,
|
pub widget: Widget,
|
||||||
pub mode: OperationMode,
|
pub mode: OperationMode,
|
||||||
pub background: Option<u32>,
|
pub background: Option<u32>,
|
||||||
|
pub server: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@@ -161,6 +162,7 @@ impl Config {
|
|||||||
widget: widget,
|
widget: widget,
|
||||||
mode: OperationMode::LayerSurface((1024, 768)),
|
mode: OperationMode::LayerSurface((1024, 768)),
|
||||||
background: Some(0xFAFAFAFA),
|
background: Some(0xFAFAFAFA),
|
||||||
|
server: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,6 +255,7 @@ impl Config {
|
|||||||
OperationMode::LayerSurface((1024, 1))
|
OperationMode::LayerSurface((1024, 1))
|
||||||
},
|
},
|
||||||
background: Some(0xFAFAFAFA),
|
background: Some(0xFAFAFAFA),
|
||||||
|
server: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+53
-8
@@ -9,8 +9,6 @@ mod state;
|
|||||||
mod utils;
|
mod utils;
|
||||||
mod widgets;
|
mod widgets;
|
||||||
|
|
||||||
use std::fs::File;
|
|
||||||
|
|
||||||
use wayland_client::{Connection, QueueHandle, WaylandSource};
|
use wayland_client::{Connection, QueueHandle, WaylandSource};
|
||||||
|
|
||||||
use calloop::{
|
use calloop::{
|
||||||
@@ -25,10 +23,20 @@ use event::{Event, Events};
|
|||||||
use fonts::{FontMap, MaybeFontMap};
|
use fonts::{FontMap, MaybeFontMap};
|
||||||
use keyboard::{KeyRepeatSource, RepeatMessage};
|
use keyboard::{KeyRepeatSource, RepeatMessage};
|
||||||
use state::State;
|
use state::State;
|
||||||
|
use utils::{
|
||||||
|
desktop::{load_desktop_files, write_desktop_cache},
|
||||||
|
xdg,
|
||||||
|
};
|
||||||
use widgets::{Geometry, Widget};
|
use widgets::{Geometry, Widget};
|
||||||
use utils::{xdg, desktop::{load_desktop_files, write_desktop_cache}};
|
|
||||||
|
|
||||||
use std::{env, rc::Rc, thread};
|
use std::{
|
||||||
|
env,
|
||||||
|
fs::File,
|
||||||
|
io::{BufRead, BufReader, Write},
|
||||||
|
os::unix::net::{UnixListener, UnixStream},
|
||||||
|
rc::Rc,
|
||||||
|
thread,
|
||||||
|
};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut args = env::args();
|
let mut args = env::args();
|
||||||
@@ -39,12 +47,10 @@ fn main() {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
match args.next() {
|
match args.next() {
|
||||||
Some(ref s) if s == "--config" => {
|
Some(ref s) if s == "--config" => match args.next() {
|
||||||
match args.next() {
|
|
||||||
Some(ref s) => config_file = s.clone(),
|
Some(ref s) => config_file = s.clone(),
|
||||||
None => panic!("missing argument to --config"),
|
None => panic!("missing argument to --config"),
|
||||||
}
|
},
|
||||||
}
|
|
||||||
Some(ref s) if s == "generate" => {
|
Some(ref s) if s == "generate" => {
|
||||||
let config = match args.next() {
|
let config = match args.next() {
|
||||||
Some(ref s) if s == "v1" => Config::generate_v1(),
|
Some(ref s) if s == "v1" => Config::generate_v1(),
|
||||||
@@ -135,6 +141,11 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.expect("Failed to insert keyrepeat source!");
|
.expect("Failed to insert keyrepeat source!");
|
||||||
|
|
||||||
|
let socket_path = match env::var("XDG_RUNTIME_DIR") {
|
||||||
|
Ok(dir) => dir + "/wldash",
|
||||||
|
Err(_) => "/tmp/wldash".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
let events = Events::new(ping_sender);
|
let events = Events::new(ping_sender);
|
||||||
|
|
||||||
let mut fm = FontMap::new();
|
let mut fm = FontMap::new();
|
||||||
@@ -144,6 +155,40 @@ fn main() {
|
|||||||
Err(_) => panic!("configuration file missing"),
|
Err(_) => panic!("configuration file missing"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if config.server {
|
||||||
|
if let Ok(mut socket) = UnixStream::connect(socket_path.clone()) {
|
||||||
|
socket.write_all(b"kill\n").unwrap();
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let _ = std::fs::remove_file(socket_path.clone());
|
||||||
|
let _ = thread::Builder::new()
|
||||||
|
.name("ipc_server".to_string())
|
||||||
|
.spawn(move || {
|
||||||
|
let listener = UnixListener::bind(socket_path.clone()).unwrap();
|
||||||
|
loop {
|
||||||
|
match listener.accept() {
|
||||||
|
Ok((stream, _)) => {
|
||||||
|
let _ = thread::Builder::new().name("ipc_client".to_string()).spawn(
|
||||||
|
move || {
|
||||||
|
let r = BufReader::new(stream);
|
||||||
|
for line in r.lines() {
|
||||||
|
match line {
|
||||||
|
Ok(ref cmd) if cmd == "kill" => {
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(font_paths) = config.font_paths {
|
if let Some(font_paths) = config.font_paths {
|
||||||
for (key, value) in font_paths.into_iter() {
|
for (key, value) in font_paths.into_iter() {
|
||||||
fm.add_font_path(Box::leak(key.into_boxed_str()), value);
|
fm.add_font_path(Box::leak(key.into_boxed_str()), value);
|
||||||
|
|||||||
Reference in New Issue
Block a user